Merge "Only setup SecondaryDropTarget in onDragStart" into tm-dev am: a2ecf75082 am: 9899c3f028

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/18580266

Change-Id: Ib8da8d3fa08aad0335b9d5cfcf50e2a5c2f12dbd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Alex Chau
2022-05-25 13:24:01 +00:00
committed by Automerger Merge Worker
4 changed files with 41 additions and 12 deletions
@@ -179,7 +179,12 @@ public abstract class ButtonDropTarget extends TextView
@Override @Override
public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { 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); setVisibility(mActive ? View.VISIBLE : View.GONE);
mAccessibleDrag = options.isAccessibleDrag; mAccessibleDrag = options.isAccessibleDrag;
@@ -191,6 +196,11 @@ public abstract class ButtonDropTarget extends TextView
return supportsDrop(dragObject.dragInfo); return supportsDrop(dragObject.dragInfo);
} }
/**
* Setups button for the specified ItemInfo.
*/
protected abstract void setupItemInfo(ItemInfo info);
protected abstract boolean supportsDrop(ItemInfo info); protected abstract boolean supportsDrop(ItemInfo info);
public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view); public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view);
@@ -84,6 +84,9 @@ public class DeleteDropTarget extends ButtonDropTarget {
return LauncherAccessibilityDelegate.REMOVE; return LauncherAccessibilityDelegate.REMOVE;
} }
@Override
protected void setupItemInfo(ItemInfo info) {}
@Override @Override
protected boolean supportsDrop(ItemInfo info) { protected boolean supportsDrop(ItemInfo info) {
return true; return true;
@@ -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.Launcher.REQUEST_RECONFIGURE_APPWIDGET;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; 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.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.RECONFIGURE;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_DISMISS_PREDICTION_UNDO; 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; private boolean mHadPendingAlarm;
protected int mCurrentAccessibilityAction = -1; protected int mCurrentAccessibilityAction = -1;
public SecondaryDropTarget(Context context, AttributeSet attrs) { public SecondaryDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0); this(context, attrs, 0);
} }
@@ -133,25 +135,34 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList
return mCurrentAccessibilityAction; return mCurrentAccessibilityAction;
} }
@Override
protected void setupItemInfo(ItemInfo info) {
int buttonType = getButtonType(info, getViewUnderDrag(info));
if (buttonType != INVALID) {
setupUi(buttonType);
}
}
@Override @Override
protected boolean supportsDrop(ItemInfo info) { protected boolean supportsDrop(ItemInfo info) {
return supportsAccessibilityDrop(info, getViewUnderDrag(info)); return getButtonType(info, getViewUnderDrag(info)) != INVALID;
} }
@Override @Override
public boolean supportsAccessibilityDrop(ItemInfo info, View view) { public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
return getButtonType(info, view) != INVALID;
}
private int getButtonType(ItemInfo info, View view) {
if (view instanceof AppWidgetHostView) { if (view instanceof AppWidgetHostView) {
if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) { if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
setupUi(RECONFIGURE); return RECONFIGURE;
return true;
} }
return false; return INVALID;
} else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) { } else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) {
setupUi(DISMISS_PREDICTION); return DISMISS_PREDICTION;
return true;
} }
setupUi(UNINSTALL);
Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user); Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
if (uninstallDisabled == null) { if (uninstallDisabled == null) {
UserManager userManager = UserManager userManager =
@@ -165,16 +176,20 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList
mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT); mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
mCacheExpireAlarm.setOnAlarmListener(this); mCacheExpireAlarm.setOnAlarmListener(this);
if (uninstallDisabled) { if (uninstallDisabled) {
return false; return INVALID;
} }
if (info instanceof ItemInfoWithIcon) { if (info instanceof ItemInfoWithIcon) {
ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info; ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) { if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0
return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0; && (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) == 0) {
return INVALID;
} }
} }
return getUninstallTarget(info) != null; if (getUninstallTarget(info) == null) {
return INVALID;
}
return UNINSTALL;
} }
/** /**
@@ -60,6 +60,7 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
public static final int DISMISS_PREDICTION = R.id.action_dismiss_prediction; public static final int DISMISS_PREDICTION = R.id.action_dismiss_prediction;
public static final int PIN_PREDICTION = R.id.action_pin_prediction; public static final int PIN_PREDICTION = R.id.action_pin_prediction;
public static final int RECONFIGURE = R.id.action_reconfigure; public static final int RECONFIGURE = R.id.action_reconfigure;
public static final int INVALID = -1;
protected static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace; protected static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace;
protected static final int MOVE = R.id.action_move; protected static final int MOVE = R.id.action_move;
protected static final int MOVE_TO_WORKSPACE = R.id.action_move_to_workspace; protected static final int MOVE_TO_WORKSPACE = R.id.action_move_to_workspace;