Search in sources :

Example 6 with ComponentKeyMapper

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);
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey)

Example 7 with ComponentKeyMapper

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);
}
Also used : IconCache(com.android.launcher3.icons.IconCache) ArrayList(java.util.ArrayList) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) AppInfo(com.android.launcher3.AppInfo)

Example 8 with ComponentKeyMapper

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;
}
Also used : ArrayList(java.util.ArrayList) ItemInfoWithIcon(com.android.launcher3.ItemInfoWithIcon)

Example 9 with ComponentKeyMapper

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;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) AppTargetCompat(com.saggitt.omega.predictions.AppTargetCompat) ComponentName(android.content.ComponentName)

Example 10 with ComponentKeyMapper

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();
}
Also used : BACKGROUND_APP(com.android.launcher3.LauncherState.BACKGROUND_APP) LauncherLogProto(com.android.launcher3.userevent.nano.LauncherLogProto) IntStream(java.util.stream.IntStream) Context(android.content.Context) NonNull(androidx.annotation.NonNull) ItemInfo(com.android.launcher3.model.data.ItemInfo) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) HotseatPredictionController(com.android.launcher3.hybridhotseat.HotseatPredictionController) OVERVIEW(com.android.launcher3.LauncherState.OVERVIEW) LauncherSettings(com.android.launcher3.LauncherSettings) StateListener(com.android.launcher3.statemanager.StateManager.StateListener) OnUpdateListener(com.android.launcher3.allapps.AllAppsStore.OnUpdateListener) OptionalInt(java.util.OptionalInt) AppTarget(android.app.prediction.AppTarget) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ArrayList(java.util.ArrayList) Utilities(com.android.launcher3.Utilities) MainThreadInitializedObject(com.android.launcher3.util.MainThreadInitializedObject) AppPredictor(android.app.prediction.AppPredictor) Launcher(com.android.launcher3.Launcher) ItemInfoUpdateReceiver(com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver) ComponentName(android.content.ComponentName) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) LauncherAppState(com.android.launcher3.LauncherAppState) ITEM_TYPE_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) LauncherState(com.android.launcher3.LauncherState) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) List(java.util.List) Nullable(androidx.annotation.Nullable) ComponentKey(com.android.launcher3.util.ComponentKey) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) OnIDPChangeListener(com.android.launcher3.InvariantDeviceProfile.OnIDPChangeListener) Collections(java.util.Collections) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) ComponentKey(com.android.launcher3.util.ComponentKey)

Aggregations

ComponentKey (com.android.launcher3.util.ComponentKey)9 ArrayList (java.util.ArrayList)9 ComponentName (android.content.ComponentName)6 AppTarget (android.app.prediction.AppTarget)5 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)5 ComponentKeyMapper (com.android.launcher3.appprediction.ComponentKeyMapper)4 ShortcutKey (com.android.launcher3.shortcuts.ShortcutKey)4 AppPredictor (android.app.prediction.AppPredictor)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)3 Launcher (com.android.launcher3.Launcher)3 LauncherAppState (com.android.launcher3.LauncherAppState)3 LauncherSettings (com.android.launcher3.LauncherSettings)3 Utilities (com.android.launcher3.Utilities)3 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)3 Animator (android.animation.Animator)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 AppPredictionContext (android.app.prediction.AppPredictionContext)2