Colorize ExpandingEntryCards further.
This moves the responsibility of coloring from the QuickContactActivity
to the ExpandingEntryCard.
Change-Id: I991464b7bc5dfeb2092e057ceafc77538ee1ad64
diff --git a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
index 18703d1..209284f 100644
--- a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
+++ b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -122,7 +123,10 @@
private List<Entry> mEntries;
private List<View> mEntryViews;
private LinearLayout mEntriesViewGroup;
+ private final Drawable mCollapseArrowDrawable;
+ private final Drawable mExpandArrowDrawable;
private int mThemeColor;
+ private ColorFilter mThemeColorFilter;
private final OnClickListener mExpandCollapseButtonListener = new OnClickListener() {
@Override
@@ -146,6 +150,17 @@
mEntriesViewGroup = (LinearLayout)
expandingEntryCardView.findViewById(R.id.content_area_linear_layout);
mTitleTextView = (TextView) expandingEntryCardView.findViewById(R.id.title);
+ mCollapseArrowDrawable =
+ getResources().getDrawable(R.drawable.expanding_entry_card_collapse_white_24);
+ mExpandArrowDrawable =
+ getResources().getDrawable(R.drawable.expanding_entry_card_expand_white_24);
+
+ mExpandCollapseButton = inflater.inflate(
+ R.layout.quickcontact_expanding_entry_card_button, this, false);
+ mExpandCollapseTextView = (TextView) mExpandCollapseButton.findViewById(R.id.text);
+ mExpandCollapseButton.setOnClickListener(mExpandCollapseButtonListener);
+
+
}
/**
@@ -154,19 +169,21 @@
* @param entries The Entry list to display.
*/
public void initialize(List<Entry> entries, int numInitialVisibleEntries,
- boolean isExpanded, int themeColor) {
+ boolean isExpanded) {
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
mIsExpanded = isExpanded;
mEntries = entries;
mEntryViews = new ArrayList<View>(entries.size());
mCollapsedEntriesCount = Math.min(numInitialVisibleEntries, entries.size());
- mThemeColor = themeColor;
- if (mExpandCollapseButton == null) {
- createExpandButton(layoutInflater);
+ if (mIsExpanded) {
+ updateExpandCollapseButton(getCollapseButtonText());
+ } else {
+ updateExpandCollapseButton(getExpandButtonText());
}
inflateViewsIfNeeded(layoutInflater);
insertEntriesIntoViewGroup();
+ applyColor();
}
/**
@@ -260,18 +277,6 @@
}
}
- private void createExpandButton(LayoutInflater layoutInflater) {
- mExpandCollapseButton = layoutInflater.inflate(
- R.layout.quickcontact_expanding_entry_card_button, this, false);
- mExpandCollapseTextView = (TextView) mExpandCollapseButton.findViewById(R.id.text);
- if (mIsExpanded) {
- updateExpandCollapseButton(getCollapseButtonText());
- } else {
- updateExpandCollapseButton(getExpandButtonText());
- }
- mExpandCollapseButton.setOnClickListener(mExpandCollapseButtonListener);
- }
-
/**
* Lazily inflate the number of views currently needed, and bind data from
* mEntries into these views.
@@ -283,6 +288,41 @@
}
}
+ public void setColorAndFilter(int color, ColorFilter colorFilter) {
+ mThemeColor = color;
+ mThemeColorFilter = colorFilter;
+ applyColor();
+ }
+
+ /**
+ * The ColorFilter is passed in along with the color so that a new one only needs to be created
+ * once for the entire activity.
+ * 1. Title
+ * 2. Entry icons
+ * 3. Expand/Collapse Text
+ * 4. Expand/Collapse Button
+ */
+ public void applyColor() {
+ if (mThemeColor != 0 && mThemeColorFilter != null) {
+ // Title
+ if (mTitleTextView != null) {
+ mTitleTextView.setTextColor(mThemeColor);
+ }
+
+ // Entry icons
+ if (mEntries != null) {
+ for (Entry entry : mEntries) {
+ entry.getIcon().setColorFilter(mThemeColorFilter);
+ }
+ }
+
+ // Expand/Collapse
+ mExpandCollapseTextView.setTextColor(mThemeColor);
+ mCollapseArrowDrawable.setColorFilter(mThemeColorFilter);
+ mExpandArrowDrawable.setColorFilter(mThemeColorFilter);
+ }
+ }
+
private View createEntryView(LayoutInflater layoutInflater, Entry entry) {
View view = layoutInflater.inflate(
R.layout.expanding_entry_card_item, this, false);
@@ -335,15 +375,12 @@
}
private void updateExpandCollapseButton(CharSequence buttonText) {
- int resId = mIsExpanded ? R.drawable.expanding_entry_card_collapse_white_24
- : R.drawable.expanding_entry_card_expand_white_24;
- // TODO: apply color theme to the drawable
- Drawable drawable = getResources().getDrawable(resId);
+ final Drawable arrow = mIsExpanded ? mCollapseArrowDrawable : mExpandArrowDrawable;
if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
- mExpandCollapseTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable,
+ mExpandCollapseTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, arrow,
null);
} else {
- mExpandCollapseTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null,
+ mExpandCollapseTextView.setCompoundDrawablesWithIntrinsicBounds(arrow, null, null,
null);
}
mExpandCollapseTextView.setText(buttonText);
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index b186038..303dae5 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -31,6 +31,7 @@
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
+import android.graphics.ColorFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
@@ -93,7 +94,6 @@
import com.android.contacts.util.SchedulingUtils;
import com.android.contacts.widget.MultiShrinkScroller;
import com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -159,9 +159,6 @@
private Contact mContactData;
private ContactLoader mContactLoader;
- private PorterDuffColorFilter mColorFilter;
- List<Drawable> mDrawablesToTint;
-
private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter();
/**
@@ -380,7 +377,6 @@
}
}
- mDrawablesToTint = new ArrayList<>();
mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager()
.findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT);
if (mSelectAccountFragmentListener == null) {
@@ -564,8 +560,7 @@
if (entries.size() > 0) {
mCommunicationCard.initialize(entries,
/* numInitialVisibleEntries = */ MIN_NUM_COMMUNICATION_ENTRIES_SHOWN,
- /* isExpanded = */ false,
- /* themeColor = */ 0);
+ /* isExpanded = */ false);
}
final boolean hasData = !sortedActionMimeTypes.isEmpty();
@@ -730,10 +725,13 @@
@Override
protected void onPostExecute(Integer color) {
super.onPostExecute(color);
- mColorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
- // Make sure the color is valid. Also check that the Photo has not changed. If it
- // has changed, the new tint color needs to be extracted
- if (color != 0 && imageViewDrawable == mPhotoView.getDrawable()) {
+ // Check that the Photo has not changed. If it has changed, the new tint color
+ // needs to be extracted
+ if (imageViewDrawable == mPhotoView.getDrawable()) {
+ // If the color is invalid, use the predefined default
+ if (color == 0) {
+ color = getResources().getColor(R.color.actionbar_background_color);
+ }
// TODO: animate from the previous tint.
mScroller.setHeaderTintColor(color);
@@ -746,10 +744,10 @@
mStatusBarColor = Color.HSVToColor(hsvComponents);
updateStatusBarColor();
- for (Drawable drawable : mDrawablesToTint) {
- applyThemeColorIfAvailable(drawable);
- }
- mDrawablesToTint.clear();
+ final ColorFilter colorFilter =
+ new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
+ mCommunicationCard.setColorAndFilter(color, colorFilter);
+ mRecentCard.setColorAndFilter(color, colorFilter);
}
}
}.execute();
@@ -819,20 +817,17 @@
case Phone.CONTENT_ITEM_TYPE:
header = String.valueOf(action.getBody());
footer = String.valueOf(action.getSubtitle());
- icon = applyThemeColorIfAvailable(
- getResources().getDrawable(R.drawable.ic_phone_24dp));
+ icon = getResources().getDrawable(R.drawable.ic_phone_24dp);
break;
case Email.CONTENT_ITEM_TYPE:
header = String.valueOf(action.getBody());
footer = String.valueOf(action.getSubtitle());
- icon = applyThemeColorIfAvailable(
- getResources().getDrawable(R.drawable.ic_email_24dp));
+ icon = getResources().getDrawable(R.drawable.ic_email_24dp);
break;
case StructuredPostal.CONTENT_ITEM_TYPE:
header = String.valueOf(action.getBody());
footer = String.valueOf(action.getSubtitle());
- icon = applyThemeColorIfAvailable(
- getResources().getDrawable(R.drawable.ic_place_24dp));
+ icon = getResources().getDrawable(R.drawable.ic_place_24dp);
break;
default:
header = String.valueOf(action.getSubtitle());
@@ -844,8 +839,7 @@
// Add SMS in addition to phone calls
if (action.getMimeType().equals(Phone.CONTENT_ITEM_TYPE)) {
- entries.add(new Entry(applyThemeColorIfAvailable(getResources().getDrawable(
- R.drawable.ic_message_24dp)),
+ entries.add(new Entry(getResources().getDrawable(R.drawable.ic_message_24dp),
getResources().getString(R.string.send_message), null, header,
action.getAlternateIntent(), /* isEditable = */ false));
}
@@ -856,7 +850,7 @@
private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) {
List<Entry> entries = new ArrayList<>();
for (ContactInteraction interaction : interactions) {
- entries.add(new Entry(applyThemeColorIfAvailable(interaction.getIcon(this)),
+ entries.add(new Entry(interaction.getIcon(this),
interaction.getViewHeader(this),
interaction.getViewBody(this),
interaction.getBodyIcon(this),
@@ -1012,8 +1006,7 @@
if (allInteractions.size() > 0) {
mRecentCard.initialize(contactInteractionsToEntries(allInteractions),
/* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN,
- /* isExpanded = */ false,
- /* themeColor = */ 0);
+ /* isExpanded = */ false);
mRecentCard.setVisibility(View.VISIBLE);
}
}
@@ -1032,20 +1025,6 @@
}
/**
- * Applies the theme color as extracted in
- * {@link #extractAndApplyTintFromPhotoViewAsynchronously()} if available. If the color is not
- * available, store a reference to the drawable to tint when a color becomes available.
- */
- private Drawable applyThemeColorIfAvailable(Drawable drawable) {
- if (mColorFilter != null) {
- drawable.setColorFilter(mColorFilter);
- } else {
- mDrawablesToTint.add(drawable);
- }
- return drawable;
- }
-
- /**
* Returns true if it is possible to edit the current contact.
*/
private boolean isContactEditable() {
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index b38f5cf..96a3d0b 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -152,8 +152,6 @@
R.dimen.quickcontact_starting_header_height);
mTransparentStartHeight = (int) getResources().getDimension(
R.dimen.quickcontact_starting_empty_height);
- mHeaderTintColor = mContext.getResources().getColor(
- R.color.actionbar_background_color);
mToolbarElevation = mContext.getResources().getDimension(
R.dimen.quick_contact_toolbar_elevation);