Search in sources :

Example 16 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsTableUtilsTest method initTestWidgets.

private void initTestWidgets() {
    List<Point> widgetSizes = List.of(new Point(1, 1), new Point(2, 2), new Point(2, 3), new Point(2, 4), new Point(4, 4));
    ArrayList<WidgetItem> widgetItems = new ArrayList<>();
    widgetSizes.stream().forEach(widgetSize -> {
        ShadowPackageManager packageManager = shadowOf(mContext.getPackageManager());
        AppWidgetProviderInfo info = new AppWidgetProviderInfo();
        info.provider = ComponentName.createRelative(TEST_PACKAGE, ".WidgetProvider_" + widgetSize.x + "x" + widgetSize.y);
        LauncherAppWidgetProviderInfo widgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
        widgetInfo.spanX = widgetSize.x;
        widgetInfo.spanY = widgetSize.y;
        ReflectionHelpers.setField(widgetInfo, "providerInfo", packageManager.addReceiverIfNotPresent(widgetInfo.provider));
        widgetItems.add(new WidgetItem(widgetInfo, mTestProfile, mIconCache));
    });
    mWidget1x1 = widgetItems.get(0);
    mWidget2x2 = widgetItems.get(1);
    mWidget2x3 = widgetItems.get(2);
    mWidget2x4 = widgetItems.get(3);
    mWidget4x4 = widgetItems.get(4);
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) WidgetItem(com.android.launcher3.model.WidgetItem) Point(android.graphics.Point)

Example 17 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupDataProvider method getRecommendedWidgets.

/**
 * Returns a list of recommended widgets.
 */
public List<WidgetItem> getRecommendedWidgets() {
    HashMap<ComponentKey, WidgetItem> allWidgetItems = new HashMap<>();
    mAllWidgets.stream().filter(entry -> entry instanceof WidgetsListContentEntry).forEach(entry -> ((WidgetsListContentEntry) entry).mWidgets.forEach(widget -> allWidgetItems.put(new ComponentKey(widget.componentName, widget.user), widget)));
    return mRecommendedWidgets.stream().map(recommendedWidget -> allWidgetItems.get(new ComponentKey(recommendedWidget.getTargetComponent(), recommendedWidget.user))).filter(Objects::nonNull).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) NonNull(androidx.annotation.NonNull) ItemInfo(com.android.launcher3.model.data.ItemInfo) HashMap(java.util.HashMap) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) WidgetItem(com.android.launcher3.model.WidgetItem) Map(java.util.Map) Log(android.util.Log) PrintWriter(java.io.PrintWriter) ComponentName(android.content.ComponentName) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Predicate(java.util.function.Predicate) PackageUserKey(com.android.launcher3.util.PackageUserKey) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) NotificationListener(com.android.launcher3.notification.NotificationListener) ShortcutUtil(com.android.launcher3.util.ShortcutUtil) ComponentKey(com.android.launcher3.util.ComponentKey) Collections(java.util.Collections) StatusBarNotification(android.service.notification.StatusBarNotification) DotInfo(com.android.launcher3.dot.DotInfo) HashMap(java.util.HashMap) ComponentKey(com.android.launcher3.util.ComponentKey) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 18 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class AddItemActivity method setupShortcut.

private void setupShortcut() {
    PinShortcutRequestActivityInfo shortcutInfo = new PinShortcutRequestActivityInfo(mRequest, this);
    mWidgetCell.getWidgetView().setTag(new PendingAddShortcutInfo(shortcutInfo));
    applyWidgetItemAsync(() -> new WidgetItem(shortcutInfo, mApp.getIconCache(), getPackageManager()));
}
Also used : PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 19 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

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 20 with WidgetItem

use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherPreviewRenderer method inflateAndAddWidgets.

private void inflateAndAddWidgets(LauncherAppWidgetInfo info, WidgetsModel widgetsModel) {
    WidgetItem widgetItem = widgetsModel.getWidgetProviderInfoByProviderName(info.providerName);
    if (widgetItem == null) {
        return;
    }
    inflateAndAddWidgets(info, widgetItem.widgetInfo);
}
Also used : WidgetItem(com.android.launcher3.model.WidgetItem)

Aggregations

WidgetItem (com.android.launcher3.model.WidgetItem)37 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)17 ArrayList (java.util.ArrayList)15 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)11 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)10 ComponentName (android.content.ComponentName)9 Test (org.junit.Test)9 ShadowPackageManager (org.robolectric.shadows.ShadowPackageManager)9 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)8 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)7 Size (android.util.Size)6 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)5 TableRow (android.widget.TableRow)4 PackageUserKey (com.android.launcher3.util.PackageUserKey)4 PackageManager (android.content.pm.PackageManager)3 Nullable (androidx.annotation.Nullable)3 DeviceProfile (com.android.launcher3.DeviceProfile)3 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)3