Search in sources :

Example 1 with CustomActionsPopup

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;
}
Also used : CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Handler(android.os.Handler) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) Folder(com.android.launcher3.folder.Folder) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) IntArray(com.android.launcher3.util.IntArray) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) BubbleTextView(com.android.launcher3.BubbleTextView) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Workspace(com.android.launcher3.Workspace)

Example 2 with CustomActionsPopup

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);
}
Also used : KeyboardShortcutGroup(android.view.KeyboardShortcutGroup) CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) ArrayList(java.util.ArrayList) KeyboardShortcutInfo(android.view.KeyboardShortcutInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) ScrimView(com.android.launcher3.views.ScrimView) DragView(com.android.launcher3.dragndrop.DragView)

Example 3 with CustomActionsPopup

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;
}
Also used : CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ItemInfo(com.android.launcher3.ItemInfo) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Handler(android.os.Handler) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) Folder(com.android.launcher3.folder.Folder) AppInfo(com.android.launcher3.AppInfo) IntArray(com.android.launcher3.util.IntArray) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) BubbleTextView(com.android.launcher3.BubbleTextView) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) Workspace(com.android.launcher3.Workspace)

Example 4 with CustomActionsPopup

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);
}
Also used : KeyboardShortcutGroup(android.view.KeyboardShortcutGroup) CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) ArrayList(java.util.ArrayList) KeyboardShortcutInfo(android.view.KeyboardShortcutInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) QsbContainerView(com.android.launcher3.qsb.QsbContainerView) FloatingSurfaceView(com.android.launcher3.views.FloatingSurfaceView) AppWidgetHostView(android.appwidget.AppWidgetHostView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) ScrimView(com.android.launcher3.views.ScrimView) DragView(com.android.launcher3.dragndrop.DragView)

Aggregations

CustomActionsPopup (com.android.launcher3.keyboard.CustomActionsPopup)4 ArrayList (java.util.ArrayList)4 AppWidgetHostView (android.appwidget.AppWidgetHostView)2 DialogInterface (android.content.DialogInterface)2 Handler (android.os.Handler)2 KeyboardShortcutGroup (android.view.KeyboardShortcutGroup)2 KeyboardShortcutInfo (android.view.KeyboardShortcutInfo)2 View (android.view.View)2 BubbleTextView (com.android.launcher3.BubbleTextView)2 ButtonDropTarget (com.android.launcher3.ButtonDropTarget)2 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)2 Workspace (com.android.launcher3.Workspace)2 AllAppsContainerView (com.android.launcher3.allapps.AllAppsContainerView)2 DragView (com.android.launcher3.dragndrop.DragView)2 Folder (com.android.launcher3.folder.Folder)2 ItemInfo (com.android.launcher3.model.data.ItemInfo)2 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)2 IntArray (com.android.launcher3.util.IntArray)2 OptionsPopupView (com.android.launcher3.views.OptionsPopupView)2 ScrimView (com.android.launcher3.views.ScrimView)2