From f9fe6c11d3ccc186f48a2e4535ff75780fab5a1a Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Tue, 2 May 2017 13:34:12 -0700 Subject: [PATCH] Fix issue in InsetDrawable where master inset attribute get ignored. Test: builds, and did manual test b/37752336 Change-Id: I85182a4cf94fa5bcb7c2ac09c701496fb3e72f61 --- core/res/res/drawable/sym_def_app_icon.xml | 5 +---- .../graphics/drawable/InsetDrawable.java | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/res/res/drawable/sym_def_app_icon.xml b/core/res/res/drawable/sym_def_app_icon.xml index 0fdb0ddf842ca..9c024025d4aa3 100644 --- a/core/res/res/drawable/sym_def_app_icon.xml +++ b/core/res/res/drawable/sym_def_app_icon.xml @@ -2,10 +2,7 @@ - + diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index bc401918df6b7..443aa4931ee3f 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -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) {