Fixing topView not being considered in all places when calculating accessible
and focusable views
Bug: 30563273
Change-Id: I6253ce33ee5c328efdde2ea733029975b31e5eb8
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 7bcd631..1d5ece2 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -3151,6 +3151,14 @@
}
}
+ public View getTopFloatingView() {
+ View topView = getOpenShortcutsContainer();
+ if (topView == null) {
+ topView = getWorkspace().getOpenFolder();
+ }
+ return topView;
+ }
+
/**
* @return The open shortcuts container, or null if there is none
*/
diff --git a/src/com/android/launcher3/PinchToOverviewListener.java b/src/com/android/launcher3/PinchToOverviewListener.java
index 6ee96fc..48a75d1 100644
--- a/src/com/android/launcher3/PinchToOverviewListener.java
+++ b/src/com/android/launcher3/PinchToOverviewListener.java
@@ -102,8 +102,8 @@
// once the state switching animation is complete.
return false;
}
- if (mWorkspace.getOpenFolder() != null) {
- // Don't listen for the pinch gesture if a folder is open.
+ if (mLauncher.getTopFloatingView() != null) {
+ // Don't listen for the pinch gesture if a floating view is open.
return false;
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index f2cf120..e34f509 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -58,6 +58,8 @@
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;
import com.android.launcher3.compat.UserHandleCompat;
@@ -906,4 +908,15 @@
ta.recycle();
return colorAccent;
}
+
+ public static void sendCustomAccessibilityEvent(View target, int type, String text) {
+ AccessibilityManager accessibilityManager = (AccessibilityManager)
+ target.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
+ if (accessibilityManager.isEnabled()) {
+ AccessibilityEvent event = AccessibilityEvent.obtain(type);
+ target.onInitializeAccessibilityEvent(event);
+ event.getText().add(text);
+ accessibilityManager.sendAccessibilityEvent(event);
+ }
+ }
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 947aa50..d5f1363 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1858,19 +1858,6 @@
}
@Override
- protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
- if (!mLauncher.isAppsViewVisible()) {
- final Folder openFolder = getOpenFolder();
- if (openFolder != null) {
- return openFolder.requestFocus(direction, previouslyFocusedRect);
- } else {
- return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
- }
- }
- return false;
- }
-
- @Override
public int getDescendantFocusability() {
if (workspaceInModalState()) {
return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
@@ -1878,18 +1865,6 @@
return super.getDescendantFocusability();
}
- @Override
- public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
- if (!mLauncher.isAppsViewVisible()) {
- final Folder openFolder = getOpenFolder();
- if (openFolder != null) {
- openFolder.addFocusables(views, direction);
- } else {
- super.addFocusables(views, direction, focusableMode);
- }
- }
- }
-
public boolean workspaceInModalState() {
return mState != State.NORMAL;
}
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index dcff89f..e5ec6ba 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -343,16 +343,9 @@
}
private void sendTapOutsideFolderAccessibilityEvent(boolean isEditingName) {
- AccessibilityManager accessibilityManager = (AccessibilityManager)
- getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
- if (accessibilityManager.isEnabled()) {
- int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close;
- AccessibilityEvent event = AccessibilityEvent.obtain(
- AccessibilityEvent.TYPE_VIEW_FOCUSED);
- onInitializeAccessibilityEvent(event);
- event.getText().add(getContext().getString(stringId));
- accessibilityManager.sendAccessibilityEvent(event);
- }
+ int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close;
+ Utilities.sendCustomAccessibilityEvent(
+ this, AccessibilityEvent.TYPE_VIEW_FOCUSED, getContext().getString(stringId));
}
private boolean isInAccessibleDrag() {
@@ -362,37 +355,27 @@
@Override
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
// Shortcuts can appear above folder
- View topView = mLauncher.getOpenShortcutsContainer();
+ View topView = mLauncher.getTopFloatingView();
if (topView != null) {
- return handleTopViewSendAccessibilityEvent(topView, child, event);
- }
-
- topView = mLauncher.getWorkspace().getOpenFolder();
- if (topView != null) {
- return handleTopViewSendAccessibilityEvent(topView, child, event);
+ if (child == topView) {
+ return super.onRequestSendAccessibilityEvent(child, event);
+ }
+ if (isInAccessibleDrag() && child instanceof DropTargetBar) {
+ return super.onRequestSendAccessibilityEvent(child, event);
+ }
+ // Skip propagating onRequestSendAccessibilityEvent for all other children
+ // which are not topView
+ return false;
}
return super.onRequestSendAccessibilityEvent(child, event);
}
- private boolean handleTopViewSendAccessibilityEvent(
- View topView, View child, AccessibilityEvent event) {
- if (child == topView) {
- return super.onRequestSendAccessibilityEvent(child, event);
- }
- if (isInAccessibleDrag() && child instanceof DropTargetBar) {
- return super.onRequestSendAccessibilityEvent(child, event);
- }
- // Skip propagating onRequestSendAccessibilityEvent for all other children
- // which are not topView
- return false;
- }
-
@Override
public void addChildrenForAccessibility(ArrayList<View> childrenForAccessibility) {
- Folder currentFolder = mLauncher.getWorkspace().getOpenFolder();
- if (currentFolder != null) {
- // Only add the folder as a child for accessibility when it is open
- childrenForAccessibility.add(currentFolder);
+ View topView = mLauncher.getTopFloatingView();
+ if (topView != null) {
+ // Only add the top view as a child for accessibility when it is open
+ childrenForAccessibility.add(topView);
if (isInAccessibleDrag()) {
childrenForAccessibility.add(mLauncher.getDropTargetBar());
@@ -1037,6 +1020,26 @@
return mBackgroundAlpha;
}
+ @Override
+ protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
+ View topView = mLauncher.getTopFloatingView();
+ if (topView != null) {
+ return topView.requestFocus(direction, previouslyFocusedRect);
+ } else {
+ return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
+ }
+ }
+
+ @Override
+ public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
+ View topView = mLauncher.getTopFloatingView();
+ if (topView != null) {
+ topView.addFocusables(views, direction);
+ } else {
+ super.addFocusables(views, direction, focusableMode);
+ }
+ }
+
public void setTouchCompleteListener(TouchCompleteListener listener) {
mTouchCompleteListener = listener;
}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 1e87202..19956a9 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -42,7 +42,6 @@
import android.view.View;
import android.view.ViewDebug;
import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
@@ -52,7 +51,6 @@
import com.android.launcher3.Alarm;
import com.android.launcher3.CellLayout;
-import com.android.launcher3.CellLayout.CellInfo;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
@@ -77,7 +75,6 @@
import com.android.launcher3.dragndrop.DragController.DragListener;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
-import com.android.launcher3.logging.UserEventDispatcher.LaunchSourceProvider;
import com.android.launcher3.pageindicators.PageIndicatorDots;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -366,7 +363,8 @@
LauncherModel.updateItemInDatabase(mLauncher, mInfo);
if (commit) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_renamed, newTitle));
}
@@ -605,7 +603,9 @@
openFolderAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ Folder.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
mContent.getAccessibilityDescription());
mState = STATE_ANIMATING;
}
@@ -675,17 +675,6 @@
mDragController.addDragListener(this);
}
- @Thunk void sendCustomAccessibilityEvent(int type, String text) {
- AccessibilityManager accessibilityManager = (AccessibilityManager)
- getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
- if (accessibilityManager.isEnabled()) {
- AccessibilityEvent event = AccessibilityEvent.obtain(type);
- onInitializeAccessibilityEvent(event);
- event.getText().add(text);
- accessibilityManager.sendAccessibilityEvent(event);
- }
- }
-
public void animateClosed() {
if (!(getParent() instanceof DragLayer)) return;
final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 0, 0.9f, 0.9f);
@@ -697,7 +686,9 @@
}
@Override
public void onAnimationStart(Animator animation) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ Folder.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_closed));
mState = STATE_ANIMATING;
}
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
index 4100795..3c7ba32 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
@@ -31,7 +31,6 @@
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
-import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
@@ -65,7 +64,6 @@
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.graphics.TriangleShape;
-import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -255,8 +253,10 @@
@Override
public void onAnimationEnd(Animator animation) {
mOpenCloseAnimator = null;
-
- sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+ Utilities.sendCustomAccessibilityEvent(
+ DeepShortcutsContainer.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ getContext().getString(R.string.action_deep_shortcut));
}
});