From c11f2eddf5b69bbf0091d1c9a7f1f31f7cab2dbf Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 16 Aug 2017 12:01:26 -0700 Subject: [PATCH] Display user profile information in settings activity Allow for editing // FREEBIE --- AndroidManifest.xml | 12 +++ res/drawable-hdpi/clear_profile_avatar.png | Bin 0 -> 851 bytes res/drawable-mdpi/clear_profile_avatar.png | Bin 0 -> 690 bytes res/drawable-xhdpi/clear_profile_avatar.png | Bin 0 -> 1196 bytes res/drawable-xxhdpi/clear_profile_avatar.png | Bin 0 -> 1902 bytes res/drawable-xxxhdpi/clear_profile_avatar.png | Bin 0 -> 2719 bytes res/layout/profile_create_activity.xml | 3 +- res/layout/profile_preference_view.xml | 35 ++++++++ res/values/strings.xml | 18 ++++- res/xml/preferences.xml | 4 + .../ApplicationPreferencesActivity.java | 16 ++++ .../securesms/ClearProfileAvatarActivity.java | 26 ++++++ .../securesms/CreateProfileActivity.java | 53 +++++++----- .../RegistrationProgressActivity.java | 4 +- .../preferences/ProfilePreference.java | 76 ++++++++++++++++++ 15 files changed, 222 insertions(+), 25 deletions(-) create mode 100644 res/drawable-hdpi/clear_profile_avatar.png create mode 100644 res/drawable-mdpi/clear_profile_avatar.png create mode 100644 res/drawable-xhdpi/clear_profile_avatar.png create mode 100644 res/drawable-xxhdpi/clear_profile_avatar.png create mode 100644 res/drawable-xxxhdpi/clear_profile_avatar.png create mode 100644 res/layout/profile_preference_view.xml create mode 100644 src/org/thoughtcrime/securesms/ClearProfileAvatarActivity.java create mode 100644 src/org/thoughtcrime/securesms/preferences/ProfilePreference.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5ef6716825..f066027380 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -388,6 +388,18 @@ android:theme="@style/TextSecure.LightTheme" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/> + + + + + + + + diff --git a/res/drawable-hdpi/clear_profile_avatar.png b/res/drawable-hdpi/clear_profile_avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..85126cb69925347f36c91322e3fbe8fd9d793e1a GIT binary patch literal 851 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@Zgyv2V3zW9aSW-r_4bapM@XOq`-lHN zTxns>yn8b)Dsg|B_*lTs?Sc`{QZrEr*SCuolL^|709(zt`EH-~0H{9c~X#AgJ8U@gb0R zQ%~1B%}|TF=Kml5P4RUQGzk!0_u^xlTy)90Y8~B=#n0uWCb?~@57a-tVBVJUbzDaR z*;MX%=bQ8_&|Y%nb+G@H-B{x+Gg-tY# z=9J=pSdnzzuc5|x>W(z634LFUnX1H(`5v)fI+y9^^3#Rhl3Yh@BY8r){N7#V4Y-yf zd27l+?T$t_@51)#Qtm7BiWclDUBb4@vvy8I&9C_rtY&OCaZtQd%KK#}kE|xEm574r z9d|Fy=aMxW8)hdhm?-dWDf@~#=9SyJm)x5DZ{Ec4cLi?@-tB+({PFd*@e3W)%O-Xm zoy6>6HqG_b4L(L81;$e@3vR^(JzwQHH~!d%kKdoK2~g<&w|Iw*gLsyw>3pB~9~JYM zq+WTx-`n1=?!cr%G@9b+uzvn>@s9F?Ra`IrUH!sTYF5p&!f^hTGt<93a9KX*jaIay z^a?%GNx#08W)`NUdzi|8eZZz=y}aAQ_O;5_x;r<|{raDp)N|$X?InJ1Kfd7G%yX;h z`aDL5ck{2#FsWd@+3(z|y1B`2>cXpE*k9e7vf!}k1qZ`(HzprdVp}`!#3ALG7r6qi z=goN<*M8_k*{^{2T65RRe@nd4<-daGWXzvWRnmt#-W6JZfAzzanP04d$-QZX+*M)U zsm*mSJazlq^;c)!J^diA=UV;|#&;i$WMbkvLz$nvNSy8G`P#2OxSVmpB1Z=riYaj?VeK*e>0!{9R-9!+ATlb0w4->BoO)ZH%$ayLj@t<^|0! z6CQ%9nS_FKmk9#7UDTeRBEBq<23^(TdmPXQIUcc6o1;r+Co5*>}mu3Q4qcLAVoZQQS>0WJlM4P@;P73LaNy&*{-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7Q}e3WiHJ9Wih^+s-)#7_?d)edDSv>oj2-f$;!k48b?nZk09o63LB{xFzb z;%1s!B=hL=dh8Op4yXBBH!T03xy0>O%gTe~DWM4fT-6zn literal 0 HcmV?d00001 diff --git a/res/drawable-xxhdpi/clear_profile_avatar.png b/res/drawable-xxhdpi/clear_profile_avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..93e07e60c109cbcf49a0465e21f372672f86c397 GIT binary patch literal 1902 zcmdUw`8U*yAI3i;W?T%FT^D08_BE0vCKNLm8q2+8NmE&_B^gYXQj-c{#(HJBqx(Uc zhGZ#&QLeIN%VdcWAq?dj+$L*Rzuxox2fpXL-p_N+`#irqKRu~#I0v|hf(QTraEzlp ze%~oSP8hnc3#VtE0|3kvV}H_vH2&rN*)R`JDd@CmkVPx{WbKBnQ_2v&!+1m7xl+&b zuw;!2@TO4*#Su_OxCNMgJ8$Ai5Dr$G7J4c8muYzUAXE(urH%D} zju>6~Oh8#VJ}HczcmAHYWB$dRU;Mo&=_~QBp_~|${PNs?tyeJvwHBp2iM`hG$`Qs% zi5skUyRWMdSq3h@Hl9?|KzVcY+JcrYY0u}b4!9qZMe_YEruFyeI(*)$SBQbL*;`{= za|9^fAJdNr0;1H(739p1IPeI$b4B;+s>$0#|HY8Z#-q2?TxR0U6+^&$5PiV_p-`b7 z6^z6lM!k}^%|>Di{XtdM66@fJ1#M)4j#OV137Y4P$OeCsuo)p8YzkJWw=ESTO`v~q+ida>Ba9- z-)6Fo4He86ilCL!Tez@x&~)?OaX%+2 z`uX~!o20hqUo4ERtS3pkD2uQ&%Er#$c1v3T;N3-S&81s$`R?V!r7nG zL4uvMQp(wV(zz>gw5*lNPyh=@7ge571yo7}a=92Z-Ogv1h^7-@k~zw(kx=i3UmzC+ z2EVNOHa*P4r@FYpR38b@av|^L*rDNndbI^$t&}WV{d^b?572Ufjq`PNq`k>hiv}Na zShDYdciGj$s^+S1oYotd(y*P+AgLT0iBF7zKXYX9M4&4_K2 zPpGU=D0Q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)?xB?48a`0AdB1_ApIZ~a@NZa+ z5jS{E6sH=;|2B;#B?rtiBATrjKV?-8cLvpayOefo^K!U(=YTU$>xo~9rQ^!#%nmL8 zm84y5<7$q(pbzEe{OFbRf{!_J!jtG3GhPPH1zCa?!fiyBHuxLevZ!tXI=J@gxtj}z znLA5@(2Kt^)P~aKIhD!KqA*n#aH0{^c23xc1g0wqdt2!4ElHjE>5Gc6FPJ zSOAqY1d#82R_HA^PCLAUb=sME<*%Fq%H?ymk#_dnnoo;bX7Qhmd>zY*ZjWK5+4X+X z2KOE-R$9lDxBUY8!o_>vd9+xS`?C%7zlrW1x7?JQ>3wB0-pWh& zNPwC4%1F)oV%Q-5iM@i#emY19P{1fI6EU!bv#@E?04aSU2 z`BK{g=rVlLfO_$H1W$CAI`OpU@`+6rtU5$`SN&LzF;zPH>=CN*+>Y?=Uwbek39NcK zCX9CrXN!D<9+c%lFi&T54xgFfPOj}PfKxh7|Gwoqsyse4BrEeir?$jj)wthJuMPVP zLy46Z$V@H0vK82hRsEvt3gkWH`avx#e?tftJ2u%F%;$L?1ec?K3{SM z=}Q|Z&L;;q)sABycVl-nO5jtFjrN79#;e1wOW{E@YyX^x+7|d&dinP1KEJWsu!^5Y zDt4(?APv%=N^Cd%)MUvrZ@lw7^4T|e)9CK!PGue(>K+!hs1^IT2U{9klSwQtJz5=` zfx_0%CmTkS^G=h`BbIX9@aU`$)Kh;^@8|Wj>n7?gC6KRrd$xc6dUnP&r_FSNdvW1# zns!u2!6HW&eoS9c{+FiwUnw)G3a|vc#+^(5k+Z7%iQwfK<&0YPeZr6J>SXU~S8>eu G#y + android:layout_height="64dp" + android:transitionName="avatar"/> + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index db8b4eee15..d98b3bb676 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -73,6 +73,10 @@ Incoming call + + Remove + Remove profile photo? + Your safety number with %1$s has changed. This could either mean that someone is trying to intercept your communication, or that %2$s simply reinstalled Signal. You may wish to verify your safety number with this contact. @@ -613,6 +617,14 @@ Signal update A new version of Signal is available, tap to update + + Send message? + Send + + + Send message? + Send + Your contact is running an old version of Signal. Please ask them to update before verifying your safety number. Your contact is running a newer version of Signal with an incompatible QR code format. Please update to compare. @@ -1087,6 +1099,7 @@ Linked devices Invite friends Archived conversations + Remove photo Import / export @@ -1409,10 +1422,7 @@ Transport icon - Send message? - Send - Send message? - Send + diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 373b8392ed..49c56459cc 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -1,6 +1,10 @@ + + + diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 0266765a65..fcdc34798d 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -34,6 +34,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; +import android.support.v7.app.AppCompatActivity; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment; @@ -60,6 +61,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA { private static final String TAG = ApplicationPreferencesActivity.class.getSimpleName(); + private static final String PREFERENCE_CATEGORY_PROFILE = "preference_category_profile"; private static final String PREFERENCE_CATEGORY_SMS_MMS = "preference_category_sms_mms"; private static final String PREFERENCE_CATEGORY_NOTIFICATIONS = "preference_category_notifications"; private static final String PREFERENCE_CATEGORY_APP_PROTECTION = "preference_category_app_protection"; @@ -138,6 +140,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA addPreferencesFromResource(R.xml.preferences); MasterSecret masterSecret = getArguments().getParcelable("master_secret"); + this.findPreference(PREFERENCE_CATEGORY_PROFILE) + .setOnPreferenceClickListener(new ProfileClickListener()); this.findPreference(PREFERENCE_CATEGORY_SMS_MMS) .setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_SMS_MMS)); this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS) @@ -273,5 +277,17 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA return true; } } + + private class ProfileClickListener implements Preference.OnPreferenceClickListener { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(preference.getContext(), CreateProfileActivity.class); + intent.putExtra(CreateProfileActivity.EXCLUDE_SYSTEM, true); + + ((BaseActionBarActivity)getActivity()).startActivitySceneTransition(intent, getActivity().findViewById(R.id.avatar), "avatar"); + return true; + } + } } + } diff --git a/src/org/thoughtcrime/securesms/ClearProfileAvatarActivity.java b/src/org/thoughtcrime/securesms/ClearProfileAvatarActivity.java new file mode 100644 index 0000000000..4400b2997d --- /dev/null +++ b/src/org/thoughtcrime/securesms/ClearProfileAvatarActivity.java @@ -0,0 +1,26 @@ +package org.thoughtcrime.securesms; + + +import android.app.Activity; +import android.content.Intent; +import android.support.v7.app.AlertDialog; + +public class ClearProfileAvatarActivity extends Activity { + + @Override + public void onResume() { + super.onResume(); + + new AlertDialog.Builder(this) + .setTitle(R.string.ClearProfileActivity_remove_profile_photo) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> finish()) + .setPositiveButton(R.string.ClearProfileActivity_remove, (dialog, which) -> { + Intent result = new Intent(); + result.putExtra("delete", true); + setResult(Activity.RESULT_OK, result); + finish(); + }) + .show(); + } + +} diff --git a/src/org/thoughtcrime/securesms/CreateProfileActivity.java b/src/org/thoughtcrime/securesms/CreateProfileActivity.java index ad40ed238e..568b2da403 100644 --- a/src/org/thoughtcrime/securesms/CreateProfileActivity.java +++ b/src/org/thoughtcrime/securesms/CreateProfileActivity.java @@ -53,6 +53,8 @@ import org.whispersystems.signalservice.api.util.StreamDetails; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; +import java.util.LinkedList; +import java.util.List; import java.util.concurrent.ExecutionException; import javax.inject.Inject; @@ -63,6 +65,9 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i private static final String TAG = CreateProfileActivity.class.getSimpleName(); + public static final String NEXT_INTENT = "next_intent"; + public static final String EXCLUDE_SYSTEM = "exclude_system"; + private static final int REQUEST_CODE_AVATAR = 1; @Inject SignalServiceAccountManager accountManager; @@ -74,8 +79,9 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i private EmojiToggle emojiToggle; private EmojiDrawer emojiDrawer; + private Intent nextIntent; private byte[] avatarBytes; - private File captureFile; + private File captureFile; @Override public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) { @@ -88,8 +94,8 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i initializeResources(); initializeEmojiInput(); - initializeProfileName(); - initializeProfileAvatar(); + initializeProfileName(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false)); + initializeProfileAvatar(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false)); ApplicationContext.getInstance(this).injectDependencies(this); } @@ -123,7 +129,13 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i inputFile = Uri.fromFile(captureFile); } - new Crop(inputFile).output(outputFile).asSquare().start(this); + if (data.getBooleanExtra("delete", false)) { + avatarBytes = null; + avatar.setImageDrawable(ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp) + .asDrawable(this, getResources().getColor(R.color.grey_400))); + } else { + new Crop(inputFile).output(outputFile).asSquare().start(this); + } } break; @@ -148,6 +160,7 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i this.emojiDrawer = ViewUtil.findById(this, R.id.emoji_drawer); this.container = ViewUtil.findById(this, R.id.container); this.finishButton = ViewUtil.findById(this, R.id.finish_button); + this.nextIntent = getIntent().getParcelableExtra(NEXT_INTENT); this.avatar.setImageDrawable(ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp) .asDrawable(this, getResources().getColor(R.color.grey_400))); @@ -160,7 +173,7 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i captureFile = null; } - Intent chooserIntent = createAvatarSelectionIntent(captureFile); + Intent chooserIntent = createAvatarSelectionIntent(captureFile, avatarBytes != null); startActivityForResult(chooserIntent, REQUEST_CODE_AVATAR); }); @@ -169,13 +182,13 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i }); } - private void initializeProfileName() { + private void initializeProfileName(boolean excludeSystem) { if (!TextUtils.isEmpty(TextSecurePreferences.getProfileName(this))) { String profileName = TextSecurePreferences.getProfileName(this); name.setText(profileName); name.setSelection(profileName.length(), profileName.length()); - } else { + } else if (!excludeSystem) { SystemProfileUtil.getSystemProfileName(this).addListener(new ListenableFuture.Listener() { @Override public void onSuccess(String result) { @@ -193,7 +206,7 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i } } - private void initializeProfileAvatar() { + private void initializeProfileAvatar(boolean excludeSystem) { Address ourAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(this)); if (AvatarHelper.getAvatarFile(this, ourAddress).exists() && AvatarHelper.getAvatarFile(this, ourAddress).length() > 0) { @@ -217,7 +230,7 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i } } }.execute(); - } else { + } else if (!excludeSystem) { SystemProfileUtil.getSystemProfileAvatar(this, new ProfileMediaConstraints()).addListener(new ListenableFuture.Listener() { @Override public void onSuccess(byte[] result) { @@ -266,8 +279,9 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i this.name.setOnClickListener(v -> container.showSoftkey(name)); } - private Intent createAvatarSelectionIntent(@Nullable File captureFile) { - Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); + private Intent createAvatarSelectionIntent(@Nullable File captureFile, boolean includeClear) { + List extraIntents = new LinkedList<>(); + Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); galleryIntent.setType("image/*"); if (!IntentUtils.isResolvable(CreateProfileActivity.this, galleryIntent)) { @@ -276,23 +290,23 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i } Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + cameraIntent.putExtra(EXTRA_OUTPUT, Uri.fromFile(captureFile)); if (captureFile != null && cameraIntent.resolveActivity(getPackageManager()) != null) { - cameraIntent.putExtra(EXTRA_OUTPUT, Uri.fromFile(captureFile)); - } else { - cameraIntent = null; + extraIntents.add(cameraIntent); + } + + if (includeClear) { + extraIntents.add(new Intent("org.thoughtcrime.securesms.action.CLEAR_PROFILE_PHOTO")); } Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.CreateProfileActivity_profile_photo)); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents.toArray(new Intent[0])); - if (cameraIntent != null) { - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {cameraIntent}); - } return chooserIntent; } - private void handleUpload() { final String name; final StreamDetails avatar; @@ -342,7 +356,8 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i if (result) { if (captureFile != null) captureFile.delete(); - startActivity(new Intent(CreateProfileActivity.this, ConversationListActivity.class)); + if (nextIntent != null) startActivity(nextIntent); + finish(); } else { Toast.makeText(CreateProfileActivity.this, R.string.CreateProfileActivity_problem_setting_profile, Toast.LENGTH_LONG).show(); diff --git a/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java b/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java index 589d460cd9..b4b7bd9447 100644 --- a/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java +++ b/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java @@ -342,7 +342,9 @@ public class RegistrationProgressActivity extends BaseActionBarActivity { } shutdownService(); - startActivity(new Intent(this, CreateProfileActivity.class)); + Intent intent = new Intent(this, CreateProfileActivity.class); + intent.putExtra(CreateProfileActivity.NEXT_INTENT, new Intent(this, ConversationListActivity.class)); + startActivity(intent); finish(); } diff --git a/src/org/thoughtcrime/securesms/preferences/ProfilePreference.java b/src/org/thoughtcrime/securesms/preferences/ProfilePreference.java new file mode 100644 index 0000000000..ac975b9dcf --- /dev/null +++ b/src/org/thoughtcrime/securesms/preferences/ProfilePreference.java @@ -0,0 +1,76 @@ +package org.thoughtcrime.securesms.preferences; + + +import android.content.Context; +import android.os.AsyncTask; +import android.os.Build; +import android.preference.Preference; +import android.support.annotation.RequiresApi; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import org.thoughtcrime.securesms.R; +import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; +import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory; +import org.thoughtcrime.securesms.database.Address; +import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.thoughtcrime.securesms.util.ViewUtil; + +public class ProfilePreference extends Preference { + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public ProfilePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + initialize(); + } + + public ProfilePreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initialize(); + } + + public ProfilePreference(Context context, AttributeSet attrs) { + super(context, attrs); + initialize(); + } + + public ProfilePreference(Context context) { + super(context); + initialize(); + } + + private void initialize() { + setLayoutResource(R.layout.profile_preference_view); + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + final ImageView avatar = ViewUtil.findById(view, R.id.avatar); + final TextView profileName = ViewUtil.findById(view, R.id.profile_name); + final TextView profileNumber = ViewUtil.findById(view, R.id.number); + final Address localAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(getContext())); + + new AsyncTask() { + @Override + protected ContactPhoto doInBackground(Void... params) { + return ContactPhotoFactory.getSignalAvatarContactPhoto(getContext(), localAddress, null, getContext().getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size)); + } + + @Override + protected void onPostExecute(ContactPhoto contactPhoto) { + avatar.setImageDrawable(contactPhoto.asDrawable(getContext(), 0)); + } + }.execute(); + + if (!TextUtils.isEmpty(TextSecurePreferences.getProfileName(getContext()))) { + profileName.setText(TextSecurePreferences.getProfileName(getContext())); + } + + profileNumber.setText(localAddress.toPhoneString()); + } +}