Search in sources :

Example 91 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Trebuchet by LineageOS.

the class Launcher method handleActivityResult.

private void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (isWorkspaceLoading()) {
        // process the result once the workspace has loaded.
        mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
        return;
    }
    mPendingActivityResult = null;
    // Reset the startActivity waiting flag
    final PendingRequestArgs requestArgs = mPendingRequestArgs;
    setWaitingForResult(null);
    if (requestArgs == null) {
        return;
    }
    final int pendingAddWidgetId = requestArgs.getWidgetId();
    Runnable exitSpringLoaded = new Runnable() {

        @Override
        public void run() {
            mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
        }
    };
    if (requestCode == REQUEST_BIND_APPWIDGET) {
        // This is called only if the user did not previously have permissions to bind widgets
        final int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (resultCode == RESULT_CANCELED) {
            completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
        } else if (resultCode == RESULT_OK) {
            addAppWidgetImpl(appWidgetId, requestArgs, null, requestArgs.getWidgetHandler(), ON_ACTIVITY_RESULT_ANIMATION_DELAY);
        }
        return;
    }
    boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET);
    // We have special handling for widgets
    if (isWidgetDrop) {
        final int appWidgetId;
        int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (widgetId < 0) {
            appWidgetId = pendingAddWidgetId;
        } else {
            appWidgetId = widgetId;
        }
        final int result;
        if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
            Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + "returned from the widget configuration activity.");
            result = RESULT_CANCELED;
            completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, () -> getStateManager().goToState(NORMAL));
        } else {
            if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                // When the screen id represents an actual screen (as opposed to a rank)
                // we make sure that the drop page actually exists.
                requestArgs.screenId = ensurePendingDropLayoutExists(requestArgs.screenId);
            }
            final CellLayout dropLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
            dropLayout.setDropPending(true);
            final Runnable onComplete = new Runnable() {

                @Override
                public void run() {
                    completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
                    dropLayout.setDropPending(false);
                }
            };
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, onComplete);
        }
        return;
    }
    if (requestCode == REQUEST_RECONFIGURE_APPWIDGET || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
        if (resultCode == RESULT_OK) {
            // Update the widget view.
            completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
        }
        // Leave the widget in the pending state if the user canceled the configure.
        return;
    }
    if (requestCode == REQUEST_CREATE_SHORTCUT) {
        // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
        if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
            completeAdd(requestCode, data, -1, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
        } else if (resultCode == RESULT_CANCELED) {
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
        }
    }
    mDragLayer.clearAnimatedView();
}
Also used : ActivityResultInfo(com.android.launcher3.util.ActivityResultInfo) PendingRequestArgs(com.android.launcher3.util.PendingRequestArgs)

Example 92 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Trebuchet by LineageOS.

the class Launcher method completeAddShortcut.

/**
 * Add a shortcut to the workspace or to a Folder.
 *
 * @param data The intent describing the shortcut.
 */
private void completeAddShortcut(Intent data, int container, int screenId, int cellX, int cellY, PendingRequestArgs args) {
    if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT || args.getPendingIntent().getComponent() == null) {
        return;
    }
    int[] cellXY = mTmpAddItemCellCoordinates;
    CellLayout layout = getCellLayout(container, screenId);
    WorkspaceItemInfo info = null;
    if (Utilities.ATLEAST_OREO) {
        info = PinRequestHelper.createWorkspaceItemFromPinItemRequest(this, PinRequestHelper.getPinItemRequest(data), 0);
    }
    if (info == null) {
        // Legacy shortcuts are only supported for primary profile.
        info = Process.myUserHandle().equals(args.user) ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
        if (info == null) {
            Log.e(TAG, "Unable to parse a valid custom shortcut result");
            return;
        } else if (!new PackageManagerHelper(this).hasPermissionForActivity(info.intent, args.getPendingIntent().getComponent().getPackageName())) {
            // The app is trying to add a shortcut without sufficient permissions
            Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
            return;
        }
    }
    if (container < 0) {
        // Adding a shortcut to the Workspace.
        final View view = createShortcut(info);
        boolean foundCellSpan = false;
        // First we check if we already know the exact location where we want to add this item.
        if (cellX >= 0 && cellY >= 0) {
            cellXY[0] = cellX;
            cellXY[1] = cellY;
            foundCellSpan = true;
            DragObject dragObject = new DragObject(getApplicationContext());
            dragObject.dragInfo = info;
            // If appropriate, either create a folder or add to an existing folder
            if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, true, dragObject)) {
                return;
            }
            if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, true)) {
                return;
            }
        } else {
            foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
        }
        if (!foundCellSpan) {
            mWorkspace.onNoCellFound(layout);
            return;
        }
        getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
        mWorkspace.addInScreen(view, info);
    } else {
        // Adding a shortcut to a Folder.
        FolderIcon folderIcon = findFolderIcon(container);
        if (folderIcon != null) {
            FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
            folderInfo.add(info, args.rank, false);
        } else {
            Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
        }
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) DragObject(com.android.launcher3.DropTarget.DragObject) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) 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) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 93 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Trebuchet by LineageOS.

the class Launcher method completeAddAppWidget.

/**
 * Add a widget to the workspace.
 *
 * @param appWidgetId The app widget id
 */
@Thunk
void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
    if (appWidgetInfo == null) {
        appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
    }
    LauncherAppWidgetInfo launcherInfo;
    launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
    launcherInfo.spanX = itemInfo.spanX;
    launcherInfo.spanY = itemInfo.spanY;
    launcherInfo.minSpanX = itemInfo.minSpanX;
    launcherInfo.minSpanY = itemInfo.minSpanY;
    launcherInfo.user = appWidgetInfo.getProfile();
    getModelWriter().addItemToDatabase(launcherInfo, itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
    if (hostView == null) {
        // Perform actual inflation because we're live
        hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
    }
    hostView.setVisibility(View.VISIBLE);
    prepareAppWidget(hostView, launcherInfo);
    mWorkspace.addInScreen(hostView, launcherInfo);
    announceForAccessibility(R.string.item_added_to_workspace);
}
Also used : LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) Thunk(com.android.launcher3.util.Thunk)

Example 94 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Trebuchet by LineageOS.

the class FocusHelper method handleIconKeyEvent.

/**
 * Handles key events in a workspace containing icons.
 */
static boolean handleIconKeyEvent(View v, int keyCode, KeyEvent e) {
    boolean consume = FocusLogic.shouldConsume(keyCode);
    if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
        return consume;
    }
    Launcher launcher = Launcher.getLauncher(v.getContext());
    DeviceProfile profile = launcher.getDeviceProfile();
    if (DEBUG) {
        Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s", KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout()));
    }
    // Initialize the variables.
    ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
    CellLayout iconLayout = (CellLayout) parent.getParent();
    final Workspace workspace = (Workspace) iconLayout.getParent();
    final ViewGroup dragLayer = (ViewGroup) workspace.getParent();
    final ViewGroup tabs = (ViewGroup) dragLayer.findViewById(R.id.drop_target_bar);
    final Hotseat hotseat = (Hotseat) dragLayer.findViewById(R.id.hotseat);
    final ItemInfo itemInfo = (ItemInfo) v.getTag();
    final int iconIndex = parent.indexOfChild(v);
    final int pageIndex = workspace.indexOfChild(iconLayout);
    final int pageCount = workspace.getChildCount();
    CellLayout hotseatLayout = (CellLayout) hotseat.getChildAt(0);
    ShortcutAndWidgetContainer hotseatParent = hotseatLayout.getShortcutsAndWidgets();
    int[][] matrix;
    // with the hotseat.
    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !profile.isVerticalBarLayout()) {
        matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && profile.isVerticalBarLayout()) {
        matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
    } else {
        matrix = FocusLogic.createSparseMatrix(iconLayout);
    }
    // Process the focus.
    int newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, iconIndex, pageIndex, pageCount, Utilities.isRtl(v.getResources()));
    boolean isRtl = Utilities.isRtl(v.getResources());
    View newIcon = null;
    CellLayout workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex);
    switch(newIconIndex) {
        case FocusLogic.NOOP:
            if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                newIcon = tabs;
            }
            break;
        case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
        case FocusLogic.NEXT_PAGE_RIGHT_COLUMN:
            int newPageIndex = pageIndex - 1;
            if (newIconIndex == FocusLogic.NEXT_PAGE_RIGHT_COLUMN) {
                newPageIndex = pageIndex + 1;
            }
            int row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY;
            parent = getCellLayoutChildrenForIndex(workspace, newPageIndex);
            if (parent != null) {
                iconLayout = (CellLayout) parent.getParent();
                matrix = FocusLogic.createSparseMatrixWithPivotColumn(iconLayout, iconLayout.getCountX(), row);
                newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, FocusLogic.PIVOT, newPageIndex, pageCount, Utilities.isRtl(v.getResources()));
                if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
                    newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
                    newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else {
                    newIcon = parent.getChildAt(newIconIndex);
                }
            }
            break;
        case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
            workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex - 1);
            newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
            if (newIcon == null) {
                // Check the hotseat if no focusable item was found on the workspace.
                newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
                workspace.snapToPage(pageIndex - 1);
            }
            break;
        case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
            newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
            break;
        case FocusLogic.NEXT_PAGE_FIRST_ITEM:
            newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
            break;
        case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
        case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN:
            newPageIndex = pageIndex + 1;
            if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN) {
                newPageIndex = pageIndex - 1;
            }
            row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY;
            parent = getCellLayoutChildrenForIndex(workspace, newPageIndex);
            if (parent != null) {
                iconLayout = (CellLayout) parent.getParent();
                matrix = FocusLogic.createSparseMatrixWithPivotColumn(iconLayout, -1, row);
                newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, FocusLogic.PIVOT, newPageIndex, pageCount, Utilities.isRtl(v.getResources()));
                if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
                    newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
                    newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else {
                    newIcon = parent.getChildAt(newIconIndex);
                }
            }
            break;
        case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
            newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
            if (newIcon == null) {
                // Check the hotseat if no focusable item was found on the workspace.
                newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
            }
            break;
        case FocusLogic.CURRENT_PAGE_LAST_ITEM:
            newIcon = getFirstFocusableIconInReverseReadingOrder(workspaceLayout, isRtl);
            if (newIcon == null) {
                // Check the hotseat if no focusable item was found on the workspace.
                newIcon = getFirstFocusableIconInReverseReadingOrder(hotseatLayout, isRtl);
            }
            break;
        default:
            // current page, some item.
            if (0 <= newIconIndex && newIconIndex < parent.getChildCount()) {
                newIcon = parent.getChildAt(newIconIndex);
            } else if (parent.getChildCount() <= newIconIndex && newIconIndex < parent.getChildCount() + hotseatParent.getChildCount()) {
                newIcon = hotseatParent.getChildAt(newIconIndex - parent.getChildCount());
            }
            break;
    }
    if (newIcon != null) {
        newIcon.requestFocus();
        playSoundEffect(keyCode, v);
    }
    return consume;
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) ViewGroup(android.view.ViewGroup) View(android.view.View) FolderPagedView(com.android.launcher3.folder.FolderPagedView)

Example 95 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Trebuchet by LineageOS.

the class FocusHelper method handleNextPageFirstItem.

private static View handleNextPageFirstItem(Workspace workspace, CellLayout hotseatLayout, int pageIndex, boolean isRtl) {
    if (pageIndex + 1 >= workspace.getPageCount()) {
        return null;
    }
    CellLayout workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex + 1);
    View newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
    if (newIcon == null) {
        // Check the hotseat if no focusable item was found on the workspace.
        newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
        workspace.snapToPage(pageIndex + 1);
    }
    return newIcon;
}
Also used : View(android.view.View) FolderPagedView(com.android.launcher3.folder.FolderPagedView)

Aggregations

View (android.view.View)143 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)124 Point (android.graphics.Point)115 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)97 Rect (android.graphics.Rect)93 ArrayList (java.util.ArrayList)91 ItemInfo (com.android.launcher3.model.data.ItemInfo)86 DragView (com.android.launcher3.dragndrop.DragView)77 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)73 AppWidgetHostView (android.appwidget.AppWidgetHostView)72 Workspace (com.android.launcher3.Workspace)63 SuppressLint (android.annotation.SuppressLint)58 DraggableView (com.android.launcher3.dragndrop.DraggableView)58 Test (org.junit.Test)57 FolderInfo (com.android.launcher3.model.data.FolderInfo)55 CellLayout (com.android.launcher3.CellLayout)51 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)47 IntArray (com.android.launcher3.util.IntArray)45 Intent (android.content.Intent)43 ValueAnimator (android.animation.ValueAnimator)41