Search in sources :

Example 6 with SHAPE_PROGRESS_DURATION

use of com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherSwipeHandlerV2 method createIconHomeAnimationFactory.

private HomeAnimationFactory createIconHomeAnimationFactory(View workspaceView) {
    RectF iconLocation = new RectF();
    FloatingIconView floatingIconView = getFloatingIconView(mActivity, workspaceView, true, /* hideOriginal */
    iconLocation, false);
    // We want the window alpha to be 0 once this threshold is met, so that the
    // FolderIconView can be seen morphing into the icon shape.
    float windowAlphaThreshold = 1f - SHAPE_PROGRESS_DURATION;
    return new FloatingViewHomeAnimationFactory(floatingIconView) {

        @Nullable
        @Override
        protected View getViewIgnoredInWorkspaceRevealAnimation() {
            return workspaceView;
        }

        @NonNull
        @Override
        public RectF getWindowTargetRect() {
            return iconLocation;
        }

        @Override
        public void setAnimation(RectFSpringAnim anim) {
            super.setAnimation(anim);
            anim.addAnimatorListener(floatingIconView);
            floatingIconView.setOnTargetChangeListener(anim::onTargetPositionChanged);
            floatingIconView.setFastFinishRunnable(anim::end);
        }

        @Override
        public void update(RectF currentRect, float progress, float radius) {
            super.update(currentRect, progress, radius);
            floatingIconView.update(1f, /* alpha */
            255, /* fgAlpha */
            currentRect, progress, windowAlphaThreshold, radius, false);
        }
    };
}
Also used : RectF(android.graphics.RectF) RectFSpringAnim(com.android.quickstep.util.RectFSpringAnim) FloatingIconView(com.android.launcher3.views.FloatingIconView) FloatingIconView.getFloatingIconView(com.android.launcher3.views.FloatingIconView.getFloatingIconView)

Example 7 with SHAPE_PROGRESS_DURATION

use of com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION in project android_packages_apps_404Launcher by P-404.

the class QuickstepTransitionManager method getClosingWindowAnimators.

/**
 * Closing animator that animates the window into its final location on the workspace.
 */
private void getClosingWindowAnimators(AnimatorSet animation, RemoteAnimationTargetCompat[] targets, View launcherView, PointF velocityPxPerS) {
    FloatingIconView floatingIconView = null;
    FloatingWidgetView floatingWidget = null;
    RectF targetRect = new RectF();
    RemoteAnimationTargetCompat runningTaskTarget = null;
    boolean isTransluscent = false;
    for (RemoteAnimationTargetCompat target : targets) {
        if (target.mode == MODE_CLOSING) {
            runningTaskTarget = target;
            isTransluscent = runningTaskTarget.isTranslucent;
            break;
        }
    }
    // Get floating view and target rect.
    if (launcherView instanceof LauncherAppWidgetHostView) {
        Size windowSize = new Size(mDeviceProfile.availableWidthPx, mDeviceProfile.availableHeightPx);
        int fallbackBackgroundColor = FloatingWidgetView.getDefaultBackgroundColor(mLauncher, runningTaskTarget);
        floatingWidget = FloatingWidgetView.getFloatingWidgetView(mLauncher, (LauncherAppWidgetHostView) launcherView, targetRect, windowSize, mDeviceProfile.isMultiWindowMode ? 0 : getWindowCornerRadius(mLauncher), isTransluscent, fallbackBackgroundColor);
    } else if (launcherView != null) {
        floatingIconView = getFloatingIconView(mLauncher, launcherView, true, /* hideOriginal */
        targetRect, false);
    } else {
        targetRect.set(getDefaultWindowTargetRect());
    }
    final RectF startRect = new RectF(0, 0, mDeviceProfile.widthPx, mDeviceProfile.heightPx);
    RectFSpringAnim anim = new RectFSpringAnim(startRect, targetRect, mLauncher, mDeviceProfile);
    // Hook up floating views to the closing window animators.
    final int rotationChange = getRotationChange(targets);
    Rect windowTargetBounds = getWindowTargetBounds(targets, rotationChange);
    if (floatingIconView != null) {
        anim.addAnimatorListener(floatingIconView);
        floatingIconView.setOnTargetChangeListener(anim::onTargetPositionChanged);
        floatingIconView.setFastFinishRunnable(anim::end);
        FloatingIconView finalFloatingIconView = floatingIconView;
        // We want the window alpha to be 0 once this threshold is met, so that the
        // FolderIconView can be seen morphing into the icon shape.
        final float windowAlphaThreshold = 1f - SHAPE_PROGRESS_DURATION;
        RectFSpringAnim.OnUpdateListener runner = new SpringAnimRunner(targets, targetRect, windowTargetBounds) {

            @Override
            public void onUpdate(RectF currentRectF, float progress) {
                finalFloatingIconView.update(1f, 255, /* fgAlpha */
                currentRectF, progress, windowAlphaThreshold, getCornerRadius(progress), false);
                super.onUpdate(currentRectF, progress);
            }
        };
        anim.addOnUpdateListener(runner);
    } else if (floatingWidget != null) {
        anim.addAnimatorListener(floatingWidget);
        floatingWidget.setOnTargetChangeListener(anim::onTargetPositionChanged);
        floatingWidget.setFastFinishRunnable(anim::end);
        final float floatingWidgetAlpha = isTransluscent ? 0 : 1;
        FloatingWidgetView finalFloatingWidget = floatingWidget;
        RectFSpringAnim.OnUpdateListener runner = new SpringAnimRunner(targets, targetRect, windowTargetBounds) {

            @Override
            public void onUpdate(RectF currentRectF, float progress) {
                final float fallbackBackgroundAlpha = 1 - mapBoundToRange(progress, 0.8f, 1, 0, 1, EXAGGERATED_EASE);
                final float foregroundAlpha = mapBoundToRange(progress, 0.5f, 1, 0, 1, EXAGGERATED_EASE);
                finalFloatingWidget.update(currentRectF, floatingWidgetAlpha, foregroundAlpha, fallbackBackgroundAlpha, 1 - progress);
                super.onUpdate(currentRectF, progress);
            }
        };
        anim.addOnUpdateListener(runner);
    }
    // Use a fixed velocity to start the animation.
    animation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            anim.start(mLauncher, velocityPxPerS);
        }
    });
}
Also used : FloatingIconView(com.android.launcher3.views.FloatingIconView) FloatingIconView.getFloatingIconView(com.android.launcher3.views.FloatingIconView.getFloatingIconView) Rect(android.graphics.Rect) FloatingWidgetView(com.android.quickstep.views.FloatingWidgetView) Size(android.util.Size) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) Point(android.graphics.Point) RectF(android.graphics.RectF) RectFSpringAnim(com.android.quickstep.util.RectFSpringAnim) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 8 with SHAPE_PROGRESS_DURATION

use of com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION in project android_packages_apps_404Launcher by P-404.

the class LauncherSwipeHandlerV2 method createIconHomeAnimationFactory.

private HomeAnimationFactory createIconHomeAnimationFactory(View workspaceView) {
    RectF iconLocation = new RectF();
    FloatingIconView floatingIconView = getFloatingIconView(mActivity, workspaceView, true, /* hideOriginal */
    iconLocation, false);
    // We want the window alpha to be 0 once this threshold is met, so that the
    // FolderIconView can be seen morphing into the icon shape.
    float windowAlphaThreshold = 1f - SHAPE_PROGRESS_DURATION;
    return new FloatingViewHomeAnimationFactory(floatingIconView) {

        @Nullable
        @Override
        protected View getViewIgnoredInWorkspaceRevealAnimation() {
            return workspaceView;
        }

        @NonNull
        @Override
        public RectF getWindowTargetRect() {
            return iconLocation;
        }

        @Override
        public void setAnimation(RectFSpringAnim anim) {
            super.setAnimation(anim);
            anim.addAnimatorListener(floatingIconView);
            floatingIconView.setOnTargetChangeListener(anim::onTargetPositionChanged);
            floatingIconView.setFastFinishRunnable(anim::end);
        }

        @Override
        public void update(RectF currentRect, float progress, float radius) {
            super.update(currentRect, progress, radius);
            floatingIconView.update(1f, /* alpha */
            255, /* fgAlpha */
            currentRect, progress, windowAlphaThreshold, radius, false);
        }
    };
}
Also used : RectF(android.graphics.RectF) RectFSpringAnim(com.android.quickstep.util.RectFSpringAnim) FloatingIconView(com.android.launcher3.views.FloatingIconView) FloatingIconView.getFloatingIconView(com.android.launcher3.views.FloatingIconView.getFloatingIconView)

Example 9 with SHAPE_PROGRESS_DURATION

use of com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION in project Neo-Launcher by NeoApplications.

the class QuickstepAppTransitionManagerImpl method getOpeningWindowAnimators.

/**
 * @return Animator that controls the window of the opening targets.
 */
private ValueAnimator getOpeningWindowAnimators(View v, RemoteAnimationTargetCompat[] targets, Rect windowTargetBounds, boolean toggleVisibility) {
    RectF bounds = new RectF();
    FloatingIconView floatingView = FloatingIconView.getFloatingIconView(mLauncher, v, toggleVisibility, bounds, true);
    Rect crop = new Rect();
    Matrix matrix = new Matrix();
    RemoteAnimationTargetSet openingTargets = new RemoteAnimationTargetSet(targets, MODE_OPENING);
    SyncRtSurfaceTransactionApplierCompat surfaceApplier = new SyncRtSurfaceTransactionApplierCompat(floatingView);
    openingTargets.addDependentTransactionApplier(surfaceApplier);
    // Scale the app icon to take up the entire screen. This simplifies the math when
    // animating the app window position / scale.
    float smallestSize = Math.min(windowTargetBounds.height(), windowTargetBounds.width());
    float maxScaleX = smallestSize / bounds.width();
    float maxScaleY = smallestSize / bounds.height();
    float scale = Math.max(maxScaleX, maxScaleY);
    float startScale = 1f;
    if (v instanceof BubbleTextView && !(v.getParent() instanceof DeepShortcutView)) {
        Drawable dr = ((BubbleTextView) v).getIcon();
        if (dr instanceof FastBitmapDrawable) {
            startScale = ((FastBitmapDrawable) dr).getAnimatedScale();
        }
    }
    final float initialStartScale = startScale;
    int[] dragLayerBounds = new int[2];
    mDragLayer.getLocationOnScreen(dragLayerBounds);
    // Animate the app icon to the center of the window bounds in screen coordinates.
    float centerX = windowTargetBounds.centerX() - dragLayerBounds[0];
    float centerY = windowTargetBounds.centerY() - dragLayerBounds[1];
    float dX = centerX - bounds.centerX();
    float dY = centerY - bounds.centerY();
    boolean useUpwardAnimation = bounds.top > centerY || Math.abs(dY) < mLauncher.getDeviceProfile().cellHeightPx;
    final long xDuration = useUpwardAnimation ? APP_LAUNCH_CURVED_DURATION : APP_LAUNCH_DOWN_DURATION;
    final long yDuration = useUpwardAnimation ? APP_LAUNCH_DURATION : APP_LAUNCH_DOWN_CURVED_DURATION;
    final long alphaDuration = useUpwardAnimation ? APP_LAUNCH_ALPHA_DURATION : APP_LAUNCH_ALPHA_DOWN_DURATION;
    RectF targetBounds = new RectF(windowTargetBounds);
    RectF currentBounds = new RectF();
    RectF temp = new RectF();
    ValueAnimator appAnimator = ValueAnimator.ofFloat(0, 1);
    appAnimator.setDuration(APP_LAUNCH_DURATION);
    appAnimator.setInterpolator(LINEAR);
    appAnimator.addListener(floatingView);
    appAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (v instanceof BubbleTextView) {
                ((BubbleTextView) v).setStayPressed(false);
            }
            openingTargets.release();
        }
    });
    float shapeRevealDuration = APP_LAUNCH_DURATION * SHAPE_PROGRESS_DURATION;
    final float startCrop;
    final float endCrop;
    if (mDeviceProfile.isVerticalBarLayout()) {
        startCrop = windowTargetBounds.height();
        endCrop = windowTargetBounds.width();
    } else {
        startCrop = windowTargetBounds.width();
        endCrop = windowTargetBounds.height();
    }
    final float initialWindowRadius = supportsRoundedCornersOnWindows(mLauncher.getResources()) ? startCrop / 2f : 0f;
    final float windowRadius = mDeviceProfile.isMultiWindowMode ? 0 : getWindowCornerRadius(mLauncher.getResources());
    appAnimator.addUpdateListener(new MultiValueUpdateListener() {

        FloatProp mDx = new FloatProp(0, dX, 0, xDuration, AGGRESSIVE_EASE);

        FloatProp mDy = new FloatProp(0, dY, 0, yDuration, AGGRESSIVE_EASE);

        FloatProp mIconScale = new FloatProp(initialStartScale, scale, 0, APP_LAUNCH_DURATION, EXAGGERATED_EASE);

        FloatProp mIconAlpha = new FloatProp(1f, 0f, APP_LAUNCH_ALPHA_START_DELAY, alphaDuration, LINEAR);

        FloatProp mCroppedSize = new FloatProp(startCrop, endCrop, 0, CROP_DURATION, EXAGGERATED_EASE);

        FloatProp mWindowRadius = new FloatProp(initialWindowRadius, windowRadius, 0, RADIUS_DURATION, EXAGGERATED_EASE);

        @Override
        public void onUpdate(float percent) {
            // Calculate app icon size.
            float iconWidth = bounds.width() * mIconScale.value;
            float iconHeight = bounds.height() * mIconScale.value;
            // Animate the window crop so that it starts off as a square.
            final int windowWidth;
            final int windowHeight;
            if (mDeviceProfile.isVerticalBarLayout()) {
                windowWidth = (int) mCroppedSize.value;
                windowHeight = windowTargetBounds.height();
            } else {
                windowWidth = windowTargetBounds.width();
                windowHeight = (int) mCroppedSize.value;
            }
            crop.set(0, 0, windowWidth, windowHeight);
            // Scale the app window to match the icon size.
            float scaleX = iconWidth / windowWidth;
            float scaleY = iconHeight / windowHeight;
            float scale = Math.min(1f, Math.max(scaleX, scaleY));
            float scaledWindowWidth = windowWidth * scale;
            float scaledWindowHeight = windowHeight * scale;
            float offsetX = (scaledWindowWidth - iconWidth) / 2;
            float offsetY = (scaledWindowHeight - iconHeight) / 2;
            // Calculate the window position
            temp.set(bounds);
            temp.offset(dragLayerBounds[0], dragLayerBounds[1]);
            temp.offset(mDx.value, mDy.value);
            Utilities.scaleRectFAboutCenter(temp, mIconScale.value);
            float transX0 = temp.left - offsetX;
            float transY0 = temp.top - offsetY;
            float croppedHeight = (windowTargetBounds.height() - crop.height()) * scale;
            float croppedWidth = (windowTargetBounds.width() - crop.width()) * scale;
            SurfaceParams[] params = new SurfaceParams[targets.length];
            for (int i = targets.length - 1; i >= 0; i--) {
                RemoteAnimationTargetCompat target = targets[i];
                Rect targetCrop;
                final float alpha;
                final float cornerRadius;
                if (target.mode == MODE_OPENING) {
                    matrix.setScale(scale, scale);
                    matrix.postTranslate(transX0, transY0);
                    targetCrop = crop;
                    alpha = 1f - mIconAlpha.value;
                    cornerRadius = mWindowRadius.value;
                    matrix.mapRect(currentBounds, targetBounds);
                    if (mDeviceProfile.isVerticalBarLayout()) {
                        currentBounds.right -= croppedWidth;
                    } else {
                        currentBounds.bottom -= croppedHeight;
                    }
                    floatingView.update(currentBounds, mIconAlpha.value, percent, 0f, cornerRadius * scale, true);
                } else {
                    matrix.setTranslate(target.position.x, target.position.y);
                    targetCrop = target.sourceContainerBounds;
                    alpha = 1f;
                    cornerRadius = 0;
                }
                params[i] = new SurfaceParams(target.leash, alpha, matrix, targetCrop, RemoteAnimationProvider.getLayer(target, MODE_OPENING), cornerRadius);
            }
            surfaceApplier.scheduleApply(params);
        }
    });
    return appAnimator;
}
Also used : SyncRtSurfaceTransactionApplierCompat(com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat) FloatingIconView(com.android.launcher3.views.FloatingIconView) Rect(android.graphics.Rect) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) Drawable(android.graphics.drawable.Drawable) ValueAnimator(android.animation.ValueAnimator) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) RemoteAnimationTargetSet(com.android.quickstep.util.RemoteAnimationTargetSet) RectF(android.graphics.RectF) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) Matrix(android.graphics.Matrix) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SurfaceParams(com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams)

Example 10 with SHAPE_PROGRESS_DURATION

use of com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION in project Neo-Launcher by NeoApplications.

the class FloatingIconView method update.

/**
 * Positions this view to match the size and location of {@param rect}.
 * @param alpha The alpha to set this view.
 * @param progress A value from [0, 1] that represents the animation progress.
 * @param shapeProgressStart The progress value at which to start the shape reveal.
 * @param cornerRadius The corner radius of {@param rect}.
 */
public void update(RectF rect, float alpha, float progress, float shapeProgressStart, float cornerRadius, boolean isOpening) {
    setAlpha(alpha);
    LayoutParams lp = (LayoutParams) getLayoutParams();
    float dX = mIsRtl ? rect.left - (mLauncher.getDeviceProfile().widthPx - lp.getMarginStart() - lp.width) : rect.left - lp.getMarginStart();
    float dY = rect.top - lp.topMargin;
    setTranslationX(dX);
    setTranslationY(dY);
    float minSize = Math.min(lp.width, lp.height);
    float scaleX = rect.width() / minSize;
    float scaleY = rect.height() / minSize;
    float scale = Math.max(1f, Math.min(scaleX, scaleY));
    setPivotX(0);
    setPivotY(0);
    setScaleX(scale);
    setScaleY(scale);
    // shapeRevealProgress = 1 when progress = shapeProgressStart + SHAPE_PROGRESS_DURATION
    float toMax = isOpening ? 1 / SHAPE_PROGRESS_DURATION : 1f;
    float shapeRevealProgress = Utilities.boundToRange(mapToRange(Math.max(shapeProgressStart, progress), shapeProgressStart, 1f, 0, toMax, LINEAR), 0, 1);
    if (mIsVerticalBarLayout) {
        mOutline.right = (int) (rect.width() / scale);
    } else {
        mOutline.bottom = (int) (rect.height() / scale);
    }
    mTaskCornerRadius = cornerRadius / scale;
    if (mIsAdaptiveIcon) {
        if (!isOpening && progress >= shapeProgressStart) {
            if (mRevealAnimator == null) {
                mRevealAnimator = (ValueAnimator) IconShape.getShape().createRevealAnimator(this, mStartRevealRect, mOutline, mTaskCornerRadius, !isOpening);
                mRevealAnimator.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mRevealAnimator = null;
                    }
                });
                mRevealAnimator.start();
                // We pause here so we can set the current fraction ourselves.
                mRevealAnimator.pause();
            }
            mRevealAnimator.setCurrentFraction(shapeRevealProgress);
        }
        float drawableScale = (mIsVerticalBarLayout ? mOutline.width() : mOutline.height()) / minSize;
        setBackgroundDrawableBounds(drawableScale);
        if (isOpening) {
            // Center align foreground
            int height = mFinalDrawableBounds.height();
            int width = mFinalDrawableBounds.width();
            int diffY = mIsVerticalBarLayout ? 0 : (int) (((height * drawableScale) - height) / 2);
            int diffX = mIsVerticalBarLayout ? (int) (((width * drawableScale) - width) / 2) : 0;
            sTmpRect.set(mFinalDrawableBounds);
            sTmpRect.offset(diffX, diffY);
            mForeground.setBounds(sTmpRect);
        } else {
            // Spring the foreground relative to the icon's movement within the DragLayer.
            int diffX = (int) (dX / mLauncher.getDeviceProfile().availableWidthPx * FG_TRANS_X_FACTOR);
            int diffY = (int) (dY / mLauncher.getDeviceProfile().availableHeightPx * FG_TRANS_Y_FACTOR);
            mFgSpringX.animateToFinalPosition(diffX);
            mFgSpringY.animateToFinalPosition(diffY);
        }
    }
    invalidate();
    invalidateOutline();
}
Also used : LayoutParams(com.android.launcher3.InsettableFrameLayout.LayoutParams) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Aggregations

RectF (android.graphics.RectF)13 FloatingIconView (com.android.launcher3.views.FloatingIconView)13 RectFSpringAnim (com.android.quickstep.util.RectFSpringAnim)11 FloatingIconView.getFloatingIconView (com.android.launcher3.views.FloatingIconView.getFloatingIconView)9 Animator (android.animation.Animator)8 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)7 ObjectAnimator (android.animation.ObjectAnimator)7 ValueAnimator (android.animation.ValueAnimator)7 Rect (android.graphics.Rect)6 RemoteAnimationTargetCompat (com.android.systemui.shared.system.RemoteAnimationTargetCompat)6 Point (android.graphics.Point)5 Size (android.util.Size)4 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)4 FloatingWidgetView (com.android.quickstep.views.FloatingWidgetView)4 AnimatorSet (android.animation.AnimatorSet)2 Matrix (android.graphics.Matrix)2 Drawable (android.graphics.drawable.Drawable)2 View (android.view.View)2 AnimatorPlaybackController (com.android.launcher3.anim.AnimatorPlaybackController)2 DeepShortcutView (com.android.launcher3.shortcuts.DeepShortcutView)2