Clean up attribute apis based on api council feedback.

Bug: 127714248
Test: None
Change-Id: I40596a88e7e446c6a25f2b9074bb88a0a417ed63
This commit is contained in:
Aurimas Liutikas
2019-03-07 11:21:51 -08:00
parent 436a76d1fa
commit f9dbd5fed6
5 changed files with 30 additions and 21 deletions

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;
}
if (mSourceLayoutId != ID_NULL) {
stack.add(mSourceLayoutId);
public int[] getAttributeResolutionStack(@AttrRes int attribute) {
if (!sDebugViewAttributes
|| mAttributeResolutionStacks == null
|| mAttributeResolutionStacks.get(attribute) == null) {
return new int[0];
}
int[] attributeResolutionStack = mAttributeResolutionStacks.get(attribute);
if (attributeResolutionStack == null) {
return stack;
int stackSize = attributeResolutionStack.length;
if (mSourceLayoutId != ID_NULL) {
stackSize++;
}
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.

View File

@@ -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++;

View File

@@ -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,