Search in sources :

Example 1 with FixedContainerItems

use of com.android.launcher3.model.BgDataModel.FixedContainerItems in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatPredictionModel method convertDataModelToAppTargetBundle.

/**
 * Creates and returns bundle using workspace items
 */
public static Bundle convertDataModelToAppTargetBundle(Context context, BgDataModel dataModel) {
    Bundle bundle = new Bundle();
    ArrayList<AppTargetEvent> events = new ArrayList<>();
    ArrayList<ItemInfo> workspaceItems = dataModel.getAllWorkspaceItems();
    for (ItemInfo item : workspaceItems) {
        AppTarget target = getAppTargetFromInfo(context, item);
        if (target != null && !isTrackedForPrediction(item))
            continue;
        events.add(wrapAppTargetWithLocation(target, AppTargetEvent.ACTION_PIN, item));
    }
    ArrayList<AppTarget> currentTargets = new ArrayList<>();
    FixedContainerItems hotseatItems = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
    if (hotseatItems != null) {
        for (ItemInfo itemInfo : hotseatItems.items) {
            AppTarget target = getAppTargetFromInfo(context, itemInfo);
            if (target != null)
                currentTargets.add(target);
        }
    }
    bundle.putParcelableArrayList(BUNDLE_KEY_PIN_EVENTS, events);
    bundle.putParcelableArrayList(BUNDLE_KEY_CURRENT_ITEMS, currentTargets);
    return bundle;
}
Also used : AppTarget(android.app.prediction.AppTarget) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTargetEvent(android.app.prediction.AppTargetEvent)

Example 2 with FixedContainerItems

use of com.android.launcher3.model.BgDataModel.FixedContainerItems in project android_packages_apps_Launcher3 by crdroidandroid.

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).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.
}
Also used : CONTAINER_WIDGETS_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION) ComponentName(android.content.ComponentName) LauncherAppState(com.android.launcher3.LauncherAppState) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) Set(java.util.Set) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) List(java.util.List) ComponentKey(com.android.launcher3.util.ComponentKey) Map(java.util.Map) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ComponentKey(com.android.launcher3.util.ComponentKey) PackageUserKey(com.android.launcher3.util.PackageUserKey) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTarget(android.app.prediction.AppTarget) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) List(java.util.List) ComponentName(android.content.ComponentName)

Example 3 with FixedContainerItems

use of com.android.launcher3.model.BgDataModel.FixedContainerItems in project android_packages_apps_Launcher3 by crdroidandroid.

the class BaseLoaderResults method bindWorkspace.

/**
 * Binds all loaded data to actual views on the main thread.
 */
public void bindWorkspace() {
    // Save a copy of all the bg-thread collections
    ArrayList<ItemInfo> workspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> appWidgets = new ArrayList<>();
    final IntArray orderedScreenIds = new IntArray();
    ArrayList<FixedContainerItems> extraItems = new ArrayList<>();
    synchronized (mBgDataModel) {
        workspaceItems.addAll(mBgDataModel.workspaceItems);
        appWidgets.addAll(mBgDataModel.appWidgets);
        orderedScreenIds.addAll(mBgDataModel.collectWorkspaceScreens());
        mBgDataModel.extraItems.forEach(extraItems::add);
        mBgDataModel.lastBindId++;
        mMyBindingId = mBgDataModel.lastBindId;
    }
    for (Callbacks cb : mCallbacksList) {
        new WorkspaceBinder(cb, mUiExecutor, mApp, mBgDataModel, mMyBindingId, workspaceItems, appWidgets, extraItems, orderedScreenIds).bind();
    }
}
Also used : IntArray(com.android.launcher3.util.IntArray) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) ItemInfo(com.android.launcher3.model.data.ItemInfo) ArrayList(java.util.ArrayList) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems)

Example 4 with FixedContainerItems

use of com.android.launcher3.model.BgDataModel.FixedContainerItems in project android_packages_apps_Launcher3 by crdroidandroid.

the class BaseModelUpdateTask method bindExtraContainerItems.

public void bindExtraContainerItems(FixedContainerItems item) {
    FixedContainerItems copy = item.clone();
    scheduleCallbackTask(c -> c.bindExtraContainerItems(copy));
}
Also used : FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems)

Example 5 with FixedContainerItems

use of com.android.launcher3.model.BgDataModel.FixedContainerItems in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherPreviewRenderer method populate.

private void populate(BgDataModel dataModel, Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
    // Separate the items that are on the current screen, and the other remaining items.
    ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
    ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
    filterCurrentWorkspaceItems(0, /* currentScreenId */
    dataModel.workspaceItems, currentWorkspaceItems, otherWorkspaceItems);
    filterCurrentWorkspaceItems(0, /* currentScreenId */
    dataModel.appWidgets, currentAppWidgets, otherAppWidgets);
    sortWorkspaceItemsSpatially(mIdp, currentWorkspaceItems);
    for (ItemInfo itemInfo : currentWorkspaceItems) {
        switch(itemInfo.itemType) {
            case Favorites.ITEM_TYPE_APPLICATION:
            case Favorites.ITEM_TYPE_SHORTCUT:
            case Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                inflateAndAddIcon((WorkspaceItemInfo) itemInfo);
                break;
            case Favorites.ITEM_TYPE_FOLDER:
                inflateAndAddFolder((FolderInfo) itemInfo);
                break;
            default:
                break;
        }
    }
    for (ItemInfo itemInfo : currentAppWidgets) {
        switch(itemInfo.itemType) {
            case Favorites.ITEM_TYPE_APPWIDGET:
            case Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
                if (widgetProviderInfoMap != null) {
                    inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo, widgetProviderInfoMap);
                } else {
                    inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo, dataModel.widgetsModel);
                }
                break;
            default:
                break;
        }
    }
    IntArray ranks = getMissingHotseatRanks(currentWorkspaceItems, mDp.numShownHotseatIcons);
    FixedContainerItems hotseatpredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
    List<ItemInfo> predictions = hotseatpredictions == null ? Collections.emptyList() : hotseatpredictions.items;
    int count = Math.min(ranks.size(), predictions.size());
    for (int i = 0; i < count; i++) {
        int rank = ranks.get(i);
        WorkspaceItemInfo itemInfo = new WorkspaceItemInfo((WorkspaceItemInfo) predictions.get(i));
        itemInfo.container = CONTAINER_HOTSEAT_PREDICTION;
        itemInfo.rank = rank;
        itemInfo.cellX = mHotseat.getCellXFromOrder(rank);
        itemInfo.cellY = mHotseat.getCellYFromOrder(rank);
        itemInfo.screenId = rank;
        inflateAndAddPredictedIcon(itemInfo);
    }
    // Add first page QSB
    if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
        View qsb = mHomeElementInflater.inflate(R.layout.search_container_workspace, mWorkspace, false);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, mWorkspace.getCountX(), 1);
        lp.canReorder = false;
        mWorkspace.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true);
    }
    measureView(mRootView, mDp.widthPx, mDp.heightPx);
    dispatchVisibilityAggregated(mRootView, true);
    measureView(mRootView, mDp.widthPx, mDp.heightPx);
    // Additional measure for views which use auto text size API
    measureView(mRootView, mDp.widthPx, mDp.heightPx);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) BaseLauncherAppWidgetHostView(com.android.launcher3.widget.BaseLauncherAppWidgetHostView) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) SparseIntArray(android.util.SparseIntArray) IntArray(com.android.launcher3.util.IntArray) CellLayout(com.android.launcher3.CellLayout) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)6 AppTarget (android.app.prediction.AppTarget)3 ItemInfo (com.android.launcher3.model.data.ItemInfo)3 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)3 ArrayList (java.util.ArrayList)3 ComponentName (android.content.ComponentName)2 LauncherAppState (com.android.launcher3.LauncherAppState)2 PredictorState (com.android.launcher3.model.QuickstepModelDelegate.PredictorState)2 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)2 IntArray (com.android.launcher3.util.IntArray)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 AppTargetEvent (android.app.prediction.AppTargetEvent)1 AppWidgetHostView (android.appwidget.AppWidgetHostView)1 Context (android.content.Context)1 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)1 LauncherApps (android.content.pm.LauncherApps)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 Bundle (android.os.Bundle)1