Search in sources :

Example 1 with ComponentKeyMapper

use of com.android.launcher3.appprediction.ComponentKeyMapper in project android_packages_apps_Trebuchet by LineageOS.

the class HotseatPredictionController method mapToWorkspaceItemInfo.

private List<WorkspaceItemInfo> mapToWorkspaceItemInfo(List<ComponentKeyMapper> components) {
    AllAppsStore allAppsStore = mLauncher.getAppsView().getAppsStore();
    if (allAppsStore.getApps().length == 0) {
        return Collections.emptyList();
    }
    List<WorkspaceItemInfo> predictedApps = new ArrayList<>();
    for (ComponentKeyMapper mapper : components) {
        ItemInfoWithIcon info = mapper.getApp(allAppsStore);
        if (info instanceof AppInfo) {
            WorkspaceItemInfo predictedApp = new WorkspaceItemInfo((AppInfo) info);
            predictedApp.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
            predictedApps.add(predictedApp);
        } else if (info instanceof WorkspaceItemInfo) {
            WorkspaceItemInfo predictedApp = new WorkspaceItemInfo((WorkspaceItemInfo) info);
            predictedApp.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
            predictedApps.add(predictedApp);
        } else {
            if (DEBUG) {
                Log.e(TAG, "Predicted app not found: " + mapper);
            }
        }
        // Stop at the number of hotseat items
        if (predictedApps.size() == mHotSeatItemsCount) {
            break;
        }
    }
    return predictedApps;
}
Also used : ArrayList(java.util.ArrayList) AllAppsStore(com.android.launcher3.allapps.AllAppsStore) ComponentKeyMapper(com.android.launcher3.appprediction.ComponentKeyMapper) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 2 with ComponentKeyMapper

use of com.android.launcher3.appprediction.ComponentKeyMapper in project android_packages_apps_Trebuchet by LineageOS.

the class HotseatPredictionController method setPredictedApps.

private void setPredictedApps(List<AppTarget> appTargets) {
    mComponentKeyMappers.clear();
    if (appTargets.isEmpty()) {
        mRestoreHelper.restoreBackup();
    }
    StringBuilder predictionLog = new StringBuilder("predictedApps: [\n");
    ArrayList<ComponentKey> componentKeys = new ArrayList<>();
    for (AppTarget 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());
        }
        componentKeys.add(key);
        predictionLog.append(key.toString());
        predictionLog.append(",rank:");
        predictionLog.append(appTarget.getRank());
        predictionLog.append("\n");
        mComponentKeyMappers.add(new ComponentKeyMapper(key, mDynamicItemCache));
    }
    predictionLog.append("]");
    if (Utilities.IS_DEBUG_DEVICE) {
        HotseatFileLog.INSTANCE.get(mLauncher).log(TAG, predictionLog.toString());
    }
    updateDependencies();
    fillGapsWithPrediction();
    mPredictionModel.cachePredictionComponentKeys(componentKeys);
}
Also used : AppTarget(android.app.prediction.AppTarget) ComponentKey(com.android.launcher3.util.ComponentKey) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) ComponentKeyMapper(com.android.launcher3.appprediction.ComponentKeyMapper)

Example 3 with ComponentKeyMapper

use of com.android.launcher3.appprediction.ComponentKeyMapper in project android_packages_apps_Trebuchet by LineageOS.

the class HotseatPredictionController method encodeHotseatLayoutIntoPredictionRank.

/**
 * Fill in predicted_rank field based on app prediction.
 * Only applicable when {@link ItemInfo#itemType} is PREDICTED_HOTSEAT
 */
public static void encodeHotseatLayoutIntoPredictionRank(@NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target) {
    QuickstepLauncher launcher = QuickstepLauncher.ACTIVITY_TRACKER.getCreatedActivity();
    if (launcher == null || launcher.getHotseatPredictionController() == null || itemInfo.getTargetComponent() == null) {
        return;
    }
    HotseatPredictionController controller = launcher.getHotseatPredictionController();
    final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
    final List<ComponentKeyMapper> predictedApps = controller.mComponentKeyMappers;
    OptionalInt rank = IntStream.range(0, predictedApps.size()).filter((i) -> k.equals(predictedApps.get(i).getComponentKey())).findFirst();
    target.predictedRank = 10000 + (controller.mPredictedSpotsCount * 100) + (rank.isPresent() ? rank.getAsInt() + 1 : 0);
}
Also used : ComponentKeyMapper(com.android.launcher3.appprediction.ComponentKeyMapper) NonNull(androidx.annotation.NonNull) Animator(android.animation.Animator) LauncherSettings(com.android.launcher3.LauncherSettings) DynamicItemCache(com.android.launcher3.appprediction.DynamicItemCache) IconCache(com.android.launcher3.icons.IconCache) AppTarget(android.app.prediction.AppTarget) Process(android.os.Process) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) LAUNCHER_HOTSEAT_RANKED(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOTSEAT_RANKED) HotseatEduController.getSettingsIntent(com.android.launcher3.hybridhotseat.HotseatEduController.getSettingsIntent) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) AnimationSuccessListener(com.android.launcher3.anim.AnimationSuccessListener) SCALE_PROPERTY(com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY) Log(android.util.Log) Utilities(com.android.launcher3.Utilities) AppPredictor(android.app.prediction.AppPredictor) QuickstepLauncher(com.android.launcher3.uioverrides.QuickstepLauncher) Launcher(com.android.launcher3.Launcher) ObjectAnimator(android.animation.ObjectAnimator) AppPredictionManager(android.app.prediction.AppPredictionManager) AllAppsStore(com.android.launcher3.allapps.AllAppsStore) PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) ViewGroup(android.view.ViewGroup) DragOptions(com.android.launcher3.dragndrop.DragOptions) HapticFeedbackConstants(android.view.HapticFeedbackConstants) List(java.util.List) Nullable(androidx.annotation.Nullable) AppPredictionContext(android.app.prediction.AppPredictionContext) NORMAL(com.android.launcher3.LauncherState.NORMAL) LauncherLogProto(com.android.launcher3.userevent.nano.LauncherLogProto) IntStream(java.util.stream.IntStream) AppInfo(com.android.launcher3.model.data.AppInfo) ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) Snackbar(com.android.launcher3.views.Snackbar) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) ItemLongClickListener(com.android.launcher3.touch.ItemLongClickListener) PredictedHotseatContainer(com.android.launcher3.logger.LauncherAtom.PredictedHotseatContainer) AppTargetEvent(android.app.prediction.AppTargetEvent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AnimatorSet(android.animation.AnimatorSet) DragSource(com.android.launcher3.DragSource) WeakReference(java.lang.ref.WeakReference) SystemShortcut(com.android.launcher3.popup.SystemShortcut) CHANGE_FLAG_GRID(com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_GRID) IntArray(com.android.launcher3.util.IntArray) InstanceId(com.android.launcher3.logging.InstanceId) ArrowTipView(com.android.launcher3.views.ArrowTipView) ComponentName(android.content.ComponentName) DropTarget(com.android.launcher3.DropTarget) LauncherAppState(com.android.launcher3.LauncherAppState) DragController(com.android.launcher3.dragndrop.DragController) OnboardingPrefs(com.android.launcher3.util.OnboardingPrefs) Hotseat(com.android.launcher3.Hotseat) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) R(com.android.launcher3.R) ComponentKey(com.android.launcher3.util.ComponentKey) Collections(java.util.Collections) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) ComponentKey(com.android.launcher3.util.ComponentKey) QuickstepLauncher(com.android.launcher3.uioverrides.QuickstepLauncher) OptionalInt(java.util.OptionalInt) ComponentKeyMapper(com.android.launcher3.appprediction.ComponentKeyMapper)

Example 4 with ComponentKeyMapper

use of com.android.launcher3.appprediction.ComponentKeyMapper in project android_packages_apps_Trebuchet by LineageOS.

the class HotseatPredictionController method showCachedItems.

/**
 * Create WorkspaceItemInfo objects and binds PredictedAppIcon views for cached predicted items.
 */
public void showCachedItems(List<AppInfo> apps, IntArray ranks) {
    if (hasPredictions() && mAppPredictor != null) {
        mAppPredictor.requestPredictionUpdate();
        fillGapsWithPrediction();
        return;
    }
    int count = Math.min(ranks.size(), apps.size());
    List<WorkspaceItemInfo> items = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        WorkspaceItemInfo item = new WorkspaceItemInfo(apps.get(i));
        ComponentKey componentKey = new ComponentKey(item.getTargetComponent(), item.user);
        preparePredictionInfo(item, ranks.get(i));
        items.add(item);
        mComponentKeyMappers.add(new ComponentKeyMapper(componentKey, mDynamicItemCache));
    }
    updateDependencies();
    bindItems(items, false, null);
}
Also used : ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) ComponentKeyMapper(com.android.launcher3.appprediction.ComponentKeyMapper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 5 with ComponentKeyMapper

use of com.android.launcher3.appprediction.ComponentKeyMapper in project android_packages_apps_Trebuchet by LineageOS.

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;
    }
    if (itemInfo.container != LauncherSettings.Favorites.CONTAINER_PREDICTION) {
        HotseatPredictionController.encodeHotseatLayoutIntoPredictionRank(itemInfo, target);
        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 = 0 - rank);
}
Also used : 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