android.view.animation.Transformation Java Examples

The following examples show how to use android.view.animation.Transformation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwipeRefreshLayout.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress
                    .setAlpha((int) (startingAlpha+ ((endingAlpha - startingAlpha)
                            * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}
 
Example #2
Source File: DownExpandAnimation.java    From RxAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    super.applyTransformation(interpolatedTime, t);

    if (interpolatedTime < 1.0f) {

        // Calculating the new bottom margin, and setting it
        mViewLayoutParams.bottomMargin = mMarginStart
                + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);

        // Invalidating the layout, making us seeing the changes we made
        mAnimatedView.requestLayout();

        // Making sure we didn't run the ending before (it happens!)
    } else if (!mWasEndedAlready) {
        mViewLayoutParams.bottomMargin = mMarginEnd;
        mAnimatedView.requestLayout();

        if (mIsVisibleAfter) {
            mAnimatedView.setVisibility(View.GONE);
        }
        mWasEndedAlready = true;
    }
}
 
Example #3
Source File: ReboundLayout.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    float progress = ((endProgress - startProgress) * interpolatedTime) + startProgress;
    Log.i(TAG, "applyTransformation: interpolatedTime =" + interpolatedTime);
    if (mOrientation == LinearLayout.HORIZONTAL) {
        scrollBy((int) ((MAX_WIDTH - getScrollX()) * progress), 0);
    } else {

        float v = (MAX_WIDTH - getScrollY()) * progress;
        Log.i(TAG, "applyTransformation: getScrollY() =" + getScrollY() + " progress = " + progress + " v =" + v);
        scrollBy(0, (int) v);
    }

    if (progress >= 1) {
        isRunAnim = false;
    }
}
 
Example #4
Source File: QuestionWidget.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example #5
Source File: ViewAnimation.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
private static Animation expandAction(final View v) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final int targtetHeight = v.getMeasuredHeight();

    v.getLayoutParams().height = 0;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
    return a;
}
 
Example #6
Source File: CircleBar.java    From CircleProgressBar with MIT License 6 votes vote down vote up
/**
 * 每次系统调用这个方法时, 改变mSweepAnglePer,mPercent,stepnumbernow的值,
 * 然后调用postInvalidate()不停的绘制view。
 */
@Override
protected void applyTransformation(float interpolatedTime,
                                   Transformation t) {
    super.applyTransformation(interpolatedTime, t);
    if (interpolatedTime < 1.0f) {
        mPercent = Float.parseFloat(fnum.format(interpolatedTime
                * stepnumber * 100f / stepnumbermax));// 将浮点值四舍五入保留一位小数
        mSweepAnglePer = interpolatedTime * stepnumber * 360
                / stepnumbermax;
        stepnumbernow = (int) (interpolatedTime * stepnumber);
    } else {
        mPercent = Float.parseFloat(fnum.format(stepnumber * 100f
                / stepnumbermax));// 将浮点值四舍五入保留一位小数
        mSweepAnglePer = stepnumber * 360 / stepnumbermax;
        stepnumbernow = stepnumber;
    }
    postInvalidate();
}
 
Example #7
Source File: SwipeRefreshLayout.java    From android-source-codes with Creative Commons Attribution 4.0 International 6 votes vote down vote up
private void startScaleDownReturnToStartAnimation(int from,
        Animation.AnimationListener listener) {
    mFrom = from;
    if (isAlphaUsedForScale()) {
        mStartingScale = mProgress.getAlpha();
    } else {
        mStartingScale = ViewCompat.getScaleX(mCircleView);
    }
    mScaleDownToStartAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            float targetScale = (mStartingScale + (-mStartingScale  * interpolatedTime));
            setAnimationProgress(targetScale);
            moveToStart(interpolatedTime);
        }
    };
    mScaleDownToStartAnimation.setDuration(SCALE_DOWN_DURATION);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleDownToStartAnimation);
}
 
Example #8
Source File: FlipAnimation.java    From FragmentAnimations with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    float value = mEnter ? (interpolatedTime - 1.0f) : interpolatedTime;
    if (mDirection == RIGHT) value *= -1.0f;
    mRotationY = -value * 180.0f;
    mTranslationX = -value * mWidth;

    super.applyTransformation(interpolatedTime, t);

    // Hide entering/exiting view before/after half point.
    if (mEnter) {
        mAlpha = interpolatedTime <= 0.5f ? 0.0f : 1.0f;
    } else {
        mAlpha = interpolatedTime <= 0.5f ? 1.0f : 0.0f;
    }

    applyTransformation(t);
}
 
Example #9
Source File: SwipeRefreshLayout.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress
                    .setAlpha((int) (startingAlpha+ ((endingAlpha - startingAlpha)
                            * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}
 
Example #10
Source File: CollapseView.java    From AndroidProjects with MIT License 6 votes vote down vote up
/**
 * 折叠
 *
 * @param view 视图
 */
private void collapse(final View view) {
    final int measuredHeight = view.getMeasuredHeight();
    Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            Log.e("TAG", "interpolatedTime = " + interpolatedTime);
            if (interpolatedTime == 1) {
                mContentRelativeLayout.setVisibility(GONE);
            } else {
                view.getLayoutParams().height = measuredHeight - (int) (measuredHeight * interpolatedTime);
                view.requestLayout();
            }
        }
    };
    animation.setDuration(duration);
    view.startAnimation(animation);
}
 
Example #11
Source File: Rotate3dAnimation.java    From Android-tv-widget with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();
    if (mReverse) {
        camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
    } else {
        camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
    }
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}
 
Example #12
Source File: ExpandCollapseAnimation.java    From iSCAU-Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {

	super.applyTransformation(interpolatedTime, t);
	if (interpolatedTime < 1.0f) {
		if(mType == EXPAND) {
			mLayoutParams.bottomMargin =  -mEndHeight + (int) (mEndHeight * interpolatedTime);
		} else {
			mLayoutParams.bottomMargin = - (int) (mEndHeight * interpolatedTime);
		}
		Log.d("ExpandCollapseAnimation", "anim height " + mLayoutParams.bottomMargin);
		mAnimatedView.requestLayout();
	} else {
		if(mType == EXPAND) {
			mLayoutParams.bottomMargin = 0;
			mAnimatedView.requestLayout();
		} else {
			mLayoutParams.bottomMargin = -mEndHeight;
			mAnimatedView.setVisibility(View.GONE);
			mAnimatedView.requestLayout();
		}
	}
}
 
Example #13
Source File: SwipyRefreshLayout.java    From SwipyRefreshLayout with MIT License 6 votes vote down vote up
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress
                    .setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha)
                            * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}
 
Example #14
Source File: SwipeRefreshLayout.java    From mooc_hyman with Apache License 2.0 6 votes vote down vote up
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mBottomProgress
                    .setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha)
                            * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mBottomCircleView.setAnimationListener(null);
    mBottomCircleView.clearAnimation();
    mBottomCircleView.startAnimation(alpha);
    return alpha;
}
 
Example #15
Source File: SwipeRefreshLayout.java    From BookReader with Apache License 2.0 6 votes vote down vote up
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress
                    .setAlpha((int) (startingAlpha+ ((endingAlpha - startingAlpha)
                            * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}
 
Example #16
Source File: AndroidTreeView.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example #17
Source File: BasicUiUtils.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public static void collapseViews(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if(interpolatedTime == 1){
                v.setVisibility(View.GONE);
            }else{
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)*1);
    v.startAnimation(a);
}
 
Example #18
Source File: Rotate3dAnimation.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();
    if (mReverse) {
        camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
    } else {
        camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
    }
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}
 
Example #19
Source File: SwipeRefreshLayout.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private void startScaleUpAnimation(AnimationListener listener) {
    mCircleView.setVisibility(View.VISIBLE);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // Pre API 11, alpha is used in place of scale up to show the
        // progress circle appearing.
        // Don't adjust the alpha during appearance otherwise.
        mProgress.setAlpha(MAX_ALPHA);
    }
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleAnimation);
}
 
Example #20
Source File: Rotate3dAnimation.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    float xDegrees = fromXDegrees + ((toXDegrees - fromXDegrees) * interpolatedTime);
    float yDegrees = fromYDegrees + ((toYDegrees - fromYDegrees) * interpolatedTime);
    float zDegrees = fromZDegrees + ((toZDegrees - fromZDegrees) * interpolatedTime);

    final Matrix matrix = t.getMatrix();

    camera.save();
    camera.rotateX(xDegrees);
    camera.rotateY(yDegrees);
    camera.rotateZ(zDegrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-this.width, -this.height);
    matrix.postTranslate(this.width, this.height);
}
 
Example #21
Source File: AndroidTreeView.java    From imsdk-android with MIT License 6 votes vote down vote up
private static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example #22
Source File: CropImageAnimation.java    From timecat with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {

    mAnimRect.left = mStartCropWindowRect.left + (mEndCropWindowRect.left - mStartCropWindowRect.left) * interpolatedTime;
    mAnimRect.top = mStartCropWindowRect.top + (mEndCropWindowRect.top - mStartCropWindowRect.top) * interpolatedTime;
    mAnimRect.right = mStartCropWindowRect.right + (mEndCropWindowRect.right - mStartCropWindowRect.right) * interpolatedTime;
    mAnimRect.bottom = mStartCropWindowRect.bottom + (mEndCropWindowRect.bottom - mStartCropWindowRect.bottom) * interpolatedTime;
    mCropOverlayView.setCropWindowRect(mAnimRect);

    for (int i = 0; i < mAnimPoints.length; i++) {
        mAnimPoints[i] = mStartBoundPoints[i] + (mEndBoundPoints[i] - mStartBoundPoints[i]) * interpolatedTime;
    }
    mCropOverlayView.setBounds(mAnimPoints, mImageView.getWidth(), mImageView.getHeight());

    for (int i = 0; i < mAnimMatrix.length; i++) {
        mAnimMatrix[i] = mStartImageMatrix[i] + (mEndImageMatrix[i] - mStartImageMatrix[i]) * interpolatedTime;
    }
    Matrix m = mImageView.getImageMatrix();
    m.setValues(mAnimMatrix);
    mImageView.setImageMatrix(m);

    mImageView.invalidate();
    mCropOverlayView.invalidate();
}
 
Example #23
Source File: SwipeRefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
private void startScaleUpAnimation(AnimationListener listener) {
    mCircleView.setVisibility(View.VISIBLE);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // Pre API 11, alpha is used in place of scale up to show the
        // progress circle appearing.
        // Don't adjust the alpha during appearance otherwise.
        mProgress.setAlpha(MAX_ALPHA);
    }
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleAnimation);
}
 
Example #24
Source File: UserInfoAnimator.java    From umeng_community_android with MIT License 6 votes vote down vote up
@Override
protected void initAnimation(final boolean show) {
    mAnimation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime < 0) { // 预处理加速器可能出现负数
                return;
            }
            MarginLayoutParams params = (MarginLayoutParams) mView.getLayoutParams();
            policyMargin(interpolatedTime, params, show);
            mView.setLayoutParams(params);
        }
    };
    mAnimation.setDuration(500);
    mAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
}
 
Example #25
Source File: AdapterUtils.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example #26
Source File: SelectModeTest.java    From android-databinding with Apache License 2.0 6 votes vote down vote up
/** collapse animation while start delete item */
private void collapse(final View view, Animation.AnimationListener al) {
    final int originHeight = view.getMeasuredHeight();
    Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
                view.getLayoutParams().height = originHeight - (int) (originHeight * interpolatedTime);
                view.requestLayout();
        }
        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    if (al != null) {
        animation.setAnimationListener(al);
    }
    animation.setDuration(300);
    view.startAnimation(animation);
}
 
Example #27
Source File: RotateAndTranslateAnimation.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float degrees = mFromDegrees + ((mToDegrees - mFromDegrees) * interpolatedTime);
    if (mPivotX == 0.0f && mPivotY == 0.0f) {
        t.getMatrix().setRotate(degrees);
    } else {
        t.getMatrix().setRotate(degrees, mPivotX, mPivotY);
    }

    float dx = mFromXDelta;
    float dy = mFromYDelta;
    if (mFromXDelta != mToXDelta) {
        dx = mFromXDelta + ((mToXDelta - mFromXDelta) * interpolatedTime);
    }
    if (mFromYDelta != mToYDelta) {
        dy = mFromYDelta + ((mToYDelta - mFromYDelta) * interpolatedTime);
    }

    t.getMatrix().postTranslate(dx, dy);
}
 
Example #28
Source File: CollapseAnimator.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 6 votes vote down vote up
public static void expand(final View v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example #29
Source File: SwipeRefreshLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress
                    .setAlpha((int) (startingAlpha+ ((endingAlpha - startingAlpha)
                            * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}
 
Example #30
Source File: Rotate3dAnimation.java    From BookLoadingView with Apache License 2.0 6 votes vote down vote up
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();
    if (mReverse) {
        camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
    } else {
        camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
    }
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}