Search in sources :

Example 21 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Trebuchet by LineageOS.

the class PopupDataProvider method getShortcutCountForItem.

public int getShortcutCountForItem(ItemInfo info) {
    if (!ShortcutUtil.supportsDeepShortcuts(info)) {
        return 0;
    }
    ComponentName component = info.getTargetComponent();
    if (component == null) {
        return 0;
    }
    Integer count = mDeepShortcutMap.get(new ComponentKey(component, info.user));
    return count == null ? 0 : count;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) ComponentName(android.content.ComponentName)

Example 22 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Trebuchet by LineageOS.

the class BgDataModel method updateDeepShortcutCounts.

/**
 * Clear all the deep shortcut counts for the given package, and re-add the new shortcut counts.
 */
public synchronized void updateDeepShortcutCounts(String packageName, UserHandle user, List<ShortcutInfo> shortcuts) {
    if (packageName != null) {
        Iterator<ComponentKey> keysIter = deepShortcutMap.keySet().iterator();
        while (keysIter.hasNext()) {
            ComponentKey next = keysIter.next();
            if (next.componentName.getPackageName().equals(packageName) && next.user.equals(user)) {
                keysIter.remove();
            }
        }
    }
    // Now add the new shortcuts to the map.
    for (ShortcutInfo shortcut : shortcuts) {
        boolean shouldShowInContainer = shortcut.isEnabled() && (shortcut.isDeclaredInManifest() || shortcut.isDynamic()) && shortcut.getActivity() != null;
        if (shouldShowInContainer) {
            ComponentKey targetComponent = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle());
            Integer previousCount = deepShortcutMap.get(targetComponent);
            deepShortcutMap.put(targetComponent, previousCount == null ? 1 : previousCount + 1);
        }
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentKey(com.android.launcher3.util.ComponentKey)

Example 23 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Trebuchet by LineageOS.

the class PredictionModel method cachePredictionComponentKeys.

/**
 * Formats and stores a list of component key in device preferences.
 */
@AnyThread
public void cachePredictionComponentKeys(List<ComponentKey> componentKeys) {
    MODEL_EXECUTOR.execute(() -> {
        LauncherAppState appState = LauncherAppState.getInstance(mContext);
        StringBuilder builder = new StringBuilder();
        int count = Math.min(componentKeys.size(), MAX_CACHE_ITEMS);
        for (int i = 0; i < count; i++) {
            builder.append(serializeComponentKeyToString(componentKeys.get(i)));
            builder.append("\n");
        }
        if (componentKeys.isEmpty()) /* should invalidate loader items */
        {
            appState.getModel().enqueueModelUpdateTask(new BaseModelUpdateTask() {

                @Override
                public void execute(LauncherAppState app, BgDataModel model, AllAppsList apps) {
                    model.cachedPredictedItems.clear();
                }
            });
        }
        mDevicePrefs.edit().putString(CACHED_ITEMS_KEY, builder.toString()).apply();
    });
}
Also used : LauncherAppState(com.android.launcher3.LauncherAppState) ResourceBasedOverride(com.android.launcher3.util.ResourceBasedOverride) AnyThread(androidx.annotation.AnyThread)

Example 24 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Trebuchet by LineageOS.

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<>();
    for (ItemInfo itemInfo : dataModel.itemsIdMap) {
        if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT && mUser.equals(itemInfo.user)) {
            WorkspaceItemInfo si = (WorkspaceItemInfo) itemInfo;
            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);
                    continue;
                }
                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) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) 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 25 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class IconPreview method loadPreviewComponents.

public void loadPreviewComponents() {
    List<ComponentKey> list = new ArrayList<>();
    String[] components = OmegaAppPredictor.Companion.getPLACE_HOLDERS();
    for (String placeHolder : components) {
        Intent intent = mPackageManager.getLaunchIntentForPackage(placeHolder);
        if (intent != null) {
            ComponentName componentInfo = intent.getComponent();
            if (componentInfo != null) {
                list.add(new ComponentKey(componentInfo, Process.myUserHandle()));
            }
        }
    }
    mPreviewAppComponents.clear();
    mPreviewAppComponents.addAll(list);
    mPreviewApps.clear();
    mPreviewApps.addAll(processPreviewAppComponents(mPreviewAppComponents));
    applyPreviewIcons();
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

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