diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 491d95d13e..c1599cb83a 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2154,12 +2154,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); @@ -2224,12 +2241,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); @@ -2252,6 +2282,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;