Search in sources :

Example 1 with AppWidgetManagerCompat

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

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<ComponentWithLabel> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabel> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(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 : LauncherAppsCompat.getInstance(context).getCustomShortcutActivityList(packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_DOGFOOD_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) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.compat.ShortcutConfigActivityInfo) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel)

Example 2 with AppWidgetManagerCompat

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

the class WidgetsListAdapterTest method generateSampleMap.

/**
 * Helper method to generate the sample widget model map that can be used for the tests
 * @param num the number of WidgetItem the map should contain
 * @return
 */
private ArrayList<WidgetListRowEntry> generateSampleMap(int num) {
    ArrayList<WidgetListRowEntry> result = new ArrayList<>();
    if (num <= 0)
        return result;
    MultiHashMap<PackageItemInfo, WidgetItem> newMap = new MultiHashMap();
    AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(mContext);
    for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(null)) {
        WidgetItem wi = new WidgetItem(LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, widgetInfo), mTestProfile, mIconCache);
        PackageItemInfo pInfo = new PackageItemInfo(wi.componentName.getPackageName());
        pInfo.title = pInfo.packageName;
        pInfo.user = wi.user;
        pInfo.iconBitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8);
        newMap.addToList(pInfo, wi);
        if (newMap.size() == num) {
            break;
        }
    }
    for (Map.Entry<PackageItemInfo, ArrayList<WidgetItem>> entry : newMap.entrySet()) {
        result.add(new WidgetListRowEntry(entry.getKey(), entry.getValue()));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PackageItemInfo(com.android.launcher3.model.PackageItemInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) WidgetItem(com.android.launcher3.model.WidgetItem) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) MultiHashMap(com.android.launcher3.util.MultiHashMap) Map(java.util.Map) MultiHashMap(com.android.launcher3.util.MultiHashMap)

Aggregations

AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)2 LauncherAppWidgetProviderInfo (com.android.launcher3.LauncherAppWidgetProviderInfo)2 AppWidgetManagerCompat (com.android.launcher3.compat.AppWidgetManagerCompat)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 PackageManager (android.content.pm.PackageManager)1 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)1 ShortcutConfigActivityInfo (com.android.launcher3.compat.ShortcutConfigActivityInfo)1 ComponentWithLabel (com.android.launcher3.icons.ComponentWithLabel)1 PackageItemInfo (com.android.launcher3.model.PackageItemInfo)1 WidgetItem (com.android.launcher3.model.WidgetItem)1 MultiHashMap (com.android.launcher3.util.MultiHashMap)1 Map (java.util.Map)1