diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-01-08 16:59:04 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-01-16 17:40:41 -0800 |
commit | 71b5c0b988a64b3a0613ded5403749bc537ee8a5 (patch) | |
tree | dec5e13b1ef53a7005a9776387fc0a4c1895c39c /src/com/android/launcher3/LauncherAccessibilityDelegate.java | |
parent | 08f7261d11a53ae4b330ad4fa897b8519de3d750 (diff) | |
download | android_packages_apps_Trebuchet-71b5c0b988a64b3a0613ded5403749bc537ee8a5.tar.gz android_packages_apps_Trebuchet-71b5c0b988a64b3a0613ded5403749bc537ee8a5.tar.bz2 android_packages_apps_Trebuchet-71b5c0b988a64b3a0613ded5403749bc537ee8a5.zip |
Adding accessibility controls
> Adding 'Remove' option to workspace items
> Adding 'Add to workspace' to all apps and widget list items, which
adds the item to the first available space, giving preference to
the current workspace screen
> Adding 'App info' and 'Uninstall' options to appropriate items
Bug: 18482913
Change-Id: Ifab7423af2d9ba502b5a2771b37bb5436b3df937
Diffstat (limited to 'src/com/android/launcher3/LauncherAccessibilityDelegate.java')
-rw-r--r-- | src/com/android/launcher3/LauncherAccessibilityDelegate.java | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/com/android/launcher3/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/LauncherAccessibilityDelegate.java new file mode 100644 index 000000000..c9e277e4c --- /dev/null +++ b/src/com/android/launcher3/LauncherAccessibilityDelegate.java @@ -0,0 +1,109 @@ +package com.android.launcher3; + +import android.annotation.TargetApi; +import android.os.Build; +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.LauncherModel.ScreenPosProvider; + +import java.util.ArrayList; + +@TargetApi(Build.VERSION_CODES.LOLLIPOP) +public class LauncherAccessibilityDelegate extends AccessibilityDelegate { + + public static final int REMOVE = R.id.action_remove; + public static final int INFO = R.id.action_info; + public static final int UNINSTALL = R.id.action_uninstall; + public static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace; + + private final SparseArray<AccessibilityAction> mActions = + new SparseArray<AccessibilityAction>(); + private final Launcher mLauncher; + + public LauncherAccessibilityDelegate(Launcher launcher) { + mLauncher = launcher; + + mActions.put(REMOVE, new AccessibilityAction(REMOVE, + launcher.getText(R.string.delete_target_label))); + mActions.put(INFO, new AccessibilityAction(INFO, + launcher.getText(R.string.info_target_label))); + mActions.put(UNINSTALL, new AccessibilityAction(UNINSTALL, + launcher.getText(R.string.delete_target_uninstall_label))); + mActions.put(ADD_TO_WORKSPACE, new AccessibilityAction(ADD_TO_WORKSPACE, + launcher.getText(R.string.action_add_to_workspace))); + } + + @Override + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host, info); + if (!(host.getTag() instanceof ItemInfo)) return; + ItemInfo item = (ItemInfo) host.getTag(); + + if ((item instanceof ShortcutInfo) + || (item instanceof LauncherAppWidgetInfo) + || (item instanceof FolderInfo)) { + // Workspace shortcut / widget + info.addAction(mActions.get(REMOVE)); + } else if ((item instanceof AppInfo) || (item instanceof PendingAddItemInfo)) { + // App or Widget from customization tray + if (item instanceof AppInfo) { + info.addAction(mActions.get(UNINSTALL)); + } + info.addAction(mActions.get(INFO)); + info.addAction(mActions.get(ADD_TO_WORKSPACE)); + } + } + + @Override + public boolean performAccessibilityAction(View host, int action, Bundle args) { + if ((host.getTag() instanceof ItemInfo) + && performAction(host, (ItemInfo) host.getTag(), action)) { + return true; + } + return super.performAccessibilityAction(host, action, args); + } + + public boolean performAction(View host, ItemInfo item, int action) { + if (action == REMOVE) { + return DeleteDropTarget.removeWorkspaceOrFolderItem(mLauncher, item, host); + } else if (action == INFO) { + InfoDropTarget.startDetailsActivityForInfo(item, mLauncher); + return true; + } else if (action == UNINSTALL) { + DeleteDropTarget.uninstallApp(mLauncher, (AppInfo) item); + return true; + } else if (action == ADD_TO_WORKSPACE) { + final int preferredPage = mLauncher.getWorkspace().getCurrentPage(); + final ScreenPosProvider screenProvider = new ScreenPosProvider() { + + @Override + public int getScreenIndex(ArrayList<Long> screenIDs) { + return preferredPage; + } + }; + if (item instanceof AppInfo) { + final ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>(); + addShortcuts.add(((AppInfo) item).makeShortcut()); + mLauncher.showWorkspace(true, new Runnable() { + + @Override + public void run() { + mLauncher.getModel().addAndBindAddedWorkspaceApps( + mLauncher, addShortcuts, screenProvider, 0, true); + } + }); + return true; + } else if (item instanceof PendingAddItemInfo) { + mLauncher.getModel().addAndBindPendingItem( + mLauncher, (PendingAddItemInfo) item, screenProvider, 0); + return true; + } + } + return false; + } +} |