OSDN Git Service

CircleFramedDrawable incorrectly has implicit dependency on the hosting view size.
authorSvetoslav <svetoslavganov@google.com>
Thu, 25 Apr 2013 17:33:08 +0000 (10:33 -0700)
committerSvetoslav <svetoslavganov@google.com>
Thu, 25 Apr 2013 17:41:15 +0000 (10:41 -0700)
CircleFramedDrawable was trying to draw itself as big as the hosting view by
looking at the canvas size. However, due to inconsistent API behavior for the
cases with and without hardware acceleration the canvas size returns the
size of clipped canvas or the size of the entire canvas, respectively. While
we should fix the inconsistent API behavior, it is not correct for a lower
level component to know about the higher level one, i.e. a drawable trying
to infer the size of the hosting view. The hosting view should set the size
of the drawable. This change removes the dependency on the host view size and
if one wants to enlarge the drawable, he/she should just set the scale.

bug:8671059

Change-Id: Idc572da7dff60fd10cb37d3c3eca27aac2c0a21f

src/com/android/settings/users/CircleFramedDrawable.java

index 7af2508..671cfbe 100644 (file)
@@ -123,12 +123,10 @@ class CircleFramedDrawable extends Drawable {
 
     @Override
     public void draw(Canvas canvas) {
-        // clear background
-        final float outside = Math.min(canvas.getWidth(), canvas.getHeight());
-        final float inside = mScale * outside;
-        final float pad = (outside - inside) / 2f;
+        final float inside = mScale * mSize;
+        final float pad = (mSize - inside) / 2f;
 
-        mDstRect.set(pad, pad, outside - pad, outside - pad);
+        mDstRect.set(pad, pad, mSize - pad, mSize - pad);
         canvas.drawBitmap(mBitmap, mSrcRect, mDstRect, null);
 
         mFrameRect.set(mDstRect);