From 68706ebe5abec756caaa6a7cb225beeaa26f9b13 Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Thu, 29 Apr 2021 15:24:54 -0700 Subject: [PATCH] Focus on newly-added workspace items for accessibility. Fixes: 177972980 Test: manual Change-Id: Ic31a940aba7bd08eb9d4236d9c963006a18c9f4d --- src/com/android/launcher3/Launcher.java | 34 ++++++++++++++++++- .../LauncherAccessibilityDelegate.java | 5 ++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 5896f5a4de..75eaeb2c0e 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2159,12 +2159,29 @@ public class Launcher extends StatefulActivity implements Launche */ @Override public void bindItems(final List items, final boolean forceAnimateIcons) { + bindItems(items, forceAnimateIcons, /* focusFirstItemForAccessibility= */ false); + } + + + /** + * Bind the items start-end from the list. + * + * Implementation of the method from LauncherModel.Callbacks. + * + * @param focusFirstItemForAccessibility true iff the first item to be added to the workspace + * should be focused for accessibility. + */ + public void bindItems( + final List items, + final boolean forceAnimateIcons, + final boolean focusFirstItemForAccessibility) { // Get the list of added items and intersect them with the set of items here final Collection bounceAnims = new ArrayList<>(); final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); Workspace workspace = mWorkspace; int newItemsScreenId = -1; int end = items.size(); + View newView = null; for (int i = 0; i < end; i++) { final ItemInfo item = items.get(i); @@ -2229,12 +2246,25 @@ public class Launcher extends StatefulActivity implements Launche bounceAnims.add(createNewAppBounceAnimation(view, i)); newItemsScreenId = item.screenId; } + + if (newView == null) { + newView = view; + } } - // Animate to the correct page + View viewToFocus = newView; + // Animate to the correct pager if (animateIcons && newItemsScreenId > -1) { AnimatorSet anim = new AnimatorSet(); anim.playTogether(bounceAnims); + if (focusFirstItemForAccessibility && viewToFocus != null) { + anim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + viewToFocus.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); + } + }); + } int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId); @@ -2257,6 +2287,8 @@ public class Launcher extends StatefulActivity implements Launche } else { mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); } + } else if (focusFirstItemForAccessibility && viewToFocus != null) { + viewToFocus.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); } workspace.requestLayout(); } diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index dbdfb2b663..c580d47994 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -230,7 +230,10 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]); - mLauncher.bindItems(Collections.singletonList(info), true); + mLauncher.bindItems( + Collections.singletonList(info), + /* forceAnimateIcons= */ true, + /* focusFirstItemForAccessibility= */ true); announceConfirmation(R.string.item_added_to_workspace); } else if (item instanceof PendingAddItemInfo) { PendingAddItemInfo info = (PendingAddItemInfo) item;