Merge "Focus on newly-added workspace items for accessibility." into sc-dev am: 2fd0be4b15 am: 2dd1321dbf

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14357544

Change-Id: I01e7f750ccc0a17ac3f9800b3a0154e4ce197d23
This commit is contained in:
TreeHugger Robot
2021-05-11 00:08:57 +00:00
committed by Automerger Merge Worker
2 changed files with 37 additions and 2 deletions
+33 -1
View File
@@ -2154,12 +2154,29 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
*/
@Override
public void bindItems(final List<ItemInfo> 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<ItemInfo> items,
final boolean forceAnimateIcons,
final boolean focusFirstItemForAccessibility) {
// Get the list of added items and intersect them with the set of items here
final Collection<Animator> 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<LauncherState> 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<LauncherState> implements Launche
} else {
mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
}
} else if (focusFirstItemForAccessibility && viewToFocus != null) {
viewToFocus.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
workspace.requestLayout();
}
@@ -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;