Add additional tracing for nav button backgrounds
- Add app systrace events - Ensure we actually end the animations when jumping to current state Change-Id: I8712c019e655eb860e2f919e8d2eae47e380a235 Bug: 156744680 Test: Take systrace and verify events show
This commit is contained in:
@@ -28,7 +28,7 @@ import android.graphics.PixelFormat;
|
||||
import android.graphics.RecordingCanvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.os.Trace;
|
||||
import android.view.RenderNodeAnimator;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
@@ -74,6 +74,11 @@ public class KeyButtonRipple extends Drawable {
|
||||
private final HashSet<Animator> mRunningAnimations = new HashSet<>();
|
||||
private final ArrayList<Animator> mTmpArray = new ArrayList<>();
|
||||
|
||||
private final TraceAnimatorListener mExitHwTraceAnimator =
|
||||
new TraceAnimatorListener("exitHardware");
|
||||
private final TraceAnimatorListener mEnterHwTraceAnimator =
|
||||
new TraceAnimatorListener("enterHardware");
|
||||
|
||||
public enum Type {
|
||||
OVAL,
|
||||
ROUNDED_RECT
|
||||
@@ -221,7 +226,7 @@ public class KeyButtonRipple extends Drawable {
|
||||
|
||||
@Override
|
||||
public void jumpToCurrentState() {
|
||||
cancelAnimations("jumpToCurrentState");
|
||||
endAnimations("jumpToCurrentState", false /* cancel */);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,7 +240,6 @@ public class KeyButtonRipple extends Drawable {
|
||||
}
|
||||
|
||||
public void setPressed(boolean pressed) {
|
||||
Log.d("b/63783866", "KeyButtonRipple.setPressed: pressed=" + pressed);
|
||||
if (mDark != mLastDark && pressed) {
|
||||
mRipplePaint = null;
|
||||
mLastDark = mDark;
|
||||
@@ -255,14 +259,19 @@ public class KeyButtonRipple extends Drawable {
|
||||
mHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
private void cancelAnimations(String reason) {
|
||||
Log.d("b/63783866", "KeyButtonRipple.cancelAnimations: reason=" + reason);
|
||||
private void endAnimations(String reason, boolean cancel) {
|
||||
Trace.beginSection("KeyButtonRipple.endAnim: reason=" + reason + " cancel=" + cancel);
|
||||
Trace.endSection();
|
||||
mVisible = false;
|
||||
mTmpArray.addAll(mRunningAnimations);
|
||||
int size = mTmpArray.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Animator a = mTmpArray.get(i);
|
||||
a.cancel();
|
||||
if (cancel) {
|
||||
a.cancel();
|
||||
} else {
|
||||
a.end();
|
||||
}
|
||||
}
|
||||
mTmpArray.clear();
|
||||
mRunningAnimations.clear();
|
||||
@@ -287,7 +296,7 @@ public class KeyButtonRipple extends Drawable {
|
||||
}
|
||||
|
||||
private void enterSoftware() {
|
||||
cancelAnimations("enterSoftware");
|
||||
endAnimations("enterSoftware", true /* cancel */);
|
||||
mVisible = true;
|
||||
mGlowAlpha = getMaxGlowAlpha();
|
||||
ObjectAnimator scaleAnimator = ObjectAnimator.ofFloat(this, "glowScale",
|
||||
@@ -373,8 +382,7 @@ public class KeyButtonRipple extends Drawable {
|
||||
}
|
||||
|
||||
private void enterHardware() {
|
||||
Log.d("b/63783866", "enterHardware");
|
||||
cancelAnimations("enterHardware");
|
||||
endAnimations("enterHardware", true /* cancel */);
|
||||
mVisible = true;
|
||||
mDrawingHardwareGlow = true;
|
||||
setExtendStart(CanvasProperty.createFloat(getExtendSize() / 2));
|
||||
@@ -391,6 +399,7 @@ public class KeyButtonRipple extends Drawable {
|
||||
endAnim.setDuration(ANIMATION_DURATION_SCALE);
|
||||
endAnim.setInterpolator(mInterpolator);
|
||||
endAnim.addListener(mAnimatorListener);
|
||||
endAnim.addListener(mEnterHwTraceAnimator);
|
||||
endAnim.setTarget(mTargetView);
|
||||
|
||||
if (isHorizontal()) {
|
||||
@@ -426,13 +435,13 @@ public class KeyButtonRipple extends Drawable {
|
||||
}
|
||||
|
||||
private void exitHardware() {
|
||||
Log.d("b/63783866", "exitHardware");
|
||||
mPaintProp = CanvasProperty.createPaint(getRipplePaint());
|
||||
final RenderNodeAnimator opacityAnim = new RenderNodeAnimator(mPaintProp,
|
||||
RenderNodeAnimator.PAINT_ALPHA, 0);
|
||||
opacityAnim.setDuration(ANIMATION_DURATION_FADE);
|
||||
opacityAnim.setInterpolator(Interpolators.ALPHA_OUT);
|
||||
opacityAnim.addListener(mAnimatorListener);
|
||||
opacityAnim.addListener(mExitHwTraceAnimator);
|
||||
opacityAnim.setTarget(mTargetView);
|
||||
|
||||
opacityAnim.start();
|
||||
@@ -443,16 +452,41 @@ public class KeyButtonRipple extends Drawable {
|
||||
|
||||
private final AnimatorListenerAdapter mAnimatorListener =
|
||||
new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mRunningAnimations.remove(animation);
|
||||
if (mRunningAnimations.isEmpty() && !mPressed) {
|
||||
mVisible = false;
|
||||
mDrawingHardwareGlow = false;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static final class TraceAnimatorListener extends AnimatorListenerAdapter {
|
||||
private final String mName;
|
||||
TraceAnimatorListener(String name) {
|
||||
mName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
Trace.beginSection("KeyButtonRipple.start." + mName);
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
Trace.beginSection("KeyButtonRipple.cancel." + mName);
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mRunningAnimations.remove(animation);
|
||||
if (mRunningAnimations.isEmpty() && !mPressed) {
|
||||
mVisible = false;
|
||||
mDrawingHardwareGlow = false;
|
||||
invalidateSelf();
|
||||
}
|
||||
Trace.beginSection("KeyButtonRipple.end." + mName);
|
||||
Trace.endSection();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolator with a smooth log deceleration
|
||||
|
||||
Reference in New Issue
Block a user