Add RenderNodeAnimator support check

This commit is contained in:
seven332 committed 2015-05-10 02:41:13 +08:00
1 parent 056df13e66
commit d617ef402d
5 files changed
+36 -17

No files matched your search

@@ -17,11 +17,11 @@ package com.hippo.effect;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.os.Build;
import android.view.RenderNodeAnimator;
import android.view.View;
import com.hippo.animation.SimpleAnimatorListener;
import com.hippo.util.AnimationUtils;
import com.hippo.util.ViewUtils;
public class ViewTransition {
@@ -83,9 +83,7 @@ public class ViewTransition {
}
View viewToHide = views[oldShownView];
View viewToShow = views[shownView];
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
viewToHide.isAttachedToWindow() &&
viewToShow.isAttachedToWindow()) {
if (AnimationUtils.isSupportRenderNodeAnimator(viewToHide, viewToShow)) {
startAnimationsL(viewToHide, viewToShow);
} else {
startAnimations(views[oldShownView], views[shownView]);
@@ -52,8 +52,8 @@ import com.hippo.ehviewer.widget.SearchBar;
import com.hippo.ehviewer.widget.SearchDatabase;
import com.hippo.ehviewer.widget.SearchLayout;
import com.hippo.scene.Scene;
import com.hippo.util.AnimationUtils;
import com.hippo.util.AssertUtils;
import com.hippo.util.InterpolatorUtils;
import com.hippo.util.Log;
import com.hippo.util.MathUtils;
import com.hippo.util.ViewUtils;
@@ -226,7 +226,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
PropertyValuesHolder scaleYPvh = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f);
ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mCornerFab, scaleXPvh, scaleYPvh);
oa.setDuration(ANIMATE_TIME / 2);
oa.setInterpolator(InterpolatorUtils.SLOW_FAST_INTERPOLATOR);
oa.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR);
oa.setRepeatCount(1);
oa.setRepeatMode(ValueAnimator.REVERSE);
final Drawable finalDrawable = drawable;
@@ -15,14 +15,36 @@
package com.hippo.util;
import android.annotation.TargetApi;
import android.graphics.Canvas;
import android.os.Build;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.view.View;
import android.view.animation.Interpolator;
public final class InterpolatorUtils {
public final class AnimationUtils {
public static final Interpolator FAST_SLOW_INTERPOLATOR = new LinearOutSlowInInterpolator();
public static final Interpolator SLOW_FAST_INTERPOLATOR = new FastOutLinearInInterpolator();
public static final Interpolator SLOW_FAST_SLOW_INTERPOLATOR = new FastOutSlowInInterpolator();
@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean isSupportRenderNodeAnimator(View... views) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return false;
}
for (View v : views) {
if (!v.isAttachedToWindow()) {
return false;
}
}
return true;
}
public static boolean isSupportRenderNodeAnimator(Canvas canvas) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
canvas.isHardwareAccelerated();
}
}
@@ -35,7 +35,7 @@ import android.widget.TextView;
import com.hippo.animation.SimpleAnimatorListener;
import com.hippo.ehviewer.R;
import com.hippo.util.InterpolatorUtils;
import com.hippo.util.AnimationUtils;
import com.hippo.util.MathUtils;
public class CheckTextView extends TextView implements OnClickListener, Hotspotable {
@@ -141,11 +141,11 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
if (mChecked) {
startRadius = 0;
endRadius = mMaxRadius;
interpolator = InterpolatorUtils.FAST_SLOW_INTERPOLATOR;
interpolator = AnimationUtils.FAST_SLOW_INTERPOLATOR;
} else {
startRadius = mMaxRadius;
endRadius = 0;
interpolator = InterpolatorUtils.SLOW_FAST_INTERPOLATOR;
interpolator = AnimationUtils.SLOW_FAST_INTERPOLATOR;
}
mPropPaint = CanvasProperty.createPaint(mPaint);
mPropRadius = CanvasProperty.createFloat(startRadius);
@@ -168,11 +168,11 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
if (mChecked) {
startRadius = 0;
endRadius = mMaxRadius;
interpolator = InterpolatorUtils.FAST_SLOW_INTERPOLATOR;
interpolator = AnimationUtils.FAST_SLOW_INTERPOLATOR;
} else {
startRadius = mMaxRadius;
endRadius = 0;
interpolator = InterpolatorUtils.SLOW_FAST_INTERPOLATOR;
interpolator = AnimationUtils.SLOW_FAST_INTERPOLATOR;
}
mRadius = startRadius;
@@ -199,8 +199,7 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);
boolean useHardware = canvas.isHardwareAccelerated() &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
boolean useHardware = AnimationUtils.isSupportRenderNodeAnimator(canvas);
if (mPrepareAnimator) {
mPrepareAnimator = false;
@@ -30,7 +30,7 @@ import android.view.animation.Interpolator;
import com.hippo.animation.SimpleAnimatorListener;
import com.hippo.ehviewer.R;
import com.hippo.util.InterpolatorUtils;
import com.hippo.util.AnimationUtils;
public class FabLayout extends ViewGroup implements View.OnClickListener {
@@ -272,14 +272,14 @@ public class FabLayout extends ViewGroup implements View.OnClickListener {
endTranslationY = 0f;
startAlpha = 0f;
endAlpha = 1f;
interpolator = InterpolatorUtils.FAST_SLOW_INTERPOLATOR;
interpolator = AnimationUtils.FAST_SLOW_INTERPOLATOR;
} else {
startTranslationY = 0f;
endTranslationY = mMainFabCenterY -
(child.getTop() + (child.getHeight() / 2));
startAlpha = 1f;
endAlpha = 0f;
interpolator = InterpolatorUtils.SLOW_FAST_INTERPOLATOR;
interpolator = AnimationUtils.SLOW_FAST_INTERPOLATOR;
}
PropertyValuesHolder translationYPvh = PropertyValuesHolder.ofFloat(