diff options
author | Alan Viverette <alanv@google.com> | 2014-02-20 22:03:55 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-02-20 22:03:55 +0000 |
commit | d85e7840b03b64b2aa75361b739d0316ef1a9270 (patch) | |
tree | ff781ab1971819e244d246a692d8bacb436677f9 | |
parent | a50d7cf2d5b70cceef3b34d98df1d0d6be49dcb1 (diff) | |
parent | cb29189c29a553a8005044f32de37a610f2857db (diff) | |
download | frameworks_base-d85e7840b03b64b2aa75361b739d0316ef1a9270.zip frameworks_base-d85e7840b03b64b2aa75361b739d0316ef1a9270.tar.gz frameworks_base-d85e7840b03b64b2aa75361b739d0316ef1a9270.tar.bz2 |
Merge "Fix density in touch feedback drawable"
-rw-r--r-- | graphics/java/android/graphics/drawable/Ripple.java | 4 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java | 49 |
2 files changed, 21 insertions, 32 deletions
diff --git a/graphics/java/android/graphics/drawable/Ripple.java b/graphics/java/android/graphics/drawable/Ripple.java index cbe20dc..618afb8 100644 --- a/graphics/java/android/graphics/drawable/Ripple.java +++ b/graphics/java/android/graphics/drawable/Ripple.java @@ -32,10 +32,10 @@ class Ripple { private static final TimeInterpolator INTERPOLATOR = new DecelerateInterpolator(2.0f); /** Starting radius for a ripple. */ - private static final int STARTING_RADIUS_DP = 40; + private static final int STARTING_RADIUS_DP = 16; /** Radius when finger is outside view bounds. */ - private static final int OUTSIDE_RADIUS_DP = 40; + private static final int OUTSIDE_RADIUS_DP = 16; /** Margin when constraining outside touches (fraction of outer radius). */ private static final float OUTSIDE_MARGIN = 0.8f; diff --git a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java b/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java index f7cd9de..a21f1e0 100644 --- a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java +++ b/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java @@ -25,7 +25,6 @@ import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Rect; -import android.graphics.Xfermode; import android.os.SystemClock; import android.util.AttributeSet; import android.util.DisplayMetrics; @@ -79,7 +78,7 @@ public class TouchFeedbackDrawable extends Drawable { private Paint mRipplePaint; /** Target density of the display into which ripples are drawn. */ - private int mTargetDensity; + private float mDensity = 1.0f; /** Whether the animation runnable has been posted. */ private boolean mAnimating; @@ -90,9 +89,7 @@ public class TouchFeedbackDrawable extends Drawable { TouchFeedbackDrawable(TouchFeedbackState state, Resources res) { if (res != null) { - mTargetDensity = res.getDisplayMetrics().densityDpi; - } else if (state != null) { - mTargetDensity = state.mTargetDensity; + mDensity = res.getDisplayMetrics().density; } mState = state; @@ -143,32 +140,30 @@ public class TouchFeedbackDrawable extends Drawable { return mState.mColorStateList != null && mState.mColorStateList.isStateful(); } - /** - * Set the density at which this drawable will be rendered. - * - * @param density The density scale for this drawable. - */ - public void setTargetDensity(int density) { - if (mTargetDensity != density) { - mTargetDensity = density == 0 ? DisplayMetrics.DENSITY_DEFAULT : density; - // TODO: Update density in ripples? - invalidateSelf(); - } - } - @Override public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { super.inflate(r, parser, attrs); - final TypedArray a = r.obtainAttributes(attrs, - com.android.internal.R.styleable.ColorDrawable); + final TypedArray a = r.obtainAttributes( + attrs, com.android.internal.R.styleable.ColorDrawable); mState.mColorStateList = a.getColorStateList( com.android.internal.R.styleable.ColorDrawable_color); a.recycle(); - mState.mXfermode = null; //new PorterDuffXfermode(Mode.SRC_ATOP); - mState.mProjected = false; + setTargetDensity(r.getDisplayMetrics()); + } + + /** + * Set the density at which this drawable will be rendered. + * + * @param metrics The display metrics for this drawable. + */ + private void setTargetDensity(DisplayMetrics metrics) { + if (mDensity != metrics.density) { + mDensity = metrics.density; + invalidateSelf(); + } } /** @@ -196,12 +191,13 @@ public class TouchFeedbackDrawable extends Drawable { final Rect bounds = getBounds(); final Ripple newRipple = new Ripple(bounds, padding, bounds.exactCenterX(), - bounds.exactCenterY(), mTargetDensity); + bounds.exactCenterY(), mDensity); newRipple.enter(); mActiveRipples.add(newRipple); mTouchedRipples.put(id, newRipple); } else { + // TODO: How do we want to respond to movement? //ripple.move(x, y); } @@ -296,7 +292,6 @@ public class TouchFeedbackDrawable extends Drawable { mRipplePaint.setAntiAlias(true); } - mRipplePaint.setXfermode(mState.mXfermode); mRipplePaint.setColor(color); final int restoreCount = canvas.save(); @@ -345,16 +340,10 @@ public class TouchFeedbackDrawable extends Drawable { static class TouchFeedbackState extends ConstantState { ColorStateList mColorStateList; - Xfermode mXfermode; - int mTargetDensity; - boolean mProjected; public TouchFeedbackState(TouchFeedbackState orig) { if (orig != null) { mColorStateList = orig.mColorStateList; - mXfermode = orig.mXfermode; - mTargetDensity = orig.mTargetDensity; - mProjected = orig.mProjected; } } |