Search in sources :

Example 26 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Launcher3 by AOSPA.

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.setRemoteViewsPreview(PinItemDragListener.getPreview(mRequest));
    mAppWidgetManager = new WidgetManagerHelper(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this);
    PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(widgetInfo, CONTAINER_PIN_WIDGETS);
    pendingInfo.spanX = Math.min(mIdp.numColumns, widgetInfo.spanX);
    pendingInfo.spanY = Math.min(mIdp.numRows, widgetInfo.spanY);
    mWidgetOptions = pendingInfo.getDefaultSizeOptions(this);
    mWidgetCell.getWidgetView().setTag(pendingInfo);
    applyWidgetItemAsync(() -> new WidgetItem(widgetInfo, mIdp, mApp.getIconCache()));
    return true;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 27 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Launcher3 by AOSPA.

the class LauncherPreviewRenderer method inflateAndAddWidgets.

private void inflateAndAddWidgets(LauncherAppWidgetInfo info, LauncherAppWidgetProviderInfo providerInfo) {
    AppWidgetHostView view;
    if (FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()) {
        view = mAppWidgetHost.createView(mContext, info.appWidgetId, providerInfo);
    } else {
        view = new NavigableAppWidgetHostView(this) {

            @Override
            protected boolean shouldAllowDirectClick() {
                return false;
            }
        };
        view.setAppWidget(-1, providerInfo);
        view.updateAppWidget(null);
    }
    if (mWallpaperColorResources != null) {
        view.setColorResources(mWallpaperColorResources);
    }
    view.setTag(info);
    addInScreenFromBind(view, info);
}
Also used : BaseLauncherAppWidgetHostView(com.android.launcher3.widget.BaseLauncherAppWidgetHostView) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView)

Example 28 with LauncherAppWidgetProviderInfo

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

the class LauncherAppWidgetHost method createView.

public AppWidgetHostView createView(Context context, int appWidgetId, LauncherAppWidgetProviderInfo appWidget) {
    if (appWidget.isCustomWidget()) {
        LauncherAppWidgetHostView lahv = new LauncherAppWidgetHostView(context);
        lahv.setAppWidget(0, appWidget);
        CustomWidgetManager.INSTANCE.get(context).onViewCreated(lahv);
        return lahv;
    } else if ((mFlags & FLAG_LISTENING) == 0) {
        DeferredAppWidgetHostView view = new DeferredAppWidgetHostView(context);
        view.setAppWidget(appWidgetId, appWidget);
        mViews.put(appWidgetId, view);
        return view;
    } else {
        try {
            return super.createView(context, appWidgetId, appWidget);
        } catch (Exception e) {
            if (!Utilities.isBinderSizeError(e)) {
                throw new RuntimeException(e);
            }
            // If the exception was thrown while fetching the remote views, let the view stay.
            // This will ensure that if the widget posts a valid update later, the view
            // will update.
            LauncherAppWidgetHostView view = mViews.get(appWidgetId);
            if (view == null) {
                view = onCreateView(mContext, appWidgetId, appWidget);
            }
            view.setAppWidget(appWidgetId, appWidget);
            view.switchToErrorView();
            return view;
        }
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) DeferredAppWidgetHostView(com.android.launcher3.widget.DeferredAppWidgetHostView) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 29 with LauncherAppWidgetProviderInfo

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

the class BindWidgetTest method verifyWidgetPresent.

private void verifyWidgetPresent(LauncherAppWidgetProviderInfo info) {
    final Widget widget = mLauncher.getWorkspace().tryGetWidget(info.label, DEFAULT_UI_TIMEOUT);
    assertTrue("Widget is not present", widget != null);
}
Also used : Widget(com.android.launcher3.tapl.Widget)

Example 30 with LauncherAppWidgetProviderInfo

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

the class BindWidgetTest method testBindNormalWidget_withoutConfig.

@Test
public void testBindNormalWidget_withoutConfig() {
    LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(this, false);
    LauncherAppWidgetInfo item = createWidgetInfo(info, getTargetContext(), true);
    addItemToScreen(item);
    verifyWidgetPresent(info);
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

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