Search in sources :

Example 56 with ComponentKey

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

the class UserLockStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
    if (mIsUserUnlocked) {
        QueryResult shortcuts = new ShortcutRequest(context, mUser).query(ShortcutRequest.PINNED);
        if (shortcuts.wasSuccess()) {
            for (ShortcutInfo shortcut : shortcuts) {
                pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
            }
        } else {
            // Shortcut manager can fail due to some race condition when the lock state
            // changes too frequently. For the purpose of the update,
            // consider it as still locked.
            mIsUserUnlocked = false;
        }
    }
    // Update the workspace to reflect the changes to updated shortcuts residing on it.
    ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
    HashSet<ShortcutKey> removedKeys = new HashSet<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                if (mIsUserUnlocked) {
                    ShortcutKey key = ShortcutKey.fromItemInfo(si);
                    ShortcutInfo shortcut = pinnedShortcuts.get(key);
                    // (probably due to clear data), delete the workspace item as well
                    if (shortcut == null) {
                        removedKeys.add(key);
                        return;
                    }
                    si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
                    si.updateFromDeepShortcutInfo(shortcut, context);
                    app.getIconCache().getShortcutIcon(si, shortcut);
                } else {
                    si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
                }
                updatedWorkspaceItemInfos.add(si);
            }
        });
    }
    bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
    if (!removedKeys.isEmpty()) {
        deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
    }
    // Remove shortcut id map for that user
    Iterator<ComponentKey> keysIter = dataModel.deepShortcutMap.keySet().iterator();
    while (keysIter.hasNext()) {
        if (keysIter.next().user.equals(mUser)) {
            keysIter.remove();
        }
    }
    if (mIsUserUnlocked) {
        dataModel.updateDeepShortcutCounts(null, mUser, new ShortcutRequest(context, mUser).query(ShortcutRequest.ALL));
    }
    bindDeepShortcuts(dataModel);
}
Also used : Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) QueryResult(com.android.launcher3.shortcuts.ShortcutRequest.QueryResult) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 57 with ComponentKey

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

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 58 with ComponentKey

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

the class IconPackManager method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getData() != null) {
        String pkg = intent.getData().getEncodedSchemeSpecificPart();
        if (pkg != null) {
            Log.d(TAG, "Received intent action " + intent.getAction() + " for " + pkg);
            AppReloader appReloader = AppReloader.get(mContext);
            // Create a list of apps that are using the changed package icon pack,
            // either through the global setting or with an override.
            Set<ComponentKey> updateKeys = appReloader.withIconPack(pkg);
            // Remove the changed package from the providers to reload the application info.
            mProviders.remove(pkg);
            // This can reset the global preference, so do this after creating the list.
            reloadProviders();
            // Ensure all icons are up-to-date after this icon pack change.
            // Calendar and clock information will automatically be reloaded by this call.
            appReloader.reload(updateKeys);
        }
    }
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) AppReloader(com.android.launcher3.util.AppReloader)

Example 59 with ComponentKey

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

the class ThirdPartyDrawableFactory method newIcon.

@Override
public FastBitmapDrawable newIcon(Context context, ItemInfoWithIcon info) {
    if (info != null && info.getTargetComponent() != null && info.itemType == ITEM_TYPE_APPLICATION) {
        ComponentKey key = new ComponentKey(info.getTargetComponent(), info.user);
        IconResolver resolver = mManager.resolve(key);
        mCalendars.setIsDynamic(key, (resolver != null && resolver.isCalendar()) || info.getTargetComponent().getPackageName().equals(DynamicCalendar.CALENDAR));
        if (Utilities.ATLEAST_OREO) {
            if (resolver != null) {
                if (resolver.isClock()) {
                    Drawable drawable = resolver.getIcon(0, () -> null);
                    if (drawable != null) {
                        FastBitmapDrawable fb = mCustomClockDrawer.drawIcon(info, drawable, resolver.clockData());
                        fb.setIsDisabled(info.isDisabled());
                        return fb;
                    }
                }
            } else if (info.getTargetComponent().equals(DynamicClock.DESK_CLOCK)) {
                return mDynamicClockDrawer.drawIcon(info);
            }
        }
    }
    return super.newIcon(context, info);
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) IconResolver(com.android.launcher3.icons.pack.IconResolver) ComponentKey(com.android.launcher3.util.ComponentKey) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Drawable(android.graphics.drawable.Drawable)

Example 60 with ComponentKey

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

the class LauncherPreviewRenderer method inflateAndAddWidgets.

private void inflateAndAddWidgets(LauncherAppWidgetInfo info, Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
    if (widgetProviderInfoMap == null) {
        return;
    }
    AppWidgetProviderInfo providerInfo = widgetProviderInfoMap.get(new ComponentKey(info.providerName, info.user));
    if (providerInfo == null) {
        return;
    }
    inflateAndAddWidgets(info, LauncherAppWidgetProviderInfo.fromProviderInfo(getApplicationContext(), providerInfo));
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ComponentKey(com.android.launcher3.util.ComponentKey)

Aggregations

ComponentKey (com.android.launcher3.util.ComponentKey)98 ComponentName (android.content.ComponentName)40 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)26 ArrayList (java.util.ArrayList)26 ShortcutInfo (android.content.pm.ShortcutInfo)21 UserHandle (android.os.UserHandle)20 HashMap (java.util.HashMap)19 ShortcutKey (com.android.launcher3.shortcuts.ShortcutKey)17 PackageUserKey (com.android.launcher3.util.PackageUserKey)17 Intent (android.content.Intent)16 HashSet (java.util.HashSet)16 Context (android.content.Context)15 ItemInfo (com.android.launcher3.model.data.ItemInfo)14 List (java.util.List)13 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)12 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)11 AppTarget (android.app.prediction.AppTarget)10 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)10 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)10 QueryResult (com.android.launcher3.shortcuts.ShortcutRequest.QueryResult)10