This commit is contained in:
Andrew 2023-10-16 16:13:44 +02:00 committed by GitHub
commit e6383569e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import android.graphics.drawable.LayerDrawable;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.appcompat.content.res.AppCompatResources;
import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.TextDrawable;
import com.makeramen.roundedimageview.RoundedDrawable; import com.makeramen.roundedimageview.RoundedDrawable;
@ -31,7 +32,7 @@ public class ResourceContactPhoto implements FallbackContactPhoto {
@Override @Override
public Drawable asDrawable(Context context, int color, boolean inverted) { public Drawable asDrawable(Context context, int color, boolean inverted) {
Drawable background = TextDrawable.builder().buildRound(" ", inverted ? Color.WHITE : color); Drawable background = TextDrawable.builder().buildRound(" ", inverted ? Color.WHITE : color);
RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(context.getResources().getDrawable(resourceId)); RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(AppCompatResources.getDrawable(context, resourceId);
foreground.setScaleType(ImageView.ScaleType.CENTER_CROP); foreground.setScaleType(ImageView.ScaleType.CENTER_CROP);
@ -39,8 +40,10 @@ public class ResourceContactPhoto implements FallbackContactPhoto {
foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
} }
Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark Drawable gradient = AppCompatResources.getDrawable(
: R.drawable.avatar_gradient_light); context,
ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark : R.drawable.avatar_gradient_light
);
return new ExpandingLayerDrawable(new Drawable[] {background, foreground, gradient}); return new ExpandingLayerDrawable(new Drawable[] {background, foreground, gradient});
} }