From 2b25ded506ae6c0dd91992ec5bc4ae49234c9843 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Thu, 2 Feb 2023 14:48:45 -0800 Subject: [PATCH] Update notification dot renderer when we update the taskbar icon size. Test: swipe to home with an app that has a notification dot observe no jump in dot size Bug: 264709741 Change-Id: I5d56fe57e74ed7b094477ecd8727152f3f522042 --- .../taskbar/TaskbarActivityContext.java | 28 +++++++++---------- src/com/android/launcher3/DeviceProfile.java | 19 +++++++++++-- .../launcher3/DeviceProfileBaseTest.kt | 4 ++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 20e4b55b6d..d5ae276781 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -285,22 +285,20 @@ public class TaskbarActivityContext extends BaseTaskbarContext { * the icon size */ private void matchDeviceProfile(DeviceProfile originDeviceProfile, Resources resources) { - mDeviceProfile = originDeviceProfile.copy(this); - // Taskbar should match the number of icons of hotseat - mDeviceProfile.numShownHotseatIcons = originDeviceProfile.numShownHotseatIcons; - // Same QSB width to have a smooth animation - mDeviceProfile.hotseatQsbWidth = originDeviceProfile.hotseatQsbWidth; - // Update the size of the icons - updateIconSize(resources); - } + mDeviceProfile = originDeviceProfile.toBuilder(this) + .withDimensionsOverride(deviceProfile -> { + // Taskbar should match the number of icons of hotseat + deviceProfile.numShownHotseatIcons = originDeviceProfile.numShownHotseatIcons; + // Same QSB width to have a smooth animation + deviceProfile.hotseatQsbWidth = originDeviceProfile.hotseatQsbWidth; - - private void updateIconSize(Resources resources) { - mDeviceProfile.iconSizePx = resources.getDimensionPixelSize( - DisplayController.isTransientTaskbar(this) - ? R.dimen.transient_taskbar_icon_size - : R.dimen.taskbar_icon_size); - mDeviceProfile.updateIconSize(1f, resources); + // Update icon size + deviceProfile.iconSizePx = resources.getDimensionPixelSize( + DisplayController.isTransientTaskbar(TaskbarActivityContext.this) + ? R.dimen.transient_taskbar_icon_size + : R.dimen.taskbar_icon_size); + deviceProfile.updateIconSize(1f, resources); + }).build(); } /** diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 9f9c6f9937..0cefb7e666 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -57,6 +57,7 @@ import com.android.launcher3.util.WindowBounds; import java.io.PrintWriter; import java.util.Locale; +import java.util.function.Consumer; @SuppressLint("NewApi") public class DeviceProfile { @@ -67,6 +68,7 @@ public class DeviceProfile { public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f); public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE; + public static final Consumer DEFAULT_DIMENSION_PROVIDER = dp -> {}; // Ratio of empty space, qsb should take up to appear visually centered. private final float mQsbCenterFactor; @@ -271,7 +273,8 @@ public class DeviceProfile { DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds, SparseArray dotRendererCache, boolean isMultiWindowMode, boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode, - @NonNull final ViewScaleProvider viewScaleProvider) { + @NonNull final ViewScaleProvider viewScaleProvider, + @NonNull final Consumer dimensionOverrideProvider) { this.inv = inv; this.isLandscape = windowBounds.isLandscape(); @@ -571,6 +574,8 @@ public class DeviceProfile { mViewScaleProvider = viewScaleProvider; + dimensionOverrideProvider.accept(this); + // This is done last, after iconSizePx is calculated above. mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache); mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache); @@ -1752,6 +1757,8 @@ public class DeviceProfile { private SparseArray mDotRendererCache; + private Consumer mOverrideProvider; + public Builder(Context context, InvariantDeviceProfile inv, Info info) { mContext = context; mInv = inv; @@ -1788,6 +1795,11 @@ public class DeviceProfile { return this; } + public Builder withDimensionsOverride(Consumer overrideProvider) { + mOverrideProvider = overrideProvider; + return this; + } + /** * Set the viewScaleProvider for the builder * @@ -1817,9 +1829,12 @@ public class DeviceProfile { if (mViewScaleProvider == null) { mViewScaleProvider = DEFAULT_PROVIDER; } + if (mOverrideProvider == null) { + mOverrideProvider = DEFAULT_DIMENSION_PROVIDER; + } return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache, mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay, - mIsGestureMode, mViewScaleProvider); + mIsGestureMode, mViewScaleProvider, mOverrideProvider); } } diff --git a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt index b7d0f2856f..0aecfb2c35 100644 --- a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt +++ b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt @@ -20,6 +20,7 @@ import android.graphics.PointF import android.graphics.Rect import android.util.SparseArray import androidx.test.core.app.ApplicationProvider +import com.android.launcher3.DeviceProfile.DEFAULT_DIMENSION_PROVIDER import com.android.launcher3.DeviceProfile.DEFAULT_PROVIDER import com.android.launcher3.util.DisplayController.Info import com.android.launcher3.util.WindowBounds @@ -60,7 +61,8 @@ abstract class DeviceProfileBaseTest { transposeLayoutWithOrientation, useTwoPanels, isGestureMode, - DEFAULT_PROVIDER + DEFAULT_PROVIDER, + DEFAULT_DIMENSION_PROVIDER ) protected fun initializeVarsForPhone(