mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 08:02:24 +00:00
Use identicons as profile pictures
This commit is contained in:
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.preferences.widgets;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Outline;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -9,16 +10,15 @@ import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewOutlineProvider;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.lelloman.identicon.drawable.ClassicIdenticonDrawable;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
public class ProfilePreference extends Preference {
|
||||
@@ -65,15 +65,37 @@ public class ProfilePreference extends Preference {
|
||||
public void refresh() {
|
||||
if (profileNumberView == null) return;
|
||||
|
||||
final Address localAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(getContext()));
|
||||
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext());
|
||||
final Address localAddress = Address.fromSerialized(userHexEncodedPublicKey);
|
||||
final String profileName = TextSecurePreferences.getProfileName(getContext());
|
||||
|
||||
avatarView.setOutlineProvider(new ViewOutlineProvider() {
|
||||
|
||||
@Override
|
||||
public void getOutline(View view, Outline outline) {
|
||||
outline.setOval(0, 0, view.getWidth(), view.getHeight());
|
||||
}
|
||||
});
|
||||
avatarView.setClipToOutline(true);
|
||||
avatarView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
avatarView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
ClassicIdenticonDrawable identicon = new ClassicIdenticonDrawable(avatarView.getWidth(), avatarView.getHeight(), userHexEncodedPublicKey.hashCode());
|
||||
avatarView.setImageDrawable(identicon);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
GlideApp.with(getContext().getApplicationContext())
|
||||
.load(new ProfileContactPhoto(localAddress, String.valueOf(TextSecurePreferences.getProfileAvatarId(getContext()))))
|
||||
.error(new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp).asDrawable(getContext(), getContext().getResources().getColor(R.color.grey_400)))
|
||||
.circleCrop()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.into(avatarView);
|
||||
*/
|
||||
|
||||
if (!TextUtils.isEmpty(profileName)) {
|
||||
profileNameView.setText(profileName);
|
||||
|
||||
Reference in New Issue
Block a user