From 158caf466c5c87c7d2ffde582d9fd243d0e0d0f1 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Tue, 24 May 2022 17:09:32 +0100 Subject: [PATCH] Only setup SecondaryDropTarget in onDragStart - In LauncherAccessibilityDelegate.getsupportedActions, it calls supportsAccessibilityDrop on each button regardless if DropTargetBar is visible or not. SecondaryDropTarget.supportsAccessibilityDrop attempts to setupUi which causes measure/layout of DropTargetBar (as well as DragLayer) each time LauncherAccessibilityDelegate.getsupportedActions is called - To avoid this, only setupUi in onDragStart. In other cases don't call setUi. - Also fixed a bug that when accessibility is on, upon dragging a suggested app, the secondary action suddenly changed to Uninstall Fix: 233383721 Test: Enable accessibility, observe no excessive amount of onLayout is called on DropTargetBar Change-Id: I4d1a00d320cceed81fa1312b5fc5f1081637bea8 --- .../android/launcher3/ButtonDropTarget.java | 12 +++++- .../android/launcher3/DeleteDropTarget.java | 3 ++ .../launcher3/SecondaryDropTarget.java | 37 +++++++++++++------ .../LauncherAccessibilityDelegate.java | 1 + 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index 8da4f053df..3b24df2f18 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -179,7 +179,12 @@ public abstract class ButtonDropTarget extends TextView @Override public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { - mActive = !options.isKeyboardDrag && supportsDrop(dragObject.dragInfo); + if (options.isKeyboardDrag) { + mActive = false; + } else { + setupItemInfo(dragObject.dragInfo); + mActive = supportsDrop(dragObject.dragInfo); + } setVisibility(mActive ? View.VISIBLE : View.GONE); mAccessibleDrag = options.isAccessibleDrag; @@ -191,6 +196,11 @@ public abstract class ButtonDropTarget extends TextView return supportsDrop(dragObject.dragInfo); } + /** + * Setups button for the specified ItemInfo. + */ + protected abstract void setupItemInfo(ItemInfo info); + protected abstract boolean supportsDrop(ItemInfo info); public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view); diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index 371bb80484..95d3ad9dbb 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -84,6 +84,9 @@ public class DeleteDropTarget extends ButtonDropTarget { return LauncherAccessibilityDelegate.REMOVE; } + @Override + protected void setupItemInfo(ItemInfo info) {} + @Override protected boolean supportsDrop(ItemInfo info) { return true; diff --git a/src/com/android/launcher3/SecondaryDropTarget.java b/src/com/android/launcher3/SecondaryDropTarget.java index 5b037e4db8..f8bc1f4e6e 100644 --- a/src/com/android/launcher3/SecondaryDropTarget.java +++ b/src/com/android/launcher3/SecondaryDropTarget.java @@ -6,6 +6,7 @@ import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURA import static com.android.launcher3.Launcher.REQUEST_RECONFIGURE_APPWIDGET; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DISMISS_PREDICTION; +import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.INVALID; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_DISMISS_PREDICTION_UNDO; @@ -69,6 +70,7 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList private boolean mHadPendingAlarm; protected int mCurrentAccessibilityAction = -1; + public SecondaryDropTarget(Context context, AttributeSet attrs) { this(context, attrs, 0); } @@ -133,25 +135,34 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList return mCurrentAccessibilityAction; } + @Override + protected void setupItemInfo(ItemInfo info) { + int buttonType = getButtonType(info, getViewUnderDrag(info)); + if (buttonType != INVALID) { + setupUi(buttonType); + } + } + @Override protected boolean supportsDrop(ItemInfo info) { - return supportsAccessibilityDrop(info, getViewUnderDrag(info)); + return getButtonType(info, getViewUnderDrag(info)) != INVALID; } @Override public boolean supportsAccessibilityDrop(ItemInfo info, View view) { + return getButtonType(info, view) != INVALID; + } + + private int getButtonType(ItemInfo info, View view) { if (view instanceof AppWidgetHostView) { if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) { - setupUi(RECONFIGURE); - return true; + return RECONFIGURE; } - return false; + return INVALID; } else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) { - setupUi(DISMISS_PREDICTION); - return true; + return DISMISS_PREDICTION; } - setupUi(UNINSTALL); Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user); if (uninstallDisabled == null) { UserManager userManager = @@ -165,16 +176,20 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT); mCacheExpireAlarm.setOnAlarmListener(this); if (uninstallDisabled) { - return false; + return INVALID; } if (info instanceof ItemInfoWithIcon) { ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info; - if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) { - return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0; + if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0 + && (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) == 0) { + return INVALID; } } - return getUninstallTarget(info) != null; + if (getUninstallTarget(info) == null) { + return INVALID; + } + return UNINSTALL; } /** diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index 44d57d7a6b..79214e896a 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -60,6 +60,7 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate