Search in sources :

Example 11 with ClipRectAnimation

use of android.view.animation.ClipRectAnimation in project android_frameworks_base by crdroidandroid.

the class AppTransition method createThumbnailAspectScaleAnimationLocked.

/**
     * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
     * when a thumbnail is specified with the pending animation override.
     */
Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets, Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
    Animation a;
    final int thumbWidthI = thumbnailHeader.getWidth();
    final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
    final int thumbHeightI = thumbnailHeader.getHeight();
    final int appWidth = appRect.width();
    float scaleW = appWidth / thumbWidth;
    getNextAppTransitionStartRect(taskId, mTmpRect);
    final float fromX;
    float fromY;
    final float toX;
    float toY;
    final float pivotX;
    final float pivotY;
    if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
        fromX = mTmpRect.left;
        fromY = mTmpRect.top;
        // For the curved translate animation to work, the pivot points needs to be at the
        // same absolute position as the one from the real surface.
        toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
        toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
        pivotX = mTmpRect.width() / 2;
        pivotY = appRect.height() / 2 / scaleW;
        if (mGridLayoutRecentsEnabled) {
            // In the grid layout, the header is displayed above the thumbnail instead of
            // overlapping it.
            fromY -= thumbHeightI;
            toY -= thumbHeightI * scaleW;
        }
    } else {
        pivotX = 0;
        pivotY = 0;
        fromX = mTmpRect.left;
        fromY = mTmpRect.top;
        toX = appRect.left;
        toY = appRect.top;
    }
    final long duration = getAspectScaleDuration();
    final Interpolator interpolator = getAspectScaleInterpolator();
    if (mNextAppTransitionScaleUp) {
        // Animation up from the thumbnail to the full screen
        Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
        scale.setInterpolator(interpolator);
        scale.setDuration(duration);
        Animation alpha = new AlphaAnimation(1f, 0f);
        alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
        alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS ? duration / 2 : duration);
        Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
        translate.setInterpolator(interpolator);
        translate.setDuration(duration);
        mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
        mTmpToClipRect.set(appRect);
        // Containing frame is in screen space, but we need the clip rect in the
        // app space.
        mTmpToClipRect.offsetTo(0, 0);
        mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
        mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
        if (contentInsets != null) {
            mTmpToClipRect.inset((int) (-contentInsets.left * scaleW), (int) (-contentInsets.top * scaleW), (int) (-contentInsets.right * scaleW), (int) (-contentInsets.bottom * scaleW));
        }
        Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
        clipAnim.setInterpolator(interpolator);
        clipAnim.setDuration(duration);
        // This AnimationSet uses the Interpolators assigned above.
        AnimationSet set = new AnimationSet(false);
        set.addAnimation(scale);
        if (!mGridLayoutRecentsEnabled) {
            // In the grid layout, the header should be shown for the whole animation.
            set.addAnimation(alpha);
        }
        set.addAnimation(translate);
        set.addAnimation(clipAnim);
        a = set;
    } else {
        // Animation down from the full screen to the thumbnail
        Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
        scale.setInterpolator(interpolator);
        scale.setDuration(duration);
        Animation alpha = new AlphaAnimation(0f, 1f);
        alpha.setInterpolator(mThumbnailFadeInInterpolator);
        alpha.setDuration(duration);
        Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
        translate.setInterpolator(interpolator);
        translate.setDuration(duration);
        // This AnimationSet uses the Interpolators assigned above.
        AnimationSet set = new AnimationSet(false);
        set.addAnimation(scale);
        if (!mGridLayoutRecentsEnabled) {
            // In the grid layout, the header should be shown for the whole animation.
            set.addAnimation(alpha);
        }
        set.addAnimation(translate);
        a = set;
    }
    return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0, null);
}
Also used : ScaleAnimation(android.view.animation.ScaleAnimation) WindowAnimation_wallpaperCloseExitAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation) CurvedTranslateAnimation(com.android.server.wm.animation.CurvedTranslateAnimation) WindowAnimation_activityOpenEnterAnimation(com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation) WindowAnimation_wallpaperOpenExitAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation) WindowAnimation_taskToBackEnterAnimation(com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation) WindowAnimation_activityOpenExitAnimation(com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation) TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) ClipRectAnimation(android.view.animation.ClipRectAnimation) WindowAnimation_wallpaperOpenEnterAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation) WindowAnimation_launchTaskBehindTargetAnimation(com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation) WindowAnimation_launchTaskBehindSourceAnimation(com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation) WindowAnimation_taskCloseExitAnimation(com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) WindowAnimation_wallpaperIntraCloseEnterAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation) WindowAnimation_taskToBackExitAnimation(com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation) WindowAnimation_activityCloseEnterAnimation(com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation) WindowAnimation_taskCloseEnterAnimation(com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation) WindowAnimation_taskOpenEnterAnimation(com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation) WindowAnimation_wallpaperIntraCloseExitAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation) ClipRectTBAnimation(com.android.server.wm.animation.ClipRectTBAnimation) WindowAnimation_taskOpenExitAnimation(com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation) ClipRectLRAnimation(com.android.server.wm.animation.ClipRectLRAnimation) WindowAnimation_activityCloseExitAnimation(com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation) WindowAnimation_taskToFrontEnterAnimation(com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation) WindowAnimation_wallpaperIntraOpenEnterAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation) WindowAnimation_wallpaperIntraOpenExitAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation) WindowAnimation_taskToFrontExitAnimation(com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation) WindowAnimation_wallpaperCloseEnterAnimation(com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation) ClipRectAnimation(android.view.animation.ClipRectAnimation) PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator) AnimationSet(android.view.animation.AnimationSet) AlphaAnimation(android.view.animation.AlphaAnimation) ScaleAnimation(android.view.animation.ScaleAnimation)

Example 12 with ClipRectAnimation

use of android.view.animation.ClipRectAnimation in project android_frameworks_base by crdroidandroid.

the class AppTransition method createRelaunchAnimation.

private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
    getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
    final int left = mTmpFromClipRect.left;
    final int top = mTmpFromClipRect.top;
    mTmpFromClipRect.offset(-left, -top);
    // TODO: Isn't that strange that we ignore exact position of the containingFrame?
    mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
    AnimationSet set = new AnimationSet(true);
    float fromWidth = mTmpFromClipRect.width();
    float toWidth = mTmpToClipRect.width();
    float fromHeight = mTmpFromClipRect.height();
    // While the window might span the whole display, the actual content will be cropped to the
    // system decoration frame, for example when the window is docked. We need to take into
    // account the visible height when constructing the animation.
    float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
    int translateAdjustment = 0;
    if (fromWidth <= toWidth && fromHeight <= toHeight) {
        // The final window is larger in both dimensions than current window (e.g. we are
        // maximizing), so we can simply unclip the new window and there will be no disappearing
        // frame.
        set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
    } else {
        // The disappearing window has one larger dimension. We need to apply scaling, so the
        // first frame of the entry animation matches the old window.
        set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
        // We might not be going exactly full screen, but instead be aligned under the status
        // bar using cropping. We still need to account for the cropped part, which will also
        // be scaled.
        translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
    }
    // We animate the translation from the old position of the removed window, to the new
    // position of the added window. The latter might not be full screen, for example docked for
    // docked windows.
    TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left, 0, top - containingFrame.top - translateAdjustment, 0);
    set.addAnimation(translate);
    set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
    set.setZAdjustment(Animation.ZORDER_TOP);
    return set;
}
Also used : ClipRectAnimation(android.view.animation.ClipRectAnimation) CurvedTranslateAnimation(com.android.server.wm.animation.CurvedTranslateAnimation) TranslateAnimation(android.view.animation.TranslateAnimation) AnimationSet(android.view.animation.AnimationSet) ScaleAnimation(android.view.animation.ScaleAnimation)

Aggregations

AnimationSet (android.view.animation.AnimationSet)12 ClipRectAnimation (android.view.animation.ClipRectAnimation)12 ScaleAnimation (android.view.animation.ScaleAnimation)12 TranslateAnimation (android.view.animation.TranslateAnimation)12 CurvedTranslateAnimation (com.android.server.wm.animation.CurvedTranslateAnimation)12 AlphaAnimation (android.view.animation.AlphaAnimation)8 Animation (android.view.animation.Animation)8 WindowAnimation_activityCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation)8 WindowAnimation_activityCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation)8 WindowAnimation_activityOpenEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation)8 WindowAnimation_activityOpenExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation)8 WindowAnimation_launchTaskBehindSourceAnimation (com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation)8 WindowAnimation_launchTaskBehindTargetAnimation (com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation)8 WindowAnimation_taskCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation)8 WindowAnimation_taskCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation)8 WindowAnimation_taskOpenEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation)8 WindowAnimation_taskOpenExitAnimation (com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation)8 WindowAnimation_taskToBackEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation)8 WindowAnimation_taskToBackExitAnimation (com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation)8 WindowAnimation_taskToFrontEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation)8