use of com.android.launcher3.appprediction.ComponentKeyMapper in project Neo-Launcher by NeoApplications.
the class PredictionUiStateManager method fillInPredictedRank.
/**
* Fill in predicted_rank field based on app prediction.
* Only applicable when {@link ItemInfo#itemType} is one of the followings:
* {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
* {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
* {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
*/
public static void fillInPredictedRank(@NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target) {
final PredictionUiStateManager manager = PredictionUiStateManager.INSTANCE.getNoCreate();
if (manager == null || itemInfo.getTargetComponent() == null || itemInfo.user == null || (itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)) {
return;
}
final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
final List<ComponentKeyMapper> predictedApps = manager.getCurrentState().apps;
IntStream.range(0, predictedApps.size()).filter((i) -> k.equals(predictedApps.get(i).getComponentKey())).findFirst().ifPresent((rank) -> target.predictedRank = rank);
}
use of com.android.launcher3.appprediction.ComponentKeyMapper in project Neo-Launcher by NeoApplications.
the class PredictionUiStateManager method updateDependencies.
private void updateDependencies(PredictionState state) {
if (!state.isEnabled || mAppsView == null) {
return;
}
IconCache iconCache = LauncherAppState.getInstance(mContext).getIconCache();
List<String> instantAppsToLoad = new ArrayList<>();
List<ShortcutKey> shortcutsToLoad = new ArrayList<>();
int total = state.apps.size();
for (int i = 0, count = 0; i < total && count < mMaxIconsPerRow; i++) {
ComponentKeyMapper mapper = state.apps.get(i);
// Update instant apps
if (COMPONENT_CLASS_MARKER.equals(mapper.getComponentClass())) {
instantAppsToLoad.add(mapper.getPackage());
count++;
} else if (mapper.getComponentKey() instanceof ShortcutKey) {
shortcutsToLoad.add((ShortcutKey) mapper.getComponentKey());
count++;
} else {
// Reload high res icon
AppInfo info = (AppInfo) mapper.getApp(mAppsView.getAppsStore());
if (info != null) {
if (info.usingLowResIcon()) {
// TODO: Update icon cache to support null callbacks.
iconCache.updateIconInBackground(this, info);
}
count++;
}
}
}
mDynamicItemCache.cacheItems(shortcutsToLoad, instantAppsToLoad);
}
use of com.android.launcher3.appprediction.ComponentKeyMapper in project Neo-Launcher by NeoApplications.
the class PredictionRowView method processPredictedAppComponents.
private List<ItemInfoWithIcon> processPredictedAppComponents(List<ComponentKeyMapper> components) {
if (getAppsStore().getApps().length == 0) {
// Apps have not been bound yet.
return Collections.emptyList();
}
List<ItemInfoWithIcon> predictedApps = new ArrayList<>();
for (ComponentKeyMapper mapper : components) {
ItemInfoWithIcon info = mapper.getApp(getAppsStore());
if (info != null) {
ItemInfoWithIcon predictedApp = info.clone();
predictedApp.container = LauncherSettings.Favorites.CONTAINER_PREDICTION;
predictedApps.add(predictedApp);
} else {
if (FeatureFlags.IS_DOGFOOD_BUILD) {
Log.e(TAG, "Predicted app not found: " + mapper);
}
}
// Stop at the number of predicted apps
if (predictedApps.size() == mNumPredictedAppsPerRow) {
break;
}
}
return predictedApps;
}
use of com.android.launcher3.appprediction.ComponentKeyMapper in project Neo-Launcher by NeoApplications.
the class PredictionUiStateManager method parseLastState.
private PredictionState parseLastState() {
PredictionState state = new PredictionState();
state.isEnabled = mGettingValidPredictionResults;
if (!state.isEnabled) {
state.apps = Collections.EMPTY_LIST;
return state;
}
state.apps = new ArrayList<>();
List<AppTargetCompat> appTargets = mPredictionServicePredictions[mActiveClient.ordinal()];
if (!appTargets.isEmpty()) {
for (AppTargetCompat appTarget : appTargets) {
ComponentKey key;
if (appTarget.getShortcutInfo() != null) {
key = ShortcutKey.fromInfo(appTarget.getShortcutInfo());
} else {
key = new ComponentKey(new ComponentName(appTarget.getPackageName(), appTarget.getClassName()), appTarget.getUser());
}
state.apps.add(new ComponentKeyMapper(mContext, key, mDynamicItemCache));
}
}
updateDependencies(state);
return state;
}
use of com.android.launcher3.appprediction.ComponentKeyMapper in project android_packages_apps_Trebuchet by LineageOS.
the class PredictionUiStateManager method getAllAppsRank.
/**
* Returns ranking info for the app within all apps prediction.
* Only applicable when {@link ItemInfo#itemType} is one of the followings:
* {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
* {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
* {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
*/
public OptionalInt getAllAppsRank(@Nullable ItemInfo itemInfo) {
if (itemInfo == null || itemInfo.getTargetComponent() == null || itemInfo.user == null) {
return OptionalInt.empty();
}
if (itemInfo.itemType == ITEM_TYPE_APPLICATION || itemInfo.itemType == ITEM_TYPE_SHORTCUT || itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
final List<ComponentKeyMapper> apps = getCurrentState().apps;
return IntStream.range(0, apps.size()).filter(index -> key.equals(apps.get(index).getComponentKey())).findFirst();
}
return OptionalInt.empty();
}
Aggregations