Search in sources :

Example 86 with Folder

use of com.android.launcher3.tapl.Folder in project Neo-Launcher by NeoApplications.

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(mLauncher);
    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;
    DragLayer dragLayer = mLauncher.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_DOGFOOD_BUILD) {
            Log.e(TAG, "Opening folder (" + this + ") which already has a parent:" + getParent());
        }
    }
    mContent.completePendingPageChanges();
    mContent.snapToPageImmediately(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;
    AnimatorSet anim = new FolderAnimationManager(this, true).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();
            mLauncher.getUserEventDispatcher().logActionOnItem(Touch.TAP, Direction.NONE, ItemType.FOLDER_ICON, mInfo.cellX, mInfo.cellY);
            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(mLauncher, android.R.interpolator.fast_out_slow_in));
                mPageIndicator.playEntryAnimation();
                if (updateAnimationFlag) {
                    mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher.getModelWriter());
                }
            }
        });
    } else {
        mFolderName.setTranslationX(0);
    }
    mPageIndicator.stopAllAnimations();
    startAnimation(anim);
    // 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 : DragLayer(com.android.launcher3.dragndrop.DragLayer) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SuppressLint(android.annotation.SuppressLint) AnimatorSet(android.animation.AnimatorSet) SuppressLint(android.annotation.SuppressLint)

Example 87 with Folder

use of com.android.launcher3.tapl.Folder in project Neo-Launcher by NeoApplications.

the class Folder method onDrop.

@Override
public void onDrop(DragObject d, DragOptions options) {
    // the target location again such that the icon is placed of the final page.
    if (!mContent.rankOnCurrentPage(mEmptyCellRank)) {
        // Reorder again.
        mTargetRank = getTargetRank(d, null);
        // Rearrange items immediately.
        mReorderAlarmListener.onAlarm(mReorderAlarm);
        mOnScrollHintAlarm.cancelAlarm();
        mScrollPauseAlarm.cancelAlarm();
    }
    mContent.completePendingPageChanges();
    PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo ? (PendingAddShortcutInfo) d.dragInfo : null;
    WorkspaceItemInfo pasiSi = pasi != null ? pasi.activityInfo.createWorkspaceItemInfo() : null;
    if (pasi != null && pasiSi == null) {
        // There is no WorkspaceItemInfo, so we have to go through a configuration activity.
        pasi.container = mInfo.id;
        pasi.rank = mEmptyCellRank;
        mLauncher.addPendingItem(pasi, pasi.container, pasi.screenId, null, pasi.spanX, pasi.spanY);
        d.deferDragViewCleanupPostAnimation = false;
        mRearrangeOnClose = true;
    } else {
        final WorkspaceItemInfo si;
        if (pasiSi != null) {
            si = pasiSi;
        } else if (d.dragInfo instanceof AppInfo) {
            // Came from all apps -- make a copy.
            si = ((AppInfo) d.dragInfo).makeWorkspaceItem();
        } else {
            // WorkspaceItemInfo
            si = (WorkspaceItemInfo) d.dragInfo;
        }
        View currentDragView;
        if (mIsExternalDrag) {
            currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
            // Actually move the item in the database if it was an external drag. Call this
            // before creating the view, so that WorkspaceItemInfo is updated appropriately.
            mLauncher.getModelWriter().addOrMoveItemInDatabase(si, mInfo.id, 0, si.cellX, si.cellY);
            mIsExternalDrag = false;
        } else {
            currentDragView = mCurrentDragView;
            mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
        }
        if (d.dragView.hasDrawn()) {
            // Temporarily reset the scale such that the animation target gets calculated
            // correctly.
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, null);
            setScaleX(scaleX);
            setScaleY(scaleY);
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            currentDragView.setVisibility(VISIBLE);
        }
        mItemsInvalidated = true;
        rearrangeChildren();
        // Temporarily suppress the listener, as we did all the work already here.
        try (SuppressInfoChanges s = new SuppressInfoChanges()) {
            mInfo.add(si, mEmptyCellRank, false);
        }
        // #onDropCompleted.
        if (d.dragSource != this) {
            updateItemLocationsInDatabaseBatch();
        }
    }
    // Clear the drag info, as it is no longer being dragged.
    mDragInProgress = false;
    if (mContent.getPageCount() > 1) {
        // The animation has already been shown while opening the folder.
        mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher.getModelWriter());
    }
    mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
    if (d.stateAnnouncer != null) {
        d.stateAnnouncer.completeAction(R.string.item_moved);
    }
}
Also used : PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) 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.WorkspaceItemInfo) AppInfo(com.android.launcher3.AppInfo)

Example 88 with Folder

use of com.android.launcher3.tapl.Folder in project Neo-Launcher by NeoApplications.

the class Folder method centerAboutIcon.

private void centerAboutIcon() {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    DragLayer parent = mLauncher.getDragLayer();
    int width = getFolderWidth();
    int height = getFolderHeight();
    parent.getDescendantRectRelativeToSelf(mFolderIcon, sTempRect);
    int centerX = sTempRect.centerX();
    int centerY = sTempRect.centerY();
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;
    // We need to bound the folder to the currently visible workspace area
    if (mLauncher.getStateManager().getState().overviewUi) {
        parent.getDescendantRectRelativeToSelf(mLauncher.getOverviewPanel(), sTempRect);
    } else {
        mLauncher.getWorkspace().getPageAreaRelativeToDragLayer(sTempRect);
    }
    int left = Math.min(Math.max(sTempRect.left, centeredLeft), sTempRect.right - width);
    int top = Math.min(Math.max(sTempRect.top, centeredTop), sTempRect.bottom - height);
    int distFromEdgeOfScreen = mLauncher.getWorkspace().getPaddingLeft() + getPaddingLeft();
    if (grid.isPhone && (grid.availableWidthPx - width) < 4 * distFromEdgeOfScreen) {
        // Center the folder if it is very close to being centered anyway, by virtue of
        // filling the majority of the viewport. ie. remove it from the uncanny valley
        // of centeredness.
        left = (grid.availableWidthPx - width) / 2;
    } else if (width >= sTempRect.width()) {
        // If the folder doesn't fit within the bounds, center it about the desired bounds
        left = sTempRect.left + (sTempRect.width() - width) / 2;
    }
    if (height >= sTempRect.height()) {
        // Folder height is greater than page height, center on page
        top = sTempRect.top + (sTempRect.height() - height) / 2;
    } else {
        // Folder height is less than page height, so bound it to the absolute open folder
        // bounds if necessary
        Rect folderBounds = grid.getAbsoluteOpenFolderBounds();
        left = Math.max(folderBounds.left, Math.min(left, folderBounds.right - width));
        top = Math.max(folderBounds.top, Math.min(top, folderBounds.bottom - height));
    }
    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    lp.width = width;
    lp.height = height;
    lp.x = left;
    lp.y = top;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect) SuppressLint(android.annotation.SuppressLint)

Example 89 with Folder

use of com.android.launcher3.tapl.Folder in project Neo-Launcher by NeoApplications.

the class Folder method updateTextViewFocus.

// This method keeps track of the first and last item in the folder for the purposes
// of keyboard focus
public void updateTextViewFocus() {
    final View firstChild = mContent.getFirstItem();
    final View lastChild = mContent.getLastItem();
    if (firstChild != null && lastChild != null) {
        mFolderName.setNextFocusDownId(lastChild.getId());
        mFolderName.setNextFocusRightId(lastChild.getId());
        mFolderName.setNextFocusLeftId(lastChild.getId());
        mFolderName.setNextFocusUpId(lastChild.getId());
        // Hitting TAB from the folder name wraps around to the first item on the current
        // folder page, and hitting SHIFT+TAB from that item wraps back to the folder name.
        mFolderName.setNextFocusForwardId(firstChild.getId());
        // When clicking off the folder when editing the name, this Folder gains focus. When
        // pressing an arrow key from that state, give the focus to the first item.
        this.setNextFocusDownId(firstChild.getId());
        this.setNextFocusRightId(firstChild.getId());
        this.setNextFocusLeftId(firstChild.getId());
        this.setNextFocusUpId(firstChild.getId());
        // When pressing shift+tab in the above state, give the focus to the last item.
        setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                boolean isShiftPlusTab = keyCode == KeyEvent.KEYCODE_TAB && event.hasModifiers(KeyEvent.META_SHIFT_ON);
                if (isShiftPlusTab && Folder.this.isFocused()) {
                    return lastChild.requestFocus();
                }
                return false;
            }
        });
    } else {
        setOnKeyListener(null);
    }
}
Also used : KeyEvent(android.view.KeyEvent) 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) SuppressLint(android.annotation.SuppressLint)

Example 90 with Folder

use of com.android.launcher3.tapl.Folder in project Neo-Launcher by NeoApplications.

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();
        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();
    // 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, mLauncher.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.WorkspaceItemInfo)

Aggregations

View (android.view.View)119 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)112 FolderInfo (com.android.launcher3.model.data.FolderInfo)93 ItemInfo (com.android.launcher3.model.data.ItemInfo)86 Point (android.graphics.Point)83 FolderIcon (com.android.launcher3.folder.FolderIcon)83 Folder (com.android.launcher3.folder.Folder)82 AppWidgetHostView (android.appwidget.AppWidgetHostView)80 SuppressLint (android.annotation.SuppressLint)73 DragView (com.android.launcher3.dragndrop.DragView)64 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)64 Rect (android.graphics.Rect)63 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)61 BubbleTextView (com.android.launcher3.BubbleTextView)56 ArrayList (java.util.ArrayList)49 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)47 Animator (android.animation.Animator)40 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)40 Drawable (android.graphics.drawable.Drawable)37 CellLayout (com.android.launcher3.CellLayout)37