Merge "Make drag and drop also work when the widget tray is still in scroll mode." into ub-launcher3-burnaby
diff --git a/res/values/config.xml b/res/values/config.xml
index 21e1d69..6ef8635 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -100,4 +100,6 @@
<item type="id" name="action_add_to_workspace" />
<item type="id" name="action_move" />
<item type="id" name="action_move_to_workspace" />
+ <item type="id" name="action_move_screen_backwards" />
+ <item type="id" name="action_move_screen_forwards" />
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 57f23ae..1681fc6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -243,4 +243,13 @@
<!-- Accessibility action to move an item from folder to workspace. [CHAR_LIMIT=30] [DO NOT TRANSLATE] -->
<string name="action_move_to_workspace">Move to home screen</string>
+
+ <!-- Accessibility action to move an homescreen to the left. [CHAR_LIMIT=30] [DO NOT TRANSLATE] -->
+ <string name="action_move_screen_left">Move screen to left</string>
+
+ <!-- Accessibility action to move an homescreen to the right. [CHAR_LIMIT=30] [DO NOT TRANSLATE] -->
+ <string name="action_move_screen_right">Move screen to right</string>
+
+ <!-- Accessibility confirmation when a screen was moved [DO NOT TRANSLATE] -->
+ <string name="screen_moved">Screen moved</string>
</resources>
diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java
index dd646bb..3b25dca 100644
--- a/src/com/android/launcher3/AllAppsList.java
+++ b/src/com/android/launcher3/AllAppsList.java
@@ -24,6 +24,7 @@
import com.android.launcher3.compat.UserHandleCompat;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
@@ -117,6 +118,16 @@
}
}
+ public void updateIconsAndLabels(HashSet<String> packages, UserHandleCompat user,
+ ArrayList<AppInfo> outUpdates) {
+ for (AppInfo info : data) {
+ if (info.user.equals(user) && packages.contains(info.componentName.getPackageName())) {
+ mIconCache.updateTitleAndIcon(info);
+ outUpdates.add(info);
+ }
+ }
+ }
+
/**
* Add and remove icons for this package which has been updated.
*/
diff --git a/src/com/android/launcher3/AppsContainerView.java b/src/com/android/launcher3/AppsContainerView.java
index f7adaf8..c3cf629 100644
--- a/src/com/android/launcher3/AppsContainerView.java
+++ b/src/com/android/launcher3/AppsContainerView.java
@@ -232,8 +232,15 @@
mFixedBounds.set(fixedBounds);
}
- updateBackgrounds();
- updatePaddings();
+ // Post the updates since they can trigger a relayout, and this call can be triggered from
+ // a layout pass itself.
+ post(new Runnable() {
+ @Override
+ public void run() {
+ updateBackgrounds();
+ updatePaddings();
+ }
+ });
}
@Override
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index fd45714..6c2aa39 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -407,6 +407,20 @@
}
/**
+ * Updates {@param application} only if a valid entry is found.
+ */
+ public synchronized void updateTitleAndIcon(AppInfo application) {
+ CacheEntry entry = cacheLocked(application.componentName, null, application.user,
+ false, application.usingLowResIcon);
+ if (entry.icon != null && !isDefaultIcon(entry.icon, application.user)) {
+ application.title = entry.title;
+ application.iconBitmap = entry.icon;
+ application.contentDescription = entry.contentDescription;
+ application.usingLowResIcon = entry.isLowResIcon;
+ }
+ }
+
+ /**
* Returns a high res icon for the given intent and user
*/
public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user) {
@@ -655,7 +669,7 @@
}
private static final class IconDB extends SQLiteOpenHelper {
- private final static int DB_VERSION = 3;
+ private final static int DB_VERSION = 4;
private final static String TABLE_NAME = "icons";
private final static String COLUMN_ROWID = "rowid";
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 95ff6a4..ddbae3a 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -107,6 +107,7 @@
@Thunk DeferredHandler mHandler = new DeferredHandler();
@Thunk LoaderTask mLoaderTask;
@Thunk boolean mIsLoaderTaskRunning;
+ @Thunk boolean mHasLoaderCompletedOnce;
private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings";
@@ -128,6 +129,12 @@
// a normal load, we also clear this set of Runnables.
static final ArrayList<Runnable> mDeferredBindRunnables = new ArrayList<Runnable>();
+ /**
+ * Set of runnables to be called on the background thread after the workspace binding
+ * is complete.
+ */
+ static final ArrayList<Runnable> mBindCompleteRunnables = new ArrayList<Runnable>();
+
@Thunk WeakReference<Callbacks> mCallbacks;
// < only access in worker thread >
@@ -263,6 +270,19 @@
}
}
+ /**
+ * Runs the specified runnable after the loader is complete
+ */
+ private void runAfterBindCompletes(Runnable r) {
+ if (isLoadingWorkspace() || !mHasLoaderCompletedOnce) {
+ synchronized (mBindCompleteRunnables) {
+ mBindCompleteRunnables.add(r);
+ }
+ } else {
+ runOnWorkerThread(r);
+ }
+ }
+
boolean canMigrateFromOldLauncherDb(Launcher launcher) {
return mOldContentProviderExists && !launcher.isLauncherPreinstalled() ;
}
@@ -424,7 +444,7 @@
* Find a position on the screen for the given size or adds a new screen.
* @return screenId and the coordinates for the item.
*/
- @Thunk static Pair<Long, int[]> findSpaceForItem(
+ @Thunk Pair<Long, int[]> findSpaceForItem(
Context context,
ArrayList<Long> workspaceScreens,
ArrayList<Long> addedWorkspaceScreensFinal,
@@ -432,7 +452,7 @@
LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
// Use sBgItemsIdMap as all the items are already loaded.
- // TODO: Throw exception is above condition is not met.
+ assertWorkspaceLoaded();
synchronized (sBgLock) {
for (ItemInfo info : sBgItemsIdMap) {
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
@@ -875,12 +895,18 @@
updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase");
}
+ private void assertWorkspaceLoaded() {
+ if (LauncherAppState.isDogfoodBuild() && (isLoadingWorkspace() || !mHasLoaderCompletedOnce)) {
+ throw new RuntimeException("Trying to add shortcut while loader is running");
+ }
+ }
+
/**
* Returns true if the shortcuts already exists on the workspace. This must be called after
* the workspace has been loaded. We identify a shortcut by its intent.
- * TODO: Throw exception is above condition is not met.
*/
- @Thunk static boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) {
+ @Thunk boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) {
+ assertWorkspaceLoaded();
final String intentWithPkg, intentWithoutPkg;
final String packageName;
if (intent.getComponent() != null) {
@@ -1390,6 +1416,16 @@
mHandler.post(r);
}
}
+
+ // Run all the bind complete runnables after workspace is bound.
+ if (!mBindCompleteRunnables.isEmpty()) {
+ synchronized (mBindCompleteRunnables) {
+ for (final Runnable r : mBindCompleteRunnables) {
+ runOnWorkerThread(r);
+ }
+ mBindCompleteRunnables.clear();
+ }
+ }
}
public void stopLoader() {
@@ -1615,6 +1651,7 @@
mLoaderTask = null;
}
mIsLoaderTaskRunning = false;
+ mHasLoaderCompletedOnce = true;
}
}
@@ -2730,6 +2767,7 @@
}
if (!mAllAppsLoaded) {
loadAllApps();
+ updateAllAppsIconsCache();
synchronized (LoaderTask.this) {
if (mStopped) {
return;
@@ -2784,9 +2822,6 @@
return;
}
- final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
- mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
-
final List<UserHandleCompat> profiles = mUserManager.getUserProfiles();
// Clear the list of apps
@@ -2794,7 +2829,7 @@
for (UserHandleCompat user : profiles) {
// Query for the set of apps
final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
- List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user);
+ final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user);
if (DEBUG_LOADERS) {
Log.d(TAG, "getActivityList took "
+ (SystemClock.uptimeMillis()-qiaTime) + "ms for user " + user);
@@ -2806,42 +2841,6 @@
return;
}
- // Update icon cache
- HashSet<String> updatedPackages = mIconCache.updateDBIcons(user, apps);
-
- // If any package icon has changed (app was updated while launcher was dead),
- // update the corresponding shortcuts.
- if (!updatedPackages.isEmpty()) {
- final ArrayList<ShortcutInfo> updates = new ArrayList<ShortcutInfo>();
- synchronized (sBgLock) {
- for (ItemInfo info : sBgItemsIdMap) {
- if (info instanceof ShortcutInfo && user.equals(info.user)
- && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
- ShortcutInfo si = (ShortcutInfo) info;
- ComponentName cn = si.getTargetComponent();
- if (cn != null && updatedPackages.contains(cn.getPackageName())) {
- si.updateIcon(mIconCache);
- updates.add(si);
- }
- }
- }
- }
-
- if (!updates.isEmpty()) {
- final UserHandleCompat userFinal = user;
- mHandler.post(new Runnable() {
-
- public void run() {
- Callbacks cb = getCallback();
- if (cb != null) {
- cb.bindShortcutsChanged(
- updates, new ArrayList<ShortcutInfo>(), userFinal);
- }
- }
- });
- }
- }
-
// Create the ApplicationInfos
for (int i = 0; i < apps.size(); i++) {
LauncherActivityInfoCompat app = apps.get(i);
@@ -2849,11 +2848,15 @@
mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache));
}
- if (!user.equals(UserHandleCompat.myUserHandle())) {
- ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user);
- if (heuristic != null) {
- heuristic.processUserApps(apps);
- }
+ final ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user);
+ if (heuristic != null) {
+ runAfterBindCompletes(new Runnable() {
+
+ @Override
+ public void run() {
+ heuristic.processUserApps(apps);
+ }
+ });
}
}
// Huh? Shouldn't this be inside the Runnable below?
@@ -2888,6 +2891,68 @@
}
}
+ private void updateAllAppsIconsCache() {
+ final ArrayList<AppInfo> updatedApps = new ArrayList<>();
+
+ for (UserHandleCompat user : mUserManager.getUserProfiles()) {
+ // Query for the set of apps
+ final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user);
+ // Fail if we don't have any apps
+ // TODO: Fix this. Only fail for the current user.
+ if (apps == null || apps.isEmpty()) {
+ return;
+ }
+
+ // Update icon cache
+ HashSet<String> updatedPackages = mIconCache.updateDBIcons(user, apps);
+
+ // If any package icon has changed (app was updated while launcher was dead),
+ // update the corresponding shortcuts.
+ if (!updatedPackages.isEmpty()) {
+ final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<>();
+ synchronized (sBgLock) {
+ for (ItemInfo info : sBgItemsIdMap) {
+ if (info instanceof ShortcutInfo && user.equals(info.user)
+ && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+ ShortcutInfo si = (ShortcutInfo) info;
+ ComponentName cn = si.getTargetComponent();
+ if (cn != null && updatedPackages.contains(cn.getPackageName())) {
+ si.updateIcon(mIconCache);
+ updatedShortcuts.add(si);
+ }
+ }
+ }
+ mBgAllAppsList.updateIconsAndLabels(updatedPackages, user, updatedApps);
+ }
+
+ if (!updatedShortcuts.isEmpty()) {
+ final UserHandleCompat userFinal = user;
+ mHandler.post(new Runnable() {
+
+ public void run() {
+ Callbacks cb = getCallback();
+ if (cb != null) {
+ cb.bindShortcutsChanged(updatedShortcuts,
+ new ArrayList<ShortcutInfo>(), userFinal);
+ }
+ }
+ });
+ }
+ }
+ }
+ if (!updatedApps.isEmpty()) {
+ mHandler.post(new Runnable() {
+
+ public void run() {
+ Callbacks cb = getCallback();
+ if (cb != null) {
+ cb.bindAppsUpdated(updatedApps);
+ }
+ }
+ });
+ }
+ }
+
public void dumpState() {
synchronized (sBgLock) {
Log.d(TAG, "mLoaderTask.mContext=" + mContext);
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index a4593ec..0739bab 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -559,7 +559,7 @@
/**
* Sets the current page.
*/
- void setCurrentPage(int currentPage) {
+ public void setCurrentPage(int currentPage) {
if (!mScroller.isFinished()) {
abortScrollerAnimation(true);
}
@@ -2535,7 +2535,7 @@
}
}
- protected void onStartReordering() {
+ public void onStartReordering() {
// Set the touch state to reordering (allows snapping to pages, dragging a child, etc.)
mTouchState = TOUCH_STATE_REORDERING;
mIsReordering = true;
@@ -2555,7 +2555,7 @@
}
}
- protected void onEndReordering() {
+ public void onEndReordering() {
mIsReordering = false;
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index e7a41e0..f2fa59b 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -63,6 +63,7 @@
import com.android.launcher3.LauncherAccessibilityDelegate.AccessibilityDragSource;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.UninstallDropTarget.UninstallSource;
+import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.Thunk;
@@ -277,6 +278,8 @@
// Handles workspace state transitions
private WorkspaceStateTransitionAnimation mStateTransitionAnimation;
+ private AccessibilityDelegate mPagesAccessibilityDelegate;
+
private final Runnable mBindPages = new Runnable() {
@Override
public void run() {
@@ -2000,14 +2003,14 @@
range[1] = Math.max(0, end);
}
- protected void onStartReordering() {
+ public void onStartReordering() {
super.onStartReordering();
showOutlines();
// Reordering handles its own animations, disable the automatic ones.
disableLayoutTransitions();
}
- protected void onEndReordering() {
+ public void onEndReordering() {
super.onEndReordering();
if (mLauncher.isWorkspaceLoading()) {
@@ -2068,11 +2071,45 @@
return mState;
}
- private void updateAccessibilityFlags() {
- int accessible = mState == State.NORMAL ?
- IMPORTANT_FOR_ACCESSIBILITY_NO :
- IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
- setImportantForAccessibility(accessible);
+ public void updateAccessibilityFlags() {
+ if (Utilities.isLmpOrAbove()) {
+ int total = getPageCount();
+ for (int i = numCustomPages(); i < total; i++) {
+ updateAccessibilityFlags((CellLayout) getPageAt(i), i);
+ }
+ if (mState == State.NORMAL) {
+ setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
+ } else {
+ setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
+ }
+ } else {
+ int accessible = mState == State.NORMAL ?
+ IMPORTANT_FOR_ACCESSIBILITY_NO :
+ IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
+ setImportantForAccessibility(accessible);
+ }
+ }
+
+ private void updateAccessibilityFlags(CellLayout page, int pageNo) {
+ if (mState == State.OVERVIEW) {
+ page.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
+ page.getShortcutsAndWidgets().setImportantForAccessibility(
+ IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
+ page.setContentDescription(getPageDescription(pageNo));
+
+ if (mPagesAccessibilityDelegate == null) {
+ mPagesAccessibilityDelegate = new OverviewScreenAccessibilityDelegate(this);
+ }
+ page.setAccessibilityDelegate(mPagesAccessibilityDelegate);
+ } else {
+ int accessible = mState == State.NORMAL ?
+ IMPORTANT_FOR_ACCESSIBILITY_NO :
+ IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
+ page.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
+ page.getShortcutsAndWidgets().setImportantForAccessibility(accessible);
+ page.setContentDescription(null);
+ page.setAccessibilityDelegate(null);
+ }
}
@Override
@@ -4460,11 +4497,15 @@
}
protected String getCurrentPageDescription() {
- int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
- int delta = numCustomPages();
if (hasCustomContent() && getNextPage() == 0) {
return mCustomContentDescription;
}
+ int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
+ return getPageDescription(page);
+ }
+
+ private String getPageDescription(int page) {
+ int delta = numCustomPages();
return String.format(getContext().getString(R.string.workspace_scroll_format),
page + 1 - delta, getChildCount() - delta);
}
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index a0cedeb..61a64e3 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -24,8 +24,11 @@
import android.content.Context;
import android.content.res.Resources;
import android.view.View;
+import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.DecelerateInterpolator;
+
import com.android.launcher3.util.Thunk;
import java.util.HashMap;
@@ -190,7 +193,7 @@
final HashMap<View, Integer> layerViews) {
AccessibilityManager am = (AccessibilityManager)
mLauncher.getSystemService(Context.ACCESSIBILITY_SERVICE);
- boolean accessibilityEnabled = am.isEnabled();
+ final boolean accessibilityEnabled = am.isEnabled();
// Reinitialize animation arrays for the current workspace state
reinitializeAnimationArrays();
@@ -301,7 +304,7 @@
}
final View searchBar = mLauncher.getOrCreateQsbBar();
- final View overviewPanel = mLauncher.getOverviewPanel();
+ final ViewGroup overviewPanel = mLauncher.getOverviewPanel();
final View hotseat = mLauncher.getHotseat();
final View pageIndicator = mWorkspace.getPageIndicator();
if (animated) {
@@ -424,6 +427,11 @@
@Override
public void onAnimationEnd(Animator animation) {
mStateAnimator = null;
+
+ if (accessibilityEnabled && overviewPanel.getVisibility() == View.VISIBLE) {
+ overviewPanel.getChildAt(0).performAccessibilityAction(
+ AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
+ }
}
});
} else {
@@ -443,6 +451,11 @@
mWorkspace.setScaleX(mNewScale);
mWorkspace.setScaleY(mNewScale);
mWorkspace.setTranslationY(finalWorkspaceTranslationY);
+
+ if (accessibilityEnabled && overviewPanel.getVisibility() == View.VISIBLE) {
+ overviewPanel.getChildAt(0).performAccessibilityAction(
+ AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
+ }
}
if (stateIsNormal) {
diff --git a/src/com/android/launcher3/accessibility/OverviewScreenAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/OverviewScreenAccessibilityDelegate.java
new file mode 100644
index 0000000..d3f5230
--- /dev/null
+++ b/src/com/android/launcher3/accessibility/OverviewScreenAccessibilityDelegate.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.accessibility;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.util.SparseArray;
+import android.view.View;
+import android.view.View.AccessibilityDelegate;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
+
+import com.android.launcher3.R;
+import com.android.launcher3.Workspace;
+
+public class OverviewScreenAccessibilityDelegate extends AccessibilityDelegate {
+
+ private static final int MOVE_BACKWARD = R.id.action_move_screen_backwards;
+ private static final int MOVE_FORWARD = R.id.action_move_screen_forwards;
+
+ private final SparseArray<AccessibilityAction> mActions = new SparseArray<>();
+ private final Workspace mWorkspace;
+
+ public OverviewScreenAccessibilityDelegate(Workspace workspace) {
+ mWorkspace = workspace;
+
+ Context context = mWorkspace.getContext();
+ boolean isRtl = mWorkspace.isLayoutRtl();
+ mActions.put(MOVE_BACKWARD, new AccessibilityAction(MOVE_BACKWARD,
+ context.getText(isRtl ? R.string.action_move_screen_right :
+ R.string.action_move_screen_left)));
+ mActions.put(MOVE_FORWARD, new AccessibilityAction(MOVE_FORWARD,
+ context.getText(isRtl ? R.string.action_move_screen_left :
+ R.string.action_move_screen_right)));
+ }
+
+ @Override
+ public boolean performAccessibilityAction(View host, int action, Bundle args) {
+ if (host != null) {
+ if (action == AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS ) {
+ int index = mWorkspace.indexOfChild(host);
+ mWorkspace.setCurrentPage(index);
+ } else if (action == MOVE_FORWARD) {
+ movePage(mWorkspace.indexOfChild(host) + 1, host);
+ return true;
+ } else if (action == MOVE_BACKWARD) {
+ movePage(mWorkspace.indexOfChild(host) - 1, host);
+ return true;
+ }
+ }
+
+ return super.performAccessibilityAction(host, action, args);
+ }
+
+ private void movePage(int finalIndex, View view) {
+ mWorkspace.onStartReordering();
+ mWorkspace.removeView(view);
+ mWorkspace.addView(view, finalIndex);
+ mWorkspace.onEndReordering();
+ mWorkspace.announceForAccessibility(mWorkspace.getContext().getText(R.string.screen_moved));
+
+ mWorkspace.updateAccessibilityFlags();
+ view.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
+ }
+
+ @Override
+ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfo(host, info);
+
+ int index = mWorkspace.indexOfChild(host);
+ if (index < mWorkspace.getChildCount() - 1) {
+ info.addAction(mActions.get(MOVE_FORWARD));
+ }
+ if (index > mWorkspace.numCustomPages()) {
+ info.addAction(mActions.get(MOVE_BACKWARD));
+ }
+ }
+}