Search in sources :

Example 36 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Trebuchet by LineageOS.

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.LauncherAppWidgetProviderInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler)

Example 37 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetsModel method update.

/**
 * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
 *                    only widgets and shortcuts associated with the package/user are.
 */
public List<ComponentWithLabelAndIcon> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabelAndIcon> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
            LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
            widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
            updatedItems.add(launcherWidgetInfo);
        }
        // Shortcuts
        for (ShortcutConfigActivityInfo info : queryList(context, packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
        // the returned value may be incomplete and will not be refreshed until the next
        // time Launcher starts.
        // TODO: after figuring out a repro step, introduce a dirty bit to check when
        // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    app.getWidgetCache().removeObsoletePreviews(widgetsAndShortcuts, packageUser);
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ArrayList(java.util.ArrayList) PackageManager(android.content.pm.PackageManager) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper)

Example 38 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Trebuchet by LineageOS.

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) {

            @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.setPreview(getPreview(mRequest));
    }
    return dragHelper;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.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 39 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project Neo-Launcher by NeoApplications.

the class Launcher method inflateAppWidget.

private View inflateAppWidget(LauncherAppWidgetInfo item) {
    if (mIsSafeModeEnabled) {
        PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, mIconCache, true);
        prepareAppWidget(view, item);
        return view;
    }
    TraceHelper.beginSection("BIND_WIDGET");
    final LauncherAppWidgetProviderInfo appWidgetInfo;
    if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
        // If the provider is not ready, bind as a pending widget.
        appWidgetInfo = null;
    } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
        // The widget id is not valid. Try to find the widget based on the provider info.
        appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
    } else {
        appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
    }
    // If the provider is ready, but the width is not yet restored, try to restore it.
    if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
        if (appWidgetInfo == null) {
            Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId + " belongs to component " + item.providerName + ", as the provider is null");
            getModelWriter().deleteItemFromDatabase(item);
            return null;
        }
        // If we do not have a valid id, try to bind an id.
        if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
                // Id has not been allocated yet. Allocate a new id.
                item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
                item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
                // Also try to bind the widget. If the bind fails, the user will be shown
                // a click to setup UI, which will ask for the bind permission.
                PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
                pendingInfo.spanX = item.spanX;
                pendingInfo.spanY = item.spanY;
                pendingInfo.minSpanX = item.minSpanX;
                pendingInfo.minSpanY = item.minSpanY;
                Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
                boolean isDirectConfig = item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
                if (isDirectConfig && item.bindOptions != null) {
                    Bundle newOptions = item.bindOptions.getExtras();
                    if (options != null) {
                        newOptions.putAll(options);
                    }
                    options = newOptions;
                }
                boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(item.appWidgetId, appWidgetInfo, options);
                // We tried to bind once. If we were not able to bind, we would need to
                // go through the permission dialog, which means we cannot skip the config
                // activity.
                item.bindOptions = null;
                item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
                // Bind succeeded
                if (success) {
                    // If the widget has a configure activity, it is still needs to set it up,
                    // otherwise the widget is ready to go.
                    item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig ? LauncherAppWidgetInfo.RESTORE_COMPLETED : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
                }
                getModelWriter().updateItemInDatabase(item);
            }
        } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY) && (appWidgetInfo.configure == null)) {
            // The widget was marked as UI not ready, but there is no configure activity to
            // update the UI.
            item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
            getModelWriter().updateItemInDatabase(item);
        }
    }
    final AppWidgetHostView view;
    if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
        // Verify that we own the widget
        if (appWidgetInfo == null) {
            FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
            getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
            return null;
        }
        item.minSpanX = appWidgetInfo.minSpanX;
        item.minSpanY = appWidgetInfo.minSpanY;
        view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
    } else {
        view = new PendingAppWidgetHostView(this, item, mIconCache, false);
    }
    prepareAppWidget(view, item);
    TraceHelper.endSection("BIND_WIDGET", "id=" + item.appWidgetId);
    return view;
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) Bundle(android.os.Bundle) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView)

Example 40 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project Neo-Launcher by NeoApplications.

the class AddItemActivity method setupWidget.

private boolean setupWidget() {
    LauncherAppWidgetProviderInfo widgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this, mRequest.getAppWidgetProviderInfo(this));
    if (widgetInfo.minSpanX > mIdp.numColumns || widgetInfo.minSpanY > mIdp.numRows) {
        // Cannot add widget
        return false;
    }
    mWidgetCell.setPreview(PinItemDragListener.getPreview(mRequest));
    mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this);
    PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(widgetInfo);
    pendingInfo.spanX = Math.min(mIdp.numColumns, widgetInfo.spanX);
    pendingInfo.spanY = Math.min(mIdp.numRows, widgetInfo.spanY);
    mWidgetOptions = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
    mWidgetCell.getWidgetView().setTag(pendingInfo);
    applyWidgetItemAsync(() -> new WidgetItem(widgetInfo, mIdp, mApp.getIconCache()));
    return true;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) LauncherAppWidgetHost(com.android.launcher3.LauncherAppWidgetHost) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) WidgetItem(com.android.launcher3.model.WidgetItem)

Aggregations

Test (org.junit.Test)108 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)81 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)77 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)65 SmallTest (androidx.test.filters.SmallTest)52 LargeTest (androidx.test.filters.LargeTest)42 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)42 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)33 Bundle (android.os.Bundle)32 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)31 Point (android.graphics.Point)29 LauncherAppWidgetProviderInfo (com.android.launcher3.LauncherAppWidgetProviderInfo)28 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)23 Context (android.content.Context)23 DeviceProfile (com.android.launcher3.DeviceProfile)23 ArrayList (java.util.ArrayList)21 AppWidgetHostView (android.appwidget.AppWidgetHostView)20 WidgetItem (com.android.launcher3.model.WidgetItem)17 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)14 WidgetAddFlowHandler (com.android.launcher3.widget.WidgetAddFlowHandler)14