Search in sources :

Example 16 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Launcher3 by AOSPA.

the class FloatingTaskView method addAnimation.

public void addAnimation(PendingAnimation animation, RectF startingBounds, Rect endBounds, View viewToCover, boolean fadeWithThumbnail) {
    final BaseDragLayer dragLayer = mActivity.getDragLayer();
    int[] dragLayerBounds = new int[2];
    dragLayer.getLocationOnScreen(dragLayerBounds);
    SplitOverlayProperties prop = new SplitOverlayProperties(endBounds, startingBounds, viewToCover, dragLayerBounds[0], dragLayerBounds[1]);
    ValueAnimator transitionAnimator = ValueAnimator.ofFloat(0, 1);
    animation.add(transitionAnimator);
    long animDuration = animation.getDuration();
    Rect crop = new Rect();
    RectF floatingTaskViewBounds = new RectF();
    final float initialWindowRadius = supportsRoundedCornersOnWindows(getResources()) ? Math.max(crop.width(), crop.height()) / 2f : 0f;
    if (fadeWithThumbnail) {
        animation.addFloat(mSplitPlaceholderView, SplitPlaceholderView.ALPHA_FLOAT, 0, 1, ACCEL);
        animation.addFloat(mImageView, LauncherAnimUtils.VIEW_ALPHA, 1, 0, DEACCEL_3);
    }
    MultiValueUpdateListener listener = new MultiValueUpdateListener() {

        final FloatProp mWindowRadius = new FloatProp(initialWindowRadius, initialWindowRadius, 0, animDuration, LINEAR);

        final FloatProp mDx = new FloatProp(0, prop.dX, 0, animDuration, LINEAR);

        final FloatProp mDy = new FloatProp(0, prop.dY, 0, animDuration, LINEAR);

        final FloatProp mTaskViewScaleX = new FloatProp(prop.initialTaskViewScaleX, prop.finalTaskViewScaleX, 0, animDuration, LINEAR);

        final FloatProp mTaskViewScaleY = new FloatProp(prop.initialTaskViewScaleY, prop.finalTaskViewScaleY, 0, animDuration, LINEAR);

        @Override
        public void onUpdate(float percent, boolean initOnly) {
            // Calculate the icon position.
            floatingTaskViewBounds.set(startingBounds);
            floatingTaskViewBounds.offset(mDx.value, mDy.value);
            Utilities.scaleRectFAboutCenter(floatingTaskViewBounds, mTaskViewScaleX.value, mTaskViewScaleY.value);
            update(floatingTaskViewBounds, percent, mWindowRadius.value * 1);
        }
    };
    transitionAnimator.addUpdateListener(listener);
}
Also used : RectF(android.graphics.RectF) BaseDragLayer(com.android.launcher3.views.BaseDragLayer) Rect(android.graphics.Rect) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 17 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Launcher3 by AOSPA.

the class AllAppsEduView method show.

/**
 * Shows the All Apps education view and plays the animation.
 */
public static void show(Launcher launcher) {
    final DragLayer dragLayer = launcher.getDragLayer();
    AllAppsEduView view = (AllAppsEduView) launcher.getLayoutInflater().inflate(R.layout.all_apps_edu_view, dragLayer, false);
    view.init(launcher);
    launcher.getDragLayer().addView(view);
    launcher.getStatsLogManager().logger().log(LAUNCHER_ALL_APPS_EDU_SHOWN);
    view.requestLayout();
    view.playAnimation();
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer)

Example 18 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Launcher3 by AOSPA.

the class DragLayer method animateView.

/**
 * This method animates a view at the end of a drag and drop animation.
 * @param view The view to be animated. This view is drawn directly into DragLayer, and so
 *        doesn't need to be a child of DragLayer.
 * @param to The final location of the view. Only the left and top parameters are used. This
 *        location doesn't account for scaling, and so should be centered about the desired
 *        final location (including scaling).
 * @param finalAlpha The final alpha of the view, in case we want it to fade as it animates.
 * @param finalScaleX The final scale of the view. The view is scaled about its center.
 * @param finalScaleY The final scale of the view. The view is scaled about its center.
 * @param duration The duration of the animation.
 * @param motionInterpolator The interpolator to use for the location of the view.
 * @param onCompleteRunnable Optional runnable to run on animation completion.
 * @param animationEndStyle Whether or not to fade out the view once the animation completes.
 *        {@link #ANIMATION_END_DISAPPEAR} or {@link #ANIMATION_END_REMAIN_VISIBLE}.
 * @param anchorView If not null, this represents the view which the animated view stays
 */
public void animateView(final DragView view, final Rect to, final float finalAlpha, final float finalScaleX, final float finalScaleY, int duration, final Interpolator motionInterpolator, final Runnable onCompleteRunnable, final int animationEndStyle, View anchorView) {
    view.cancelAnimation();
    view.requestLayout();
    final int[] from = getViewLocationRelativeToSelf(view);
    // Calculate the duration of the animation based on the object's distance
    final float dist = (float) Math.hypot(to.left - from[0], to.top - from[1]);
    final Resources res = getResources();
    final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist);
    // If duration < 0, this is a cue to compute the duration based on the distance
    if (duration < 0) {
        duration = res.getInteger(R.integer.config_dropAnimMaxDuration);
        if (dist < maxDist) {
            duration *= DEACCEL_1_5.getInterpolation(dist / maxDist);
        }
        duration = Math.max(duration, res.getInteger(R.integer.config_dropAnimMinDuration));
    }
    // Fall back to cubic ease out interpolator for the animation if none is specified
    TimeInterpolator interpolator = motionInterpolator == null ? DEACCEL_1_5 : motionInterpolator;
    // Animate the view
    PendingAnimation anim = new PendingAnimation(duration);
    anim.add(ofFloat(view, View.SCALE_X, finalScaleX), interpolator, SpringProperty.DEFAULT);
    anim.add(ofFloat(view, View.SCALE_Y, finalScaleY), interpolator, SpringProperty.DEFAULT);
    anim.setViewAlpha(view, finalAlpha, interpolator);
    anim.setFloat(view, VIEW_TRANSLATE_Y, to.top, interpolator);
    ObjectAnimator xMotion = ofFloat(view, VIEW_TRANSLATE_X, to.left);
    if (anchorView != null) {
        final int startScroll = anchorView.getScrollX();
        TypeEvaluator<Float> evaluator = (f, s, e) -> mapRange(f, s, e) + (anchorView.getScaleX() * (startScroll - anchorView.getScrollX()));
        xMotion.setEvaluator(evaluator);
    }
    anim.add(xMotion, interpolator, SpringProperty.DEFAULT);
    if (onCompleteRunnable != null) {
        anim.addListener(forEndCallback(onCompleteRunnable));
    }
    playDropAnimation(view, anim.buildAnim(), animationEndStyle);
}
Also used : Folder(com.android.launcher3.folder.Folder) DEACCEL_1_5(com.android.launcher3.anim.Interpolators.DEACCEL_1_5) Context(android.content.Context) Rect(android.graphics.Rect) TimeInterpolator(android.animation.TimeInterpolator) ViewGroupFocusHelper(com.android.launcher3.keyboard.ViewGroupFocusHelper) KeyEvent(android.view.KeyEvent) Animator(android.animation.Animator) Scrim(com.android.launcher3.graphics.Scrim) AnimatorListeners.forEndCallback(com.android.launcher3.anim.AnimatorListeners.forEndCallback) ArrayList(java.util.ArrayList) TypeEvaluator(android.animation.TypeEvaluator) BaseDragLayer(com.android.launcher3.views.BaseDragLayer) AccessibilityManager(android.view.accessibility.AccessibilityManager) AccessibilityManagerCompat.sendCustomAccessibilityEvent(com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent) AttributeSet(android.util.AttributeSet) MotionEvent(android.view.MotionEvent) View(android.view.View) Canvas(android.graphics.Canvas) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Launcher(com.android.launcher3.Launcher) Interpolator(android.view.animation.Interpolator) VIEW_TRANSLATE_Y(com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y) VIEW_TRANSLATE_X(com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X) ObjectAnimator(android.animation.ObjectAnimator) SpringProperty(com.android.launcher3.anim.SpringProperty) Utilities.mapRange(com.android.launcher3.Utilities.mapRange) CellLayout(com.android.launcher3.CellLayout) ObjectAnimator.ofFloat(android.animation.ObjectAnimator.ofFloat) DropTargetBar(com.android.launcher3.DropTargetBar) TouchController(com.android.launcher3.util.TouchController) R(com.android.launcher3.R) ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer) Workspace(com.android.launcher3.Workspace) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) PendingAnimation(com.android.launcher3.anim.PendingAnimation) Resources(android.content.res.Resources) PendingAnimation(com.android.launcher3.anim.PendingAnimation) ObjectAnimator.ofFloat(android.animation.ObjectAnimator.ofFloat) ObjectAnimator(android.animation.ObjectAnimator) Resources(android.content.res.Resources) TimeInterpolator(android.animation.TimeInterpolator)

Example 19 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Launcher3 by AOSPA.

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 20 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class WorkspaceAccessibilityHelper method onPopulateNodeForVirtualView.

@Override
protected void onPopulateNodeForVirtualView(int id, AccessibilityNodeInfoCompat node) {
    super.onPopulateNodeForVirtualView(id, node);
    // ExploreByTouchHelper does not currently handle view scale.
    // Update BoundsInScreen to appropriate value.
    DragLayer dragLayer = Launcher.getLauncher(mView.getContext()).getDragLayer();
    mTempCords[0] = mTempCords[1] = 0;
    float scale = dragLayer.getDescendantCoordRelativeToSelf(mView, mTempCords);
    node.getBoundsInParent(mTempRect);
    mTempRect.left = mTempCords[0] + (int) (mTempRect.left * scale);
    mTempRect.right = mTempCords[0] + (int) (mTempRect.right * scale);
    mTempRect.top = mTempCords[1] + (int) (mTempRect.top * scale);
    mTempRect.bottom = mTempCords[1] + (int) (mTempRect.bottom * scale);
    node.setBoundsInScreen(mTempRect);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer)

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