diff options
| author | 2024-11-15 10:47:07 +0000 | |
|---|---|---|
| committer | 2024-11-15 14:40:47 +0000 | |
| commit | aaac334a66a1fc270aae4dc3a7c83e70ef81b05c (patch) | |
| tree | d4f7f9235b9912a0a4b63829fb6c09fdf96fbbd9 | |
| parent | d984fd621ea94b1fba78cd647ec94fa1ec140d88 (diff) | |
[Minimal HUN] Clean up circle cropping from NotificationRowIconView
NotificationRowIconView represents small notification and it is not meant to be used to render conversation avatar.
When we enable app icon refactor, minimal hun users will not see the conversation avatar for 1-1 conversations instead application icon.
This CL cleans up circulation logic from NotificationRowIconView.java and Notification.java. Circle cropping is done in xml with background and clipToOutline
Bug: 270709257
Bug: 379253524
Test: Post a conversation notification with  Notify2 and see that icon is circular in minimal HUN.
Flag: EXEMPT trivial change
Change-Id: I1453e4c01a08eefbb8c59a9f15baa1532513643e
3 files changed, 3 insertions, 86 deletions
| diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 3d9c55c0f37a..193fe22fb8e1 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -9499,7 +9499,6 @@ public class Notification implements Parcelable                  contentView.setViewVisibility(R.id.icon, View.GONE);                  contentView.setViewVisibility(R.id.conversation_face_pile, View.GONE);                  contentView.setViewVisibility(R.id.conversation_icon, View.VISIBLE); -                contentView.setBoolean(R.id.conversation_icon, "setApplyCircularCrop", true);                  contentView.setImageViewIcon(R.id.conversation_icon, conversationIcon);              } else if (mIsGroupConversation) {                  contentView.setViewVisibility(R.id.icon, View.GONE); diff --git a/core/java/com/android/internal/widget/NotificationRowIconView.java b/core/java/com/android/internal/widget/NotificationRowIconView.java index 5fc61b00e331..c96e979138dd 100644 --- a/core/java/com/android/internal/widget/NotificationRowIconView.java +++ b/core/java/com/android/internal/widget/NotificationRowIconView.java @@ -19,12 +19,7 @@ package com.android.internal.widget;  import android.annotation.Nullable;  import android.app.Flags;  import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapShader; -import android.graphics.Canvas; -import android.graphics.Paint;  import android.graphics.Rect; -import android.graphics.drawable.BitmapDrawable;  import android.graphics.drawable.Drawable;  import android.graphics.drawable.Icon;  import android.util.AttributeSet; @@ -41,7 +36,6 @@ import android.widget.RemoteViews;  public class NotificationRowIconView extends CachingIconView {      private NotificationIconProvider mIconProvider; -    private boolean mApplyCircularCrop = false;      private Drawable mAppIcon = null;      // Padding, background and colors set on the view prior to being overridden when showing the app @@ -221,84 +215,6 @@ public class NotificationRowIconView extends CachingIconView {          }      } -    @Nullable -    @Override -    Drawable loadSizeRestrictedIcon(@Nullable Icon icon) { -        final Drawable original = super.loadSizeRestrictedIcon(icon); -        final Drawable result; -        if (mApplyCircularCrop) { -            result = makeCircularDrawable(original); -        } else { -            result = original; -        } - -        return result; -    } - -    /** -     * Enables circle crop that makes given image circular -     */ -    @RemotableViewMethod(asyncImpl = "setApplyCircularCropAsync") -    public void setApplyCircularCrop(boolean applyCircularCrop) { -        mApplyCircularCrop = applyCircularCrop; -    } - -    /** -     * Async version of {@link NotificationRowIconView#setApplyCircularCrop} -     */ -    public Runnable setApplyCircularCropAsync(boolean applyCircularCrop) { -        mApplyCircularCrop = applyCircularCrop; -        return () -> { -        }; -    } - -    @Nullable -    private Drawable makeCircularDrawable(@Nullable Drawable original) { -        if (original == null) { -            return original; -        } - -        final Bitmap source = drawableToBitmap(original); - -        int size = Math.min(source.getWidth(), source.getHeight()); - -        Bitmap squared = Bitmap.createScaledBitmap(source, size, size, /* filter= */ false); -        Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); - -        final Canvas canvas = new Canvas(result); -        final Paint paint = new Paint(); -        paint.setShader( -                new BitmapShader(squared, BitmapShader.TileMode.CLAMP, -                        BitmapShader.TileMode.CLAMP)); -        paint.setAntiAlias(true); -        float radius = size / 2f; -        canvas.drawCircle(radius, radius, radius, paint); -        return new BitmapDrawable(getResources(), result); -    } - -    private static Bitmap drawableToBitmap(Drawable drawable) { -        if (drawable instanceof BitmapDrawable bitmapDrawable) { -            final Bitmap bitmap = bitmapDrawable.getBitmap(); -            if (bitmap.getConfig() == Bitmap.Config.HARDWARE) { -                return bitmap.copy(Bitmap.Config.ARGB_8888, false); -            } else { -                return bitmap; -            } -        } - -        int width = drawable.getIntrinsicWidth(); -        width = width > 0 ? width : 1; -        int height = drawable.getIntrinsicHeight(); -        height = height > 0 ? height : 1; - -        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); -        Canvas canvas = new Canvas(bitmap); -        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); -        drawable.draw(canvas); - -        return bitmap; -    } -      /**       * A provider that allows this view to verify whether it should use the app icon instead of the       * icon provided to it via setImageIcon, as well as actually fetching the app icon. It should diff --git a/core/res/res/layout/notification_template_material_messaging_compact_heads_up.xml b/core/res/res/layout/notification_template_material_messaging_compact_heads_up.xml index 82920bad95cd..149a5a9568f2 100644 --- a/core/res/res/layout/notification_template_material_messaging_compact_heads_up.xml +++ b/core/res/res/layout/notification_template_material_messaging_compact_heads_up.xml @@ -34,12 +34,14 @@          android:maxDrawableWidth="@dimen/notification_icon_circle_size"          android:maxDrawableHeight="@dimen/notification_icon_circle_size"          /> -    <com.android.internal.widget.NotificationRowIconView +    <com.android.internal.widget.CachingIconView          android:id="@+id/conversation_icon"          android:layout_width="@dimen/notification_icon_circle_size"          android:layout_height="@dimen/notification_icon_circle_size"          android:layout_gravity="center_vertical|start"          android:layout_marginStart="@dimen/notification_icon_circle_start" +        android:background="@drawable/notification_icon_circle" +        android:clipToOutline="true"          android:maxDrawableWidth="@dimen/notification_icon_circle_size"          android:maxDrawableHeight="@dimen/notification_icon_circle_size"          android:scaleType="centerCrop" |