Search in sources :

Example 51 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ArrowOS.

the class Workspace method onDropExternal.

/**
 * Drop an item that didn't originate on one of the workspace screens.
 * It may have come from Launcher (e.g. from all apps or customize), or it may have
 * come from another app altogether.
 *
 * NOTE: This can also be called when we are outside of a drag event, when we want
 * to add an item to one of the workspace screens.
 */
private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
    if (d.dragInfo instanceof PendingAddShortcutInfo) {
        WorkspaceItemInfo si = ((PendingAddShortcutInfo) d.dragInfo).activityInfo.createWorkspaceItemInfo();
        if (si != null) {
            d.dragInfo = si;
        }
    }
    ItemInfo info = d.dragInfo;
    int spanX = info.spanX;
    int spanY = info.spanY;
    if (mDragInfo != null) {
        spanX = mDragInfo.spanX;
        spanY = mDragInfo.spanY;
    }
    final int container = mLauncher.isHotseatLayout(cellLayout) ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP;
    final int screenId = getIdForScreen(cellLayout);
    if (!mLauncher.isHotseatLayout(cellLayout) && screenId != getScreenIdForPageIndex(mCurrentPage) && !mLauncher.isInState(SPRING_LOADED)) {
        snapToPage(getPageIndexForScreenId(screenId));
    }
    if (info instanceof PendingAddItemInfo) {
        final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) info;
        boolean findNearestVacantCell = true;
        if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
            mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
            float distance = cellLayout.getDistanceFromWorkspaceCellVisualCenter(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true) || willAddToExistingUserFolder(d.dragInfo, cellLayout, mTargetCell, distance)) {
                findNearestVacantCell = false;
            }
        }
        final ItemInfo item = d.dragInfo;
        boolean updateWidgetSize = false;
        if (findNearestVacantCell) {
            int minSpanX = item.spanX;
            int minSpanY = item.spanY;
            if (item.minSpanX > 0 && item.minSpanY > 0) {
                minSpanX = item.minSpanX;
                minSpanY = item.minSpanY;
            }
            int[] resultSpan = new int[2];
            mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY, null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL);
            if (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY) {
                updateWidgetSize = true;
            }
            item.spanX = resultSpan[0];
            item.spanY = resultSpan[1];
        }
        Runnable onAnimationCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                // Normally removeExtraEmptyScreen is called in Workspace#onDrop, but when
                // adding an item that may not be dropped right away (due to a config activity)
                // we defer the removal until the activity returns.
                deferRemoveExtraEmptyScreen();
                // When dragging and dropping from customization tray, we deal with creating
                // widgets/shortcuts/folders in a slightly different way
                mLauncher.addPendingItem(pendingInfo, container, screenId, mTargetCell, item.spanX, item.spanY);
                mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
            }
        };
        boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
        AppWidgetHostView finalView = isWidget ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
        if (finalView != null && updateWidgetSize) {
            WidgetSizes.updateWidgetSizeRanges(finalView, mLauncher, item.spanX, item.spanY);
        }
        int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR;
        if (isWidget && ((PendingAddWidgetInfo) pendingInfo).info != null && ((PendingAddWidgetInfo) pendingInfo).getHandler().needsConfigure()) {
            animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN;
        }
        animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable, animationStyle, finalView, true);
    } else {
        // This is for other drag/drop cases, like dragging from All Apps
        mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
        View view;
        switch(info.itemType) {
            case ITEM_TYPE_APPLICATION:
            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
            case LauncherSettings.Favorites.ITEM_TYPE_SEARCH_ACTION:
                if (info instanceof AppInfo) {
                    // Came from all apps -- make a copy
                    info = ((AppInfo) info).makeWorkspaceItem();
                    d.dragInfo = info;
                }
                if (info instanceof SearchActionItemInfo) {
                    info = ((SearchActionItemInfo) info).createWorkspaceItem(mLauncher.getModel());
                    d.dragInfo = info;
                }
                view = mLauncher.createShortcut(cellLayout, (WorkspaceItemInfo) info);
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                view = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, mLauncher, cellLayout, (FolderInfo) info);
                break;
            default:
                throw new IllegalStateException("Unknown item type: " + info.itemType);
        }
        // dropped, without any consideration to whether there is an item there.
        if (touchXY != null) {
            mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
            float distance = cellLayout.getDistanceFromWorkspaceCellVisualCenter(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, true, d)) {
                return;
            }
            if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, true)) {
                return;
            }
        }
        if (touchXY != null) {
            // when dragging and dropping, just find the closest free spot
            mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], 1, 1, 1, 1, null, mTargetCell, null, CellLayout.MODE_ON_DROP_EXTERNAL);
        } else {
            cellLayout.findCellForSpan(mTargetCell, 1, 1);
        }
        // Add the item to DB before adding to screen ensures that the container and other
        // values of the info is properly updated.
        mLauncher.getModelWriter().addOrMoveItemInDatabase(info, container, screenId, mTargetCell[0], mTargetCell[1]);
        addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, info.spanY);
        cellLayout.onDropChild(view);
        cellLayout.getShortcutsAndWidgets().measureChild(view);
        if (d.dragView != null) {
            // We wrap the animation call in the temporary set and reset of the current
            // cellLayout to its final transform -- this means we animate the drag view to
            // the correct final location.
            setFinalTransitionTransform();
            mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, this);
            resetTransitionTransform();
        }
        mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) FolderInfo(com.android.launcher3.model.data.FolderInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 52 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ArrowOS.

the class Workspace method widgetsRestored.

public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) {
    if (!changedInfo.isEmpty()) {
        DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, mLauncher.getAppWidgetHost());
        LauncherAppWidgetInfo item = changedInfo.get(0);
        final AppWidgetProviderInfo widgetInfo;
        WidgetManagerHelper widgetHelper = new WidgetManagerHelper(getContext());
        if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            widgetInfo = widgetHelper.findProvider(item.providerName, item.user);
        } else {
            widgetInfo = widgetHelper.getLauncherAppWidgetInfo(item.appWidgetId);
        }
        if (widgetInfo != null) {
            // Re-inflate the widgets which have changed status
            widgetRefresh.run();
        } else {
            // widgetRefresh will automatically run when the packages are updated.
            // For now just update the progress bars
            mapOverItems(new ItemOperator() {

                @Override
                public boolean evaluate(ItemInfo info, View view) {
                    if (view instanceof PendingAppWidgetHostView && changedInfo.contains(info)) {
                        ((LauncherAppWidgetInfo) info).installProgress = 100;
                        ((PendingAppWidgetHostView) view).applyState();
                    }
                    // process all the shortcuts
                    return false;
                }
            });
        }
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView)

Example 53 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ArrowOS.

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 54 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ArrowOS.

the class AddItemWidgetsBottomSheet method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
    int widthUsed;
    if (mInsets.bottom > 0) {
        widthUsed = mInsets.left + mInsets.right;
    } else {
        Rect padding = deviceProfile.workspacePadding;
        widthUsed = Math.max(padding.left + padding.right, 2 * (mInsets.left + mInsets.right));
    }
    if (deviceProfile.isTablet || deviceProfile.isTwoPanels) {
        // In large screen devices, we restrict the width of the widgets picker to show part of
        // the home screen. Let's ensure the minimum width used is at least the minimum width
        // that isn't taken by the widgets picker.
        int minUsedWidth = (int) (deviceProfile.availableWidthPx * (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN));
        widthUsed = Math.max(widthUsed, minUsedWidth);
    }
    int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
    measureChildWithMargins(mContent, widthMeasureSpec, widthUsed, heightMeasureSpec, heightUsed);
    setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Rect(android.graphics.Rect) SuppressLint(android.annotation.SuppressLint)

Example 55 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ArrowOS.

the class BaseWidgetSheet method doMeasure.

/**
 * Measures the dimension of this view and its children by taking system insets, navigation bar,
 * status bar, into account.
 */
@GuardedBy("MainThread")
protected void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
    int widthUsed;
    if (mInsets.bottom > 0) {
        widthUsed = mInsets.left + mInsets.right;
    } else {
        Rect padding = deviceProfile.workspacePadding;
        widthUsed = Math.max(padding.left + padding.right, 2 * (mInsets.left + mInsets.right));
    }
    if (deviceProfile.isTablet || deviceProfile.isTwoPanels) {
        // In large screen devices, we restrict the width of the widgets picker to show part of
        // the home screen. Let's ensure the minimum width used is at least the minimum width
        // that isn't taken by the widgets picker.
        int minUsedWidth = (int) (deviceProfile.availableWidthPx * (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN));
        widthUsed = Math.max(widthUsed, minUsedWidth);
    }
    int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
    measureChildWithMargins(mContent, widthMeasureSpec, widthUsed, heightMeasureSpec, heightUsed);
    setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Rect(android.graphics.Rect) Point(android.graphics.Point) GuardedBy(androidx.annotation.GuardedBy)

Aggregations

ArrayList (java.util.ArrayList)64 Test (org.junit.Test)64 WidgetItem (com.android.launcher3.model.WidgetItem)54 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)54 PackageUserKey (com.android.launcher3.util.PackageUserKey)50 List (java.util.List)50 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)46 SmallTest (androidx.test.filters.SmallTest)44 ComponentName (android.content.ComponentName)42 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)41 Point (android.graphics.Point)40 View (android.view.View)37 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)32 Collectors (java.util.stream.Collectors)31 Context (android.content.Context)29 IconCache (com.android.launcher3.icons.IconCache)29 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)29 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)29 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)27 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)27