Messaging: Contact Colors
Adds the option to use individual colors for contacts. Matches the colors used in Contacts. Change-Id: I9f222308a900c5d47ec16f83232bd7f6d9af6cd7
This commit is contained in:
@@ -102,6 +102,23 @@
|
||||
<color name="gallery_image_pressed">#6733b5e5</color>
|
||||
<color name="attachment_preview_more_items_text_background">#44000000</color>
|
||||
|
||||
<array name="letter_tile_colors">
|
||||
<item>#DB4437</item>
|
||||
<item>#E91E63</item>
|
||||
<item>#9C27B0</item>
|
||||
<item>#673AB7</item>
|
||||
<item>#3F51B5</item>
|
||||
<item>#4285F4</item>
|
||||
<item>#039BE5</item>
|
||||
<item>#0097A7</item>
|
||||
<item>#009688</item>
|
||||
<item>#0F9D58</item>
|
||||
<item>#689F38</item>
|
||||
<item>#EF6C00</item>
|
||||
<item>#FF5722</item>
|
||||
<item>#757575</item>
|
||||
</array>
|
||||
|
||||
<color name="letter_tile_font_color">#ffffff</color>
|
||||
|
||||
<color name="audio_picker_level_primary_color">#29000000</color>
|
||||
|
||||
@@ -18,4 +18,7 @@
|
||||
<resources>
|
||||
<!-- The packaged version of APNs and MMS configurations -->
|
||||
<integer name="apnsAndMmsConfigsVersion">0</integer>
|
||||
|
||||
<!-- Use individual colors for contacts -->
|
||||
<bool name="contact_colors">true</bool>
|
||||
</resources>
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.android.messaging.datamodel.media;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
@@ -27,6 +28,7 @@ import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.media.ExifInterface;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.messaging.R;
|
||||
import com.android.messaging.util.Assert;
|
||||
@@ -42,10 +44,12 @@ import java.util.List;
|
||||
public class AvatarRequest extends UriImageRequest<AvatarRequestDescriptor> {
|
||||
private static Bitmap sDefaultPersonBitmap;
|
||||
private static Bitmap sDefaultPersonBitmapLarge;
|
||||
private TypedArray mColors;
|
||||
|
||||
public AvatarRequest(final Context context,
|
||||
final AvatarRequestDescriptor descriptor) {
|
||||
super(context, descriptor);
|
||||
mColors = mContext.getResources().obtainTypedArray(R.array.letter_tile_colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,7 +120,7 @@ public class AvatarRequest extends UriImageRequest<AvatarRequestDescriptor> {
|
||||
|
||||
private Bitmap renderDefaultAvatar(final int width, final int height) {
|
||||
final Bitmap bitmap = getBitmapPool().createOrReuseBitmap(width, height,
|
||||
getBackgroundColor());
|
||||
getBackgroundColor(AvatarUriUtil.getIdentifier(mDescriptor.uri)));
|
||||
final Canvas canvas = new Canvas(bitmap);
|
||||
|
||||
if (sDefaultPersonBitmap == null) {
|
||||
@@ -158,7 +162,7 @@ public class AvatarRequest extends UriImageRequest<AvatarRequestDescriptor> {
|
||||
final float halfHeight = height / 2;
|
||||
final int minOfWidthAndHeight = Math.min(width, height);
|
||||
final Bitmap bitmap = getBitmapPool().createOrReuseBitmap(width, height,
|
||||
getBackgroundColor());
|
||||
getBackgroundColor(AvatarUriUtil.getIdentifier(mDescriptor.uri)));
|
||||
final Resources resources = mContext.getResources();
|
||||
final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
|
||||
@@ -178,8 +182,15 @@ public class AvatarRequest extends UriImageRequest<AvatarRequestDescriptor> {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private int getBackgroundColor() {
|
||||
return mContext.getResources().getColor(R.color.primary_color);
|
||||
private int getBackgroundColor(final String identifier) {
|
||||
if (!TextUtils.isEmpty(identifier) &&
|
||||
mContext.getResources().getBoolean(R.bool.contact_colors)) {
|
||||
int idcolor = Math.abs(identifier.hashCode()) % mColors.length();
|
||||
return mColors.getColor(idcolor,
|
||||
mContext.getResources().getColor(R.color.primary_color));
|
||||
} else {
|
||||
return mContext.getResources().getColor(R.color.primary_color);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.android.messaging.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.messaging.Factory;
|
||||
@@ -52,6 +53,7 @@ public class ConversationDrawables {
|
||||
private int mIncomingAudioButtonColor;
|
||||
private int mSelectedBubbleColor;
|
||||
private int mThemeColor;
|
||||
private TypedArray mColors;
|
||||
|
||||
public static ConversationDrawables get() {
|
||||
if (sInstance == null) {
|
||||
@@ -102,10 +104,11 @@ public class ConversationDrawables {
|
||||
resources.getColor(R.color.message_audio_button_color_incoming);
|
||||
mSelectedBubbleColor = resources.getColor(R.color.message_bubble_color_selected);
|
||||
mThemeColor = resources.getColor(R.color.primary_color);
|
||||
mColors = resources.obtainTypedArray(R.array.letter_tile_colors);
|
||||
}
|
||||
|
||||
public Drawable getBubbleDrawable(final boolean selected, final boolean incoming,
|
||||
final boolean needArrow, final boolean isError) {
|
||||
final boolean needArrow, final boolean isError, final String identifier) {
|
||||
final Drawable protoDrawable;
|
||||
if (needArrow) {
|
||||
if (incoming) {
|
||||
@@ -127,7 +130,13 @@ public class ConversationDrawables {
|
||||
if (isError) {
|
||||
color = mIncomingErrorBubbleColor;
|
||||
} else {
|
||||
color = mThemeColor;
|
||||
if (identifier != null &&
|
||||
mContext.getResources().getBoolean(R.bool.contact_colors)) {
|
||||
int idcolor = Math.abs(identifier.hashCode()) % mColors.length();
|
||||
color = mColors.getColor(idcolor, mThemeColor);
|
||||
} else {
|
||||
color = mThemeColor;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
color = mOutgoingBubbleColor;
|
||||
|
||||
@@ -701,7 +701,8 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
|
||||
isSelected(),
|
||||
incoming,
|
||||
false /* needArrow */,
|
||||
mData.hasIncomingErrorStatus());
|
||||
mData.hasIncomingErrorStatus(),
|
||||
mData.getSenderContactLookupKey());
|
||||
textMinHeight = messageTextMinHeightDefault;
|
||||
textTopMargin = messageTopPaddingClustered;
|
||||
textTopPadding = textTopPaddingDefault;
|
||||
@@ -729,7 +730,8 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
|
||||
isSelected(),
|
||||
incoming,
|
||||
shouldShowMessageBubbleArrow(),
|
||||
mData.hasIncomingErrorStatus());
|
||||
mData.hasIncomingErrorStatus(),
|
||||
mData.getSenderContactLookupKey());
|
||||
textMinHeight = messageTextMinHeightDefault;
|
||||
textTopMargin = 0;
|
||||
textTopPadding = textTopPaddingDefault;
|
||||
@@ -1121,7 +1123,7 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
|
||||
audioView.bindMessagePartData(attachment, mData.getIsIncoming(), isSelected());
|
||||
audioView.setBackground(ConversationDrawables.get().getBubbleDrawable(
|
||||
isSelected(), mData.getIsIncoming(), false /* needArrow */,
|
||||
mData.hasIncomingErrorStatus()));
|
||||
mData.hasIncomingErrorStatus(), mData.getSenderContactLookupKey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1138,7 +1140,7 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
|
||||
attachment));
|
||||
personView.setBackground(ConversationDrawables.get().getBubbleDrawable(
|
||||
isSelected(), mData.getIsIncoming(), false /* needArrow */,
|
||||
mData.hasIncomingErrorStatus()));
|
||||
mData.hasIncomingErrorStatus(), mData.getSenderContactLookupKey()));
|
||||
final int nameTextColorRes;
|
||||
final int detailsTextColorRes;
|
||||
if (isSelected()) {
|
||||
|
||||
Reference in New Issue
Block a user