Search in sources :

Example 81 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.

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();
            AccessibilityManagerCompat.sendFolderOpenedEventToTest(getContext());
            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 82 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.

the class ButtonDropTarget method onDrop.

/**
 * On drop animate the dropView to the icon.
 */
@Override
public void onDrop(final DragObject d, final DragOptions options) {
    if (options.isFlingToDelete) {
        // FlingAnimation handles the animation and then calls completeDrop().
        return;
    }
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final DragView dragView = d.dragView;
    final Rect to = getIconRect(d);
    final float scale = (float) to.width() / dragView.getMeasuredWidth();
    dragView.detachContentView(/* reattachToPreviousParent= */
    true);
    mDropTargetBar.deferOnDragEnd();
    Runnable onAnimationEndRunnable = () -> {
        completeDrop(d);
        mDropTargetBar.onDragEnd();
        mLauncher.getStateManager().goToState(NORMAL);
    };
    dragLayer.animateView(d.dragView, to, scale, 0.1f, 0.1f, DRAG_VIEW_DROP_DURATION, Interpolators.DEACCEL_2, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect) DragView(com.android.launcher3.dragndrop.DragView)

Example 83 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.

the class FloatingWidgetView method getFloatingWidgetView.

/**
 * Configures and returns a an instance of {@link FloatingWidgetView} matching the appearance of
 * {@param originalView}.
 *
 * @param widgetBackgroundPosition a {@link RectF} that will be updated with the widget's
 *                                 background bounds
 * @param windowSize               the size of the window when launched
 * @param windowCornerRadius       the corner radius of the window
 */
public static FloatingWidgetView getFloatingWidgetView(Launcher launcher, LauncherAppWidgetHostView originalView, RectF widgetBackgroundPosition, Size windowSize, float windowCornerRadius, boolean appTargetsAreTranslucent, int fallbackBackgroundColor) {
    final DragLayer dragLayer = launcher.getDragLayer();
    ViewGroup parent = (ViewGroup) dragLayer.getParent();
    FloatingWidgetView floatingView = launcher.getViewCache().getView(R.layout.floating_widget_view, launcher, parent);
    floatingView.recycle();
    floatingView.init(dragLayer, originalView, widgetBackgroundPosition, windowSize, windowCornerRadius, appTargetsAreTranslucent, fallbackBackgroundColor);
    parent.addView(floatingView);
    return floatingView;
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) ViewGroup(android.view.ViewGroup)

Example 84 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.

the class AppWidgetResizeFrame method snapToWidget.

private void snapToWidget(boolean animate) {
    getSnappedRectRelativeToDragLayer(sTmpRect);
    int newWidth = sTmpRect.width();
    int newHeight = sTmpRect.height();
    int newX = sTmpRect.left;
    int newY = sTmpRect.top;
    // down accordingly to provide a proper touch target.
    if (newY < 0) {
        // In this case we shift the touch region down to start at the top of the DragLayer
        mTopTouchRegionAdjustment = -newY;
    } else {
        mTopTouchRegionAdjustment = 0;
    }
    if (newY + newHeight > mDragLayer.getHeight()) {
        // In this case we shift the touch region up to end at the bottom of the DragLayer
        mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight());
    } else {
        mBottomTouchRegionAdjustment = 0;
    }
    final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    final CellLayout pairedCellLayout;
    if (mCellLayout.getParent() instanceof Workspace) {
        Workspace workspace = (Workspace) mCellLayout.getParent();
        pairedCellLayout = workspace.getScreenPair(mCellLayout);
    } else {
        pairedCellLayout = null;
    }
    if (!animate) {
        lp.width = newWidth;
        lp.height = newHeight;
        lp.x = newX;
        lp.y = newY;
        for (int i = 0; i < HANDLE_COUNT; i++) {
            mDragHandles[i].setAlpha(1f);
        }
        if (pairedCellLayout != null) {
            updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */
            1f, /* springLoadedProgress= */
            0f);
        }
        requestLayout();
    } else {
        ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp, PropertyValuesHolder.ofInt(LAYOUT_WIDTH, lp.width, newWidth), PropertyValuesHolder.ofInt(LAYOUT_HEIGHT, lp.height, newHeight), PropertyValuesHolder.ofInt(LAYOUT_X, lp.x, newX), PropertyValuesHolder.ofInt(LAYOUT_Y, lp.y, newY));
        mFirstFrameAnimatorHelper.addTo(oa).addUpdateListener(a -> requestLayout());
        AnimatorSet set = new AnimatorSet();
        set.play(oa);
        for (int i = 0; i < HANDLE_COUNT; i++) {
            set.play(mFirstFrameAnimatorHelper.addTo(ObjectAnimator.ofFloat(mDragHandles[i], ALPHA, 1f)));
        }
        if (pairedCellLayout != null) {
            updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */
            1f, /* springLoadedProgress= */
            0f, /* animatorSet= */
            set);
        }
        set.setDuration(SNAP_DURATION);
        set.start();
    }
    setFocusableInTouchMode(true);
    requestFocus();
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet)

Example 85 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.

the class FloatingIconView method getFloatingIconView.

/**
 * Creates a floating icon view for {@param originalView}.
 * @param originalView The view to copy
 * @param hideOriginal If true, it will hide {@param originalView} while this view is visible.
 *                     Else, we will not draw anything in this view.
 * @param positionOut Rect that will hold the size and position of v.
 * @param isOpening True if this view replaces the icon for app open animation.
 */
public static FloatingIconView getFloatingIconView(Launcher launcher, View originalView, boolean hideOriginal, RectF positionOut, boolean isOpening) {
    final DragLayer dragLayer = launcher.getDragLayer();
    ViewGroup parent = (ViewGroup) dragLayer.getParent();
    FloatingIconView view = launcher.getViewCache().getView(R.layout.floating_icon_view, launcher, parent);
    view.recycle();
    // Get the drawable on the background thread
    boolean shouldLoadIcon = originalView.getTag() instanceof ItemInfo && hideOriginal;
    if (shouldLoadIcon) {
        if (sIconLoadResult != null && sIconLoadResult.itemInfo == originalView.getTag()) {
            view.mIconLoadResult = sIconLoadResult;
        } else {
            view.mIconLoadResult = fetchIcon(launcher, originalView, (ItemInfo) originalView.getTag(), isOpening);
        }
        view.setOriginalDrawableBackground(view.mIconLoadResult.btvDrawable);
    }
    sIconLoadResult = null;
    view.mIsVerticalBarLayout = launcher.getDeviceProfile().isVerticalBarLayout();
    view.mIsOpening = isOpening;
    view.mOriginalIcon = originalView;
    view.mPositionOut = positionOut;
    // Match the position of the original view.
    view.matchPositionOf(launcher, originalView, isOpening, positionOut);
    // We need to add it to the overlay, but keep it invisible until animation starts..
    view.setVisibility(INVISIBLE);
    parent.addView(view);
    dragLayer.addView(view.mListenerView);
    view.mListenerView.setListener(view::fastFinish);
    view.mEndRunnable = () -> {
        view.mEndRunnable = null;
        if (hideOriginal) {
            if (isOpening) {
                setIconAndDotVisible(originalView, true);
                view.finish(dragLayer);
            } else {
                originalView.setVisibility(VISIBLE);
                if (originalView instanceof IconLabelDotView) {
                    setIconAndDotVisible(originalView, true);
                }
                view.finish(dragLayer);
            }
        } else {
            view.finish(dragLayer);
        }
    };
    // the icon is not left in a hidden state.
    if (shouldLoadIcon) {
        view.checkIconResult(originalView);
    }
    return view;
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) ItemInfo(com.android.launcher3.model.data.ItemInfo) ViewGroup(android.view.ViewGroup)

Aggregations

DragLayer (com.android.launcher3.dragndrop.DragLayer)100 Rect (android.graphics.Rect)67 BaseDragLayer (com.android.launcher3.views.BaseDragLayer)33 ViewGroup (android.view.ViewGroup)23 Resources (android.content.res.Resources)22 AnimatorSet (android.animation.AnimatorSet)20 View (android.view.View)18 SuppressLint (android.annotation.SuppressLint)16 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)15 DeviceProfile (com.android.launcher3.DeviceProfile)15 Workspace (com.android.launcher3.Workspace)15 Animator (android.animation.Animator)14 ObjectAnimator (android.animation.ObjectAnimator)14 Point (android.graphics.Point)12 ItemInfo (com.android.launcher3.model.data.ItemInfo)12 CellLayout (com.android.launcher3.CellLayout)11 DragView (com.android.launcher3.dragndrop.DragView)11 ArrayList (java.util.ArrayList)11 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)10 Drawable (android.graphics.drawable.Drawable)10