mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 18:57:43 +00:00
Update fallback avatars.
This commit is contained in:
parent
bab92fca7b
commit
a3cba66450
11
res/drawable/avatar_gradient_dark.xml
Normal file
11
res/drawable/avatar_gradient_dark.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:startColor="@color/transparent_black_30"
|
||||
android:endColor="@color/transparent_black" />
|
||||
|
||||
</shape>
|
11
res/drawable/avatar_gradient_light.xml
Normal file
11
res/drawable/avatar_gradient_light.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:startColor="@color/transparent_white_30"
|
||||
android:endColor="@color/transparent" />
|
||||
|
||||
</shape>
|
@ -68,6 +68,10 @@ public enum MaterialColor {
|
||||
return context.getResources().getColor(mainColor);
|
||||
}
|
||||
|
||||
public @ColorInt int toAvatarColor(@NonNull Context context) {
|
||||
return context.getResources().getColor(isDarkTheme(context) ? shadeColor : mainColor);
|
||||
}
|
||||
|
||||
public @ColorInt int toActionBarColor(@NonNull Context context) {
|
||||
return context.getResources().getColor(mainColor);
|
||||
}
|
||||
|
@ -2,20 +2,25 @@ package org.thoughtcrime.securesms.contacts.avatars;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.content.res.AppCompatResources;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GeneratedContactPhoto implements FallbackContactPhoto {
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile("[^\\p{L}\\p{Nd}\\p{P}\\p{S}]+");
|
||||
private static final Pattern PATTERN = Pattern.compile("[^\\p{L}\\p{Nd}\\p{P}\\p{S}]+");
|
||||
private static final Typeface TYPEFACE = Typeface.create("sans-serif-medium", Typeface.NORMAL);
|
||||
|
||||
private final String name;
|
||||
|
||||
@ -32,22 +37,39 @@ public class GeneratedContactPhoto implements FallbackContactPhoto {
|
||||
public Drawable asDrawable(Context context, int color, boolean inverted) {
|
||||
int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
||||
|
||||
return TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.width(targetSize)
|
||||
.height(targetSize)
|
||||
.textColor(inverted ? color : Color.WHITE)
|
||||
.endConfig()
|
||||
.buildRound(getCharacter(name), inverted ? Color.WHITE : color);
|
||||
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);
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
private String getCharacter(String name) {
|
||||
String cleanedName = PATTERN.matcher(name).replaceFirst("");
|
||||
private String getAbbreviation(String name) {
|
||||
String[] parts = name.split(" ");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
|
||||
if (cleanedName.isEmpty()) {
|
||||
for (int i = 0; i < parts.length && count < 2; i++) {
|
||||
String cleaned = PATTERN.matcher(parts[i]).replaceFirst("");
|
||||
if (!TextUtils.isEmpty(cleaned)) {
|
||||
builder.appendCodePoint(cleaned.codePointAt(0));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (builder.length() == 0) {
|
||||
return "#";
|
||||
} else {
|
||||
return new StringBuilder().appendCodePoint(cleanedName.codePointAt(0)).toString();
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,9 @@ import android.widget.ImageView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.makeramen.roundedimageview.RoundedDrawable;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
|
||||
public class ResourceContactPhoto implements FallbackContactPhoto {
|
||||
|
||||
private final int resourceId;
|
||||
@ -42,7 +45,10 @@ public class ResourceContactPhoto implements FallbackContactPhoto {
|
||||
foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
}
|
||||
|
||||
return new ExpandingLayerDrawable(new Drawable[] {background, foreground});
|
||||
Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark
|
||||
: R.drawable.avatar_gradient_light);
|
||||
|
||||
return new ExpandingLayerDrawable(new Drawable[] {background, foreground, gradient});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -419,7 +419,7 @@ public class Recipient implements RecipientModifiedListener {
|
||||
}
|
||||
|
||||
public synchronized @NonNull Drawable getFallbackContactPhotoDrawable(Context context, boolean inverted) {
|
||||
return getFallbackContactPhoto().asDrawable(context, getColor().toConversationColor(context), inverted);
|
||||
return getFallbackContactPhoto().asDrawable(context, getColor().toAvatarColor(context), inverted);
|
||||
}
|
||||
|
||||
public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user