Search in sources :

Example 11 with WorkspaceItemInfo

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

the class FolderPagedView method realTimeReorder.

/**
 * Reorders the items such that the {@param empty} spot moves to {@param target}
 */
public void realTimeReorder(int empty, int target) {
    if (!mViewsBound) {
        return;
    }
    completePendingPageChanges();
    int delay = 0;
    float delayAmount = START_VIEW_REORDER_DELAY;
    // Animation only happens on the current page.
    int pageToAnimate = getNextPage();
    int maxItemsPerPage = mOrganizer.getMaxItemsPerPage();
    int pageT = target / maxItemsPerPage;
    int pagePosT = target % maxItemsPerPage;
    if (pageT != pageToAnimate) {
        Log.e(TAG, "Cannot animate when the target cell is invisible");
    }
    int pagePosE = empty % maxItemsPerPage;
    int pageE = empty / maxItemsPerPage;
    int startPos, endPos;
    int moveStart, moveEnd;
    int direction;
    if (target == empty) {
        // No animation
        return;
    } else if (target > empty) {
        // Items will move backwards to make room for the empty cell.
        direction = 1;
        // If empty cell is in a different page, move them instantly.
        if (pageE < pageToAnimate) {
            moveStart = empty;
            // Instantly move the first item in the current page.
            moveEnd = pageToAnimate * maxItemsPerPage;
            // Animate the 2nd item in the current page, as the first item was already moved to
            // the last page.
            startPos = 0;
        } else {
            moveStart = moveEnd = -1;
            startPos = pagePosE;
        }
        endPos = pagePosT;
    } else {
        // The items will move forward.
        direction = -1;
        if (pageE > pageToAnimate) {
            // Move the items immediately.
            moveStart = empty;
            // Instantly move the last item in the current page.
            moveEnd = (pageToAnimate + 1) * maxItemsPerPage - 1;
            // Animations start with the second last item in the page
            startPos = maxItemsPerPage - 1;
        } else {
            moveStart = moveEnd = -1;
            startPos = pagePosE;
        }
        endPos = pagePosT;
    }
    // Instant moving views.
    while (moveStart != moveEnd) {
        int rankToMove = moveStart + direction;
        int p = rankToMove / maxItemsPerPage;
        int pagePos = rankToMove % maxItemsPerPage;
        int x = pagePos % mGridCountX;
        int y = pagePos / mGridCountX;
        final CellLayout page = getPageAt(p);
        final View v = page.getChildAt(x, y);
        if (v != null) {
            if (pageToAnimate != p) {
                page.removeView(v);
                addViewForRank(v, (WorkspaceItemInfo) v.getTag(), moveStart);
            } else {
                // Do a fake animation before removing it.
                final int newRank = moveStart;
                final float oldTranslateX = v.getTranslationX();
                Runnable endAction = new Runnable() {

                    @Override
                    public void run() {
                        mPendingAnimations.remove(v);
                        v.setTranslationX(oldTranslateX);
                        ((CellLayout) v.getParent().getParent()).removeView(v);
                        addViewForRank(v, (WorkspaceItemInfo) v.getTag(), newRank);
                    }
                };
                v.animate().translationXBy((direction > 0 ^ mIsRtl) ? -v.getWidth() : v.getWidth()).setDuration(REORDER_ANIMATION_DURATION).setStartDelay(0).withEndAction(endAction);
                mPendingAnimations.put(v, endAction);
            }
        }
        moveStart = rankToMove;
    }
    if ((endPos - startPos) * direction <= 0) {
        // No animation
        return;
    }
    CellLayout page = getPageAt(pageToAnimate);
    for (int i = startPos; i != endPos; i += direction) {
        int nextPos = i + direction;
        View v = page.getChildAt(nextPos % mGridCountX, nextPos / mGridCountX);
        if (page.animateChildToPosition(v, i % mGridCountX, i / mGridCountX, REORDER_ANIMATION_DURATION, delay, true, true)) {
            delay += delayAmount;
            delayAmount *= VIEW_REORDER_DELAY_FACTOR;
        }
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint)

Example 12 with WorkspaceItemInfo

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

the class Folder method animateOpen.

/**
 * Opens the user folder described by the specified tag. The opening of the folder
 * is animated relative to the specified View. If the View is null, no animation
 * is played.
 */
private void animateOpen(List<WorkspaceItemInfo> items, int pageNo) {
    Folder openFolder = getOpen(mActivityContext);
    if (openFolder != null && openFolder != this) {
        // Close any open folder before opening a folder.
        openFolder.close(true);
    }
    mContent.bindItems(items);
    centerAboutIcon();
    mItemsInvalidated = true;
    updateTextViewFocus();
    mIsOpen = true;
    BaseDragLayer dragLayer = mActivityContext.getDragLayer();
    // There was a one-off crash where the folder had a parent already.
    if (getParent() == null) {
        dragLayer.addView(this);
        mDragController.addDropTarget(this);
    } else {
        if (FeatureFlags.IS_STUDIO_BUILD) {
            Log.e(TAG, "Opening folder (" + this + ") which already has a parent:" + getParent());
        }
    }
    mContent.completePendingPageChanges();
    mContent.setCurrentPage(pageNo);
    // This is set to true in close(), but isn't reset to false until onDropCompleted(). This
    // leads to an inconsistent state if you drag out of the folder and drag back in without
    // dropping. One resulting issue is that replaceFolderWithFinalItem() can be called twice.
    mDeleteFolderOnDropCompleted = false;
    cancelRunningAnimations();
    FolderAnimationManager fam = new FolderAnimationManager(this, true);
    AnimatorSet anim = fam.getAnimator();
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mFolderIcon.setIconVisible(false);
            mFolderIcon.drawLeaveBehindIfExists();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;
            announceAccessibilityChanges();
            mContent.setFocusOnFirstChild();
        }
    });
    // Footer animation
    if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) {
        int footerWidth = mContent.getDesiredWidth() - mFooter.getPaddingLeft() - mFooter.getPaddingRight();
        float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString());
        float translation = (footerWidth - textWidth) / 2;
        mFolderName.setTranslationX(mContent.mIsRtl ? -translation : translation);
        mPageIndicator.prepareEntryAnimation();
        // Do not update the flag if we are in drag mode. The flag will be updated, when we
        // actually drop the icon.
        final boolean updateAnimationFlag = !mDragInProgress;
        anim.addListener(new AnimatorListenerAdapter() {

            @SuppressLint("InlinedApi")
            @Override
            public void onAnimationEnd(Animator animation) {
                mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION).translationX(0).setInterpolator(AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.fast_out_slow_in));
                mPageIndicator.playEntryAnimation();
                if (updateAnimationFlag) {
                    mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncherDelegate.getModelWriter());
                }
            }
        });
    } else {
        mFolderName.setTranslationX(0);
    }
    mPageIndicator.stopAllAnimations();
    startAnimation(anim);
    // Because t=0 has the folder match the folder icon, we can skip the
    // first frame and have the same movement one frame earlier.
    anim.setCurrentPlayTime(Math.min(getSingleFrameMs(getContext()), anim.getTotalDuration()));
    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }
    mContent.verifyVisibleHighResIcons(mContent.getNextPage());
}
Also used : BaseDragLayer(com.android.launcher3.views.BaseDragLayer) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SuppressLint(android.annotation.SuppressLint) AnimatorSet(android.animation.AnimatorSet) SuppressLint(android.annotation.SuppressLint)

Example 13 with WorkspaceItemInfo

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

the class Folder method startDrag.

public boolean startDrag(View v, DragOptions options) {
    Object tag = v.getTag();
    if (tag instanceof WorkspaceItemInfo) {
        WorkspaceItemInfo item = (WorkspaceItemInfo) tag;
        mEmptyCellRank = item.rank;
        mCurrentDragView = v;
        mDragController.addDragListener(this);
        if (options.isAccessibleDrag) {
            mDragController.addDragListener(new AccessibleDragListenerAdapter(mContent, FolderAccessibilityHelper::new) {

                @Override
                protected void enableAccessibleDrag(boolean enable) {
                    super.enableAccessibleDrag(enable);
                    mFooter.setImportantForAccessibility(enable ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS : IMPORTANT_FOR_ACCESSIBILITY_AUTO);
                }
            });
        }
        mLauncherDelegate.beginDragShared(v, this, options);
    }
    return true;
}
Also used : AccessibleDragListenerAdapter(com.android.launcher3.accessibility.AccessibleDragListenerAdapter) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 14 with WorkspaceItemInfo

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

the class Folder method onDropCompleted.

@Override
public void onDropCompleted(final View target, final DragObject d, final boolean success) {
    if (success) {
        if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) {
            replaceFolderWithFinalItem();
        }
    } else {
        // The drag failed, we need to return the item to the folder
        WorkspaceItemInfo info = (WorkspaceItemInfo) d.dragInfo;
        View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info) ? mCurrentDragView : mContent.createNewView(info);
        ArrayList<View> views = getIconsInReadingOrder();
        info.rank = Utilities.boundToRange(info.rank, 0, views.size());
        views.add(info.rank, icon);
        mContent.arrangeChildren(views);
        mItemsInvalidated = true;
        try (SuppressInfoChanges s = new SuppressInfoChanges()) {
            mFolderIcon.onDrop(d, true);
        }
    }
    if (target != this) {
        if (mOnExitAlarm.alarmPending()) {
            mOnExitAlarm.cancelAlarm();
            if (!success) {
                mSuppressFolderDeletion = true;
            }
            mScrollPauseAlarm.cancelAlarm();
            completeDragExit();
        }
    }
    mDeleteFolderOnDropCompleted = false;
    mDragInProgress = false;
    mItemAddedBackToSelfViaIcon = false;
    mCurrentDragView = null;
    // Reordering may have occured, and we need to save the new item locations. We do this once
    // at the end to prevent unnecessary database operations.
    updateItemLocationsInDatabaseBatch(false);
    // been refreshed yet.
    if (getItemCount() <= mContent.itemsPerPage()) {
        // Show the animation, next time something is added to the folder.
        mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, false, mLauncherDelegate.getModelWriter());
    }
}
Also used : ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 15 with WorkspaceItemInfo

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

the class AddWorkspaceItemsTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mItemList.isEmpty()) {
        return;
    }
    final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
    final IntArray addedWorkspaceScreensFinal = new IntArray();
    synchronized (dataModel) {
        IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
        List<ItemInfo> filteredItems = new ArrayList<>();
        for (Pair<ItemInfo, Object> entry : mItemList) {
            ItemInfo item = entry.first;
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
                // Short-circuit this logic if the icon exists somewhere on the workspace
                if (shortcutExists(dataModel, item.getIntent(), item.user)) {
                    continue;
                }
                // b/139663018 Short-circuit this logic if the icon is a system app
                if (PackageManagerHelper.isSystemApp(app.getContext(), item.getIntent())) {
                    continue;
                }
            }
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
                if (item instanceof AppInfo) {
                    item = ((AppInfo) item).makeWorkspaceItem();
                }
            }
            if (item != null) {
                filteredItems.add(item);
            }
        }
        InstallSessionHelper packageInstaller = InstallSessionHelper.INSTANCE.get(app.getContext());
        LauncherApps launcherApps = app.getContext().getSystemService(LauncherApps.class);
        for (ItemInfo item : filteredItems) {
            // Find appropriate space for the item.
            int[] coords = findSpaceForItem(app, dataModel, workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
            int screenId = coords[0];
            ItemInfo itemInfo;
            if (item instanceof WorkspaceItemInfo || item instanceof FolderInfo || item instanceof LauncherAppWidgetInfo) {
                itemInfo = item;
            } else if (item instanceof AppInfo) {
                itemInfo = ((AppInfo) item).makeWorkspaceItem();
            } else {
                throw new RuntimeException("Unexpected info type");
            }
            if (item instanceof WorkspaceItemInfo && ((WorkspaceItemInfo) item).isPromise()) {
                WorkspaceItemInfo workspaceInfo = (WorkspaceItemInfo) item;
                String packageName = item.getTargetComponent() != null ? item.getTargetComponent().getPackageName() : null;
                if (packageName == null) {
                    continue;
                }
                SessionInfo sessionInfo = packageInstaller.getActiveSessionInfo(item.user, packageName);
                if (!packageInstaller.verifySessionInfo(sessionInfo)) {
                    FileLog.d(LOG, "Item info failed session info verification. " + "Skipping : " + workspaceInfo);
                    continue;
                }
                List<LauncherActivityInfo> activities = launcherApps.getActivityList(packageName, item.user);
                boolean hasActivity = activities != null && !activities.isEmpty();
                if (sessionInfo == null) {
                    if (!hasActivity) {
                        // Session was cancelled, do not add.
                        continue;
                    }
                } else {
                    workspaceInfo.setProgressLevel((int) (sessionInfo.getProgress() * 100), PackageInstallInfo.STATUS_INSTALLING);
                }
                if (hasActivity) {
                    // App was installed while launcher was in the background,
                    // or app was already installed for another user.
                    itemInfo = new AppInfo(app.getContext(), activities.get(0), item.user).makeWorkspaceItem();
                    if (shortcutExists(dataModel, itemInfo.getIntent(), itemInfo.user)) {
                        // Icon already exists on the workspace and should not be auto-added.
                        continue;
                    }
                    WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo;
                    wii.title = "";
                    wii.bitmap = app.getIconCache().getDefaultIcon(item.user);
                    app.getIconCache().getTitleAndIcon(wii, ((WorkspaceItemInfo) itemInfo).usingLowResIcon());
                }
            }
            // Add the shortcut to the db
            getModelWriter().addItemToDatabase(itemInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coords[1], coords[2]);
            // Save the WorkspaceItemInfo for binding in the workspace
            addedItemsFinal.add(itemInfo);
            // log bitmap and label
            FileLog.d(LOG, "Adding item info to workspace: " + itemInfo);
        }
    }
    if (!addedItemsFinal.isEmpty()) {
        scheduleCallbackTask(new CallbackTask() {

            @Override
            public void execute(Callbacks callbacks) {
                final ArrayList<ItemInfo> addAnimated = new ArrayList<>();
                final ArrayList<ItemInfo> addNotAnimated = new ArrayList<>();
                if (!addedItemsFinal.isEmpty()) {
                    ItemInfo info = addedItemsFinal.get(addedItemsFinal.size() - 1);
                    int lastScreenId = info.screenId;
                    for (ItemInfo i : addedItemsFinal) {
                        if (i.screenId == lastScreenId) {
                            addAnimated.add(i);
                        } else {
                            addNotAnimated.add(i);
                        }
                    }
                }
                callbacks.bindAppsAdded(addedWorkspaceScreensFinal, addNotAnimated, addAnimated);
            }
        });
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) IntArray(com.android.launcher3.util.IntArray) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) CallbackTask(com.android.launcher3.LauncherModel.CallbackTask) LauncherApps(android.content.pm.LauncherApps) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) InstallSessionHelper(com.android.launcher3.pm.InstallSessionHelper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)348 View (android.view.View)142 ArrayList (java.util.ArrayList)125 ItemInfo (com.android.launcher3.model.data.ItemInfo)105 Intent (android.content.Intent)101 FolderInfo (com.android.launcher3.model.data.FolderInfo)83 AppInfo (com.android.launcher3.model.data.AppInfo)79 AppWidgetHostView (android.appwidget.AppWidgetHostView)73 BubbleTextView (com.android.launcher3.BubbleTextView)72 SuppressLint (android.annotation.SuppressLint)68 DragView (com.android.launcher3.dragndrop.DragView)67 ComponentName (android.content.ComponentName)66 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)62 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)61 Rect (android.graphics.Rect)58 FolderIcon (com.android.launcher3.folder.FolderIcon)58 HashSet (java.util.HashSet)54 Context (android.content.Context)53 Point (android.graphics.Point)51 WorkspaceItemInfo (com.android.launcher3.WorkspaceItemInfo)50