Merge "Pass densityDpi into RippleComponent, store as densityScale"

This commit is contained in:
Alan Viverette
2015-11-11 20:00:22 +00:00
committed by Android (Google) Code Review
3 changed files with 8 additions and 8 deletions

View File

@@ -20,6 +20,7 @@ import android.animation.Animator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.DisplayListCanvas;
import android.view.RenderNodeAnimator;
@@ -50,7 +51,7 @@ abstract class RippleComponent {
protected float mTargetRadius;
/** Screen density used to adjust pixel-based constants. */
protected float mDensity;
protected float mDensityScale;
/**
* If set, force all ripple animations to not run on RenderThread, even if it would be
@@ -71,7 +72,7 @@ abstract class RippleComponent {
}
}
public final void setup(float maxRadius, float density) {
public final void setup(float maxRadius, int densityDpi) {
if (maxRadius >= 0) {
mHasMaxRadius = true;
mTargetRadius = maxRadius;
@@ -79,7 +80,7 @@ abstract class RippleComponent {
mTargetRadius = getTargetRadius(mBounds);
}
mDensity = density;
mDensityScale = densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
onTargetRadiusChanged(mTargetRadius);
}

View File

@@ -160,7 +160,7 @@ public class RippleDrawable extends LayerDrawable {
private Paint mRipplePaint;
/** Target density of the display into which ripples are drawn. */
private float mDensity = 1.0f;
private int mDensity;
/** Whether bounds are being overridden. */
private boolean mOverrideBounds;
@@ -544,8 +544,7 @@ public class RippleDrawable extends LayerDrawable {
mBackground = new RippleBackground(this, mHotspotBounds, mForceSoftware);
}
final float densityScale = mState.mDensity * DisplayMetrics.DENSITY_DEFAULT_SCALE;
mBackground.setup(mState.mMaxRadius, densityScale);
mBackground.setup(mState.mMaxRadius, mDensity);
mBackground.enter(focused);
}

View File

@@ -168,7 +168,7 @@ class RippleForeground extends RippleComponent {
}
final int duration = (int)
(1000 * Math.sqrt(mTargetRadius / WAVE_TOUCH_DOWN_ACCELERATION * mDensity) + 0.5);
(1000 * Math.sqrt(mTargetRadius / WAVE_TOUCH_DOWN_ACCELERATION * mDensityScale) + 0.5);
final ObjectAnimator tweenRadius = ObjectAnimator.ofFloat(this, TWEEN_RADIUS, 1);
tweenRadius.setAutoCancel(true);
@@ -204,7 +204,7 @@ class RippleForeground extends RippleComponent {
private int getRadiusExitDuration() {
final float remainingRadius = mTargetRadius - getCurrentRadius();
return (int) (1000 * Math.sqrt(remainingRadius / (WAVE_TOUCH_UP_ACCELERATION
+ WAVE_TOUCH_DOWN_ACCELERATION) * mDensity) + 0.5);
+ WAVE_TOUCH_DOWN_ACCELERATION) * mDensityScale) + 0.5);
}
private float getCurrentRadius() {