Search in sources :

Example 1 with ShortcutConfigActivityInfo

use of com.android.launcher3.compat.ShortcutConfigActivityInfo in project android_packages_apps_Trebuchet by LineageOS.

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;
        }
    }
    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) PackageManager(android.content.pm.PackageManager) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper)

Example 2 with ShortcutConfigActivityInfo

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

the class Utilities method getFullDrawable.

/**
 * Returns the full drawable for {@param info}.
 * @param outObj this is set to the internal data associated with {@param info},
 *               eg {@link LauncherActivityInfo} or {@link ShortcutInfo}.
 */
public static Drawable getFullDrawable(Launcher launcher, ItemInfo info, int width, int height, boolean flattenDrawable, Object[] outObj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    IconPackManager.CustomIconEntry customIconEntry = (info instanceof WorkspaceItemInfo) ? ((WorkspaceItemInfo) info).customIconEntry : null;
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || customIconEntry != null) {
        LauncherActivityInfo activityInfo = LauncherAppsCompat.getInstance(launcher).resolveActivity(info.getIntent(), info.user);
        outObj[0] = activityInfo;
        return (activityInfo != null) ? appState.getIconCache().getFullResIcon(activityInfo, flattenDrawable) : null;
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        if (info instanceof PendingAddShortcutInfo) {
            ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
            outObj[0] = activityInfo;
            return activityInfo.getFullResIcon(appState.getIconCache());
        }
        ShortcutKey key = ShortcutKey.fromItemInfo(info);
        DeepShortcutManager sm = DeepShortcutManager.getInstance(launcher);
        List<ShortcutInfo> si = sm.queryForFullDetails(key.componentName.getPackageName(), Arrays.asList(key.getId()), key.user);
        if (si.isEmpty()) {
            return null;
        } else {
            outObj[0] = si.get(0);
            return sm.getShortcutIconDrawable(si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
        }
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(launcher, info.id, new Point(width, height));
        if (icon == null) {
            return null;
        }
        outObj[0] = icon;
        return icon;
    } else {
        return null;
    }
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) IconPackManager(com.saggitt.omega.iconpack.IconPackManager) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ShortcutConfigActivityInfo(com.android.launcher3.compat.ShortcutConfigActivityInfo) List(java.util.List) ArrayList(java.util.ArrayList) Point(android.graphics.Point) DeepShortcutManager(com.android.launcher3.shortcuts.DeepShortcutManager) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey)

Example 3 with ShortcutConfigActivityInfo

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

the class LauncherAppsCompatVL method getCustomShortcutActivityList.

@Override
public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(@Nullable PackageUserKey packageUser) {
    List<ShortcutConfigActivityInfo> result = new ArrayList<>();
    if (packageUser != null && !packageUser.mUser.equals(Process.myUserHandle())) {
        return result;
    }
    PackageManager pm = mContext.getPackageManager();
    for (ResolveInfo info : pm.queryIntentActivities(new Intent(Intent.ACTION_CREATE_SHORTCUT), 0)) {
        if (packageUser == null || packageUser.mPackageName.equals(info.activityInfo.packageName)) {
            result.add(new ShortcutConfigActivityInfoVL(info.activityInfo));
        }
    }
    return result;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ShortcutConfigActivityInfoVL(com.android.launcher3.compat.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVL)

Example 4 with ShortcutConfigActivityInfo

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

the class LauncherAppsCompatVO method getCustomShortcutActivityList.

@Override
public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(@Nullable PackageUserKey packageUser) {
    List<ShortcutConfigActivityInfo> result = new ArrayList<>();
    UserHandle myUser = Process.myUserHandle();
    final List<UserHandle> users;
    final String packageName;
    if (packageUser == null) {
        users = UserManagerCompat.getInstance(mContext).getUserProfiles();
        packageName = null;
    } else {
        users = new ArrayList<>(1);
        users.add(packageUser.mUser);
        packageName = packageUser.mPackageName;
    }
    for (UserHandle user : users) {
        boolean ignoreTargetSdk = myUser.equals(user);
        List<LauncherActivityInfo> activities = mLauncherApps.getShortcutConfigActivityList(packageName, user);
        for (LauncherActivityInfo activityInfo : activities) {
            if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
                result.add(new ShortcutConfigActivityInfoVO(activityInfo));
            }
        }
    }
    return result;
}
Also used : UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ShortcutConfigActivityInfoVO(com.android.launcher3.compat.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVO)

Example 5 with ShortcutConfigActivityInfo

use of com.android.launcher3.compat.ShortcutConfigActivityInfo 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)

Aggregations

ShortcutConfigActivityInfo (com.android.launcher3.pm.ShortcutConfigActivityInfo)10 ArrayList (java.util.ArrayList)9 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)7 PackageManager (android.content.pm.PackageManager)7 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)6 Context (android.content.Context)6 Paint (android.graphics.Paint)6 Point (android.graphics.Point)6 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)6 FolderAdaptiveIcon (com.android.launcher3.dragndrop.FolderAdaptiveIcon)6 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)6 LauncherIcons (com.android.launcher3.icons.LauncherIcons)6 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)6 List (java.util.List)6 LauncherApps (android.content.pm.LauncherApps)5 ComponentWithLabelAndIcon (com.android.launcher3.icons.ComponentWithLabelAndIcon)5 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)5 Drawable (android.graphics.drawable.Drawable)4 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)4 Canvas (android.graphics.Canvas)3