From ac282ccf7088fd49612640a3bfe81f538e5888bf Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 4 Oct 2017 15:23:33 -0700 Subject: [PATCH] Display contact color in background for generated avatars Fixes #7028 // FREEBIE --- res/drawable/ic_group_large.xml | 4 ++-- res/drawable/ic_person_large.xml | 4 ++-- res/layout/recipient_preference_activity.xml | 1 - .../securesms/RecipientPreferenceActivity.java | 9 ++++++++- .../securesms/contacts/avatars/BitmapContactPhoto.java | 5 +++++ .../securesms/contacts/avatars/ContactPhoto.java | 1 + .../contacts/avatars/GeneratedContactPhoto.java | 5 +++++ .../securesms/contacts/avatars/ResourceContactPhoto.java | 5 +++++ .../contacts/avatars/TransparentContactPhoto.java | 5 +++++ 9 files changed, 33 insertions(+), 6 deletions(-) diff --git a/res/drawable/ic_group_large.xml b/res/drawable/ic_group_large.xml index d11f0bde26..b06cdd7788 100644 --- a/res/drawable/ic_group_large.xml +++ b/res/drawable/ic_group_large.xml @@ -1,5 +1,5 @@ - diff --git a/res/drawable/ic_person_large.xml b/res/drawable/ic_person_large.xml index 39cf6fdcfc..c3324be1de 100644 --- a/res/drawable/ic_person_large.xml +++ b/res/drawable/ic_person_large.xml @@ -1,4 +1,4 @@ - + diff --git a/res/layout/recipient_preference_activity.xml b/res/layout/recipient_preference_activity.xml index 3bc0e158fb..46e2f451ab 100644 --- a/res/layout/recipient_preference_activity.xml +++ b/res/layout/recipient_preference_activity.xml @@ -25,7 +25,6 @@ diff --git a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java index f7ca9423dc..e27e360b33 100644 --- a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java +++ b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java @@ -36,6 +36,7 @@ import android.widget.TextView; import org.thoughtcrime.securesms.color.MaterialColor; import org.thoughtcrime.securesms.color.MaterialColors; import org.thoughtcrime.securesms.components.ThreadPhotoRailView; +import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.database.Address; @@ -203,7 +204,13 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi } private void setHeader(@NonNull Recipient recipient) { - this.avatar.setImageDrawable(recipient.getContactPhoto().asCallCard(this)); + ContactPhoto contactPhoto = recipient.getContactPhoto(); + + if (contactPhoto.isGenerated() || contactPhoto.isResource()) this.avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE); + else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP); + + this.avatar.setImageDrawable(contactPhoto.asCallCard(this)); + this.avatar.setBackgroundColor(recipient.getColor().toActionBarColor(this)); this.toolbarLayout.setTitle(recipient.toShortString()); this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this)); } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/BitmapContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/BitmapContactPhoto.java index 18747e2f54..c39f1d014f 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/BitmapContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/BitmapContactPhoto.java @@ -37,4 +37,9 @@ public class BitmapContactPhoto implements ContactPhoto { public boolean isGenerated() { return false; } + + @Override + public boolean isResource() { + return false; + } } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhoto.java index 06b5df8f28..0065962207 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhoto.java @@ -9,5 +9,6 @@ public interface ContactPhoto { public Drawable asDrawable(Context context, int color, boolean inverted); public Drawable asCallCard(Context context); public boolean isGenerated(); + public boolean isResource(); } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java index a4f48fdde6..4812398482 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java @@ -55,4 +55,9 @@ public class GeneratedContactPhoto implements ContactPhoto { public boolean isGenerated() { return true; } + + @Override + public boolean isResource() { + return false; + } } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java index 5ac9c6e451..d7c88acbd4 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java @@ -56,6 +56,11 @@ public class ResourceContactPhoto implements ContactPhoto { return false; } + @Override + public boolean isResource() { + return true; + } + private static class ExpandingLayerDrawable extends LayerDrawable { public ExpandingLayerDrawable(Drawable[] layers) { super(layers); diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/TransparentContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/TransparentContactPhoto.java index e1d5acb780..9623995512 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/TransparentContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/TransparentContactPhoto.java @@ -31,4 +31,9 @@ public class TransparentContactPhoto implements ContactPhoto { public boolean isGenerated() { return false; } + + @Override + public boolean isResource() { + return false; + } }