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;
}
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);
}
}
}
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();
});
}
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);
}
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();
}
Aggregations