Search in sources :

Example 11 with Transformation

use of android.view.animation.Transformation in project Reader by TheKeeperOfPie.

the class UtilsAnimation method animateExpandActionsWithHeight.

public static void animateExpandActionsWithHeight(final ViewGroup viewGroup, boolean skipFirst, final int height) {
    final List<View> children = new ArrayList<>(viewGroup.getChildCount());
    for (int index = skipFirst ? 1 : 0; index < viewGroup.getChildCount(); index++) {
        children.add(viewGroup.getChildAt(index));
    }
    final boolean isShown = viewGroup.isShown();
    float speed = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, viewGroup.getContext().getResources().getDisplayMetrics());
    Animation animation = new Animation() {

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            interpolatedTime = isShown ? 1.0f - interpolatedTime : interpolatedTime;
            for (View view : children) {
                view.setAlpha(interpolatedTime);
            }
            viewGroup.getLayoutParams().height = (int) (interpolatedTime * height);
            viewGroup.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (isShown) {
                viewGroup.setVisibility(View.GONE);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    if (!isShown) {
        viewGroup.getLayoutParams().height = 0;
        viewGroup.setVisibility(View.VISIBLE);
    }
    animation.setDuration((long) (height / speed * 2));
    viewGroup.startAnimation(animation);
    viewGroup.requestLayout();
}
Also used : Transformation(android.view.animation.Transformation) ArrayList(java.util.ArrayList) Animation(android.view.animation.Animation) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Point(android.graphics.Point)

Example 12 with Transformation

use of android.view.animation.Transformation in project Reader by TheKeeperOfPie.

the class UtilsAnimation method getExpandHeightAnimationInternal.

private static Animation getExpandHeightAnimationInternal(final View view, final int widthAtMost, final long duration, @Nullable final OnAnimationEndListener callback) {
    final int startHeight = view.getVisibility() == View.GONE ? 0 : view.getHeight();
    final int targetHeight = getMeasuredHeightWithWidth(view, widthAtMost);
    float speed = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, view.getContext().getResources().getDisplayMetrics());
    if (startHeight == targetHeight) {
        return new Animation() {
        };
    }
    Animation animationExpand = new Animation() {

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime >= 0.99f) {
                view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            } else {
                view.getLayoutParams().height = (int) (startHeight + interpolatedTime * (targetHeight - startHeight));
            }
            view.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    animationExpand.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            view.requestLayout();
            if (callback != null) {
                callback.onAnimationEnd();
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    if (view.getVisibility() == View.GONE) {
        view.getLayoutParams().height = 0;
    }
    view.setVisibility(View.VISIBLE);
    animationExpand.setDuration(duration > 0 ? duration : calculateDuration(targetHeight - startHeight, speed));
    return animationExpand;
}
Also used : Transformation(android.view.animation.Transformation) Animation(android.view.animation.Animation) Point(android.graphics.Point)

Example 13 with Transformation

use of android.view.animation.Transformation in project cornerstone by Onskreen.

the class WindowState method computeShownFrameLocked.

void computeShownFrameLocked() {
    final boolean selfTransformation = mHasLocalTransformation;
    Transformation attachedTransformation = (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) ? mAttachedWindow.mTransformation : null;
    Transformation appTransformation = (mAppToken != null && mAppToken.hasTransformation) ? mAppToken.transformation : null;
    // are currently targeting.
    if (mAttrs.type == TYPE_WALLPAPER && mService.mLowerWallpaperTarget == null && mService.mWallpaperTarget != null) {
        if (mService.mWallpaperTarget.mHasLocalTransformation && mService.mWallpaperTarget.mAnimation != null && !mService.mWallpaperTarget.mAnimation.getDetachWallpaper()) {
            attachedTransformation = mService.mWallpaperTarget.mTransformation;
            if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
                Slog.v(WindowManagerService.TAG, "WP target attached xform: " + attachedTransformation);
            }
        }
        if (mService.mWallpaperTarget.mAppToken != null && mService.mWallpaperTarget.mAppToken.hasTransformation && mService.mWallpaperTarget.mAppToken.animation != null && !mService.mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
            appTransformation = mService.mWallpaperTarget.mAppToken.transformation;
            if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
                Slog.v(WindowManagerService.TAG, "WP target app xform: " + appTransformation);
            }
        }
    }
    final boolean screenAnimation = mService.mScreenRotationAnimation != null && mService.mScreenRotationAnimation.isAnimating();
    if (selfTransformation || attachedTransformation != null || appTransformation != null || screenAnimation) {
        // cache often used attributes locally
        final Rect frame = mFrame;
        final float[] tmpFloats = mService.mTmpFloats;
        final Matrix tmpMatrix = mTmpMatrix;
        // Compute the desired transformation.
        if (screenAnimation) {
            // If we are doing a screen animation, the global rotation
            // applied to windows can result in windows that are carefully
            // aligned with each other to slightly separate, allowing you
            // to see what is behind them.  An unsightly mess.  This...
            // thing...  magically makes it call good: scale each window
            // slightly (two pixels larger in each dimension, from the
            // window's center).
            final float w = frame.width();
            final float h = frame.height();
            if (w >= 1 && h >= 1) {
                tmpMatrix.setScale(1 + 2 / w, 1 + 2 / h, w / 2, h / 2);
            } else {
                tmpMatrix.reset();
            }
        } else {
            tmpMatrix.reset();
        }
        tmpMatrix.postScale(mGlobalScale, mGlobalScale);
        if (selfTransformation) {
            tmpMatrix.postConcat(mTransformation.getMatrix());
        }
        tmpMatrix.postTranslate(frame.left + mXOffset, frame.top + mYOffset);
        if (attachedTransformation != null) {
            tmpMatrix.postConcat(attachedTransformation.getMatrix());
        }
        if (appTransformation != null) {
            tmpMatrix.postConcat(appTransformation.getMatrix());
        }
        if (screenAnimation) {
            tmpMatrix.postConcat(mService.mScreenRotationAnimation.getEnterTransformation().getMatrix());
        }
        // "convert" it into SurfaceFlinger's format
        // (a 2x2 matrix + an offset)
        // Here we must not transform the position of the surface
        // since it is already included in the transformation.
        //Slog.i(TAG, "Transform: " + matrix);
        mHaveMatrix = true;
        tmpMatrix.getValues(tmpFloats);
        mDsDx = tmpFloats[Matrix.MSCALE_X];
        mDtDx = tmpFloats[Matrix.MSKEW_Y];
        mDsDy = tmpFloats[Matrix.MSKEW_X];
        mDtDy = tmpFloats[Matrix.MSCALE_Y];
        float x = tmpFloats[Matrix.MTRANS_X];
        float y = tmpFloats[Matrix.MTRANS_Y];
        int w = frame.width();
        int h = frame.height();
        mShownFrame.set(x, y, x + w, y + h);
        // Now set the alpha...  but because our current hardware
        // can't do alpha transformation on a non-opaque surface,
        // turn it off if we are running an animation that is also
        // transforming since it is more important to have that
        // animation be smooth.
        mShownAlpha = mAlpha;
        if (!mService.mLimitedAlphaCompositing || (!PixelFormat.formatHasAlpha(mAttrs.format) || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) && x == frame.left && y == frame.top))) {
            //Slog.i(TAG, "Applying alpha transform");
            if (selfTransformation) {
                mShownAlpha *= mTransformation.getAlpha();
            }
            if (attachedTransformation != null) {
                mShownAlpha *= attachedTransformation.getAlpha();
            }
            if (appTransformation != null) {
                mShownAlpha *= appTransformation.getAlpha();
            }
            if (screenAnimation) {
                mShownAlpha *= mService.mScreenRotationAnimation.getEnterTransformation().getAlpha();
            }
        } else {
        //Slog.i(TAG, "Not applying alpha transform");
        }
        if (WindowManagerService.localLOGV)
            Slog.v(WindowManagerService.TAG, "Continuing animation in " + this + ": " + mShownFrame + ", alpha=" + mTransformation.getAlpha());
        return;
    }
    /**
	 * Author: Onskreen
	 * Date: 25/02/2011
	 *
	 * When the cornerstone is in a state change we know there is an animation. At the end
	 * of which we want the cornerstone and cornerstone panels to remain in there final
	 * animated positions, not the original position they started in (which is what
	 * happens with no changes to the logic here).
	 *
	 * We are relying on the fact that the cornerstone is always at the bottom of the
	 * mWindows, so not unsetting mCornerstoneStateChange flag until we encounter it
	 * after the animation is complete.
	 */
    if (//Cornerstone is active
    mService.mCornerstoneState != Cornerstone_State.TERMINATED && //In the midst of a cornerstone state change
    mService.mCornerstoneStateChangeAnimating && mAppToken != null) {
        //Ignore non app tokens
        WindowPanel wp = mService.findWindowPanel(this.mAppToken.token);
        if (wp != null) {
            //just in case...
            if (DEBUG_CORNERSTONE) {
                Slog.v(WindowManagerService.TAG, "WindowState.computeShownFrameLocked for: " + this);
                Slog.v(WindowManagerService.TAG, "mCornerstoneStateChangeProcessing: " + mService.mCornerstoneStateChangeProcessing);
                Slog.v(WindowManagerService.TAG, "mCornerstoneStateChangeAnimating: " + mService.mCornerstoneStateChangeAnimating);
                Slog.v(WindowManagerService.TAG, "WP: " + wp);
                Slog.v(WindowManagerService.TAG, "mFrame: " + mFrame);
                Slog.v(WindowManagerService.TAG, "mShownFrame: " + mShownFrame);
            }
            /**
				 * Cornerstone and panels should be locked to their final
				 * animated position.
				 */
            if (wp.isCornerstone() || wp.isCornerstonePanel() && mAnimating == false) {
                //Only lock the frame at the end of the animation
                if (DEBUG_CORNERSTONE) {
                    Slog.v(WindowManagerService.TAG, "Animation complete, locking frames");
                }
                Rect rect = mService.computeWindowPanelRect(wp, mService.mCurConfiguration.orientation, mService.mCornerstoneState);
                if (DEBUG_CORNERSTONE) {
                    Slog.v(WindowManagerService.TAG, "Updating " + wp + " to: " + rect);
                }
                wp.setFrame(rect);
                if (wp.isCornerstone()) {
                    if (DEBUG_CORNERSTONE)
                        Slog.v(WindowManagerService.TAG, "Setting mCornerstoneStateChangeAnimating to False");
                    mService.mCornerstoneStateChangeAnimating = false;
                }
            }
        }
    }
    mShownFrame.set(mFrame);
    if (mXOffset != 0 || mYOffset != 0) {
        mShownFrame.offset(mXOffset, mYOffset);
    }
    mShownAlpha = mAlpha;
    mHaveMatrix = false;
    mDsDx = mGlobalScale;
    mDtDx = 0;
    mDsDy = 0;
    mDtDy = mGlobalScale;
}
Also used : Transformation(android.view.animation.Transformation) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) WindowPanel(com.android.server.wm.WindowManagerService.WindowPanel)

Example 14 with Transformation

use of android.view.animation.Transformation in project cornerstone by Onskreen.

the class WindowStateAnimator method computeShownFrameLocked.

void computeShownFrameLocked() {
    final boolean selfTransformation = mHasLocalTransformation;
    Transformation attachedTransformation = (mAttachedWindow != null && mAttachedWindow.mWinAnimator.mHasLocalTransformation) ? mAttachedWindow.mWinAnimator.mTransformation : null;
    final AppWindowAnimator appAnimator = mWin.mAppToken == null ? null : mWin.mAppToken.mAppAnimator;
    Transformation appTransformation = (appAnimator != null && appAnimator.hasTransformation) ? appAnimator.transformation : null;
    // are currently targeting.
    if (mWin.mAttrs.type == TYPE_WALLPAPER && mService.mLowerWallpaperTarget == null && mService.mWallpaperTarget != null) {
        if (mService.mWallpaperTarget.mWinAnimator.mHasLocalTransformation && mService.mWallpaperTarget.mWinAnimator.mAnimation != null && !mService.mWallpaperTarget.mWinAnimator.mAnimation.getDetachWallpaper()) {
            attachedTransformation = mService.mWallpaperTarget.mWinAnimator.mTransformation;
            if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
                Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
            }
        }
        final AppWindowAnimator wpAppAnimator = mService.mWallpaperTarget.mAppToken == null ? null : mService.mWallpaperTarget.mAppToken.mAppAnimator;
        if (wpAppAnimator != null && wpAppAnimator.hasTransformation && wpAppAnimator.animation != null && !wpAppAnimator.animation.getDetachWallpaper()) {
            appTransformation = wpAppAnimator.transformation;
            if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
                Slog.v(TAG, "WP target app xform: " + appTransformation);
            }
        }
    }
    final boolean screenAnimation = mService.mAnimator.mScreenRotationAnimation != null && mService.mAnimator.mScreenRotationAnimation.isAnimating();
    if (selfTransformation || attachedTransformation != null || appTransformation != null || screenAnimation) {
        // cache often used attributes locally
        final Rect frame = mWin.mFrame;
        final float[] tmpFloats = mService.mTmpFloats;
        final Matrix tmpMatrix = mWin.mTmpMatrix;
        // Compute the desired transformation.
        if (screenAnimation) {
            // If we are doing a screen animation, the global rotation
            // applied to windows can result in windows that are carefully
            // aligned with each other to slightly separate, allowing you
            // to see what is behind them.  An unsightly mess.  This...
            // thing...  magically makes it call good: scale each window
            // slightly (two pixels larger in each dimension, from the
            // window's center).
            final float w = frame.width();
            final float h = frame.height();
            if (w >= 1 && h >= 1) {
                tmpMatrix.setScale(1 + 2 / w, 1 + 2 / h, w / 2, h / 2);
            } else {
                tmpMatrix.reset();
            }
        } else {
            tmpMatrix.reset();
        }
        tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
        if (selfTransformation) {
            tmpMatrix.postConcat(mTransformation.getMatrix());
        }
        tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
        if (attachedTransformation != null) {
            tmpMatrix.postConcat(attachedTransformation.getMatrix());
        }
        if (appTransformation != null) {
            tmpMatrix.postConcat(appTransformation.getMatrix());
        }
        if (screenAnimation) {
            tmpMatrix.postConcat(mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getMatrix());
        }
        // "convert" it into SurfaceFlinger's format
        // (a 2x2 matrix + an offset)
        // Here we must not transform the position of the surface
        // since it is already included in the transformation.
        //Slog.i(TAG, "Transform: " + matrix);
        mHaveMatrix = true;
        tmpMatrix.getValues(tmpFloats);
        mDsDx = tmpFloats[Matrix.MSCALE_X];
        mDtDx = tmpFloats[Matrix.MSKEW_Y];
        mDsDy = tmpFloats[Matrix.MSKEW_X];
        mDtDy = tmpFloats[Matrix.MSCALE_Y];
        float x = tmpFloats[Matrix.MTRANS_X];
        float y = tmpFloats[Matrix.MTRANS_Y];
        int w = frame.width();
        int h = frame.height();
        mWin.mShownFrame.set(x, y, x + w, y + h);
        // Now set the alpha...  but because our current hardware
        // can't do alpha transformation on a non-opaque surface,
        // turn it off if we are running an animation that is also
        // transforming since it is more important to have that
        // animation be smooth.
        mShownAlpha = mAlpha;
        if (!mService.mLimitedAlphaCompositing || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format) || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) && x == frame.left && y == frame.top))) {
            //Slog.i(TAG, "Applying alpha transform");
            if (selfTransformation) {
                mShownAlpha *= mTransformation.getAlpha();
            }
            if (attachedTransformation != null) {
                mShownAlpha *= attachedTransformation.getAlpha();
            }
            if (appTransformation != null) {
                mShownAlpha *= appTransformation.getAlpha();
            }
            if (screenAnimation) {
                mShownAlpha *= mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha();
            }
        } else {
        //Slog.i(TAG, "Not applying alpha transform");
        }
        if (WindowManagerService.localLOGV && (mShownAlpha == 1.0 || mShownAlpha == 0.0))
            Slog.v(TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null") + " attached=" + (attachedTransformation == null ? "null" : attachedTransformation.getAlpha()) + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha()) + " screen=" + (screenAnimation ? mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
        return;
    } else if (mWin.mIsWallpaper && (mAnimator.mPendingActions & WindowAnimator.WALLPAPER_ACTION_PENDING) != 0) {
        return;
    }
    if (WindowManagerService.localLOGV)
        Slog.v(TAG, "computeShownFrameLocked: " + this + " not attached, mAlpha=" + mAlpha);
    /**
         * Author: Onskreen
         * Date: 25/02/2011
         *
         * When the cornerstone is in a state change we know there is an animation. At the end
         * of which we want the cornerstone and cornerstone panels to remain in there final
         * animated positions, not the original position they started in (which is what
         * happens with no changes to the logic here).
         *
         * We are relying on the fact that the cornerstone is always at the bottom of the
         * mWindows, so not unsetting mCornerstoneStateChange flag until we encounter it
         * after the animation is complete.
         */
    if (//Cornerstone is active
    mService.mCornerstoneState != Cornerstone_State.TERMINATED && //In the midst of a cornerstone state change
    mService.mCornerstoneStateChangeAnimating && mWin.mAppToken != null) {
        //Ignore non app tokens
        WindowPanel wp = mService.findWindowPanel(mWin.mAppToken.token);
        if (wp != null) {
            //just in case...
            if (WindowManagerService.DEBUG_CORNERSTONE) {
                Slog.v(WindowManagerService.TAG, "WindowState.computeShownFrameLocked for: " + this);
                Slog.v(WindowManagerService.TAG, "mCornerstoneStateChangeProcessing: " + mService.mCornerstoneStateChangeProcessing);
                Slog.v(WindowManagerService.TAG, "mCornerstoneStateChangeAnimating: " + mService.mCornerstoneStateChangeAnimating);
                Slog.v(WindowManagerService.TAG, "WP: " + wp);
                Slog.v(WindowManagerService.TAG, "mFrame: " + mWin.mFrame);
                Slog.v(WindowManagerService.TAG, "mShownFrame: " + mWin.mShownFrame);
            }
            /**
				 * Cornerstone and panels should be locked to their final
				 * animated position.
				 */
            if (wp.isCornerstone() || wp.isCornerstonePanel() && mAnimating == false) {
                //Only lock the frame at the end of the animation
                if (WindowManagerService.DEBUG_CORNERSTONE) {
                    Slog.v(WindowManagerService.TAG, "Animation complete, locking frames");
                }
                Rect rect = mService.computeWindowPanelRect(wp, mService.mCurConfiguration.orientation, mService.mCornerstoneState);
                if (WindowManagerService.DEBUG_CORNERSTONE) {
                    Slog.v(WindowManagerService.TAG, "Updating " + wp + " to: " + rect);
                }
                wp.setFrame(rect);
                if (wp.isCornerstone()) {
                    if (WindowManagerService.DEBUG_CORNERSTONE)
                        Slog.v(WindowManagerService.TAG, "Setting mCornerstoneStateChangeAnimating to False");
                    mService.mCornerstoneStateChangeAnimating = false;
                }
            }
        }
    }
    mWin.mShownFrame.set(mWin.mFrame);
    if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
        mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
    }
    mShownAlpha = mAlpha;
    mHaveMatrix = false;
    mDsDx = mWin.mGlobalScale;
    mDtDx = 0;
    mDsDy = 0;
    mDtDy = mWin.mGlobalScale;
}
Also used : Transformation(android.view.animation.Transformation) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) WindowPanel(com.android.server.wm.WindowManagerService.WindowPanel) Point(android.graphics.Point)

Example 15 with Transformation

use of android.view.animation.Transformation in project Phoenix by Yalantis.

the class SunRefreshView method setupAnimations.

private void setupAnimations() {
    mAnimation = new Animation() {

        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setRotate(interpolatedTime);
        }
    };
    mAnimation.setRepeatCount(Animation.INFINITE);
    mAnimation.setRepeatMode(Animation.RESTART);
    mAnimation.setInterpolator(LINEAR_INTERPOLATOR);
    mAnimation.setDuration(ANIMATION_DURATION);
}
Also used : Transformation(android.view.animation.Transformation) Animation(android.view.animation.Animation)

Aggregations

Transformation (android.view.animation.Transformation)108 Animation (android.view.animation.Animation)61 Point (android.graphics.Point)24 Paint (android.graphics.Paint)22 AlphaAnimation (android.view.animation.AlphaAnimation)18 Animatable (android.graphics.drawable.Animatable)17 LinearInterpolator (android.view.animation.LinearInterpolator)17 Matrix (android.graphics.Matrix)15 RectF (android.graphics.RectF)13 Rect (android.graphics.Rect)7 Bitmap (android.graphics.Bitmap)6 MagnificationSpec (android.view.MagnificationSpec)5 View (android.view.View)3 BezierDecelerateInterpolator (acr.browser.lightning.interpolator.BezierDecelerateInterpolator)2 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 WindowPanel (com.android.server.wm.WindowManagerService.WindowPanel)2 Fragment (android.app.Fragment)1 FragmentTransaction (android.app.FragmentTransaction)1 Intent (android.content.Intent)1