From 52851aa3fd2dd9957e190d779f904f6abaf53fed Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 2 Sep 2016 10:41:43 -0700 Subject: Fixing topView not being considered in all places when calculating accessible and focusable views Bug: 30563273 Change-Id: I6253ce33ee5c328efdde2ea733029975b31e5eb8 --- src/com/android/launcher3/Launcher.java | 8 +++ .../android/launcher3/PinchToOverviewListener.java | 4 +- src/com/android/launcher3/Utilities.java | 13 ++++ src/com/android/launcher3/Workspace.java | 25 -------- src/com/android/launcher3/dragndrop/DragLayer.java | 71 +++++++++++----------- src/com/android/launcher3/folder/Folder.java | 25 +++----- .../shortcuts/DeepShortcutsContainer.java | 8 +-- 7 files changed, 72 insertions(+), 82 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 7bcd63172..1d5ece2ef 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -3151,6 +3151,14 @@ public class Launcher extends Activity } } + 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 6ee96fc79..48a75d111 100644 --- a/src/com/android/launcher3/PinchToOverviewListener.java +++ b/src/com/android/launcher3/PinchToOverviewListener.java @@ -102,8 +102,8 @@ public class PinchToOverviewListener extends ScaleGestureDetector.SimpleOnScaleG // 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 f2cf12099..e34f509da 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -58,6 +58,8 @@ import android.util.SparseArray; 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 @@ public final class Utilities { 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 947aa5062..d5f1363b4 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1857,19 +1857,6 @@ public class Workspace extends PagedView } - @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()) { @@ -1878,18 +1865,6 @@ public class Workspace extends PagedView return super.getDescendantFocusability(); } - @Override - public void addFocusables(ArrayList 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 dcff89f55..e5ec6ba9f 100644 --- a/src/com/android/launcher3/dragndrop/DragLayer.java +++ b/src/com/android/launcher3/dragndrop/DragLayer.java @@ -343,16 +343,9 @@ public class DragLayer extends InsettableFrameLayout { } 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 @@ public class DragLayer extends InsettableFrameLayout { @Override public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { // Shortcuts can appear above folder - View topView = mLauncher.getOpenShortcutsContainer(); - if (topView != null) { - return handleTopViewSendAccessibilityEvent(topView, child, event); - } - - topView = mLauncher.getWorkspace().getOpenFolder(); + View topView = mLauncher.getTopFloatingView(); 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 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 @@ public class DragLayer extends InsettableFrameLayout { 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 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 1e87202f0..19956a9c8 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -42,7 +42,6 @@ import android.view.MotionEvent; 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 android.widget.TextView; 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; 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 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList 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 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList 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 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList 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 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } @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 4100795cc..3c7ba327b 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java @@ -31,7 +31,6 @@ import android.graphics.drawable.ShapeDrawable; 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.DragLayer; 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 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC @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)); } }); -- cgit v1.2.3