Search in sources :

Example 31 with PendingAnimation

use of com.android.launcher3.util.PendingAnimation in project android_packages_apps_Launcher3 by AOSPA.

the class SwipeUpAnimationLogic method initTransitionEndpoints.

protected void initTransitionEndpoints(DeviceProfile dp) {
    mDp = dp;
    mTransitionDragLength = mGestureState.getActivityInterface().getSwipeUpDestinationAndLength(dp, mContext, TEMP_RECT, mRemoteTargetHandles[0].getTaskViewSimulator().getOrientationState().getOrientationHandler());
    mDragLengthFactor = (float) dp.heightPx / mTransitionDragLength;
    for (RemoteTargetHandle remoteHandle : mRemoteTargetHandles) {
        PendingAnimation pendingAnimation = new PendingAnimation(mTransitionDragLength * 2);
        TaskViewSimulator taskViewSimulator = remoteHandle.getTaskViewSimulator();
        taskViewSimulator.setDp(dp);
        taskViewSimulator.addAppToOverviewAnim(pendingAnimation, LINEAR);
        AnimatorPlaybackController playbackController = pendingAnimation.createPlaybackController();
        remoteHandle.setPlaybackController(AnimatorControllerWithResistance.createForRecents(playbackController, mContext, taskViewSimulator.getOrientationState(), mDp, taskViewSimulator.recentsViewScale, AnimatedFloat.VALUE, taskViewSimulator.recentsViewSecondaryTranslation, AnimatedFloat.VALUE));
    }
}
Also used : RemoteTargetHandle(com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle) PendingAnimation(com.android.launcher3.anim.PendingAnimation) TaskViewSimulator(com.android.quickstep.util.TaskViewSimulator) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController)

Example 32 with PendingAnimation

use of com.android.launcher3.util.PendingAnimation in project android_packages_apps_Launcher3 by AOSPA.

the class FallbackRecentsView method onPrepareGestureEndAnimation.

/**
 * When the gesture ends and we're going to recents view, we also remove the temporary
 * invisible tile added for the home task. This also pushes the remaining tiles back
 * to the center.
 */
@Override
public void onPrepareGestureEndAnimation(@Nullable AnimatorSet animatorSet, GestureState.GestureEndTarget endTarget, TaskViewSimulator[] taskViewSimulators) {
    super.onPrepareGestureEndAnimation(animatorSet, endTarget, taskViewSimulators);
    if (mHomeTaskInfo != null && endTarget == RECENTS && animatorSet != null) {
        TaskView tv = getTaskViewByTaskId(mHomeTaskInfo.taskId);
        if (tv != null) {
            PendingAnimation pa = createTaskDismissAnimation(tv, true, false, 150, false);
            pa.addEndListener(e -> setCurrentTask(-1));
            AnimatorPlaybackController controller = pa.createPlaybackController();
            controller.dispatchOnStart();
            animatorSet.play(controller.getAnimationPlayer());
        }
    }
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) TaskView(com.android.quickstep.views.TaskView) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController)

Example 33 with PendingAnimation

use of com.android.launcher3.util.PendingAnimation 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 34 with PendingAnimation

use of com.android.launcher3.util.PendingAnimation in project android_packages_apps_Trebuchet by LineageOS.

the class WorkspaceStateTransitionAnimation method setWorkspaceProperty.

/**
 * Starts a transition animation for the workspace.
 */
private void setWorkspaceProperty(LauncherState state, PropertySetter propertySetter, StateAnimationConfig config) {
    ScaleAndTranslation scaleAndTranslation = state.getWorkspaceScaleAndTranslation(mLauncher);
    ScaleAndTranslation hotseatScaleAndTranslation = state.getHotseatScaleAndTranslation(mLauncher);
    ScaleAndTranslation qsbScaleAndTranslation = state.getQsbScaleAndTranslation(mLauncher);
    mNewScale = scaleAndTranslation.scale;
    PageAlphaProvider pageAlphaProvider = state.getWorkspacePageAlphaProvider(mLauncher);
    final int childCount = mWorkspace.getChildCount();
    for (int i = 0; i < childCount; i++) {
        applyChildState(state, (CellLayout) mWorkspace.getChildAt(i), i, pageAlphaProvider, propertySetter, config);
    }
    int elements = state.getVisibleElements(mLauncher);
    Interpolator fadeInterpolator = config.getInterpolator(ANIM_WORKSPACE_FADE, pageAlphaProvider.interpolator);
    boolean playAtomicComponent = config.playAtomicOverviewScaleComponent();
    Hotseat hotseat = mWorkspace.getHotseat();
    // Since we set the pivot relative to mWorkspace, we need to scale a sibling of Workspace.
    AllAppsContainerView qsbScaleView = mLauncher.getAppsView();
    View qsbView = qsbScaleView.getSearchView();
    if (playAtomicComponent) {
        Interpolator scaleInterpolator = config.getInterpolator(ANIM_WORKSPACE_SCALE, ZOOM_OUT);
        LauncherState fromState = mLauncher.getStateManager().getState();
        boolean shouldSpring = propertySetter instanceof PendingAnimation && fromState == HINT_STATE && state == NORMAL;
        if (shouldSpring) {
            ((PendingAnimation) propertySetter).add(getSpringScaleAnimator(mLauncher, mWorkspace, mNewScale));
        } else {
            propertySetter.setFloat(mWorkspace, SCALE_PROPERTY, mNewScale, scaleInterpolator);
        }
        setPivotToScaleWithWorkspace(hotseat);
        setPivotToScaleWithWorkspace(qsbScaleView);
        float hotseatScale = hotseatScaleAndTranslation.scale;
        if (shouldSpring) {
            PendingAnimation pa = (PendingAnimation) propertySetter;
            pa.add(getSpringScaleAnimator(mLauncher, hotseat, hotseatScale));
            pa.add(getSpringScaleAnimator(mLauncher, qsbScaleView, qsbScaleAndTranslation.scale));
        } else {
            Interpolator hotseatScaleInterpolator = config.getInterpolator(ANIM_HOTSEAT_SCALE, scaleInterpolator);
            propertySetter.setFloat(hotseat, SCALE_PROPERTY, hotseatScale, hotseatScaleInterpolator);
            propertySetter.setFloat(qsbScaleView, SCALE_PROPERTY, qsbScaleAndTranslation.scale, hotseatScaleInterpolator);
        }
        float hotseatIconsAlpha = (elements & HOTSEAT_ICONS) != 0 ? 1 : 0;
        propertySetter.setViewAlpha(hotseat, hotseatIconsAlpha, fadeInterpolator);
        propertySetter.setViewAlpha(mLauncher.getWorkspace().getPageIndicator(), hotseatIconsAlpha, fadeInterpolator);
    }
    if (config.onlyPlayAtomicComponent()) {
        // Only the alpha and scale, handled above, are included in the atomic animation.
        return;
    }
    Interpolator translationInterpolator = !playAtomicComponent ? LINEAR : config.getInterpolator(ANIM_WORKSPACE_TRANSLATE, ZOOM_OUT);
    propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_X, scaleAndTranslation.translationX, translationInterpolator);
    propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_Y, scaleAndTranslation.translationY, translationInterpolator);
    Interpolator hotseatTranslationInterpolator = config.getInterpolator(ANIM_HOTSEAT_TRANSLATE, translationInterpolator);
    propertySetter.setFloat(hotseat, VIEW_TRANSLATE_Y, hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
    propertySetter.setFloat(mWorkspace.getPageIndicator(), VIEW_TRANSLATE_Y, hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
    propertySetter.setFloat(qsbView, VIEW_TRANSLATE_Y, qsbScaleAndTranslation.translationY, hotseatTranslationInterpolator);
    setScrim(propertySetter, state);
}
Also used : ScaleAndTranslation(com.android.launcher3.LauncherState.ScaleAndTranslation) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) PendingAnimation(com.android.launcher3.anim.PendingAnimation) PageAlphaProvider(com.android.launcher3.LauncherState.PageAlphaProvider) Interpolator(android.view.animation.Interpolator) View(android.view.View) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView)

Example 35 with PendingAnimation

use of com.android.launcher3.util.PendingAnimation in project android_packages_apps_Trebuchet by LineageOS.

the class TaskViewUtils method createRecentsWindowAnimator.

/**
 * Creates an animation that controls the window of the opening targets for the recents launch
 * animation.
 */
public static void createRecentsWindowAnimator(TaskView v, boolean skipViewChanges, RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets, DepthController depthController, PendingAnimation out) {
    SurfaceTransactionApplier applier = new SurfaceTransactionApplier(v);
    final RemoteAnimationTargets targets = new RemoteAnimationTargets(appTargets, wallpaperTargets, MODE_OPENING);
    targets.addReleaseCheck(applier);
    TransformParams params = new TransformParams().setSyncTransactionApplier(applier).setTargetSet(targets);
    final RecentsView recentsView = v.getRecentsView();
    int taskIndex = recentsView.indexOfChild(v);
    boolean parallaxCenterAndAdjacentTask = taskIndex != recentsView.getCurrentPage();
    int startScroll = recentsView.getScrollOffset(taskIndex);
    Context context = v.getContext();
    DeviceProfile dp = BaseActivity.fromContext(context).getDeviceProfile();
    // RecentsView never updates the display rotation until swipe-up so the value may be stale.
    // Use the display value instead.
    int displayRotation = DefaultDisplay.INSTANCE.get(context).getInfo().rotation;
    TaskViewSimulator topMostSimulator = null;
    if (targets.apps.length > 0) {
        TaskViewSimulator tsv = new TaskViewSimulator(context, recentsView.getSizeStrategy());
        tsv.setDp(dp);
        tsv.setLayoutRotation(displayRotation, displayRotation);
        tsv.setPreview(targets.apps[targets.apps.length - 1]);
        tsv.fullScreenProgress.value = 0;
        tsv.recentsViewScale.value = 1;
        tsv.setScroll(startScroll);
        out.setFloat(tsv.fullScreenProgress, AnimatedFloat.VALUE, 1, TOUCH_RESPONSE_INTERPOLATOR);
        out.setFloat(tsv.recentsViewScale, AnimatedFloat.VALUE, tsv.getFullScreenScale(), TOUCH_RESPONSE_INTERPOLATOR);
        out.setInt(tsv, TaskViewSimulator.SCROLL, 0, TOUCH_RESPONSE_INTERPOLATOR);
        out.addOnFrameCallback(() -> tsv.apply(params));
        topMostSimulator = tsv;
    }
    // Fade in the task during the initial 20% of the animation
    out.addFloat(params, TransformParams.TARGET_ALPHA, 0, 1, clampToProgress(LINEAR, 0, 0.2f));
    if (!skipViewChanges && parallaxCenterAndAdjacentTask && topMostSimulator != null) {
        out.addFloat(v, VIEW_ALPHA, 1, 0, clampToProgress(LINEAR, 0.2f, 0.4f));
        TaskViewSimulator simulatorToCopy = topMostSimulator;
        simulatorToCopy.apply(params);
        // Mt represents the overall transformation on the thumbnailView relative to the
        // Launcher's rootView
        // K(t) represents transformation on the running window by the taskViewSimulator at
        // any time t.
        // at t = 0, we know that the simulator matches the thumbnailView. So if we apply K(0)`
        // on the Launcher's rootView, the thumbnailView would match the full running task
        // window. If we apply "K(0)` K(t)" thumbnailView will match the final transformed
        // window at any time t. This gives the overall matrix on thumbnailView to be:
        // Mt K(0)` K(t)
        // During animation we apply transformation on the thumbnailView (and not the rootView)
        // to follow the TaskViewSimulator. So the final matrix applied on the thumbnailView is:
        // Mt K(0)` K(t) Mt`
        TaskThumbnailView ttv = v.getThumbnail();
        RectF tvBounds = new RectF(0, 0, ttv.getWidth(), ttv.getHeight());
        float[] tvBoundsMapped = new float[] { 0, 0, ttv.getWidth(), ttv.getHeight() };
        getDescendantCoordRelativeToAncestor(ttv, ttv.getRootView(), tvBoundsMapped, false);
        RectF tvBoundsInRoot = new RectF(tvBoundsMapped[0], tvBoundsMapped[1], tvBoundsMapped[2], tvBoundsMapped[3]);
        Matrix mt = new Matrix();
        mt.setRectToRect(tvBounds, tvBoundsInRoot, ScaleToFit.FILL);
        Matrix mti = new Matrix();
        mt.invert(mti);
        Matrix k0i = new Matrix();
        simulatorToCopy.getCurrentMatrix().invert(k0i);
        Matrix animationMatrix = new Matrix();
        out.addOnFrameCallback(() -> {
            animationMatrix.set(mt);
            animationMatrix.postConcat(k0i);
            animationMatrix.postConcat(simulatorToCopy.getCurrentMatrix());
            animationMatrix.postConcat(mti);
            ttv.setAnimationMatrix(animationMatrix);
        });
        out.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ttv.setAnimationMatrix(null);
            }
        });
    }
    out.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            targets.release();
        }
    });
    if (depthController != null) {
        out.setFloat(depthController, DEPTH, BACKGROUND_APP.getDepth(context), TOUCH_RESPONSE_INTERPOLATOR);
    }
}
Also used : Context(android.content.Context) TaskViewSimulator(com.android.quickstep.util.TaskViewSimulator) RectF(android.graphics.RectF) DeviceProfile(com.android.launcher3.DeviceProfile) SurfaceTransactionApplier(com.android.quickstep.util.SurfaceTransactionApplier) Matrix(android.graphics.Matrix) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TransformParams(com.android.quickstep.util.TransformParams) RecentsView(com.android.quickstep.views.RecentsView) TaskThumbnailView(com.android.quickstep.views.TaskThumbnailView)

Aggregations

PendingAnimation (com.android.launcher3.anim.PendingAnimation)145 AnimatorPlaybackController (com.android.launcher3.anim.AnimatorPlaybackController)58 Animator (android.animation.Animator)46 AnimatorSet (android.animation.AnimatorSet)45 Rect (android.graphics.Rect)36 ValueAnimator (android.animation.ValueAnimator)34 Point (android.graphics.Point)32 TextPaint (android.text.TextPaint)32 ObjectAnimator (android.animation.ObjectAnimator)31 Context (android.content.Context)31 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)29 View (android.view.View)29 RecentsView (com.android.quickstep.views.RecentsView)29 DeviceProfile (com.android.launcher3.DeviceProfile)27 RectF (android.graphics.RectF)26 Interpolator (android.view.animation.Interpolator)26 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)25 FloatProperty (android.util.FloatProperty)23 Matrix (android.graphics.Matrix)21 SpringProperty (com.android.launcher3.anim.SpringProperty)21