From 5711adb2c9bb0498f6cf55e71ea2f4bb97e48801 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sun, 15 Oct 2017 10:00:03 -0700 Subject: [PATCH] Fix profile out of memory errors on low mem devices Fixes #7094 // FREEBIE --- res/values/dimens.xml | 2 +- .../RecipientPreferenceActivity.java | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 2e50505b35..72b4318cdd 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -13,7 +13,7 @@ 200sp 2dp 2dp - 300dp + 64dp 50dp 230dp 8dp diff --git a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java index 0bd0ea55ea..7759a8e8b7 100644 --- a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java +++ b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java @@ -13,6 +13,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.provider.ContactsContract; import android.provider.Settings; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -26,6 +27,7 @@ import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceCategory; import android.support.v7.widget.Toolbar; +import android.util.DisplayMetrics; import android.util.Log; import android.view.MenuItem; import android.view.View; @@ -37,6 +39,7 @@ 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.contacts.avatars.ContactPhotoFactory; import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.database.Address; @@ -205,15 +208,29 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi } private void setHeader(@NonNull Recipient recipient) { - ContactPhoto contactPhoto = recipient.getContactPhoto(); + new AsyncTask() { + @Override + protected @NonNull ContactPhoto doInBackground(Void... params) { + DisplayMetrics metrics = new DisplayMetrics(); + WindowManager windowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE); + Uri contentUri = ContactsContract.Contacts.lookupContact(getContentResolver(), recipient.getContactUri()); + windowManager.getDefaultDisplay().getMetrics(metrics); - if (contactPhoto.isGenerated() || contactPhoto.isResource()) this.avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP); + return ContactPhotoFactory.getContactPhoto(RecipientPreferenceActivity.this, contentUri, + recipient.getAddress(), recipient.getName(), + metrics.widthPixels); + } - 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)); + protected void onPostExecute(@NonNull ContactPhoto contactPhoto) { + if (contactPhoto.isGenerated() || contactPhoto.isResource()) avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE); + else avatar.setScaleType(ImageView.ScaleType.CENTER_CROP); + + avatar.setImageDrawable(contactPhoto.asCallCard(RecipientPreferenceActivity.this)); + avatar.setBackgroundColor(recipient.getColor().toActionBarColor(RecipientPreferenceActivity.this)); + toolbarLayout.setTitle(recipient.toShortString()); + toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(RecipientPreferenceActivity.this)); + } + }.execute(); } @Override