Skip to content
Snippets Groups Projects
Unverified Commit fa0639d2 authored by akwizgran's avatar akwizgran
Browse files

Overlay background colour as an alternative to setAlpha().

parent bbf12ca0
No related branches found
No related tags found
No related merge requests found
...@@ -27,10 +27,25 @@ import static android.view.View.VISIBLE; ...@@ -27,10 +27,25 @@ import static android.view.View.VISIBLE;
class ContactSelectorAdapter class ContactSelectorAdapter
extends BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> { extends BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> {
private final ColorFilter grayColorFilter;
ContactSelectorAdapter(Context context, ContactSelectorAdapter(Context context,
OnItemClickListener listener) { OnItemClickListener listener) {
super(context, listener); super(context, listener);
if (Build.VERSION.SDK_INT >= 11) {
grayColorFilter = null;
} else {
// Overlay the background colour at 75% opacity
int bg = ContextCompat.getColor(context, R.color.window_background);
int alpha = (int) (255 * 0.75f);
int red = Color.red(bg);
int green = Color.green(bg);
int blue = Color.blue(bg);
bg = Color.argb(alpha, red, green, blue);
grayColorFilter = new PorterDuffColorFilter(bg,
PorterDuff.Mode.SRC_OVER);
}
} }
@Override @Override
...@@ -61,6 +76,7 @@ class ContactSelectorAdapter ...@@ -61,6 +76,7 @@ class ContactSelectorAdapter
ui.shared.setVisibility(VISIBLE); ui.shared.setVisibility(VISIBLE);
grayOutItem(ui, true); grayOutItem(ui, true);
} else { } else {
ui.layout.setEnabled(true);
ui.shared.setVisibility(GONE); ui.shared.setVisibility(GONE);
grayOutItem(ui, false); grayOutItem(ui, false);
} }
...@@ -97,27 +113,15 @@ class ContactSelectorAdapter ...@@ -97,27 +113,15 @@ class ContactSelectorAdapter
return compareByName(c1, c2); return compareByName(c1, c2);
} }
private void grayOutItem(final SelectableContactHolder ui, private void grayOutItem(SelectableContactHolder ui, boolean gray) {
final boolean gray) {
if (Build.VERSION.SDK_INT >= 11) { if (Build.VERSION.SDK_INT >= 11) {
float alpha = 1f; float alpha = gray ? 0.25f : 1f;
if (gray) alpha = 0.25f;
ui.avatar.setAlpha(alpha); ui.avatar.setAlpha(alpha);
ui.name.setAlpha(alpha); ui.name.setAlpha(alpha);
ui.shared.setAlpha(alpha);
ui.checkBox.setAlpha(alpha); ui.checkBox.setAlpha(alpha);
} else { } else {
if (gray) { if (gray) ui.avatar.setColorFilter(grayColorFilter);
ColorFilter colorFilter = new PorterDuffColorFilter( else ui.avatar.clearColorFilter();
ContextCompat.getColor(ctx, R.color.window_background),
PorterDuff.Mode.MULTIPLY);
ui.avatar.setColorFilter(colorFilter);
} else{
ui.avatar.clearColorFilter();
}
ui.name.setEnabled(!gray);
ui.shared.setEnabled(!gray);
ui.checkBox.setEnabled(!gray);
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment