Search in sources :

Example 1 with WidgetAddFlowHandler

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

the class Launcher method addAppWidgetFromDrop.

/**
 * Process a widget drop.
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
    AppWidgetHostView hostView = info.boundWidget;
    final int appWidgetId;
    WidgetAddFlowHandler addFlowHandler = info.getHandler();
    if (hostView != null) {
        // In the case where we've prebound the widget, we remove it from the DragLayer
        if (LOGD) {
            Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
        }
        getDragLayer().removeView(hostView);
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
        // Clear the boundWidget so that it doesn't get destroyed.
        info.boundWidget = null;
    } else {
        // the widget, or we need to start an activity to configure the widget, or both.
        if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
            appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider(info.componentName);
        } else {
            appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        }
        Bundle options = info.bindOptions;
        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
        } else {
            addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
        }
    }
}
Also used : PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) Bundle(android.os.Bundle) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler)

Example 2 with WidgetAddFlowHandler

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

the class PinItemDragListener method createDragHelper.

@Override
protected PendingItemDragHelper createDragHelper() {
    final PendingAddItemInfo item;
    if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
        item = new PendingAddShortcutInfo(new PinShortcutRequestActivityInfo(mRequest, mLauncher));
    } else {
        // mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET
        LauncherAppWidgetProviderInfo providerInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(mLauncher, mRequest.getAppWidgetProviderInfo(mLauncher));
        final PinWidgetFlowHandler flowHandler = new PinWidgetFlowHandler(providerInfo, mRequest);
        item = new PendingAddWidgetInfo(providerInfo, CONTAINER_PIN_WIDGETS) {

            @Override
            public WidgetAddFlowHandler getHandler() {
                return flowHandler;
            }
        };
    }
    View view = new View(mLauncher);
    view.setTag(item);
    PendingItemDragHelper dragHelper = new PendingItemDragHelper(view);
    if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_APPWIDGET) {
        dragHelper.setRemoteViewsPreview(getPreview(mRequest));
    }
    return dragHelper;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) PendingItemDragHelper(com.android.launcher3.widget.PendingItemDragHelper) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler) View(android.view.View)

Example 3 with WidgetAddFlowHandler

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

the class ItemClickHandler method onClickPendingWidget.

/**
 * Event handler for the app widget view which has not fully restored.
 */
private static void onClickPendingWidget(PendingAppWidgetHostView v, Launcher launcher) {
    if (launcher.getPackageManager().isSafeMode()) {
        Toast.makeText(launcher, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
        return;
    }
    final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
    if (v.isReadyForClickSetup()) {
        LauncherAppWidgetProviderInfo appWidgetInfo = new WidgetManagerHelper(launcher).findProvider(info.providerName, info.user);
        if (appWidgetInfo == null) {
            return;
        }
        WidgetAddFlowHandler addFlowHandler = new WidgetAddFlowHandler(appWidgetInfo);
        if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
                // This should not happen, as we make sure that an Id is allocated during bind.
                return;
            }
            addFlowHandler.startBindFlow(launcher, info.appWidgetId, info, REQUEST_BIND_PENDING_APPWIDGET);
        } else {
            addFlowHandler.startConfigActivity(launcher, info, REQUEST_RECONFIGURE_APPWIDGET);
        }
    } else {
        final String packageName = info.providerName.getPackageName();
        onClickPendingAppItem(v, launcher, packageName, info.installProgress >= 0);
    }
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler)

Aggregations

WidgetAddFlowHandler (com.android.launcher3.widget.WidgetAddFlowHandler)3 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)2 AppWidgetHostView (android.appwidget.AppWidgetHostView)1 Bundle (android.os.Bundle)1 View (android.view.View)1 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)1 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)1 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)1 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)1 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)1 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)1 PendingItemDragHelper (com.android.launcher3.widget.PendingItemDragHelper)1 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)1