use of com.android.launcher3.keyboard.CustomActionsPopup in project android_packages_apps_Trebuchet by LineageOS.
the class LauncherAccessibilityDelegate method performAction.
public boolean performAction(final View host, final ItemInfo item, int action) {
if (action == ACTION_LONG_CLICK) {
if (PopupContainerWithArrow.canShow(host, item)) {
// Long press should be consumed for workspace items, and it should invoke the
// Shortcuts / Notifications / Actions pop-up menu, and not start a drag as the
// standard long press path does.
PopupContainerWithArrow.showForIcon((BubbleTextView) host);
return true;
} else {
CustomActionsPopup popup = new CustomActionsPopup(mLauncher, host);
if (popup.canShow()) {
popup.show();
return true;
}
}
}
if (host instanceof AccessibilityActionHandler && ((AccessibilityActionHandler) host).performAccessibilityAction(action, item)) {
return true;
}
if (action == MOVE) {
beginAccessibleDrag(host, item);
} else if (action == ADD_TO_WORKSPACE) {
final int[] coordinates = new int[2];
final int screenId = findSpaceOnWorkspace(item, coordinates);
mLauncher.getStateManager().goToState(NORMAL, true, new Runnable() {
@Override
public void run() {
if (item instanceof AppInfo) {
WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
ArrayList<ItemInfo> itemList = new ArrayList<>();
itemList.add(info);
mLauncher.bindItems(itemList, true);
announceConfirmation(R.string.item_added_to_workspace);
} else if (item instanceof PendingAddItemInfo) {
PendingAddItemInfo info = (PendingAddItemInfo) item;
Workspace workspace = mLauncher.getWorkspace();
workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates, info.spanX, info.spanY);
}
}
});
return true;
} else if (action == MOVE_TO_WORKSPACE) {
Folder folder = Folder.getOpen(mLauncher);
folder.close(true);
WorkspaceItemInfo info = (WorkspaceItemInfo) item;
folder.getInfo().remove(info, false);
final int[] coordinates = new int[2];
final int screenId = findSpaceOnWorkspace(item, coordinates);
mLauncher.getModelWriter().moveItemInDatabase(info, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
// Bind the item in next frame so that if a new workspace page was created,
// it will get laid out.
new Handler().post(new Runnable() {
@Override
public void run() {
ArrayList<ItemInfo> itemList = new ArrayList<>();
itemList.add(item);
mLauncher.bindItems(itemList, true);
announceConfirmation(R.string.item_moved);
}
});
} else if (action == RESIZE) {
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
final IntArray actions = getSupportedResizeActions(host, info);
CharSequence[] labels = new CharSequence[actions.size()];
for (int i = 0; i < actions.size(); i++) {
labels[i] = mLauncher.getText(actions.get(i));
}
new AlertDialog.Builder(mLauncher).setTitle(R.string.action_resize).setItems(labels, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
performResizeAction(actions.get(which), host, info);
dialog.dismiss();
}
}).show();
return true;
} else if (action == DEEP_SHORTCUTS) {
return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
} else {
for (ButtonDropTarget dropTarget : mLauncher.getDropTargetBar().getDropTargets()) {
if (dropTarget.supportsAccessibilityDrop(item, host) && action == dropTarget.getAccessibilityAction()) {
dropTarget.onAccessibilityDrop(host, item);
return true;
}
}
}
return false;
}
use of com.android.launcher3.keyboard.CustomActionsPopup in project Neo-Launcher by NeoApplications.
the class Launcher method onProvideKeyboardShortcuts.
@Override
public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
if (isInState(NORMAL)) {
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label), KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text), KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
}
final View currentFocus = getCurrentFocus();
if (currentFocus != null) {
if (new CustomActionsPopup(this, currentFocus).canShow()) {
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions), KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
}
if (currentFocus.getTag() instanceof ItemInfo && ShortcutUtil.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.shortcuts_menu_with_notifications_description), KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
}
}
if (!shortcutInfos.isEmpty()) {
data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
}
super.onProvideKeyboardShortcuts(data, menu, deviceId);
}
use of com.android.launcher3.keyboard.CustomActionsPopup in project Neo-Launcher by NeoApplications.
the class LauncherAccessibilityDelegate method performAction.
public boolean performAction(final View host, final ItemInfo item, int action) {
if (action == ACTION_LONG_CLICK && ShortcutUtil.isDeepShortcut(item)) {
CustomActionsPopup popup = new CustomActionsPopup(mLauncher, host);
if (popup.canShow()) {
popup.show();
return true;
}
}
if (action == MOVE) {
beginAccessibleDrag(host, item);
} else if (action == ADD_TO_WORKSPACE) {
final int[] coordinates = new int[2];
final int screenId = findSpaceOnWorkspace(item, coordinates);
mLauncher.getStateManager().goToState(NORMAL, true, new Runnable() {
@Override
public void run() {
if (item instanceof AppInfo) {
WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
ArrayList<ItemInfo> itemList = new ArrayList<>();
itemList.add(info);
mLauncher.bindItems(itemList, true);
} else if (item instanceof PendingAddItemInfo) {
PendingAddItemInfo info = (PendingAddItemInfo) item;
Workspace workspace = mLauncher.getWorkspace();
workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates, info.spanX, info.spanY);
}
announceConfirmation(R.string.item_added_to_workspace);
}
});
return true;
} else if (action == MOVE_TO_WORKSPACE) {
Folder folder = Folder.getOpen(mLauncher);
folder.close(true);
WorkspaceItemInfo info = (WorkspaceItemInfo) item;
folder.getInfo().remove(info, false);
final int[] coordinates = new int[2];
final int screenId = findSpaceOnWorkspace(item, coordinates);
mLauncher.getModelWriter().moveItemInDatabase(info, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
// Bind the item in next frame so that if a new workspace page was created,
// it will get laid out.
new Handler().post(new Runnable() {
@Override
public void run() {
ArrayList<ItemInfo> itemList = new ArrayList<>();
itemList.add(item);
mLauncher.bindItems(itemList, true);
announceConfirmation(R.string.item_moved);
}
});
} else if (action == RESIZE) {
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
final IntArray actions = getSupportedResizeActions(host, info);
CharSequence[] labels = new CharSequence[actions.size()];
for (int i = 0; i < actions.size(); i++) {
labels[i] = mLauncher.getText(actions.get(i));
}
new AlertDialog.Builder(mLauncher).setTitle(R.string.action_resize).setItems(labels, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
performResizeAction(actions.get(which), host, info);
dialog.dismiss();
}
}).show();
return true;
} else if (action == DEEP_SHORTCUTS) {
return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
} else {
for (ButtonDropTarget dropTarget : mLauncher.getDropTargetBar().getDropTargets()) {
if (dropTarget.supportsAccessibilityDrop(item, host) && action == dropTarget.getAccessibilityAction()) {
dropTarget.onAccessibilityDrop(host, item);
return true;
}
}
}
return false;
}
use of com.android.launcher3.keyboard.CustomActionsPopup in project android_packages_apps_Trebuchet by LineageOS.
the class Launcher method onProvideKeyboardShortcuts.
@Override
public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
if (isInState(NORMAL)) {
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label), KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text), KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
}
final View currentFocus = getCurrentFocus();
if (currentFocus != null) {
if (new CustomActionsPopup(this, currentFocus).canShow()) {
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions), KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
}
if (currentFocus.getTag() instanceof ItemInfo && ShortcutUtil.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.shortcuts_menu_with_notifications_description), KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
}
}
if (!shortcutInfos.isEmpty()) {
data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
}
super.onProvideKeyboardShortcuts(data, menu, deviceId);
}
Aggregations