Merge "Focus on newly added app for all Accessibility use cases when adding an app to the home screen." into main

This commit is contained in:
Treehugger Robot authored and Android (Google) Code Review committed 2025-01-24 14:02:44 -08:00
commit 1809cb6ff3
1 file changed
+19
+19
View File
@@ -16,6 +16,7 @@
package com.android.launcher3;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.dragndrop.DraggableView.DRAGGABLE_ICON;
import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_REORDER_PREVIEW_OFFSET;
@@ -47,6 +48,7 @@ import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
@@ -69,6 +71,7 @@ import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.folder.PreviewBackground;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.util.CellAndSpan;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.MSDLPlayerWrapper;
@@ -785,6 +788,22 @@ public class CellLayout extends ViewGroup {
}
mShortcutsAndWidgets.addView(child, index, lp);
// Whenever an app is added, if Accessibility service is enabled, focus on that app.
if (mActivity instanceof Launcher) {
Launcher.cast(mActivity).getStateManager().addStateListener(
new StateManager.StateListener<LauncherState>() {
@Override
public void onStateTransitionComplete(LauncherState finalState) {
if (finalState == NORMAL) {
child.performAccessibilityAction(
AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
Launcher.cast(mActivity).getStateManager()
.removeStateListener(this);
}
}
});
}
if (markCells) markCellsAsOccupiedForView(child);
return true;