add getAlpha() to Drawable

Drawable has setAlpha(int), but no getAlpha() (although some subclasses have added the
method). This makes it more tedious to use the property. For example, animations that wish to
animate this property must explicitly give it a start value since this value cannot be queried
from the object.

The trick is that setAlpha(int) is abstract, only implemented by subclasses. We cannot take this
approach for getAlpha(), as we would break all subclasses of Drawable until they implemented the
method. Instead, we'll add a default method which returns an invalid value, making it easier for
clients of the method to detect whether the value is valid.

All subclasses of Drawble in frameworks have been changed to add an override of getAlpha() when
appropriate.

Issue #7485875 Drawables is missing getAlpha()

Change-Id: I06b6e35f1a56d202838eca44759c85c82595020a
This commit is contained in:
Chet Haase
2013-03-08 14:02:04 -08:00
parent 1ccdf0ee16
commit b1af7f3d4b
17 changed files with 91 additions and 34 deletions

View File

@@ -455,6 +455,11 @@ public class BitmapDrawable extends Drawable {
}
}
@Override
public int getAlpha() {
return mBitmapState.mPaint.getAlpha();
}
@Override
public void setColorFilter(ColorFilter cf) {
mBitmapState.mPaint.setColorFilter(cf);