Break out rotation animation into animation utils
This commit is contained in:
parent
086f915e20
commit
6f4e4115d8
@ -0,0 +1,52 @@
|
||||
package acr.browser.lightning.animation;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
import android.widget.ImageView;
|
||||
|
||||
/**
|
||||
* Animation specific helper code.
|
||||
*/
|
||||
public class AnimationUtils {
|
||||
|
||||
/**
|
||||
* Creates an animation that rotates an {@link ImageView}
|
||||
* around the Y axis by 180 degrees and changes the image
|
||||
* resource shown when the view is rotated 90 degrees to the user.
|
||||
*
|
||||
* @param imageView the view to rotate.
|
||||
* @param drawableRes the drawable to set when the view
|
||||
* is rotated by 90 degrees.
|
||||
* @return an animation that will change the image shown by the view.
|
||||
*/
|
||||
@NonNull
|
||||
public static Animation createRotationTransitionAnimation(@NonNull final ImageView imageView,
|
||||
@DrawableRes final int drawableRes) {
|
||||
Animation animation = new Animation() {
|
||||
|
||||
private boolean mSetFinalDrawable;
|
||||
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
if (interpolatedTime < 0.5f) {
|
||||
imageView.setRotationY(90 * interpolatedTime * 2f);
|
||||
} else {
|
||||
if (!mSetFinalDrawable) {
|
||||
mSetFinalDrawable = true;
|
||||
imageView.setImageResource(drawableRes);
|
||||
}
|
||||
imageView.setRotationY((-90) + (90 * (interpolatedTime - 0.5f) * 2f));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
animation.setDuration(300);
|
||||
animation.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
|
||||
return animation;
|
||||
}
|
||||
|
||||
}
|
@ -16,10 +16,7 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.Transformation;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@ -40,6 +37,7 @@ import javax.inject.Inject;
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.activity.ReadingActivity;
|
||||
import acr.browser.lightning.activity.TabsManager;
|
||||
import acr.browser.lightning.animation.AnimationUtils;
|
||||
import acr.browser.lightning.app.BrowserApp;
|
||||
import acr.browser.lightning.browser.BookmarksView;
|
||||
import acr.browser.lightning.constant.Constants;
|
||||
@ -240,16 +238,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void reinitializePreferences() {
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
@ -293,40 +281,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
resource = R.drawable.ic_action_back;
|
||||
}
|
||||
|
||||
final Animation startRotation = new Animation() {
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
mBookmarkTitleImage.setRotationY(90 * interpolatedTime);
|
||||
}
|
||||
};
|
||||
final Animation finishRotation = new Animation() {
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
mBookmarkTitleImage.setRotationY((-90) + (90 * interpolatedTime));
|
||||
}
|
||||
};
|
||||
startRotation.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
mBookmarkTitleImage.setImageResource(resource);
|
||||
mBookmarkTitleImage.startAnimation(finishRotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
});
|
||||
startRotation.setInterpolator(new AccelerateInterpolator());
|
||||
finishRotation.setInterpolator(new DecelerateInterpolator());
|
||||
startRotation.setDuration(250);
|
||||
finishRotation.setDuration(250);
|
||||
|
||||
if (animate) {
|
||||
mBookmarkTitleImage.startAnimation(startRotation);
|
||||
Animation transition = AnimationUtils.createRotationTransitionAnimation(mBookmarkTitleImage, resource);
|
||||
mBookmarkTitleImage.startAnimation(transition);
|
||||
} else {
|
||||
mBookmarkTitleImage.setImageResource(resource);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user