From 9dbbd01204d349f51c766e86bbcb0b4668889324 Mon Sep 17 00:00:00 2001 From: minch Date: Thu, 23 Jan 2025 19:05:09 +0000 Subject: [PATCH] Add `offsetTranslationX` for the AddDesktopButton Apply the `offsetTranslationX` to the AddDesktopButton inside `updatePageOffsets`, so the button can be set to offscreen when needed. This requires us to differentiate the `gridTranslationX` and the `offsetTranslationX` for this button as well. Flag: com.android.window.flags.enable_multiple_desktops_frontend com.android.window.flags.enable_multiple_desktops_backend Fix: 389209282 Test: Manual Change-Id: Id157c41577b2f47b220558b353f07a4ecb0ec3b5 --- .../quickstep/views/AddDesktopButton.kt | 25 +++++++++++++++++++ .../android/quickstep/views/RecentsView.java | 8 +++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt b/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt index 1dab18a251..e353160c0c 100644 --- a/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt +++ b/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt @@ -21,7 +21,9 @@ import android.graphics.drawable.ShapeDrawable import android.graphics.drawable.shapes.RoundRectShape import android.util.AttributeSet import android.widget.ImageButton +import com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X import com.android.launcher3.R +import com.android.launcher3.util.MultiPropertyFactory /** * Button for supporting multiple desktop sessions. The button will be next to the first TaskView @@ -30,6 +32,29 @@ import com.android.launcher3.R class AddDesktopButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ImageButton(context, attrs) { + private enum class TranslationX { + GRID, + OFFSET, + } + + private val multiTranslationX = + MultiPropertyFactory(this, VIEW_TRANSLATE_X, TranslationX.entries.size) { a: Float, b: Float + -> + a + b + } + + var gridTranslationX + get() = multiTranslationX[TranslationX.GRID.ordinal].value + set(value) { + multiTranslationX[TranslationX.GRID.ordinal].value = value + } + + var offsetTranslationX + get() = multiTranslationX[TranslationX.OFFSET.ordinal].value + set(value) { + multiTranslationX[TranslationX.OFFSET.ordinal].value = value + } + override fun onFinishInflate() { super.onFinishInflate() diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 684e84a480..f727d4f81f 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -3466,7 +3466,7 @@ public abstract class RecentsView< // `mAddDesktopButton`, shift `mAddDesktopButton` to accommodate. translationX += largeTaskWidthAndSpacing; } - mAddDesktopButton.setTranslationX(translationX); + mAddDesktopButton.setGridTranslationX(translationX); } final TaskView runningTask = getRunningTaskView(); @@ -4972,8 +4972,8 @@ public abstract class RecentsView< } else if (child instanceof ClearAllButton) { getPagedOrientationHandler().getPrimaryViewTranslate().set(child, totalTranslationX); - } else { - // TODO(b/389209581): Handle the page offsets update of the 'mAddDesktopButton'. + } else if (child instanceof AddDesktopButton addDesktopButton) { + addDesktopButton.setOffsetTranslationX(totalTranslationX); } if (mEnableDrawingLiveTile && i == getRunningTaskIndex()) { runActionOnRemoteHandles( @@ -6156,7 +6156,7 @@ public abstract class RecentsView< if (addDesktopButtonIndex != -1 && addDesktopButtonIndex < outPageScrolls.length) { outPageScrolls[addDesktopButtonIndex] = newPageScrolls[addDesktopButtonIndex] + Math.round( - mAddDesktopButton.getTranslationX()); + mAddDesktopButton.getGridTranslationX()); } int lastTaskScroll = getLastTaskScroll(clearAllScroll, clearAllWidth);