diff options
author | Adam Cohen <adamcohen@google.com> | 2015-05-26 23:03:31 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2015-05-27 13:55:09 -0700 |
commit | 1558893b873cd55b2df779f594f1de3c370d3328 (patch) | |
tree | dc79aa6ae27c704d74ce904a9860c9ae320e898c /src/com/android/launcher3/util | |
parent | bbcf5ac7aa73a3ce07215d77a0b496cf7fb00f29 (diff) | |
download | android_packages_apps_Trebuchet-1558893b873cd55b2df779f594f1de3c370d3328.tar.gz android_packages_apps_Trebuchet-1558893b873cd55b2df779f594f1de3c370d3328.tar.bz2 android_packages_apps_Trebuchet-1558893b873cd55b2df779f594f1de3c370d3328.zip |
Make sure all transition components run on the same thread
-> The framework circular reveal transition runs on the render
thread which can cause problems when mixed in an AnimatorSet
with transitions that don't run on the render thread
-> See issue 17556455
issue 21445293
Change-Id: Ie19c184c55060651e817d426ec83049b06af56ba
Diffstat (limited to 'src/com/android/launcher3/util')
-rw-r--r-- | src/com/android/launcher3/util/RevealOutlineProvider.java | 49 | ||||
-rw-r--r-- | src/com/android/launcher3/util/UiThreadCircularReveal.java | 55 |
2 files changed, 104 insertions, 0 deletions
diff --git a/src/com/android/launcher3/util/RevealOutlineProvider.java b/src/com/android/launcher3/util/RevealOutlineProvider.java new file mode 100644 index 000000000..0db3984f8 --- /dev/null +++ b/src/com/android/launcher3/util/RevealOutlineProvider.java @@ -0,0 +1,49 @@ +package com.android.launcher3.util; + +import android.annotation.TargetApi; +import android.graphics.Outline; +import android.graphics.Rect; +import android.os.Build; +import android.view.View; +import android.view.ViewOutlineProvider; + +@TargetApi(Build.VERSION_CODES.LOLLIPOP) +public class RevealOutlineProvider extends ViewOutlineProvider { + + private int mCenterX; + private int mCenterY; + private float mRadius0; + private float mRadius1; + private int mCurrentRadius; + + private final Rect mOval; + + /** + * @param x reveal center x + * @param y reveal center y + * @param r0 initial radius + * @param r1 final radius + */ + public RevealOutlineProvider(int x, int y, float r0, float r1) { + mCenterX = x; + mCenterY = y; + mRadius0 = r0; + mRadius1 = r1; + + mOval = new Rect(); + } + + public void setProgress(float progress) { + mCurrentRadius = (int) ((1 - progress) * mRadius0 + progress * mRadius1); + + mOval.left = mCenterX - mCurrentRadius; + mOval.top = mCenterY - mCurrentRadius; + mOval.right = mCenterX + mCurrentRadius; + mOval.bottom = mCenterY + mCurrentRadius; + } + + @Override + public void getOutline(View v, Outline outline) { + outline.setRoundRect(mOval, mCurrentRadius); + } +} diff --git a/src/com/android/launcher3/util/UiThreadCircularReveal.java b/src/com/android/launcher3/util/UiThreadCircularReveal.java new file mode 100644 index 000000000..c7324fb1b --- /dev/null +++ b/src/com/android/launcher3/util/UiThreadCircularReveal.java @@ -0,0 +1,55 @@ +package com.android.launcher3.util; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ValueAnimator; +import android.animation.ValueAnimator.AnimatorUpdateListener; +import android.annotation.TargetApi; +import android.os.Build; +import android.view.View; +import android.view.ViewOutlineProvider; + +import com.android.launcher3.Utilities; + +@TargetApi(Build.VERSION_CODES.LOLLIPOP) +public class UiThreadCircularReveal { + + public static ValueAnimator createCircularReveal(View v, int x, int y, float r0, float r1) { + ValueAnimator va = ValueAnimator.ofFloat(0f, 1f); + + final View revealView = v; + final RevealOutlineProvider outlineProvider = new RevealOutlineProvider(x, y, r0, r1); + final ViewOutlineProvider originalProvider = revealView.getOutlineProvider(); + final float elevation = v.getElevation(); + + va.addListener(new AnimatorListenerAdapter() { + public void onAnimationStart(Animator animation) { + revealView.setOutlineProvider(outlineProvider); + revealView.setClipToOutline(true); + revealView.setTranslationZ(-elevation); + } + + public void onAnimationEnd(Animator animation) { + revealView.setOutlineProvider(originalProvider); + revealView.setClipToOutline(false); + revealView.setTranslationZ(0); + } + + }); + + va.addUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator arg0) { + float progress = arg0.getAnimatedFraction(); + outlineProvider.setProgress(progress); + if (Utilities.isLmpMR1OrAbove()) { + revealView.invalidateOutline(); + } else { + // On L, a bug requires calling a full view invalidate. + revealView.invalidate(); + } + } + }); + return va; + } +} |