Search in sources :

Example 1 with ResourceProvider

use of com.android.systemui.plugins.ResourceProvider in project android_packages_apps_Launcher3 by crdroidandroid.

the class WorkspaceStateTransitionAnimation method getSpringScaleAnimator.

/**
 * Returns a spring based animator for the scale property of {@param v}.
 */
public static ValueAnimator getSpringScaleAnimator(Launcher launcher, View v, float scale) {
    ResourceProvider rp = DynamicResource.provider(launcher);
    float damping = rp.getFloat(R.dimen.hint_scale_damping_ratio);
    float stiffness = rp.getFloat(R.dimen.hint_scale_stiffness);
    float velocityPxPerS = rp.getDimension(R.dimen.hint_scale_velocity_dp_per_s);
    return new SpringAnimationBuilder(v.getContext()).setStiffness(stiffness).setDampingRatio(damping).setMinimumVisibleChange(MIN_VISIBLE_CHANGE_SCALE).setEndValue(scale).setStartValue(SCALE_PROPERTY.get(v)).setStartVelocity(velocityPxPerS).build(v, SCALE_PROPERTY);
}
Also used : ResourceProvider(com.android.systemui.plugins.ResourceProvider) SpringAnimationBuilder(com.android.launcher3.anim.SpringAnimationBuilder)

Example 2 with ResourceProvider

use of com.android.systemui.plugins.ResourceProvider in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherSwipeHandlerV2 method createIconHomeAnimationFactory.

private HomeAnimationFactory createIconHomeAnimationFactory(View workspaceView) {
    final ResourceProvider rp = DynamicResource.provider(mActivity);
    final float transY = dpToPx(rp.getFloat(R.dimen.swipe_up_trans_y_dp));
    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) {

        // There is a delay in loading the icon, so we need to keep the window
        // opaque until it is ready.
        private boolean mIsFloatingIconReady = false;

        @Override
        public RectF getWindowTargetRect() {
            super.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 boolean keepWindowOpaque() {
            if (mIsFloatingIconReady || floatingIconView.isVisibleToUser()) {
                mIsFloatingIconReady = true;
                return false;
            }
            return true;
        }

        @Override
        public void update(@Nullable AppCloseConfig config, RectF currentRect, float progress, float radius) {
            super.update(config, currentRect, progress, radius);
            int fgAlpha = 255;
            if (config != null && PROTOTYPE_APP_CLOSE.get()) {
                progress = config.getInterpolatedProgress();
                fgAlpha = config.getFgAlpha();
            }
            floatingIconView.update(1f, 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) ResourceProvider(com.android.systemui.plugins.ResourceProvider) AppCloseConfig(com.android.quickstep.util.AppCloseConfig) Nullable(androidx.annotation.Nullable)

Example 3 with ResourceProvider

use of com.android.systemui.plugins.ResourceProvider in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentsView method cancelSplitSelect.

public PendingAnimation cancelSplitSelect(boolean animate) {
    SplitSelectStateController splitController = mSplitPlaceholderView.getSplitController();
    SplitPositionOption splitOption = splitController.getActiveSplitPositionOption();
    Rect initialBounds = splitController.getInitialBounds();
    splitController.resetState();
    int duration = mActivity.getStateManager().getState().getTransitionDuration(getContext());
    PendingAnimation pendingAnim = new PendingAnimation(duration);
    if (!animate) {
        resetFromSplitSelectionState();
        return pendingAnim;
    }
    addViewInLayout(mSplitHiddenTaskView, mSplitHiddenTaskViewIndex, mSplitHiddenTaskView.getLayoutParams());
    mSplitHiddenTaskView.setAlpha(0);
    int[] oldScroll = new int[getChildCount()];
    getPageScrolls(oldScroll, false, view -> view.getVisibility() != GONE && view != mSplitHiddenTaskView);
    int[] newScroll = new int[getChildCount()];
    getPageScrolls(newScroll, false, SIMPLE_SCROLL_LOGIC);
    boolean needsCurveUpdates = false;
    for (int i = mSplitHiddenTaskViewIndex; i >= 0; i--) {
        View child = getChildAt(i);
        if (child == mSplitHiddenTaskView) {
            TaskView taskView = (TaskView) child;
            int dir = mOrientationHandler.getSplitTaskViewDismissDirection(splitOption, mActivity.getDeviceProfile());
            FloatProperty<TaskView> dismissingTaskViewTranslate;
            Rect hiddenBounds = new Rect(taskView.getLeft(), taskView.getTop(), taskView.getRight(), taskView.getBottom());
            int distanceDelta = 0;
            if (dir == PagedOrientationHandler.SPLIT_TRANSLATE_SECONDARY_NEGATIVE) {
                dismissingTaskViewTranslate = taskView.getSecondaryDissmissTranslationProperty();
                distanceDelta = initialBounds.top - hiddenBounds.top;
                taskView.layout(initialBounds.left, hiddenBounds.top, initialBounds.right, hiddenBounds.bottom);
            } else {
                dismissingTaskViewTranslate = taskView.getPrimaryDismissTranslationProperty();
                distanceDelta = initialBounds.left - hiddenBounds.left;
                taskView.layout(hiddenBounds.left, initialBounds.top, hiddenBounds.right, initialBounds.bottom);
                if (dir == PagedOrientationHandler.SPLIT_TRANSLATE_PRIMARY_POSITIVE) {
                    distanceDelta *= -1;
                }
            }
            pendingAnim.add(ObjectAnimator.ofFloat(mSplitHiddenTaskView, dismissingTaskViewTranslate, distanceDelta));
            pendingAnim.add(ObjectAnimator.ofFloat(mSplitHiddenTaskView, ALPHA, 1));
        } else {
            // ignore views to left
            if (showAsGrid()) {
                // TODO(b/186800707) handle more elegantly for grid
                continue;
            }
            int scrollDiff = newScroll[i] - oldScroll[i];
            if (scrollDiff != 0) {
                FloatProperty translationProperty = child instanceof TaskView ? ((TaskView) child).getPrimaryDismissTranslationProperty() : mOrientationHandler.getPrimaryViewTranslate();
                ResourceProvider rp = DynamicResource.provider(mActivity);
                SpringProperty sp = new SpringProperty(SpringProperty.FLAG_CAN_SPRING_ON_END).setDampingRatio(rp.getFloat(R.dimen.dismiss_task_trans_x_damping_ratio)).setStiffness(rp.getFloat(R.dimen.dismiss_task_trans_x_stiffness));
                pendingAnim.add(ObjectAnimator.ofFloat(child, translationProperty, scrollDiff).setDuration(duration), ACCEL, sp);
                needsCurveUpdates = true;
            }
        }
    }
    if (needsCurveUpdates) {
        pendingAnim.addOnFrameCallback(this::updateCurveProperties);
    }
    pendingAnim.addListener(new AnimationSuccessListener() {

        @Override
        public void onAnimationSuccess(Animator animator) {
            // TODO(b/186800707) Figure out how to undo for grid view
            // Need to handle cases where dismissed task is
            // * Top Row
            // * Bottom Row
            // * Focused Task
            updateGridProperties();
            resetFromSplitSelectionState();
        }
    });
    return pendingAnim;
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) SpringProperty(com.android.launcher3.anim.SpringProperty) Rect(android.graphics.Rect) ImageView(android.widget.ImageView) View(android.view.View) ListView(android.widget.ListView) PagedView(com.android.launcher3.PagedView) TextPaint(android.text.TextPaint) Point(android.graphics.Point) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) SplitPositionOption(com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption) ResourceProvider(com.android.systemui.plugins.ResourceProvider) SplitSelectStateController(com.android.quickstep.util.SplitSelectStateController) FloatProperty(android.util.FloatProperty) AnimationSuccessListener(com.android.launcher3.anim.AnimationSuccessListener)

Example 4 with ResourceProvider

use of com.android.systemui.plugins.ResourceProvider in project android_packages_apps_Launcher3 by crdroidandroid.

the class RectFSpringAnim method start.

/**
 * Starts the fling/spring animation.
 * @param context The activity context.
 * @param velocityPxPerMs Velocity of swipe in px/ms.
 */
public void start(Context context, PointF velocityPxPerMs) {
    // Only tell caller that we ended if both x and y animations have ended.
    OnAnimationEndListener onXEndListener = ((animation, canceled, centerX, velocityX) -> {
        mRectXAnimEnded = true;
        maybeOnEnd();
    });
    OnAnimationEndListener onYEndListener = ((animation, canceled, centerY, velocityY) -> {
        mRectYAnimEnded = true;
        maybeOnEnd();
    });
    float startX = mCurrentCenterX;
    float endX = mTargetRect.centerX();
    float minXValue = Math.min(startX, endX);
    float maxXValue = Math.max(startX, endX);
    mRectXAnim = new FlingSpringAnim(this, context, RECT_CENTER_X, startX, endX, velocityPxPerMs.x * 1000, mMinVisChange, minXValue, maxXValue, 1f, onXEndListener);
    float startVelocityY = velocityPxPerMs.y * 1000;
    // Scale the Y velocity based on the initial velocity to tune the curves.
    float springVelocityFactor = 0.1f + 0.9f * Math.abs(startVelocityY) / 20000.0f;
    float startY = mCurrentY;
    float endY = mTrackingBottomY ? mTargetRect.bottom : mTargetRect.top;
    float minYValue = Math.min(startY, endY - mYOvershoot);
    float maxYValue = Math.max(startY, endY);
    mRectYAnim = new FlingSpringAnim(this, context, RECT_Y, startY, endY, startVelocityY, mMinVisChange, minYValue, maxYValue, springVelocityFactor, onYEndListener);
    float minVisibleChange = Math.abs(1f / mStartRect.height());
    ResourceProvider rp = DynamicResource.provider(context);
    float damping = rp.getFloat(R.dimen.swipe_up_rect_scale_damping_ratio);
    float stiffness = rp.getFloat(R.dimen.swipe_up_rect_scale_stiffness);
    mRectScaleAnim = new SpringAnimation(this, RECT_SCALE_PROGRESS).setSpring(new SpringForce(1f).setDampingRatio(damping).setStiffness(stiffness)).setStartVelocity(velocityPxPerMs.y * minVisibleChange).setMaxValue(1f).setMinimumVisibleChange(minVisibleChange).addEndListener((animation, canceled, value, velocity) -> {
        mRectScaleAnimEnded = true;
        maybeOnEnd();
    });
    setCanRelease(false);
    mAnimsStarted = true;
    mRectXAnim.start();
    mRectYAnim.start();
    mRectScaleAnim.start();
    for (Animator.AnimatorListener animatorListener : mAnimatorListeners) {
        animatorListener.onAnimationStart(null);
    }
}
Also used : RectF(android.graphics.RectF) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) SpringForce(androidx.dynamicanimation.animation.SpringForce) PointF(android.graphics.PointF) FloatPropertyCompat(androidx.dynamicanimation.animation.FloatPropertyCompat) DynamicResource(com.android.launcher3.util.DynamicResource) ReleaseCheck(com.android.quickstep.RemoteAnimationTargets.ReleaseCheck) Animator(android.animation.Animator) FlingSpringAnim(com.android.launcher3.anim.FlingSpringAnim) ResourceProvider(com.android.systemui.plugins.ResourceProvider) ArrayList(java.util.ArrayList) OnAnimationEndListener(androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener) List(java.util.List) Nullable(androidx.annotation.Nullable) R(com.android.launcher3.R) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) FlingSpringAnim(com.android.launcher3.anim.FlingSpringAnim) Animator(android.animation.Animator) SpringForce(androidx.dynamicanimation.animation.SpringForce) ResourceProvider(com.android.systemui.plugins.ResourceProvider) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) OnAnimationEndListener(androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener)

Example 5 with ResourceProvider

use of com.android.systemui.plugins.ResourceProvider in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentsView method addDismissedTaskAnimations.

private void addDismissedTaskAnimations(TaskView taskView, long duration, PendingAnimation anim) {
    // Use setFloat instead of setViewAlpha as we want to keep the view visible even when it's
    // alpha is set to 0 so that it can be recycled in the view pool properly
    anim.setFloat(taskView, VIEW_ALPHA, 0, clampToProgress(ACCEL, 0, 0.5f));
    SplitSelectStateController splitController = mSplitPlaceholderView.getSplitController();
    ResourceProvider rp = DynamicResource.provider(mActivity);
    SpringProperty sp = new SpringProperty(SpringProperty.FLAG_CAN_SPRING_ON_START).setDampingRatio(rp.getFloat(R.dimen.dismiss_task_trans_y_damping_ratio)).setStiffness(rp.getFloat(R.dimen.dismiss_task_trans_y_stiffness));
    FloatProperty<TaskView> dismissingTaskViewTranslate = taskView.getSecondaryDissmissTranslationProperty();
    // TODO(b/186800707) translate entire grid size distance
    int translateDistance = mOrientationHandler.getSecondaryDimension(taskView);
    int positiveNegativeFactor = mOrientationHandler.getSecondaryTranslationDirectionFactor();
    if (splitController.isSplitSelectActive()) {
        // Have the task translate towards whatever side was just pinned
        int dir = mOrientationHandler.getSplitTaskViewDismissDirection(splitController.getActiveSplitPositionOption(), mActivity.getDeviceProfile());
        switch(dir) {
            case PagedOrientationHandler.SPLIT_TRANSLATE_SECONDARY_NEGATIVE:
                dismissingTaskViewTranslate = taskView.getSecondaryDissmissTranslationProperty();
                positiveNegativeFactor = -1;
                break;
            case PagedOrientationHandler.SPLIT_TRANSLATE_PRIMARY_POSITIVE:
                dismissingTaskViewTranslate = taskView.getPrimaryDismissTranslationProperty();
                positiveNegativeFactor = 1;
                break;
            case PagedOrientationHandler.SPLIT_TRANSLATE_PRIMARY_NEGATIVE:
                dismissingTaskViewTranslate = taskView.getPrimaryDismissTranslationProperty();
                positiveNegativeFactor = -1;
                break;
            default:
                throw new IllegalStateException("Invalid split task translation: " + dir);
        }
    }
    // Double translation distance so dismissal drag is the full height, as we only animate
    // the drag for the first half of the progress.
    anim.add(ObjectAnimator.ofFloat(taskView, dismissingTaskViewTranslate, positiveNegativeFactor * translateDistance * 2).setDuration(duration), LINEAR, sp);
    if (ENABLE_QUICKSTEP_LIVE_TILE.get() && mEnableDrawingLiveTile && taskView.isRunningTask()) {
        anim.addOnFrameCallback(() -> {
            mLiveTileTaskViewSimulator.taskSecondaryTranslation.value = mOrientationHandler.getSecondaryValue(taskView.getTranslationX(), taskView.getTranslationY());
            redrawLiveTile();
        });
    }
}
Also used : SpringProperty(com.android.launcher3.anim.SpringProperty) ResourceProvider(com.android.systemui.plugins.ResourceProvider) SplitSelectStateController(com.android.quickstep.util.SplitSelectStateController) TextPaint(android.text.TextPaint) Point(android.graphics.Point)

Aggregations

ResourceProvider (com.android.systemui.plugins.ResourceProvider)8 Animator (android.animation.Animator)3 ObjectAnimator (android.animation.ObjectAnimator)2 ValueAnimator (android.animation.ValueAnimator)2 Point (android.graphics.Point)2 RectF (android.graphics.RectF)2 TextPaint (android.text.TextPaint)2 Nullable (androidx.annotation.Nullable)2 SpringAnimationBuilder (com.android.launcher3.anim.SpringAnimationBuilder)2 SpringProperty (com.android.launcher3.anim.SpringProperty)2 SplitSelectStateController (com.android.quickstep.util.SplitSelectStateController)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 Context (android.content.Context)1 PointF (android.graphics.PointF)1 Rect (android.graphics.Rect)1 FloatProperty (android.util.FloatProperty)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 OnAnimationEndListener (androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener)1