Skip to content

Commit 89b70b8

Browse files
committed
Make tiled state a bit flag
1 parent 08f6bf7 commit 89b70b8

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

library/src/main/java/org/bitmapdecoder/IndexedDrawable.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void applyTheme(@NonNull Resources.Theme theme) {
120120
int newConfiguration = state.getChangingConfigurations() | tv.changingConfigurations;
121121

122122
state = new IndexedDrawableState(state, tintList, tv.resourceId, newConfiguration,
123-
state.getScale(), state.isTiled());
123+
state.getScale(), state.flags);
124124

125125
applyTint(StateSet.NOTHING, getState(), tintList, true);
126126
}
@@ -191,7 +191,12 @@ public void inflate(Resources r, XmlPullParser parser, AttributeSet set, Resourc
191191
int attributeConfigurations = typedArray.getChangingConfigurations();
192192

193193
if (tintList != null || resType == TYPE_ATTRIBUTE || scale != 1.0 || attributeConfigurations != 0 || tiled) {
194-
state = new IndexedDrawableState(state, tintList, tint, attributeConfigurations, scale, tiled);
194+
int flags = state.flags;
195+
if (tiled) {
196+
flags |= ShaderDrawable.TILED_MASK;
197+
}
198+
199+
state = new IndexedDrawableState(state, tintList, tint, attributeConfigurations, scale, flags);
195200

196201
if (tintList != null) {
197202
applyTint(StateSet.NOTHING, getState(), tintList, true);
@@ -211,7 +216,7 @@ public void inflate(Resources r, XmlPullParser parser, AttributeSet set, Resourc
211216
@Override
212217
public void setTintList(@Nullable ColorStateList tint) {
213218
this.state = new IndexedDrawableState(state, tint, 0, state.getChangingConfigurations(),
214-
state.getScale(), state.isTiled());
219+
state.getScale(), state.flags);
215220

216221
applyTint(getState(), getState(), tint, true);
217222
}
@@ -309,7 +314,7 @@ private void decode(Resources r, TypedValue tv) throws IOException {
309314
float scale = applyDensity(r.getDisplayMetrics(), tv.density);
310315
if (scale != 1.0) {
311316
state = new IndexedDrawableState(state, getTint(), getTintResId(), state.getChangingConfigurations(),
312-
scale, state.isTiled());
317+
scale, state.flags);
313318
}
314319
}
315320

@@ -395,21 +400,19 @@ private static class IndexedDrawableState extends State {
395400

396401
private final int configurations;
397402
private final float scale;
398-
private final boolean tiled;
399403

400404
private IndexedDrawableState(@NonNull Paint paint,
401405
@NonNull State state,
402406
ColorStateList tint,
403407
int tintResId,
404408
int configurations,
405409
float scale,
406-
boolean tiled) {
407-
super(paint, state.width, state.height, state.flags);
410+
int newFlags) {
411+
super(paint, state.width, state.height, newFlags);
408412

409413
this.tint = tint;
410414
this.tintResId = tintResId;
411415
this.scale = scale;
412-
this.tiled = tiled;
413416
this.configurations = configurations | getConfigurations(tint);
414417
}
415418

@@ -418,8 +421,8 @@ private IndexedDrawableState(@NonNull State state,
418421
int tintResId,
419422
int configurations,
420423
float scale,
421-
boolean tiled) {
422-
this(state.paint, state, tint, tintResId, configurations, scale, tiled);
424+
int newFlags) {
425+
this(state.paint, state, tint, tintResId, configurations, scale, newFlags);
423426
}
424427

425428
@NonNull
@@ -435,19 +438,14 @@ public boolean canApplyTheme() {
435438

436439
@Override
437440
protected State copy() {
438-
return new IndexedDrawableState(new Paint(paint), this, tint, tintResId, configurations, scale, tiled);
441+
return new IndexedDrawableState(new Paint(paint), this, tint, tintResId, configurations, scale, flags);
439442
}
440443

441444
@Override
442445
public int getChangingConfigurations() {
443446
return configurations;
444447
}
445448

446-
@Override
447-
protected boolean isTiled() {
448-
return tiled;
449-
}
450-
451449
@Override
452450
protected float getScale() {
453451
return scale;

library/src/main/java/org/bitmapdecoder/ShaderDrawable.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
public class ShaderDrawable extends Drawable {
3939
private static final String TAG = "pngs";
4040

41-
static final int OPAQUE_MASK = 0xF0000000;
42-
static final int COLOR_MASK = 0x00FFFFFF;
41+
static final int OPAQUE_MASK = 0b11110000000000000000000000000000;
42+
static final int TILED_MASK = 0b00001000000000000000000000000000;
43+
static final int COLOR_MASK = 0b00000000111111111111111111111111;
4344

4445
protected State state;
4546
private boolean mutated;
@@ -236,7 +237,7 @@ public int getChangingConfigurations() {
236237
}
237238

238239
protected boolean isTiled() {
239-
return false;
240+
return (flags & TILED_MASK) != 0;
240241
}
241242

242243
protected float getScale() {

0 commit comments

Comments
 (0)