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
@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);