Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0641844a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Clean up conversation icon" into rvc-dev am: d06c0497

Change-Id: I79f96eaca178ab9047c56c8cda0abf60356e9500
parents 34cdd2a8 d06c0497
Loading
Loading
Loading
Loading
+39 −23
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutInfo;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Rect;
@@ -40,18 +41,31 @@ import com.android.settingslib.R;
 * also includes shadows, which are only appropriate on top of wallpaper, not embedded in UI.
 * also includes shadows, which are only appropriate on top of wallpaper, not embedded in UI.
 */
 */
public class ConversationIconFactory extends BaseIconFactory {
public class ConversationIconFactory extends BaseIconFactory {
    // Geometry of the various parts of the design. All values are 1dp on a 48x48dp icon grid.
    // Geometry of the various parts of the design. All values are 1dp on a 56x56dp icon grid.
    // Space is left around the "head" (main avatar) for
    // Space is left around the "head" (main avatar) for
    // ........
    // ........
    // .HHHHHH.
    // .HHHHHH.
    // .HHHrrrr
    // .HHHrrrr
    // .HHHrBBr
    // .HHHrBBr
    // ....rrrr
    // ....rrrr

    // This is trying to recreate the view layout in notification_template_material_conversation.xml
    private static final float BASE_ICON_SIZE = 48f;

    private static final float RING_STROKE_WIDTH = 2f;
    private static final float HEAD_SIZE = 52f;
    private static final float HEAD_SIZE = BASE_ICON_SIZE - RING_STROKE_WIDTH * 2 - 2; // 40
    private static final float BADGE_SIZE = 12f;
    private static final float BADGE_SIZE = HEAD_SIZE * 0.4f; // 16
    private static final float BADGE_CENTER = 46f;
    private static final float CIRCLE_MARGIN = 36f;
    private static final float BADGE_ORIGIN = HEAD_SIZE - BADGE_SIZE; // 40f
    private static final float BASE_ICON_SIZE = 56f;

    private static final float OUT_CIRCLE_DIA = (BASE_ICON_SIZE - CIRCLE_MARGIN); // 20f
    private static final float INN_CIRCLE_DIA = (float) Math.sqrt(2 * BADGE_SIZE * BADGE_SIZE) ;
    private static final float OUT_CIRCLE_RAD = OUT_CIRCLE_DIA / 2;
    private static final float INN_CIRCLE_RAD = INN_CIRCLE_DIA / 2;
    // Android draws strokes centered on the radius, so our actual radius is an avg of the outside
    // and inside of the ring stroke
    private static final float CIRCLE_RADIUS =
            INN_CIRCLE_RAD + ((OUT_CIRCLE_RAD - INN_CIRCLE_RAD) / 2);
    private static final float RING_STROKE_WIDTH = (OUT_CIRCLE_DIA - INN_CIRCLE_DIA) / 2;


    final LauncherApps mLauncherApps;
    final LauncherApps mLauncherApps;
    final PackageManager mPackageManager;
    final PackageManager mPackageManager;
@@ -125,6 +139,7 @@ public class ConversationIconFactory extends BaseIconFactory {
        private int mIconSize;
        private int mIconSize;
        private Paint mRingPaint;
        private Paint mRingPaint;
        private boolean mShowRing;
        private boolean mShowRing;
        private Paint mPaddingPaint;


        public ConversationIconDrawable(Drawable baseIcon,
        public ConversationIconDrawable(Drawable baseIcon,
                Drawable badgeIcon,
                Drawable badgeIcon,
@@ -138,6 +153,9 @@ public class ConversationIconFactory extends BaseIconFactory {
            mRingPaint = new Paint();
            mRingPaint = new Paint();
            mRingPaint.setStyle(Paint.Style.STROKE);
            mRingPaint.setStyle(Paint.Style.STROKE);
            mRingPaint.setColor(ringColor);
            mRingPaint.setColor(ringColor);
            mPaddingPaint = new Paint();
            mPaddingPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mPaddingPaint.setColor(Color.WHITE);
        }
        }


        /**
        /**
@@ -165,40 +183,38 @@ public class ConversationIconFactory extends BaseIconFactory {
        public void draw(Canvas canvas) {
        public void draw(Canvas canvas) {
            final Rect bounds = getBounds();
            final Rect bounds = getBounds();


            // scale to our internal 48x48 grid
            // scale to our internal grid
            final float scale = bounds.width() / BASE_ICON_SIZE;
            final float scale = bounds.width() / BASE_ICON_SIZE;
            final int centerX = bounds.centerX();
            final int centerY = bounds.centerX();
            final int ringStrokeWidth = (int) (RING_STROKE_WIDTH * scale);
            final int ringStrokeWidth = (int) (RING_STROKE_WIDTH * scale);
            final int headSize = (int) (HEAD_SIZE * scale);
            final int headSize = (int) (HEAD_SIZE * scale);
            final int badgeSize = (int) (BADGE_SIZE * scale);
            final int badgePadding = (int) (BADGE_ORIGIN * scale);
            final int badgeCenter = (int) (BADGE_CENTER * scale);


            mPaddingPaint.setStrokeWidth(ringStrokeWidth);
            final float radius = (int) (CIRCLE_RADIUS * scale); // stroke outside
            if (mBaseIcon != null) {
            if (mBaseIcon != null) {
                mBaseIcon.setBounds(
                mBaseIcon.setBounds(0,
                        centerX - headSize / 2,
                        0,
                        centerY - headSize / 2,
                        headSize ,
                        centerX + headSize / 2,
                        headSize);
                        centerY + headSize / 2);
                mBaseIcon.draw(canvas);
                mBaseIcon.draw(canvas);
            } else {
            } else {
                Log.w("ConversationIconFactory", "ConversationIconDrawable has null base icon");
                Log.w("ConversationIconFactory", "ConversationIconDrawable has null base icon");
            }
            }
            if (mBadgeIcon != null) {
            if (mBadgeIcon != null) {
                canvas.drawCircle(badgeCenter, badgeCenter, radius, mPaddingPaint);
                mBadgeIcon.setBounds(
                mBadgeIcon.setBounds(
                        bounds.right - badgeSize - ringStrokeWidth,
                        badgePadding,
                        bounds.bottom - badgeSize - ringStrokeWidth,
                        badgePadding,
                        bounds.right - ringStrokeWidth,
                        headSize,
                        bounds.bottom - ringStrokeWidth);
                        headSize);
                mBadgeIcon.draw(canvas);
                mBadgeIcon.draw(canvas);
            } else {
            } else {
                Log.w("ConversationIconFactory", "ConversationIconDrawable has null badge icon");
                Log.w("ConversationIconFactory", "ConversationIconDrawable has null badge icon");
            }
            }
            if (mShowRing) {
            if (mShowRing) {
                mRingPaint.setStrokeWidth(ringStrokeWidth);
                mRingPaint.setStrokeWidth(ringStrokeWidth);
                final float radius = badgeSize * 0.5f + ringStrokeWidth * 0.5f; // stroke outside
                canvas.drawCircle(badgeCenter, badgeCenter, radius, mRingPaint);
                final float cx = bounds.right - badgeSize * 0.5f - ringStrokeWidth;
                final float cy = bounds.bottom - badgeSize * 0.5f - ringStrokeWidth;
                canvas.drawCircle(cx, cy, radius, mRingPaint);
            }
            }
        }
        }


+7 −7
Original line number Original line Diff line number Diff line
@@ -21,33 +21,33 @@
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusable="true"
    android:clipChildren="false"
    android:clipChildren="true"
    android:clipToPadding="true"
    android:clipToPadding="true"
    android:orientation="vertical"
    android:orientation="vertical"
    android:background="@color/notification_material_background_color"
    android:background="@color/notification_material_background_color"
    android:paddingStart="@*android:dimen/notification_content_margin_start">
    android:paddingStart="12dp">


    <!-- Package Info -->
    <!-- Package Info -->
    <LinearLayout
    <LinearLayout
        android:id="@+id/header"
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="@dimen/notification_guts_conversation_header_height"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:gravity="center_vertical"
        android:clipChildren="false"
        android:clipChildren="false"
        android:clipToPadding="false">
        android:paddingTop="8dp"
        android:clipToPadding="true">
        <ImageView
        <ImageView
            android:id="@+id/conversation_icon"
            android:id="@+id/conversation_icon"
            android:layout_width="@dimen/notification_guts_conversation_icon_size"
            android:layout_width="@dimen/notification_guts_conversation_icon_size"
            android:layout_height="@dimen/notification_guts_conversation_icon_size"
            android:layout_height="@dimen/notification_guts_conversation_icon_size"
            android:layout_centerVertical="true"
            android:layout_centerVertical="false"
            android:layout_alignParentStart="true"
            android:layout_alignParentStart="true"
            android:layout_marginEnd="15dp" />
            android:layout_marginEnd="12dp" />
        <LinearLayout
        <LinearLayout
            android:id="@+id/names"
            android:id="@+id/names"
            android:layout_weight="1"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_width="0dp"
            android:orientation="vertical"
            android:orientation="vertical"

            android:layout_height="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="@dimen/notification_guts_conversation_icon_size"
            android:minHeight="@dimen/notification_guts_conversation_icon_size"
            android:layout_centerVertical="true"
            android:layout_centerVertical="true"
+1 −1
Original line number Original line Diff line number Diff line
@@ -221,7 +221,7 @@
    <dimen name="notification_guts_button_horizontal_spacing">8dp</dimen>
    <dimen name="notification_guts_button_horizontal_spacing">8dp</dimen>


    <dimen name="notification_guts_conversation_header_height">84dp</dimen>
    <dimen name="notification_guts_conversation_header_height">84dp</dimen>
    <dimen name="notification_guts_conversation_icon_size">52dp</dimen>
    <dimen name="notification_guts_conversation_icon_size">56dp</dimen>
    <dimen name="notification_guts_conversation_action_height">56dp</dimen>
    <dimen name="notification_guts_conversation_action_height">56dp</dimen>
    <dimen name="notification_guts_conversation_action_text_padding_start">32dp</dimen>
    <dimen name="notification_guts_conversation_action_text_padding_start">32dp</dimen>