Search in sources :

Example 21 with FolderNameInfos

use of com.android.launcher3.folder.FolderNameInfos in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Folder method updateItemLocationsInDatabaseBatch.

private void updateItemLocationsInDatabaseBatch(boolean isBind) {
    FolderGridOrganizer verifier = new FolderGridOrganizer(mActivityContext.getDeviceProfile().inv).setFolderInfo(mInfo);
    ArrayList<ItemInfo> items = new ArrayList<>();
    int total = mInfo.contents.size();
    for (int i = 0; i < total; i++) {
        WorkspaceItemInfo itemInfo = mInfo.contents.get(i);
        if (verifier.updateRankAndPos(itemInfo, i)) {
            items.add(itemInfo);
        }
    }
    if (!items.isEmpty()) {
        mLauncherDelegate.getModelWriter().moveItemsInDatabase(items, mInfo.id, 0);
    }
    if (FeatureFlags.FOLDER_NAME_SUGGEST.get() && !isBind && total > 1) /* no need to update if there's one icon */
    {
        Executors.MODEL_EXECUTOR.post(() -> {
            FolderNameInfos nameInfos = new FolderNameInfos();
            FolderNameProvider fnp = FolderNameProvider.newInstance(getContext());
            fnp.getSuggestedFolderName(getContext(), mInfo.contents, nameInfos);
            mInfo.suggestedFolderNames = nameInfos;
        });
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 22 with FolderNameInfos

use of com.android.launcher3.folder.FolderNameInfos in project android_packages_apps_Launcher3 by AOSPA.

the class Folder method updateItemLocationsInDatabaseBatch.

private void updateItemLocationsInDatabaseBatch(boolean isBind) {
    FolderGridOrganizer verifier = new FolderGridOrganizer(mActivityContext.getDeviceProfile().inv).setFolderInfo(mInfo);
    ArrayList<ItemInfo> items = new ArrayList<>();
    int total = mInfo.contents.size();
    for (int i = 0; i < total; i++) {
        WorkspaceItemInfo itemInfo = mInfo.contents.get(i);
        if (verifier.updateRankAndPos(itemInfo, i)) {
            items.add(itemInfo);
        }
    }
    if (!items.isEmpty()) {
        mLauncherDelegate.getModelWriter().moveItemsInDatabase(items, mInfo.id, 0);
    }
    if (FeatureFlags.FOLDER_NAME_SUGGEST.get() && !isBind && total > 1) /* no need to update if there's one icon */
    {
        Executors.MODEL_EXECUTOR.post(() -> {
            FolderNameInfos nameInfos = new FolderNameInfos();
            FolderNameProvider fnp = FolderNameProvider.newInstance(getContext());
            fnp.getSuggestedFolderName(getContext(), mInfo.contents, nameInfos);
            mInfo.suggestedFolderNames = nameInfos;
        });
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 23 with FolderNameInfos

use of com.android.launcher3.folder.FolderNameInfos in project android_packages_apps_Launcher3 by AOSPA.

the class FolderIcon method onDrop.

private void onDrop(final WorkspaceItemInfo item, DragObject d, Rect finalRect, float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) {
    item.cellX = -1;
    item.cellY = -1;
    DragView animateView = d.dragView;
    // will not have a view to animate
    if (animateView != null && mActivity instanceof Launcher) {
        final Launcher launcher = (Launcher) mActivity;
        DragLayer dragLayer = launcher.getDragLayer();
        Rect to = finalRect;
        if (to == null) {
            to = new Rect();
            Workspace workspace = launcher.getWorkspace();
            // Set cellLayout and this to it's final state to compute final animation locations
            workspace.setFinalTransitionTransform();
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
            // Finished computing final animation locations, restore current state
            setScaleX(scaleX);
            setScaleY(scaleY);
            workspace.resetTransitionTransform();
        }
        int numItemsInPreview = Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index + 1);
        boolean itemAdded = false;
        if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) {
            List<WorkspaceItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems);
            mInfo.add(item, index, false);
            mCurrentPreviewItems.clear();
            mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
            if (!oldPreviewItems.equals(mCurrentPreviewItems)) {
                int newIndex = mCurrentPreviewItems.indexOf(item);
                if (newIndex >= 0) {
                    // If the item dropped is going to be in the preview, we update the
                    // index here to reflect its position in the preview.
                    index = newIndex;
                }
                mPreviewItemManager.hidePreviewItem(index, true);
                mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item);
                itemAdded = true;
            } else {
                removeItem(item, false);
            }
        }
        if (!itemAdded) {
            mInfo.add(item, index, true);
        }
        int[] center = new int[2];
        float scale = getLocalCenterForIndex(index, numItemsInPreview, center);
        center[0] = Math.round(scaleRelativeToDragLayer * center[0]);
        center[1] = Math.round(scaleRelativeToDragLayer * center[1]);
        to.offset(center[0] - animateView.getMeasuredWidth() / 2, center[1] - animateView.getMeasuredHeight() / 2);
        float finalAlpha = index < MAX_NUM_ITEMS_IN_PREVIEW ? 1f : 0f;
        float finalScale = scale * scaleRelativeToDragLayer;
        // Account for potentially different icon sizes with non-default grid settings
        if (d.dragSource instanceof AllAppsContainerView) {
            DeviceProfile grid = mActivity.getDeviceProfile();
            float containerScale = (1f * grid.iconSizePx / grid.allAppsIconSizePx);
            finalScale *= containerScale;
        }
        final int finalIndex = index;
        dragLayer.animateView(animateView, to, finalAlpha, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, Interpolators.DEACCEL_2, () -> {
            mPreviewItemManager.hidePreviewItem(finalIndex, false);
            mFolder.showItem(item);
        }, DragLayer.ANIMATION_END_DISAPPEAR, null);
        mFolder.hideItem(item);
        if (!itemAdded)
            mPreviewItemManager.hidePreviewItem(index, true);
        FolderNameInfos nameInfos = new FolderNameInfos();
        if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
            Executors.MODEL_EXECUTOR.post(() -> {
                d.folderNameProvider.getSuggestedFolderName(getContext(), mInfo.contents, nameInfos);
                showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
            });
        } else {
            showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
        }
    } else {
        addItem(item);
    }
}
Also used : AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) DragView(com.android.launcher3.dragndrop.DragView) DeviceProfile(com.android.launcher3.DeviceProfile) DragLayer(com.android.launcher3.dragndrop.DragLayer) Launcher(com.android.launcher3.Launcher) Workspace(com.android.launcher3.Workspace) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 24 with FolderNameInfos

use of com.android.launcher3.folder.FolderNameInfos in project android_packages_apps_Launcher3 by AOSPA.

the class FolderIcon method setLabelSuggestion.

/**
 * Set the suggested folder name.
 */
public void setLabelSuggestion(FolderNameInfos nameInfos, InstanceId instanceId) {
    if (!FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
        return;
    }
    if (!mInfo.getLabelState().equals(LabelState.UNLABELED)) {
        return;
    }
    if (nameInfos == null || !nameInfos.hasSuggestions()) {
        StatsLogManager.newInstance(getContext()).logger().withInstanceId(instanceId).withItemInfo(mInfo).log(LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_SUGGESTIONS);
        return;
    }
    if (!nameInfos.hasPrimary()) {
        StatsLogManager.newInstance(getContext()).logger().withInstanceId(instanceId).withItemInfo(mInfo).log(LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_PRIMARY);
        return;
    }
    CharSequence newTitle = nameInfos.getLabels()[0];
    FromState fromState = mInfo.getFromLabelState();
    mInfo.setTitle(newTitle, mFolder.mLauncherDelegate.getModelWriter());
    onTitleChanged(mInfo.title);
    mFolder.mFolderName.setText(mInfo.title);
    // Logging for folder creation flow
    StatsLogManager.newInstance(getContext()).logger().withInstanceId(instanceId).withItemInfo(mInfo).withFromState(fromState).withToState(ToState.TO_SUGGESTION0).withEditText(newTitle.toString()).log(LAUNCHER_FOLDER_AUTO_LABELED);
}
Also used : FromState(com.android.launcher3.logger.LauncherAtom.FromState)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)12 ArrayList (java.util.ArrayList)12 SuppressLint (android.annotation.SuppressLint)11 Rect (android.graphics.Rect)6 DeviceProfile (com.android.launcher3.DeviceProfile)6 Launcher (com.android.launcher3.Launcher)6 Workspace (com.android.launcher3.Workspace)6 AllAppsContainerView (com.android.launcher3.allapps.AllAppsContainerView)6 DragLayer (com.android.launcher3.dragndrop.DragLayer)6 DragView (com.android.launcher3.dragndrop.DragView)6 FolderNameInfos (com.android.launcher3.folder.FolderNameInfos)6 FolderNameProvider (com.android.launcher3.folder.FolderNameProvider)6 FromState (com.android.launcher3.logger.LauncherAtom.FromState)6 FolderInfo (com.android.launcher3.model.data.FolderInfo)6 ItemInfo (com.android.launcher3.model.data.ItemInfo)6 Point (android.graphics.Point)5