Search in sources :

Example 11 with LauncherAppWidgetProviderInfo

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

the class BindWidgetTest method testBindNormalWidget_withConfig.

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

Example 12 with LauncherAppWidgetProviderInfo

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

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)

Example 13 with LauncherAppWidgetProviderInfo

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

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)

Example 14 with LauncherAppWidgetProviderInfo

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

the class BindWidgetTest method testPendingWidget_autoRestored.

@Test
public void testPendingWidget_autoRestored() {
    // A non-restored widget with no config screen gets restored automatically.
    LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(this, false);
    // Do not bind the widget
    LauncherAppWidgetInfo item = createWidgetInfo(info, getTargetContext(), false);
    item.restoreStatus = LauncherAppWidgetInfo.FLAG_ID_NOT_VALID;
    addItemToScreen(item);
    verifyWidgetPresent(info);
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 15 with LauncherAppWidgetProviderInfo

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

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)

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