Search in sources :

Example 86 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

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;
        }
    }
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.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.widget.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper)

Example 87 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

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 88 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

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), mPreviewScale);
    }
    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 89 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

the class LauncherAppWidgetProviderInfoTest method isMinSizeFulfilled_minWidthAndMinResizeWidthExceededGridColumns_shouldReturnFalse.

@Test
public void isMinSizeFulfilled_minWidthAndMinResizeWidthExceededGridColumns_shouldReturnFalse() {
    LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
    info.minWidth = CELL_SIZE * (NUM_OF_COLS + 2);
    info.minHeight = 80;
    info.minResizeWidth = CELL_SIZE * (NUM_OF_COLS + 1);
    info.minResizeHeight = 50;
    InvariantDeviceProfile idp = createIDP();
    info.initSpans(mContext, idp);
    assertThat(info.isMinSizeFulfilled()).isFalse();
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 90 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

the class LauncherAppWidgetProviderInfoTest method initSpans_minWidthSmallerThanCellWidth_shouldInitializeSpansToOne.

@Test
public void initSpans_minWidthSmallerThanCellWidth_shouldInitializeSpansToOne() {
    LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
    info.minWidth = 20;
    info.minHeight = 20;
    InvariantDeviceProfile idp = createIDP();
    info.initSpans(mContext, idp);
    assertThat(info.spanX).isEqualTo(1);
    assertThat(info.spanY).isEqualTo(1);
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SmallTest(androidx.test.filters.SmallTest) 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