Back to project page vocabulary-list.
The source code is released under:
Apache License
If you think the Android project vocabulary-list listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.rulych.vocabularylist.util.impl; //from w w w . j a va2s .co m import com.rulych.vocabularylist.R; import com.rulych.vocabularylist.util.FloatingActionButtonAnimator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.content.Context; import android.view.MotionEvent; import android.view.View; import android.view.animation.AccelerateInterpolator; public class FloatingActionButtonAnimatorImpl implements FloatingActionButtonAnimator { private static final float SCALE_BASE = 1f; private static final float SCALE_TOUCHING = 1.10f; private static final float SCALE_FINAL = 1.25f; private Context mContext; private View mView; private long mDurationUp; private long mDurationDown; private float mElevationUp; private float mElevationDown; public FloatingActionButtonAnimatorImpl(Context context, View button) { mContext = context; mView = button; } public void setup() { initialize(); mView.setOnTouchListener(new TouchListener()); } private void initialize() { long duration = mContext.getResources().getInteger(android.R.integer.config_shortAnimTime); float liftingDurationFraction = 2 * SCALE_FINAL / SCALE_TOUCHING; mDurationUp = Float.valueOf(duration / liftingDurationFraction).longValue(); mDurationDown = duration - mDurationUp; mElevationUp = mContext.getResources().getDimension(R.dimen.fab_pressed_elevation); mElevationDown = mContext.getResources().getDimension(R.dimen.fab_elevation); } private void animateUp() { mView.animate() .scaleX(SCALE_TOUCHING) .scaleY(SCALE_TOUCHING) .setDuration(mDurationUp) .z(mElevationUp) .start(); } private void animateDown() { AnimatorSet animatorSet = new AnimatorSet(); AnimatorSet animatorSetUp = new AnimatorSet(); animatorSetUp.play(ObjectAnimator.ofFloat(mView, "scaleX", SCALE_FINAL)) .with(ObjectAnimator.ofFloat(mView, "scaleY", SCALE_FINAL)); AnimatorSet animatorSetDown = new AnimatorSet(); animatorSetDown.play(ObjectAnimator.ofFloat(mView, "scaleX", SCALE_BASE)) .with(ObjectAnimator.ofFloat(mView, "scaleY", SCALE_BASE)) .with(ObjectAnimator.ofFloat(mView, "z", mElevationDown)); animatorSet.play(animatorSetUp) .before(animatorSetDown); animatorSet.setDuration(mDurationDown); animatorSet.setInterpolator(new AccelerateInterpolator()); animatorSet.start(); } private class TouchListener implements View.OnTouchListener { @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: animateUp(); break; case MotionEvent.ACTION_UP: animateDown(); break; } return false; } } }