diff options
Diffstat (limited to 'java/com/android/contacts/common/lettertiles/LetterTileDrawable.java')
-rw-r--r-- | java/com/android/contacts/common/lettertiles/LetterTileDrawable.java | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java b/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java index 88522c44b..5c401fe38 100644 --- a/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java +++ b/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java @@ -29,9 +29,12 @@ import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.support.annotation.IntDef; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.telecom.TelecomManager; import android.text.TextUtils; import com.android.contacts.common.R; +import com.android.contacts.common.lettertiles.LetterTileDrawable.ContactType; import com.android.dialer.common.Assert; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -122,10 +125,16 @@ public class LetterTileDrawable extends Drawable { sLetterToTileRatio = res.getFraction(R.dimen.letter_to_tile_ratio, 1, 1); sDefaultPersonAvatar = res.getDrawable(R.drawable.product_logo_avatar_anonymous_white_color_120, null); + Assert.isNotNull(sDefaultPersonAvatar, "sDefaultPersonAvatar is null"); sDefaultBusinessAvatar = res.getDrawable(R.drawable.quantum_ic_business_vd_theme_24, null); + Assert.isNotNull(sDefaultBusinessAvatar, "sDefaultBusinessAvatar is null"); sDefaultVoicemailAvatar = res.getDrawable(R.drawable.quantum_ic_voicemail_vd_theme_24, null); + Assert.isNotNull(sDefaultVoicemailAvatar, "sDefaultVoicemailAvatar is null"); sDefaultSpamAvatar = res.getDrawable(R.drawable.quantum_ic_report_vd_theme_24, null); + Assert.isNotNull(sDefaultSpamAvatar, "sDefaultSpamAvatar is null"); sDefaultConferenceAvatar = res.getDrawable(R.drawable.quantum_ic_group_vd_theme_24, null); + Assert.isNotNull(sDefaultConferenceAvatar, "sDefaultConferenceAvatar is null"); + sPaint.setTypeface( Typeface.create(res.getString(R.string.letter_tile_letter_font_family), Typeface.NORMAL)); sPaint.setTextAlign(Align.CENTER); @@ -178,7 +187,7 @@ public class LetterTileDrawable extends Drawable { } @Override - public void draw(final Canvas canvas) { + public void draw(@NonNull final Canvas canvas) { final Rect bounds = getBounds(); if (!isVisible() || bounds.isEmpty()) { return; @@ -233,6 +242,11 @@ public class LetterTileDrawable extends Drawable { } else { // Draw the default image if there is no letter/digit to be drawn Drawable drawable = getDrawableForContactType(mContactType); + if (drawable == null) { + throw Assert.createIllegalStateFailException( + "Unable to find drawable for contact type " + mContactType); + } + drawable.setBounds(getScaledBounds(mScale, mOffset)); drawable.setAlpha(drawable == sDefaultSpamAvatar ? SPAM_ALPHA : ALPHA); drawable.draw(canvas); @@ -406,4 +420,30 @@ public class LetterTileDrawable extends Drawable { } return this; } + + /** + * Returns the appropriate LetterTileDrawable.TYPE_ based on the given primitive conditions. + * + * <p>If no special state is detected, yields TYPE_DEFAULT + */ + public static @ContactType int getContactTypeFromPrimitives( + boolean isVoicemailNumber, + boolean isSpam, + boolean isBusiness, + int numberPresentation, + boolean isConference) { + if (isVoicemailNumber) { + return LetterTileDrawable.TYPE_VOICEMAIL; + } else if (isSpam) { + return LetterTileDrawable.TYPE_SPAM; + } else if (isBusiness) { + return LetterTileDrawable.TYPE_BUSINESS; + } else if (numberPresentation == TelecomManager.PRESENTATION_RESTRICTED) { + return LetterTileDrawable.TYPE_GENERIC_AVATAR; + } else if (isConference) { + return LetterTileDrawable.TYPE_CONFERENCE; + } else { + return LetterTileDrawable.TYPE_DEFAULT; + } + } } |