From f725dd5a7e3bcf1803718749cead1520182f24e6 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 24 Sep 2018 23:41:29 -0700 Subject: [PATCH] Show profile avatar in toolbar. --- res/drawable-hdpi/ic_profile_default.png | Bin 0 -> 475 bytes res/drawable-mdpi/ic_profile_default.png | Bin 0 -> 332 bytes res/drawable-xhdpi/ic_profile_default.png | Bin 0 -> 575 bytes res/drawable-xxhdpi/ic_profile_default.png | Bin 0 -> 979 bytes res/drawable-xxxhdpi/ic_profile_default.png | Bin 0 -> 1330 bytes res/layout/conversation_list_activity.xml | 3 +- .../securesms/ConversationListActivity.java | 30 +++++++++++++ .../securesms/components/AvatarImageView.java | 3 +- .../avatars/GeneratedContactPhoto.java | 42 +++++++++++------- .../SingleRecipientNotificationBuilder.java | 2 +- .../securesms/recipients/Recipient.java | 4 +- 11 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 res/drawable-hdpi/ic_profile_default.png create mode 100644 res/drawable-mdpi/ic_profile_default.png create mode 100644 res/drawable-xhdpi/ic_profile_default.png create mode 100644 res/drawable-xxhdpi/ic_profile_default.png create mode 100644 res/drawable-xxxhdpi/ic_profile_default.png diff --git a/res/drawable-hdpi/ic_profile_default.png b/res/drawable-hdpi/ic_profile_default.png new file mode 100644 index 0000000000000000000000000000000000000000..f6ed109eceb409ab5cccce0cfe0e8d6e4cbd65af GIT binary patch literal 475 zcmV<10VMv3P)Px$l}SWFR9Fe^mcL2^K@f*?nmQobSlt8INU*jP1VM#7O9~%B@(!td2Ei`9g(yPa zAdMnuW0mt8yaS8b%VuuZyMrD0vB~WHX1<%;p9}^m(ge~3(ge1iKv5Jqx<$|EtCW0} zT)uU|7zRM5=o`60_NFm#FDrJA^RXo%| z0E`s~-_+Q`v12jeIWhXgX7XA=_ZxtkyjIZn2B0Rd74)$IXcO=DZMk#0f7i=t0osq} zXbIc>H&b=7Fxl?E>;J&!0C)S}Qw5vWzD*zt1K6|#nS=SXUq2IV|M3Qo`q3LR2&;%w}@ zL6H%<3r(lglOENz?Thz&9L6D9C`DtXq}R|zS@$>Z2Ggm_7$Gmcq^BBnpx3G+ZqnJ) zdDrnXtYLEQN8(-c=-Sn4*G=@lA%)M$YXN#CeX$NegJ~CtY|Sa R-&z0w002ovPDHLkV1i!U+O+@x literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_profile_default.png b/res/drawable-mdpi/ic_profile_default.png new file mode 100644 index 0000000000000000000000000000000000000000..c17844bd5d06ed9303108720be429c488c514920 GIT binary patch literal 332 zcmV-S0ki&zP)Px$21!IgR7ef&lrav1KoCX6#@N`%0SNI1)_5!%j^hoe=(vF1z*agND`Hf9lR$z9 zVStrHWs;YL<trPb;;(s516>Hg$S-t7xF9u(Ymc2NwQ%FH)tD@ zBe}N97@-3v=o?bQX*5L?_H`=chh@XJO@lZ=G%E``-Y0CPc`>)jFf9uDUSs&;q5XOH e^&Rtnr~^+7Vl0%w9^{Dt0000J%=P)Px$`AI}URA>e5m@!VnKoCXaL_t(QniMn?NHmnd2`JML3eG{z36RoLC?V4gskU6y^=GB@{)r<@~UlFe81f5@%=TeLLQ@8x0S4z#VW0+yQss|2mK?5^J?TA*0zQ8kAAZIBs*A(Sz26%XtS; z1Jb2kmh(oOmn&3lROLTcW`O0eo0BAz*Sy^=cLiNp4$CD8HK3#^l0*q;>zpcNxs+!x zU&IxVvRq0)1(-aC6416^s*vSU0@~hE6|!7PK-)O0LYYg`Q>+WUhAztj7H@KOW+SiSx5kZ+NYy4bc_sc4b_QHCXLW7x(0S!Cy8VZP#tuE#%NJt zxvfS=(sY$16zif(G(mqAR?BL3tMpj=Hx%fj7ZfV2w*JL1Nn7YD6xEEn)=R7QnVOzR zvf+#(p}!hV_gU*R6urVHA%I(7qiL#AmjVaZqoo@{Ts$rq-MGQAsQ14@>OUtgZDldBsAU4G z35m%8Dq)U+i^a4!xL*C*W26~lw#&Hs+37duejhxYczx#kPje>UES8Mcoy|F;0RtUS z5Ipf}TF&mfan63nFI1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WF(761oxRIGF6;=8|Jz7FPyUV{HcAe@r(2?@GZ1^Vp!73GvUCz z_FLK>jhZ`*S9JdBbS$61wAXb(weO4{`wb7XM6`TUOVd|;D+P?OowGBvy=L^Xd1Rbt zat5k@9^hBXzd1T%vcdc3DSIY`JI!{?UtpaPV7j}S?cDqw zXSamCbd&vaC1`7{S<{Dmhd=6NWmjt5rGxksNaf3fyS-siZ7={M@z z^ZsZ*HJQZbQDJ3WB)oUVr6(e5U+Wb|s=3Vl>KSyhY+=jt;{Mww9?Hu1-pCPO(^ntf zd0&Nlf}y?R`e_oo*XD~VZ}bZCEL)fpC|*!(+qwALnkP!TFG+_kkG6C;6fFMw(ix{v zW8LU~il1Xujx=k1_S?v9+uzu#r53eo%?#b}xz$|^`r)P*A3eRl&g#1eJCf)1B}n+$la4&z - handleDisplaySettings()); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); diff --git a/src/org/thoughtcrime/securesms/components/AvatarImageView.java b/src/org/thoughtcrime/securesms/components/AvatarImageView.java index f16e44d504..8bb1bfae11 100644 --- a/src/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/src/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -15,6 +15,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.contacts.avatars.ContactColors; import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto; +import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto; import org.thoughtcrime.securesms.mms.GlideRequests; import org.thoughtcrime.securesms.recipients.Recipient; @@ -57,7 +58,7 @@ public class AvatarImageView extends AppCompatImageView { .into(this); setAvatarClickHandler(recipient, quickContactEnabled); } else { - setImageDrawable(new GeneratedContactPhoto("#").asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted)); + setImageDrawable(new ResourceContactPhoto(R.drawable.ic_profile_default).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted)); super.setOnClickListener(listener); } } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java index af1ded0b95..5464486ce0 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java @@ -6,6 +6,8 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.support.annotation.NonNull; +import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.support.v7.content.res.AppCompatResources; import android.text.TextUtils; @@ -23,37 +25,43 @@ public class GeneratedContactPhoto implements FallbackContactPhoto { private static final Typeface TYPEFACE = Typeface.create("sans-serif-medium", Typeface.NORMAL); private final String name; + private final int fallbackResId; - public GeneratedContactPhoto(@NonNull String name) { - this.name = name; + public GeneratedContactPhoto(@NonNull String name, @DrawableRes int fallbackResId) { + this.name = name; + this.fallbackResId = fallbackResId; } @Override public Drawable asDrawable(Context context, int color) { - return asDrawable(context, color, false); + return asDrawable(context, color,false); } @Override public Drawable asDrawable(Context context, int color, boolean inverted) { int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size); + String character = getAbbreviation(name); - Drawable base = TextDrawable.builder() - .beginConfig() - .width(targetSize) - .height(targetSize) - .useFont(TYPEFACE) - .fontSize(ViewUtil.dpToPx(context, 24)) - .textColor(inverted ? color : Color.WHITE) - .endConfig() - .buildRound(getAbbreviation(name), inverted ? Color.WHITE : color); + if (!TextUtils.isEmpty(character)) { + Drawable base = TextDrawable.builder() + .beginConfig() + .width(targetSize) + .height(targetSize) + .useFont(TYPEFACE) + .fontSize(ViewUtil.dpToPx(context, 24)) + .textColor(inverted ? color : Color.WHITE) + .endConfig() + .buildRound(character, inverted ? Color.WHITE : color); - Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark - : R.drawable.avatar_gradient_light); + Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark + : R.drawable.avatar_gradient_light); + return new LayerDrawable(new Drawable[] { base, gradient }); + } - return new LayerDrawable(new Drawable[] { base, gradient }); + return new ResourceContactPhoto(fallbackResId).asDrawable(context, color, inverted); } - private String getAbbreviation(String name) { + private @Nullable String getAbbreviation(String name) { String[] parts = name.split(" "); StringBuilder builder = new StringBuilder(); int count = 0; @@ -67,7 +75,7 @@ public class GeneratedContactPhoto implements FallbackContactPhoto { } if (builder.length() == 0) { - return "#"; + return null; } else { return builder.toString(); } diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 45c60fc91a..db5ef29d08 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -92,7 +92,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil } else { setContentTitle(context.getString(R.string.SingleRecipientNotificationBuilder_signal)); - setLargeIcon(new GeneratedContactPhoto("Unknown").asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context))); + setLargeIcon(new GeneratedContactPhoto("Unknown", R.drawable.ic_profile_default).asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context))); } } diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index daedd4e23a..602b5b921f 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -425,8 +425,8 @@ public class Recipient implements RecipientModifiedListener { public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() { if (isResolving()) return new TransparentContactPhoto(); else if (isGroupRecipient()) return new ResourceContactPhoto(R.drawable.ic_group_white_24dp, R.drawable.ic_group_large); - else if (!TextUtils.isEmpty(name)) return new GeneratedContactPhoto(name); - else return new GeneratedContactPhoto("#"); + else if (!TextUtils.isEmpty(name)) return new GeneratedContactPhoto(name, R.drawable.ic_profile_default); + else return new ResourceContactPhoto(R.drawable.ic_profile_default); } public synchronized @Nullable ContactPhoto getContactPhoto() {