Created
June 13, 2014 15:16
-
-
Save krschultz/033cd82237715984bdfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//android.content.res.TypedArray | |
/** | |
* Retrieve the integer value for the attribute at <var>index</var>. | |
* | |
* @param index Index of attribute to retrieve. | |
* @param defValue Value to return if the attribute is not defined or | |
* not a resource. | |
* | |
* @return Attribute integer value, or defValue if not defined. | |
*/ | |
public int getInteger(int index, int defValue) { | |
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)); | |
} | |
/** | |
* Retrieve the integer value for the attribute at <var>index</var>. | |
* | |
* @param index Index of attribute to retrieve. | |
* @param defValue Value to return if the attribute is not defined. | |
* | |
* @return Attribute int value, or defValue if not defined. | |
*/ | |
public int getInt(int index, int defValue) { | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment