Search in sources :

Example 11 with PendingAddWidgetInfo

use of com.android.launcher3.widget.PendingAddWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method acceptDrop.

/**
 * {@inheritDoc}
 */
@Override
public boolean acceptDrop(DragObject d) {
    // If it's an external drop (e.g. from All Apps), check if it should be accepted
    CellLayout dropTargetLayout = mDropToLayout;
    if (d.dragSource != this) {
        // Don't accept the drop if we're not over a screen at time of drop
        if (dropTargetLayout == null) {
            return false;
        }
        if (!transitionStateShouldAllowDrop())
            return false;
        mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
        // We want the point to be mapped to the dragTarget.
        mapPointFromDropLayout(dropTargetLayout, mDragViewVisualCenter);
        int spanX;
        int spanY;
        if (mDragInfo != null) {
            final CellLayout.CellInfo dragCellInfo = mDragInfo;
            spanX = dragCellInfo.spanX;
            spanY = dragCellInfo.spanY;
        } else {
            spanX = d.dragInfo.spanX;
            spanY = d.dragInfo.spanY;
        }
        int minSpanX = spanX;
        int minSpanY = spanY;
        if (d.dragInfo instanceof PendingAddWidgetInfo) {
            minSpanX = ((PendingAddWidgetInfo) d.dragInfo).minSpanX;
            minSpanY = ((PendingAddWidgetInfo) d.dragInfo).minSpanY;
        }
        mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout, mTargetCell);
        float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
        if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) {
            return true;
        }
        if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance)) {
            return true;
        }
        int[] resultSpan = new int[2];
        mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, null, mTargetCell, resultSpan, CellLayout.MODE_ACCEPT_DROP);
        boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
        // Don't accept the drop if there's no room for the item
        if (!foundCell) {
            onNoCellFound(dropTargetLayout);
            return false;
        }
    }
    int screenId = getIdForScreen(dropTargetLayout);
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        commitExtraEmptyScreen();
    }
    return true;
}
Also used : PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 12 with PendingAddWidgetInfo

use of com.android.launcher3.widget.PendingAddWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

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);
    }
    if (hostView == null) {
        // Perform actual inflation because we're live
        hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
    }
    LauncherAppWidgetInfo launcherInfo;
    launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider, appWidgetInfo, hostView);
    launcherInfo.spanX = itemInfo.spanX;
    launcherInfo.spanY = itemInfo.spanY;
    launcherInfo.minSpanX = itemInfo.minSpanX;
    launcherInfo.minSpanY = itemInfo.minSpanY;
    launcherInfo.user = appWidgetInfo.getProfile();
    if (itemInfo instanceof PendingAddWidgetInfo) {
        launcherInfo.sourceContainer = ((PendingAddWidgetInfo) itemInfo).sourceContainer;
    } else if (itemInfo instanceof PendingRequestArgs) {
        launcherInfo.sourceContainer = ((PendingRequestArgs) itemInfo).getWidgetSourceContainer();
    }
    getModelWriter().addItemToDatabase(launcherInfo, itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
    hostView.setVisibility(View.VISIBLE);
    prepareAppWidget(hostView, launcherInfo);
    mWorkspace.addInScreen(hostView, launcherInfo);
    announceForAccessibility(R.string.item_added_to_workspace);
    // Show the widget resize frame.
    if (hostView instanceof LauncherAppWidgetHostView) {
        final LauncherAppWidgetHostView launcherHostView = (LauncherAppWidgetHostView) hostView;
        CellLayout cellLayout = getCellLayout(launcherInfo.container, launcherInfo.screenId);
        if (mStateManager.getState() == NORMAL) {
            // Show resize frame once the widget layout is drawn.
            View.OnLayoutChangeListener onLayoutChangeListener = new View.OnLayoutChangeListener() {

                @Override
                public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout);
                    launcherHostView.removeOnLayoutChangeListener(this);
                }
            };
            launcherHostView.addOnLayoutChangeListener(onLayoutChangeListener);
            // There is a small chance that the layout was already drawn before the layout
            // change listener was registered, which means that the resize frame wouldn't be
            // shown. Directly call requestLayout to force a layout change.
            launcherHostView.requestLayout();
        } else {
            mStateManager.addStateListener(new StateManager.StateListener<LauncherState>() {

                @Override
                public void onStateTransitionComplete(LauncherState finalState) {
                    if (mPrevLauncherState == SPRING_LOADED && finalState == NORMAL) {
                        AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout);
                        mStateManager.removeStateListener(this);
                    }
                }
            });
        }
    }
}
Also used : StateManager(com.android.launcher3.statemanager.StateManager) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) QsbContainerView(com.android.launcher3.qsb.QsbContainerView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) ImageView(android.widget.ImageView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) FloatingSurfaceView(com.android.launcher3.views.FloatingSurfaceView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) ScrimView(com.android.launcher3.views.ScrimView) PendingRequestArgs(com.android.launcher3.util.PendingRequestArgs) Thunk(com.android.launcher3.util.Thunk)

Example 13 with PendingAddWidgetInfo

use of com.android.launcher3.widget.PendingAddWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetUtils method createWidgetInfo.

/**
 * Creates a LauncherAppWidgetInfo corresponding to {@param info}
 *
 * @param bindWidget if true the info is bound and a valid widgetId is assigned to
 *                   the LauncherAppWidgetInfo
 */
public static LauncherAppWidgetInfo createWidgetInfo(LauncherAppWidgetProviderInfo info, Context targetContext, boolean bindWidget) {
    LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(LauncherAppWidgetInfo.NO_ID, info.provider);
    item.spanX = info.minSpanX;
    item.spanY = info.minSpanY;
    item.minSpanX = info.minSpanX;
    item.minSpanY = info.minSpanY;
    item.user = info.getProfile();
    item.cellX = 0;
    item.cellY = 1;
    item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    if (bindWidget) {
        PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(info, LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY);
        pendingInfo.spanX = item.spanX;
        pendingInfo.spanY = item.spanY;
        pendingInfo.minSpanX = item.minSpanX;
        pendingInfo.minSpanY = item.minSpanY;
        Bundle options = pendingInfo.getDefaultSizeOptions(targetContext);
        AppWidgetHost host = new LauncherAppWidgetHost(targetContext);
        int widgetId = host.allocateAppWidgetId();
        if (!new WidgetManagerHelper(targetContext).bindAppWidgetIdIfAllowed(widgetId, info, options)) {
            host.deleteAppWidgetId(widgetId);
            throw new IllegalArgumentException("Unable to bind widget id");
        }
        item.appWidgetId = widgetId;
    }
    return item;
}
Also used : PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) AppWidgetHost(android.appwidget.AppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) Bundle(android.os.Bundle) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo)

Aggregations

PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)10 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)5 AppWidgetHostView (android.appwidget.AppWidgetHostView)4 ComponentName (android.content.ComponentName)4 Point (android.graphics.Point)4 LauncherAppState (com.android.launcher3.LauncherAppState)4 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)4 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)4 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)4 AppTarget (android.app.prediction.AppTarget)3 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)3 Bundle (android.os.Bundle)3 View (android.view.View)3 CONTAINER_WIDGETS_PREDICTION (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION)3 FeatureFlags (com.android.launcher3.config.FeatureFlags)3 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)3 PredictorState (com.android.launcher3.model.QuickstepModelDelegate.PredictorState)3 AppInfo (com.android.launcher3.model.data.AppInfo)3 ItemInfo (com.android.launcher3.model.data.ItemInfo)3 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)3