Methods Summary |
---|
public boolean | getBoolean(int index, boolean defValue)Retrieve the boolean value for the attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA] != 0;
}
TypedValue v = mValue;
if (getValueAt(index, v)) {
Log.w(Resources.TAG, "Converting to boolean: " + v);
return XmlUtils.convertValueToBoolean(
v.coerceToString(), defValue);
}
Log.w(Resources.TAG, "getBoolean of bad type: 0x"
+ Integer.toHexString(type));
return defValue;
|
public int | getColor(int index, int defValue)Retrieve the color value for the attribute at index. If
the attribute references a color resource holding a complex
{@link android.content.res.ColorStateList}, then the default color from
the set is returned.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_STRING) {
final TypedValue value = mValue;
if (getValueAt(index, value)) {
ColorStateList csl = mResources.loadColorStateList(
value, value.resourceId);
return csl.getDefaultColor();
}
return defValue;
}
throw new UnsupportedOperationException("Can't convert to color: type=0x"
+ Integer.toHexString(type));
|
public ColorStateList | getColorStateList(int index)Retrieve the ColorStateList for the attribute at index.
The value may be either a single solid color or a reference to
a color or complex {@link android.content.res.ColorStateList} description.
final TypedValue value = mValue;
if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
return mResources.loadColorStateList(value, value.resourceId);
}
return null;
|
public float | getDimension(int index, float defValue)Retrieve a dimensional unit attribute at index. Unit
conversions are based on the current {@link DisplayMetrics}
associated with the resources this {@link TypedArray} object
came from.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimension(
data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
+ Integer.toHexString(type));
|
public int | getDimensionPixelOffset(int index, int defValue)Retrieve a dimensional unit attribute at index for use
as an offset in raw pixels. This is the same as
{@link #getDimension}, except the returned value is converted to
integer pixels for you. An offset conversion involves simply
truncating the base value to an integer.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelOffset(
data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
+ Integer.toHexString(type));
|
public int | getDimensionPixelSize(int index, int defValue)Retrieve a dimensional unit attribute at index for use
as a size in raw pixels. This is the same as
{@link #getDimension}, except the returned value is converted to
integer pixels for use as a size. A size conversion involves
rounding the base value, and ensuring that a non-zero base value
is at least one pixel in size.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
+ Integer.toHexString(type));
|
public android.graphics.drawable.Drawable | getDrawable(int index)Retrieve the Drawable for the attribute at index. This
gets the resource ID of the selected attribute, and uses
{@link Resources#getDrawable Resources.getDrawable} of the owning
Resources object to retrieve its Drawable.
final TypedValue value = mValue;
if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
if (false) {
System.out.println("******************************************************************");
System.out.println("Got drawable resource: type="
+ value.type
+ " str=" + value.string
+ " int=0x" + Integer.toHexString(value.data)
+ " cookie=" + value.assetCookie);
System.out.println("******************************************************************");
}
return mResources.loadDrawable(value, value.resourceId);
}
return null;
|
public float | getFloat(int index, float defValue)Retrieve the float value for the attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type == TypedValue.TYPE_FLOAT) {
return Float.intBitsToFloat(data[index+AssetManager.STYLE_DATA]);
} else if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
}
TypedValue v = mValue;
if (getValueAt(index, v)) {
Log.w(Resources.TAG, "Converting to float: " + v);
CharSequence str = v.coerceToString();
if (str != null) {
return Float.parseFloat(str.toString());
}
}
Log.w(Resources.TAG, "getFloat of bad type: 0x"
+ Integer.toHexString(type));
return defValue;
|
public float | getFraction(int index, int base, int pbase, float defValue)Retrieve a fractional unit attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type == TypedValue.TYPE_FRACTION) {
return TypedValue.complexToFraction(
data[index+AssetManager.STYLE_DATA], base, pbase);
}
throw new UnsupportedOperationException("Can't convert to fraction: type=0x"
+ Integer.toHexString(type));
|
public int | getIndex(int at)Return an index in the array that has data.
return mIndices[1+at];
|
public int | getIndexCount()Return the number of indices in the array that actually have data.
return mIndices[0];
|
public int | getInt(int index, int defValue)Retrieve the integer value for the attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
}
TypedValue v = mValue;
if (getValueAt(index, v)) {
Log.w(Resources.TAG, "Converting to int: " + v);
return XmlUtils.convertValueToInt(
v.coerceToString(), defValue);
}
Log.w(Resources.TAG, "getInt of bad type: 0x"
+ Integer.toHexString(type));
return defValue;
|
public int | getInteger(int index, int defValue)Retrieve the integer value for the attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
}
throw new UnsupportedOperationException("Can't convert to integer: type=0x"
+ Integer.toHexString(type));
|
public int | getLayoutDimension(int index, java.lang.String name)Special version of {@link #getDimensionPixelSize} for retrieving
{@link android.view.ViewGroup}'s layout_width and layout_height
attributes. This is only here for performance reasons; applications
should use {@link #getDimensionPixelSize}.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
}
throw new RuntimeException(getPositionDescription()
+ ": You must supply a " + name + " attribute.");
|
public int | getLayoutDimension(int index, int defValue)Special version of {@link #getDimensionPixelSize} for retrieving
{@link android.view.ViewGroup}'s layout_width and layout_height
attributes. This is only here for performance reasons; applications
should use {@link #getDimensionPixelSize}.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
}
return defValue;
|
public java.lang.String | getNonResourceString(int index)Retrieve the string value for the attribute at index, but
only if that string comes from an immediate value in an XML file. That
is, this does not allow references to string resources, string
attributes, or conversions from other types. As such, this method
will only return strings for TypedArray objects that come from
attributes in an XML file.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_STRING) {
final int cookie = data[index+AssetManager.STYLE_ASSET_COOKIE];
if (cookie < 0) {
return mXml.getPooledString(
data[index+AssetManager.STYLE_DATA]).toString();
}
}
return null;
|
public java.lang.String | getPositionDescription()Returns a message about the parser state suitable for printing error messages.
return mXml != null ? mXml.getPositionDescription() : "<internal>";
|
public int | getResourceId(int index, int defValue)Retrieve the resource identifier for the attribute at
index. Note that attribute resource as resolved when
the overall {@link TypedArray} object is retrieved. As a
result, this function will return the resource identifier of the
final resource value that was found, not necessarily the
original resource that was specified by the attribute.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
if (data[index+AssetManager.STYLE_TYPE] != TypedValue.TYPE_NULL) {
final int resid = data[index+AssetManager.STYLE_RESOURCE_ID];
if (resid != 0) {
return resid;
}
}
return defValue;
|
public Resources | getResources()Return the Resources object this array was loaded from.
return mResources;
|
public java.lang.String | getString(int index)Retrieve the string value for the attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return null;
} else if (type == TypedValue.TYPE_STRING) {
return loadStringValueAt(index).toString();
}
TypedValue v = mValue;
if (getValueAt(index, v)) {
Log.w(Resources.TAG, "Converting to string: " + v);
CharSequence cs = v.coerceToString();
return cs != null ? cs.toString() : null;
}
Log.w(Resources.TAG, "getString of bad type: 0x"
+ Integer.toHexString(type));
return null;
|
public java.lang.CharSequence | getText(int index)Retrieve the styled string value for the attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return null;
} else if (type == TypedValue.TYPE_STRING) {
return loadStringValueAt(index);
}
TypedValue v = mValue;
if (getValueAt(index, v)) {
Log.w(Resources.TAG, "Converting to string: " + v);
return v.coerceToString();
}
Log.w(Resources.TAG, "getString of bad type: 0x"
+ Integer.toHexString(type));
return null;
|
public java.lang.CharSequence[] | getTextArray(int index)Retrieve the CharSequence[] for the attribute at index.
This gets the resource ID of the selected attribute, and uses
{@link Resources#getTextArray Resources.getTextArray} of the owning
Resources object to retrieve its String[].
final TypedValue value = mValue;
if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
if (false) {
System.out.println("******************************************************************");
System.out.println("Got drawable resource: type="
+ value.type
+ " str=" + value.string
+ " int=0x" + Integer.toHexString(value.data)
+ " cookie=" + value.assetCookie);
System.out.println("******************************************************************");
}
return mResources.getTextArray(value.resourceId);
}
return null;
|
public boolean | getValue(int index, android.util.TypedValue outValue)Retrieve the raw TypedValue for the attribute at index.
return getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, outValue);
|
private boolean | getValueAt(int index, android.util.TypedValue outValue)
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return false;
}
outValue.type = type;
outValue.data = data[index+AssetManager.STYLE_DATA];
outValue.assetCookie = data[index+AssetManager.STYLE_ASSET_COOKIE];
outValue.resourceId = data[index+AssetManager.STYLE_RESOURCE_ID];
outValue.changingConfigurations = data[index+AssetManager.STYLE_CHANGING_CONFIGURATIONS];
if (type == TypedValue.TYPE_STRING) {
outValue.string = loadStringValueAt(index);
}
return true;
|
public boolean | hasValue(int index)Determines whether there is an attribute at index.
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
return type != TypedValue.TYPE_NULL;
|
public int | length()Return the number of values in this array.
return mLength;
|
private java.lang.CharSequence | loadStringValueAt(int index)
final int[] data = mData;
final int cookie = data[index+AssetManager.STYLE_ASSET_COOKIE];
if (cookie < 0) {
if (mXml != null) {
return mXml.getPooledString(
data[index+AssetManager.STYLE_DATA]);
}
return null;
}
//System.out.println("Getting pooled from: " + v);
return mResources.mAssets.getPooledString(
cookie, data[index+AssetManager.STYLE_DATA]);
|
public android.util.TypedValue | peekValue(int index)Retrieve the raw TypedValue for the attribute at index
and return a temporary object holding its data. This object is only
valid until the next call on to {@link TypedArray}.
final TypedValue value = mValue;
if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
return value;
}
return null;
|
public void | recycle()Give back a previously retrieved StyledAttributes, for later re-use.
synchronized (mResources.mTmpValue) {
TypedArray cached = mResources.mCachedStyledAttributes;
if (cached == null || cached.mData.length < mData.length) {
mXml = null;
mResources.mCachedStyledAttributes = this;
}
}
|
public java.lang.String | toString()
return Arrays.toString(mData);
|