From ac9df38e9f5e73661d5a2fcee40df09788885a04 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Mon, 2 Aug 2021 19:08:41 +0100 Subject: [PATCH] Make icon drawable for non-focused grid tasks smaller - Center the icon drawable in center of IconView with and allow a smlaler size to be set Bug: 194194694 Test: dismiss focus task, swipe from app etc. Change-Id: I2855249b13e2ccdb45f101bfb7afef4311f7b46f --- quickstep/res/values/dimens.xml | 2 ++ .../com/android/quickstep/views/IconView.java | 25 +++++++++++++++++-- .../com/android/quickstep/views/TaskView.java | 11 +++++--- res/values/dimens.xml | 3 ++- src/com/android/launcher3/DeviceProfile.java | 6 +++++ 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 4e97fbd961..659ff9a06a 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -16,6 +16,8 @@ 48dp + 48dp + 32dp 2dp diff --git a/quickstep/src/com/android/quickstep/views/IconView.java b/quickstep/src/com/android/quickstep/views/IconView.java index 5b0ade0d17..813e653c85 100644 --- a/quickstep/src/com/android/quickstep/views/IconView.java +++ b/quickstep/src/com/android/quickstep/views/IconView.java @@ -17,8 +17,10 @@ package com.android.quickstep.views; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.view.Gravity; import android.view.View; import com.android.launcher3.Utilities; @@ -30,6 +32,7 @@ import com.android.launcher3.Utilities; public class IconView extends View { private Drawable mDrawable; + private int mDrawableWidth, mDrawableHeight; public IconView(Context context) { super(context); @@ -50,11 +53,29 @@ public class IconView extends View { mDrawable = d; if (mDrawable != null) { mDrawable.setCallback(this); - mDrawable.setBounds(0, 0, getWidth(), getHeight()); + setDrawableSizeInternal(getWidth(), getHeight()); } invalidate(); } + /** + * Sets the size of the icon drawable. + */ + public void setDrawableSize(int iconWidth, int iconHeight) { + mDrawableWidth = iconWidth; + mDrawableHeight = iconHeight; + if (mDrawable != null) { + setDrawableSizeInternal(getWidth(), getHeight()); + } + } + + private void setDrawableSizeInternal(int selfWidth, int selfHeight) { + Rect selfRect = new Rect(0, 0, selfWidth, selfHeight); + Rect drawableRect = new Rect(); + Gravity.apply(Gravity.CENTER, mDrawableWidth, mDrawableHeight, selfRect, drawableRect); + mDrawable.setBounds(drawableRect); + } + public Drawable getDrawable() { return mDrawable; } @@ -63,7 +84,7 @@ public class IconView extends View { protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (mDrawable != null) { - mDrawable.setBounds(0, 0, w, h); + setDrawableSizeInternal(w, h); } } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java index ec08280b77..02c5d84948 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/src/com/android/quickstep/views/TaskView.java @@ -1353,9 +1353,10 @@ public class TaskView extends FrameLayout implements Reusable { float boxTranslationY; int expectedWidth; int expectedHeight; - if (mActivity.getDeviceProfile().overviewShowAsGrid) { - final int thumbnailPadding = - mActivity.getDeviceProfile().overviewTaskThumbnailTopMarginPx; + int iconDrawableSize; + DeviceProfile deviceProfile = mActivity.getDeviceProfile(); + if (deviceProfile.overviewShowAsGrid) { + final int thumbnailPadding = deviceProfile.overviewTaskThumbnailTopMarginPx; final Rect lastComputedTaskSize = getRecentsView().getLastComputedTaskSize(); final int taskWidth = lastComputedTaskSize.width(); final int taskHeight = lastComputedTaskSize.height(); @@ -1368,11 +1369,13 @@ public class TaskView extends FrameLayout implements Reusable { // that is associated with the original orientation of the focused task. boxWidth = taskWidth; boxHeight = taskHeight; + iconDrawableSize = deviceProfile.overviewTaskIconDrawableSizePx; } else { // Otherwise task is in grid, and should use lastComputedGridTaskSize. Rect lastComputedGridTaskSize = getRecentsView().getLastComputedGridTaskSize(); boxWidth = lastComputedGridTaskSize.width(); boxHeight = lastComputedGridTaskSize.height(); + iconDrawableSize = deviceProfile.overviewTaskIconDrawableSizeGridPx; } // Bound width/height to the box size. @@ -1389,6 +1392,7 @@ public class TaskView extends FrameLayout implements Reusable { boxTranslationY = 0f; expectedWidth = ViewGroup.LayoutParams.MATCH_PARENT; expectedHeight = ViewGroup.LayoutParams.MATCH_PARENT; + iconDrawableSize = deviceProfile.overviewTaskIconDrawableSizePx; } setNonGridScale(nonGridScale); @@ -1398,6 +1402,7 @@ public class TaskView extends FrameLayout implements Reusable { params.height = expectedHeight; setLayoutParams(params); } + mIconView.setDrawableSize(iconDrawableSize, iconDrawableSize); } private float getGridTrans(float endTranslation) { diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 838d0ec84f..da3725005c 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -324,7 +324,8 @@ 0dp - 0dp + 0dp + 0dp 0dp 0dp 0dp diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index d2d00c8554..d0d461d3ec 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -184,6 +184,8 @@ public class DeviceProfile { public final boolean overviewShowAsGrid; public int overviewTaskMarginPx; public int overviewTaskIconSizePx; + public int overviewTaskIconDrawableSizePx; + public int overviewTaskIconDrawableSizeGridPx; public int overviewTaskThumbnailTopMarginPx; public final int overviewActionsMarginThreeButtonPx; public final int overviewActionsTopMarginGesturePx; @@ -362,6 +364,10 @@ public class DeviceProfile { ? res.getDimensionPixelSize(R.dimen.overview_task_margin_grid) : res.getDimensionPixelSize(R.dimen.overview_task_margin); overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size); + overviewTaskIconDrawableSizePx = + res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size); + overviewTaskIconDrawableSizeGridPx = + res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid); overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2; if (overviewShowAsGrid) { if (isLandscape) {