16
16
import android .graphics .drawable .Drawable ;
17
17
18
18
import androidx .annotation .ColorInt ;
19
+ import androidx .annotation .IntRange ;
19
20
import androidx .annotation .NonNull ;
20
21
import androidx .annotation .Nullable ;
21
22
22
23
abstract class BaseDrawable extends Drawable implements TintableDrawable {
23
24
24
- protected int mAlpha = 0xFF ;
25
+ @ IntRange (from = 0 , to = 255 )
26
+ protected int mAlpha = 255 ;
27
+ @ Nullable
25
28
protected ColorFilter mColorFilter ;
29
+ @ Nullable
26
30
protected ColorStateList mTintList ;
31
+ @ NonNull
27
32
protected PorterDuff .Mode mTintMode = PorterDuff .Mode .SRC_IN ;
33
+ @ Nullable
28
34
protected PorterDuffColorFilter mTintFilter ;
29
35
30
- private DummyConstantState mConstantState = new DummyConstantState ();
36
+ @ NonNull
37
+ private final DummyConstantState mConstantState = new DummyConstantState ();
31
38
39
+ @ IntRange (from = 0 , to = 255 )
32
40
@ Override
33
41
public int getAlpha () {
34
42
return mAlpha ;
@@ -38,7 +46,7 @@ public int getAlpha() {
38
46
* {@inheritDoc}
39
47
*/
40
48
@ Override
41
- public void setAlpha (int alpha ) {
49
+ public void setAlpha (@ IntRange ( from = 0 , to = 255 ) int alpha ) {
42
50
if (mAlpha != alpha ) {
43
51
mAlpha = alpha ;
44
52
invalidateSelf ();
@@ -48,6 +56,7 @@ public void setAlpha(int alpha) {
48
56
/**
49
57
* {@inheritDoc}
50
58
*/
59
+ @ Nullable
51
60
@ Override
52
61
public ColorFilter getColorFilter () {
53
62
return mColorFilter ;
@@ -98,7 +107,7 @@ public boolean isStateful() {
98
107
}
99
108
100
109
@ Override
101
- protected boolean onStateChange (int [] state ) {
110
+ protected boolean onStateChange (@ NonNull int [] state ) {
102
111
return updateTintFilter ();
103
112
}
104
113
@@ -129,7 +138,7 @@ public int getOpacity() {
129
138
* {@inheritDoc}
130
139
*/
131
140
@ Override
132
- public void draw (Canvas canvas ) {
141
+ public void draw (@ NonNull Canvas canvas ) {
133
142
134
143
Rect bounds = getBounds ();
135
144
if (bounds .width () == 0 || bounds .height () == 0 ) {
@@ -142,17 +151,19 @@ public void draw(Canvas canvas) {
142
151
canvas .restoreToCount (saveCount );
143
152
}
144
153
154
+ @ Nullable
145
155
protected ColorFilter getColorFilterForDrawing () {
146
156
return mColorFilter != null ? mColorFilter : mTintFilter ;
147
157
}
148
158
149
- protected abstract void onDraw (Canvas canvas , int width , int height );
159
+ protected abstract void onDraw (@ NonNull Canvas canvas , int width , int height );
150
160
151
161
// Workaround LayerDrawable.ChildDrawable which calls getConstantState().newDrawable()
152
162
// without checking for null.
153
163
// We are never inflated from XML so the protocol of ConstantState does not apply to us. In
154
164
// order to make LayerDrawable happy, we return ourselves from DummyConstantState.newDrawable().
155
165
166
+ @ NonNull
156
167
@ Override
157
168
public ConstantState getConstantState () {
158
169
return mConstantState ;
0 commit comments