Merge "Fix issue in InsetDrawable where master inset attribute get ignored. Test: builds, and did manual test b/37752336" into oc-dev

This commit is contained in:
Hyunyoung Song
2017-05-05 20:52:48 +00:00
committed by Android (Google) Code Review
2 changed files with 12 additions and 12 deletions

View File

@@ -2,10 +2,7 @@
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@android:color/white" />
<foreground>
<inset android:insetLeft="27.7%"
android:insetTop="27.7%"
android:insetRight="27.7%"
android:insetBottom="27.7%">
<inset android:inset="27.7%">
<bitmap android:src="@mipmap/sym_def_app_icon"/>
</inset>
</foreground>

View File

@@ -188,19 +188,19 @@ public class InsetDrawable extends DrawableWrapper {
// Inset attribute may be overridden by more specific attributes.
if (a.hasValue(R.styleable.InsetDrawable_inset)) {
final InsetValue inset = getInset(a, R.styleable.InsetDrawable_inset, 0);
final InsetValue inset = getInset(a, R.styleable.InsetDrawable_inset, new InsetValue());
state.mInsetLeft = inset;
state.mInsetTop = inset;
state.mInsetRight = inset;
state.mInsetBottom = inset;
}
state.mInsetLeft = getInset(a, R.styleable.InsetDrawable_insetLeft, 0);
state.mInsetTop = getInset(a, R.styleable.InsetDrawable_insetTop, 0);
state.mInsetRight = getInset(a, R.styleable.InsetDrawable_insetRight, 0);
state.mInsetBottom = getInset(a, R.styleable.InsetDrawable_insetBottom, 0);
state.mInsetLeft = getInset(a, R.styleable.InsetDrawable_insetLeft, state.mInsetLeft);
state.mInsetTop = getInset(a, R.styleable.InsetDrawable_insetTop, state.mInsetTop);
state.mInsetRight = getInset(a, R.styleable.InsetDrawable_insetRight, state.mInsetRight);
state.mInsetBottom = getInset(a, R.styleable.InsetDrawable_insetBottom, state.mInsetBottom);
}
private InsetValue getInset(@NonNull TypedArray a, int index, int defaultValue) {
private InsetValue getInset(@NonNull TypedArray a, int index, InsetValue defaultValue) {
if (a.hasValue(index)) {
TypedValue tv = a.peekValue(index);
if (tv.type == TypedValue.TYPE_FRACTION) {
@@ -210,10 +210,13 @@ public class InsetDrawable extends DrawableWrapper {
}
return new InsetValue(f, 0);
} else {
return new InsetValue(0f, a.getDimensionPixelOffset(index, defaultValue));
int dimension = a.getDimensionPixelOffset(index, 0);
if (dimension != 0) {
return new InsetValue(0, dimension);
}
}
}
return new InsetValue();
return defaultValue;
}
private void getInsets(Rect out) {