use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.
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());
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 Neo-Launcher by NeoApplications.
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_Launcher3 by ArrowOS.
the class WidgetsPredictionUpdateTask method execute.
/**
* Uses the app predication result to infer widgets that the user may want to use.
*
* <p>The algorithm uses the app prediction ranking to create a widgets ranking which only
* includes one widget per app and excludes widgets that have already been added to the
* workspace.
*/
@Override
public void execute(LauncherAppState appState, BgDataModel dataModel, AllAppsList apps) {
Set<ComponentKey> widgetsInWorkspace = dataModel.appWidgets.stream().map(widget -> new ComponentKey(widget.providerName, widget.user)).collect(Collectors.toSet());
Map<PackageUserKey, List<WidgetItem>> allWidgets = dataModel.widgetsModel.getAllWidgetsWithoutShortcuts();
FixedContainerItems fixedContainerItems = mPredictorState.items;
fixedContainerItems.items.clear();
if (FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER.get()) {
for (AppTarget app : mTargets) {
PackageUserKey packageUserKey = new PackageUserKey(app.getPackageName(), app.getUser());
if (allWidgets.containsKey(packageUserKey)) {
List<WidgetItem> notAddedWidgets = allWidgets.get(packageUserKey).stream().filter(item -> !widgetsInWorkspace.contains(new ComponentKey(item.componentName, item.user))).collect(Collectors.toList());
if (notAddedWidgets.size() > 0) {
// Even an apps have more than one widgets, we only include one widget.
fixedContainerItems.items.add(new PendingAddWidgetInfo(notAddedWidgets.get(0).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
}
}
}
} else {
Map<ComponentKey, WidgetItem> widgetItems = allWidgets.values().stream().flatMap(List::stream).distinct().collect(Collectors.toMap(widget -> (ComponentKey) widget, widget -> widget));
for (AppTarget app : mTargets) {
if (TextUtils.isEmpty(app.getClassName())) {
continue;
}
ComponentKey targetWidget = new ComponentKey(new ComponentName(app.getPackageName(), app.getClassName()), app.getUser());
if (widgetItems.containsKey(targetWidget)) {
fixedContainerItems.items.add(new PendingAddWidgetInfo(widgetItems.get(targetWidget).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
}
}
}
bindExtraContainerItems(fixedContainerItems);
// Don't store widgets prediction to disk because it is not used frequently.
}
use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by ArrowOS.
the class PinnedAppsAdapter method parseComponentKey.
private ComponentKey parseComponentKey(String string) {
try {
String[] parts = string.split("#");
UserHandle user;
if (parts.length > 2) {
user = UserCache.INSTANCE.get(mLauncher).getUserForSerialNumber(Long.parseLong(parts[2]));
} else {
user = Process.myUserHandle();
}
ComponentName cn = ComponentName.unflattenFromString(parts[0]);
return new ComponentKey(cn, user);
} catch (Exception e) {
return null;
}
}
use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by ArrowOS.
the class PinnedAppsAdapter method update.
private void update(ItemInfo info, Function<ComponentKey, Boolean> op) {
ComponentKey key = new ComponentKey(info.getTargetComponent(), info.user);
if (op.apply(key)) {
createFilteredAppsList();
Set<ComponentKey> copy = new HashSet<>(mPinnedApps);
Executors.MODEL_EXECUTOR.submit(() -> mPrefs.edit().putStringSet(PINNED_APPS_KEY, copy.stream().map(this::encode).collect(Collectors.toSet())).apply());
}
}
Aggregations