Browse Source

Better interpolators for decelerate animations

master
Anthony Restaino 8 years ago
parent
commit
76b297781f
  1. 5
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 4
      app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java
  3. 4
      app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java
  4. 31
      app/src/main/java/acr/browser/lightning/interpolator/BezierDecelerateInterpolator.java
  5. 6
      app/src/main/res/anim-v21/bezier_decelerate.xml
  6. 2
      app/src/main/res/anim/bezier_decelerate.xml
  7. 2
      app/src/main/res/anim/fade_in_scale.xml
  8. 2
      app/src/main/res/anim/fade_out_scale.xml
  9. 2
      app/src/main/res/anim/slide_in_from_right.xml
  10. 2
      app/src/main/res/anim/slide_out_to_right.xml
  11. 2
      app/src/main/res/anim/slide_up_in.xml

5
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -113,6 +113,7 @@ import acr.browser.lightning.dialog.BrowserDialog;
import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.fragment.BookmarksFragment; import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.interpolator.BezierDecelerateInterpolator;
import acr.browser.lightning.receiver.NetworkReceiver; import acr.browser.lightning.receiver.NetworkReceiver;
import acr.browser.lightning.search.Suggestions; import acr.browser.lightning.search.Suggestions;
import acr.browser.lightning.utils.DrawableUtils; import acr.browser.lightning.utils.DrawableUtils;
@ -1932,7 +1933,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
}; };
show.setDuration(250); show.setDuration(250);
show.setInterpolator(new DecelerateInterpolator()); show.setInterpolator(new BezierDecelerateInterpolator());
mBrowserFrame.startAnimation(show); mBrowserFrame.startAnimation(show);
} }
} }
@ -1971,7 +1972,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
}; };
show.setDuration(250); show.setDuration(250);
show.setInterpolator(new DecelerateInterpolator()); show.setInterpolator(new BezierDecelerateInterpolator());
mBrowserFrame.startAnimation(show); mBrowserFrame.startAnimation(show);
} }
} }

4
app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java

@ -29,6 +29,8 @@ import android.view.animation.DecelerateInterpolator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import acr.browser.lightning.interpolator.BezierDecelerateInterpolator;
/** /**
* This implementation of {@link RecyclerView.ItemAnimator} provides basic * This implementation of {@link RecyclerView.ItemAnimator} provides basic
* animations on remove, add, and move events that happen to the items in * animations on remove, add, and move events that happen to the items in
@ -235,7 +237,7 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
mAddAnimations.add(holder); mAddAnimations.add(holder);
animation.alpha(1).translationY(0) animation.alpha(1).translationY(0)
.setInterpolator(new DecelerateInterpolator()).setDuration(getAddDuration()) .setInterpolator(new BezierDecelerateInterpolator()).setDuration(getAddDuration())
.setListener(new VpaListenerAdapter() { .setListener(new VpaListenerAdapter() {
@Override @Override
public void onAnimationStart(View view) { public void onAnimationStart(View view) {

4
app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java

@ -29,6 +29,8 @@ import android.view.animation.DecelerateInterpolator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import acr.browser.lightning.interpolator.BezierDecelerateInterpolator;
/** /**
* This implementation of {@link RecyclerView.ItemAnimator} provides basic * This implementation of {@link RecyclerView.ItemAnimator} provides basic
* animations on remove, add, and move events that happen to the items in * animations on remove, add, and move events that happen to the items in
@ -235,7 +237,7 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
mAddAnimations.add(holder); mAddAnimations.add(holder);
animation.alpha(1).translationX(0).setDuration(getAddDuration()) animation.alpha(1).translationX(0).setDuration(getAddDuration())
.setInterpolator(new DecelerateInterpolator()).setListener(new VpaListenerAdapter() { .setInterpolator(new BezierDecelerateInterpolator()).setListener(new VpaListenerAdapter() {
@Override @Override
public void onAnimationStart(View view) { public void onAnimationStart(View view) {
dispatchAddStarting(holder); dispatchAddStarting(holder);

31
app/src/main/java/acr/browser/lightning/interpolator/BezierDecelerateInterpolator.java

@ -0,0 +1,31 @@
package acr.browser.lightning.interpolator;
import android.os.Build;
import android.support.annotation.NonNull;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
/**
* Bezier decelerate curve similar to iOS.
* On Kitkat and below, it reverts to a
* decelerate interpolator.
*/
public class BezierDecelerateInterpolator implements Interpolator {
@NonNull
private static final Interpolator PATH_INTERPOLATOR;
static {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
PATH_INTERPOLATOR = new PathInterpolator(0.25f, 0.1f, 0.25f, 1);
} else {
PATH_INTERPOLATOR = new DecelerateInterpolator();
}
}
@Override
public float getInterpolation(float input) {
return PATH_INTERPOLATOR.getInterpolation(input);
}
}

6
app/src/main/res/anim-v21/bezier_decelerate.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:controlX1="0.25"
android:controlY1="0.1"
android:controlX2="0.25"
android:controlY2="1"/>

2
app/src/main/res/anim/bezier_decelerate.xml

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<decelerateInterpolator/>

2
app/src/main/res/anim/fade_in_scale.xml

@ -4,7 +4,7 @@
android:duration="@integer/animation_time_medium" android:duration="@integer/animation_time_medium"
android:fromXScale="0.85" android:fromXScale="0.85"
android:fromYScale="0.85" android:fromYScale="0.85"
android:interpolator="@android:interpolator/decelerate_cubic" android:interpolator="@anim/bezier_decelerate"
android:pivotX="50%p" android:pivotX="50%p"
android:pivotY="50%p" android:pivotY="50%p"
android:toXScale="1.0" android:toXScale="1.0"

2
app/src/main/res/anim/fade_out_scale.xml

@ -4,7 +4,7 @@
android:duration="@integer/animation_time_medium" android:duration="@integer/animation_time_medium"
android:fromXScale="1.0" android:fromXScale="1.0"
android:fromYScale="1.0" android:fromYScale="1.0"
android:interpolator="@android:interpolator/decelerate_cubic" android:interpolator="@anim/bezier_decelerate"
android:pivotX="50%p" android:pivotX="50%p"
android:pivotY="50%p" android:pivotY="50%p"
android:toXScale="0.85" android:toXScale="0.85"

2
app/src/main/res/anim/slide_in_from_right.xml

@ -3,7 +3,7 @@
<translate <translate
android:duration="@integer/animation_time_medium" android:duration="@integer/animation_time_medium"
android:fromXDelta="100%p" android:fromXDelta="100%p"
android:interpolator="@android:interpolator/decelerate_cubic" android:interpolator="@anim/bezier_decelerate"
android:toXDelta="0%p" /> android:toXDelta="0%p" />
<!--<alpha--> <!--<alpha-->
<!--android:duration="@android:integer/config_mediumAnimTime"--> <!--android:duration="@android:integer/config_mediumAnimTime"-->

2
app/src/main/res/anim/slide_out_to_right.xml

@ -3,7 +3,7 @@
<translate <translate
android:duration="@integer/animation_time_medium" android:duration="@integer/animation_time_medium"
android:fromXDelta="0%p" android:fromXDelta="0%p"
android:interpolator="@android:interpolator/decelerate_cubic" android:interpolator="@anim/bezier_decelerate"
android:toXDelta="100%p" /> android:toXDelta="100%p" />
<!--<alpha--> <!--<alpha-->
<!--android:duration="@android:integer/config_mediumAnimTime"--> <!--android:duration="@android:integer/config_mediumAnimTime"-->

2
app/src/main/res/anim/slide_up_in.xml

@ -3,7 +3,7 @@
<translate <translate
android:duration="@integer/animation_time_medium" android:duration="@integer/animation_time_medium"
android:fromYDelta="100%p" android:fromYDelta="100%p"
android:interpolator="@android:interpolator/decelerate_cubic" android:interpolator="@anim/bezier_decelerate"
android:toYDelta="0%p" /> android:toYDelta="0%p" />
<!--<alpha--> <!--<alpha-->
<!--android:duration="@android:integer/config_mediumAnimTime"--> <!--android:duration="@android:integer/config_mediumAnimTime"-->

Loading…
Cancel
Save