Search in sources :

Example 1 with ItemInfo

use of com.android.launcher3.model.data.ItemInfo in project Launcher3 by chislon.

the class CellLayout method animateChildToPosition.

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
    boolean[][] occupied = mOccupied;
    if (!permanent) {
        occupied = mTmpOccupied;
    }
    if (clc.indexOfChild(child) != -1) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ItemInfo info = (ItemInfo) child.getTag();
        // We cancel any existing animations
        if (mReorderAnimators.containsKey(lp)) {
            mReorderAnimators.get(lp).cancel();
            mReorderAnimators.remove(lp);
        }
        final int oldX = lp.x;
        final int oldY = lp.y;
        if (adjustOccupied) {
            occupied[lp.cellX][lp.cellY] = false;
            occupied[cellX][cellY] = true;
        }
        lp.isLockedToGrid = true;
        if (permanent) {
            lp.cellX = info.cellX = cellX;
            lp.cellY = info.cellY = cellY;
        } else {
            lp.tmpCellX = cellX;
            lp.tmpCellY = cellY;
        }
        clc.setupLp(lp);
        lp.isLockedToGrid = false;
        final int newX = lp.x;
        final int newY = lp.y;
        lp.x = oldX;
        lp.y = oldY;
        // Exit early if we're not actually moving the view
        if (oldX == newX && oldY == newY) {
            lp.isLockedToGrid = true;
            return true;
        }
        ValueAnimator va = LauncherAnimUtils.ofFloat(child, 0f, 1f);
        va.setDuration(duration);
        mReorderAnimators.put(lp, va);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = ((Float) animation.getAnimatedValue()).floatValue();
                lp.x = (int) ((1 - r) * oldX + r * newX);
                lp.y = (int) ((1 - r) * oldY + r * newY);
                child.requestLayout();
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            boolean cancelled = false;

            public void onAnimationEnd(Animator animation) {
                // place just yet.
                if (!cancelled) {
                    lp.isLockedToGrid = true;
                    child.requestLayout();
                }
                if (mReorderAnimators.containsKey(lp)) {
                    mReorderAnimators.remove(lp);
                }
            }

            public void onAnimationCancel(Animator animation) {
                cancelled = true;
            }
        });
        va.setStartDelay(delay);
        va.start();
        return true;
    }
    return false;
}
Also used : FolderRingAnimator(com.android.launcher3.FolderIcon.FolderRingAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 2 with ItemInfo

use of com.android.launcher3.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatEduController method showEdu.

void showEdu() {
    int childCount = mHotseat.getShortcutsAndWidgets().getChildCount();
    CellLayout cellLayout = mLauncher.getWorkspace().getScreenWithId(Workspace.FIRST_SCREEN_ID);
    // hotseat is already empty and does not require migration. show edu tip
    boolean requiresMigration = IntStream.range(0, childCount).anyMatch(i -> {
        View v = mHotseat.getShortcutsAndWidgets().getChildAt(i);
        return v != null && v.getTag() != null && ((ItemInfo) v.getTag()).container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
    });
    boolean canMigrateToFirstPage = cellLayout.makeSpaceForHotseatMigration(false);
    if (requiresMigration && canMigrateToFirstPage) {
        showDialog();
    } else {
        new ArrowTipView(mLauncher).show(mLauncher.getString(requiresMigration ? R.string.hotseat_tip_no_empty_slots : R.string.hotseat_auto_enrolled), mHotseat.getTop());
        mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_ONLY_TIP);
        finishOnboarding();
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrowTipView(com.android.launcher3.views.ArrowTipView) View(android.view.View) ArrowTipView(com.android.launcher3.views.ArrowTipView)

Example 3 with ItemInfo

use of com.android.launcher3.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatEduController method migrateToFolder.

/**
 * This migration places all non folder items in the hotseat into a folder and then moves
 * all folders in the hotseat to a workspace page that has enough empty spots.
 *
 * @return pageId that has accepted the items.
 */
private int migrateToFolder() {
    ArrayDeque<FolderInfo> folders = new ArrayDeque<>();
    ArrayList<WorkspaceItemInfo> putIntoFolder = new ArrayList<>();
    // separate folders and items that can get in folders
    for (int i = 0; i < mLauncher.getDeviceProfile().numShownHotseatIcons; i++) {
        View view = mHotseat.getChildAt(i, 0);
        if (view == null)
            continue;
        ItemInfo info = (ItemInfo) view.getTag();
        if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
            folders.add((FolderInfo) info);
        } else if (info instanceof WorkspaceItemInfo && info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
            putIntoFolder.add((WorkspaceItemInfo) info);
        }
    }
    // create a temp folder and add non folder items to it
    if (!putIntoFolder.isEmpty()) {
        ItemInfo firstItem = putIntoFolder.get(0);
        FolderInfo folderInfo = new FolderInfo();
        mLauncher.getModelWriter().addItemToDatabase(folderInfo, firstItem.container, firstItem.screenId, firstItem.cellX, firstItem.cellY);
        folderInfo.setTitle("", mLauncher.getModelWriter());
        folderInfo.contents.addAll(putIntoFolder);
        for (int i = 0; i < folderInfo.contents.size(); i++) {
            ItemInfo item = folderInfo.contents.get(i);
            item.rank = i;
            mLauncher.getModelWriter().moveItemInDatabase(item, folderInfo.id, 0, item.cellX, item.cellY);
        }
        folders.add(folderInfo);
    }
    mNewItems.addAll(folders);
    return placeFoldersInWorkspace(folders);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) FolderInfo(com.android.launcher3.model.data.FolderInfo) ArrowTipView(com.android.launcher3.views.ArrowTipView) View(android.view.View) ArrayDeque(java.util.ArrayDeque) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 4 with ItemInfo

use of com.android.launcher3.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatPredictionController method pinPrediction.

/**
 * Pins a predicted app icon into place.
 */
public void pinPrediction(ItemInfo info) {
    PredictedAppIcon icon = (PredictedAppIcon) mHotseat.getChildAt(mHotseat.getCellXFromOrder(info.rank), mHotseat.getCellYFromOrder(info.rank));
    if (icon == null) {
        return;
    }
    WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo((WorkspaceItemInfo) info);
    mLauncher.getModelWriter().addItemToDatabase(workspaceItemInfo, LauncherSettings.Favorites.CONTAINER_HOTSEAT, workspaceItemInfo.screenId, workspaceItemInfo.cellX, workspaceItemInfo.cellY);
    ObjectAnimator.ofFloat(icon, SCALE_PROPERTY, 1, 0.8f, 1).start();
    icon.pin(workspaceItemInfo);
    mLauncher.getStatsLogManager().logger().withItemInfo(workspaceItemInfo).log(LAUNCHER_HOTSEAT_PREDICTION_PINNED);
}
Also used : PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 5 with ItemInfo

use of com.android.launcher3.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatPredictionController method logLaunchedAppRankingInfo.

/**
 * Logs rank info based on current list of predicted items
 */
public void logLaunchedAppRankingInfo(@NonNull ItemInfo itemInfo, InstanceId instanceId) {
    ComponentName targetCN = itemInfo.getTargetComponent();
    if (targetCN == null) {
        return;
    }
    int rank = -1;
    for (int i = mPredictedItems.size() - 1; i >= 0; i--) {
        ItemInfo info = mPredictedItems.get(i);
        if (targetCN.equals(info.getTargetComponent()) && itemInfo.user.equals(info.user)) {
            rank = i;
            break;
        }
    }
    if (rank < 0) {
        return;
    }
    int cardinality = 0;
    for (PredictedAppIcon icon : getPredictedIcons()) {
        ItemInfo info = (ItemInfo) icon.getTag();
        cardinality |= 1 << info.screenId;
    }
    PredictedHotseatContainer.Builder containerBuilder = PredictedHotseatContainer.newBuilder();
    containerBuilder.setCardinality(cardinality);
    if (itemInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
        containerBuilder.setIndex(rank);
    }
    mLauncher.getStatsLogManager().logger().withInstanceId(instanceId).withRank(rank).withContainerInfo(ContainerInfo.newBuilder().setPredictedHotseatContainer(containerBuilder).build()).log(LAUNCHER_HOTSEAT_RANKED);
}
Also used : PredictedHotseatContainer(com.android.launcher3.logger.LauncherAtom.PredictedHotseatContainer) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) ComponentName(android.content.ComponentName)

Aggregations

ItemInfo (com.android.launcher3.model.data.ItemInfo)73 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)63 View (android.view.View)27 Point (android.graphics.Point)25 ArrayList (java.util.ArrayList)25 FolderInfo (com.android.launcher3.model.data.FolderInfo)18 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)18 SuppressLint (android.annotation.SuppressLint)16 AppWidgetHostView (android.appwidget.AppWidgetHostView)15 Context (android.content.Context)15 DragView (com.android.launcher3.dragndrop.DragView)15 AppInfo (com.android.launcher3.model.data.AppInfo)15 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)15 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)14 List (java.util.List)13 UserHandle (android.os.UserHandle)12 DraggableView (com.android.launcher3.dragndrop.DraggableView)12 ComponentName (android.content.ComponentName)11 Intent (android.content.Intent)11 Rect (android.graphics.Rect)11