diff options
author | 2019-03-07 11:21:51 -0800 | |
---|---|---|
committer | 2019-03-07 14:23:59 -0800 | |
commit | f9dbd5fed6168daed8d8b132fd8b9d8db32bb4cb (patch) | |
tree | 3745cccda09beea106d85f6f2325bbae6e7fbc29 | |
parent | 436a76d1fa3b5dccdd708f5a3938c35251551940 (diff) |
Clean up attribute apis based on api council feedback.
Bug: 127714248
Test: None
Change-Id: I40596a88e7e446c6a25f2b9074bb88a0a417ed63
-rw-r--r-- | api/current.txt | 4 | ||||
-rw-r--r-- | core/java/android/content/res/TypedArray.java | 11 | ||||
-rw-r--r-- | core/java/android/view/View.java | 30 | ||||
-rw-r--r-- | libs/androidfw/AttributeResolution.cpp | 2 | ||||
-rw-r--r-- | libs/androidfw/include/androidfw/AttributeResolution.h | 2 |
5 files changed, 29 insertions, 20 deletions
diff --git a/api/current.txt b/api/current.txt index 6de1383a2e05..ec469981f579 100644 --- a/api/current.txt +++ b/api/current.txt @@ -12369,7 +12369,7 @@ package android.content.res { method public String getPositionDescription(); method @AnyRes public int getResourceId(@StyleableRes int, int); method public android.content.res.Resources getResources(); - method @StyleRes public int getSourceResourceId(@StyleableRes int, @StyleRes int); + method @AnyRes public int getSourceResourceId(@StyleableRes int, @AnyRes int); method @Nullable public String getString(@StyleableRes int); method public CharSequence getText(@StyleableRes int); method public CharSequence[] getTextArray(@StyleableRes int); @@ -50381,7 +50381,7 @@ package android.view { method @android.view.ViewDebug.ExportedProperty(category="drawing") public float getAlpha(); method public android.view.animation.Animation getAnimation(); method public android.os.IBinder getApplicationWindowToken(); - method @NonNull public java.util.List<java.lang.Integer> getAttributeResolutionStack(@AttrRes int); + method @NonNull public int[] getAttributeResolutionStack(@AttrRes int); method @NonNull public java.util.Map<java.lang.Integer,java.lang.Integer> getAttributeSourceResourceMap(); method @android.view.ViewDebug.ExportedProperty @Nullable public String[] getAutofillHints(); method public final android.view.autofill.AutofillId getAutofillId(); diff --git a/core/java/android/content/res/TypedArray.java b/core/java/android/content/res/TypedArray.java index d36e076381eb..b79cf6566987 100644 --- a/core/java/android/content/res/TypedArray.java +++ b/core/java/android/content/res/TypedArray.java @@ -19,7 +19,6 @@ package android.content.res; import android.annotation.AnyRes; import android.annotation.ColorInt; import android.annotation.Nullable; -import android.annotation.StyleRes; import android.annotation.StyleableRes; import android.annotation.UnsupportedAppUsage; import android.content.pm.ActivityInfo; @@ -72,7 +71,7 @@ public class TypedArray { static final int STYLE_RESOURCE_ID = 3; static final int STYLE_CHANGING_CONFIGURATIONS = 4; static final int STYLE_DENSITY = 5; - static final int SYTLE_SOURCE_RESOURCE_ID = 6; + static final int STYLE_SOURCE_RESOURCE_ID = 6; @UnsupportedAppUsage private final Resources mResources; @@ -1134,14 +1133,14 @@ public class TypedArray { * resolved in a style or layout. * @throws RuntimeException if the TypedArray has already been recycled. */ - @StyleRes - public int getSourceResourceId(@StyleableRes int index, @StyleRes int defaultValue) { + @AnyRes + public int getSourceResourceId(@StyleableRes int index, @AnyRes int defaultValue) { if (mRecycled) { throw new RuntimeException("Cannot make calls to a recycled instance!"); } index *= STYLE_NUM_ENTRIES; - final int resid = mData[index + SYTLE_SOURCE_RESOURCE_ID]; + final int resid = mData[index + STYLE_SOURCE_RESOURCE_ID]; if (resid != 0) { return resid; } @@ -1360,7 +1359,7 @@ public class TypedArray { data[index + STYLE_CHANGING_CONFIGURATIONS]); outValue.density = data[index + STYLE_DENSITY]; outValue.string = (type == TypedValue.TYPE_STRING) ? loadStringValueAt(index) : null; - outValue.sourceResourceId = data[index + SYTLE_SOURCE_RESOURCE_ID]; + outValue.sourceResourceId = data[index + STYLE_SOURCE_RESOURCE_ID]; return true; } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 877b3044f7c3..0753ceca67d9 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -5969,20 +5969,28 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * this {@link View}. */ @NonNull - public List<Integer> getAttributeResolutionStack(@AttrRes int attribute) { - ArrayList<Integer> stack = new ArrayList<>(); - if (!sDebugViewAttributes || mAttributeResolutionStacks == null) { - return stack; + public int[] getAttributeResolutionStack(@AttrRes int attribute) { + if (!sDebugViewAttributes + || mAttributeResolutionStacks == null + || mAttributeResolutionStacks.get(attribute) == null) { + return new int[0]; } + int[] attributeResolutionStack = mAttributeResolutionStacks.get(attribute); + int stackSize = attributeResolutionStack.length; if (mSourceLayoutId != ID_NULL) { - stack.add(mSourceLayoutId); + stackSize++; } - int[] attributeResolutionStack = mAttributeResolutionStacks.get(attribute); - if (attributeResolutionStack == null) { - return stack; + + int currentIndex = 0; + int[] stack = new int[stackSize]; + + if (mSourceLayoutId != ID_NULL) { + stack[currentIndex] = mSourceLayoutId; + currentIndex++; } for (int i = 0; i < attributeResolutionStack.length; i++) { - stack.add(attributeResolutionStack[i]); + stack[currentIndex] = attributeResolutionStack[i]; + currentIndex++; } return stack; } @@ -6133,7 +6141,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, /** * Stores debugging information about attributes. This should be called in a constructor by - * every custom {@link View} that uses a custom styleable. + * every custom {@link View} that uses a custom styleable. If the custom view does not call it, + * then the custom attributes used by this view will not be visible in layout inspection tools. + * * @param context Context under which this view is created. * @param styleable A reference to styleable array R.styleable.Foo * @param attrs AttributeSet used to construct this view. diff --git a/libs/androidfw/AttributeResolution.cpp b/libs/androidfw/AttributeResolution.cpp index cc177af7be6f..e62fb614e195 100644 --- a/libs/androidfw/AttributeResolution.cpp +++ b/libs/androidfw/AttributeResolution.cpp @@ -388,7 +388,7 @@ void ApplyStyle(Theme* theme, ResXMLParser* xml_parser, uint32_t def_style_attr, out_values[STYLE_RESOURCE_ID] = resid; out_values[STYLE_CHANGING_CONFIGURATIONS] = type_set_flags; out_values[STYLE_DENSITY] = config.density; - out_values[SYTLE_SOURCE_RESOURCE_ID] = value_source_resid; + out_values[STYLE_SOURCE_RESOURCE_ID] = value_source_resid; if (value.dataType != Res_value::TYPE_NULL || value.data == Res_value::DATA_NULL_EMPTY) { indices_idx++; diff --git a/libs/androidfw/include/androidfw/AttributeResolution.h b/libs/androidfw/include/androidfw/AttributeResolution.h index 0cc1d3c56cc4..d71aad29d917 100644 --- a/libs/androidfw/include/androidfw/AttributeResolution.h +++ b/libs/androidfw/include/androidfw/AttributeResolution.h @@ -33,7 +33,7 @@ enum { STYLE_RESOURCE_ID = 3, STYLE_CHANGING_CONFIGURATIONS = 4, STYLE_DENSITY = 5, - SYTLE_SOURCE_RESOURCE_ID = 6 + STYLE_SOURCE_RESOURCE_ID = 6 }; // These are all variations of the same method. They each perform the exact same operation, |