下面列出了android.util.TypedValue#TYPE_INT_DEC 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public RadioGroupSetting(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RadioGroupSetting, defStyleAttr, 0);
mLayout = attributes.getResourceId(R.styleable.RadioGroupSetting_layout, R.layout.setting_radio_group);
mDescription = attributes.getString(R.styleable.RadioGroupSetting_description);
mOptions = attributes.getTextArray(R.styleable.RadioGroupSetting_options);
mDescriptions = attributes.getTextArray(R.styleable.RadioGroupSetting_descriptions);
mMargin = attributes.getDimension(R.styleable.RadioGroupSetting_itemMargin, getDefaultMargin());
int id = attributes.getResourceId(R.styleable.RadioGroupSetting_values, 0);
try {
TypedArray array = context.getResources().obtainTypedArray(id);
if (array.getType(0) == TypedValue.TYPE_STRING) {
mValues = getResources().getStringArray(id);
} else if (array.getType(0) == TypedValue.TYPE_INT_HEX ||
array.getType(0) == TypedValue.TYPE_INT_DEC) {
int [] values = getResources().getIntArray(id);
mValues = new Integer[values.length];
for (int i=0; i<values.length; i++) {
mValues[i] = values[i];
}
}
array.recycle();
} catch (Resources.NotFoundException ignored) {
}
attributes.recycle();
initialize(context, attrs, defStyleAttr, mLayout);
}
public ImageRadioGroupSetting(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RadioGroupSetting, defStyleAttr, 0);
mOptions = new ArrayList<>(Arrays.asList(attributes.getTextArray(R.styleable.RadioGroupSetting_options)));
int id = attributes.getResourceId(R.styleable.RadioGroupSetting_values, 0);
TypedArray array = context.getResources().obtainTypedArray(id);
if (array.getType(0) == TypedValue.TYPE_STRING) {
mValues = new ArrayList<>(Arrays.asList(getResources().getStringArray(id)));
} else if (array.getType(0) == TypedValue.TYPE_INT_HEX ||
array.getType(0) == TypedValue.TYPE_INT_DEC) {
int [] values = getResources().getIntArray(id);
mValues = new ArrayList<>(Arrays.asList(new Integer[values.length]));
for (int value : values) {
mValues.add(value);
}
}
array.recycle();
id = attributes.getResourceId(R.styleable.RadioGroupSetting_images, 0);
array = context.getResources().obtainTypedArray(id);
mImages = new Drawable[mOptions.size()];
for (int i = 0; i < mOptions.size(); ++i) {
mImages[i] = array.getDrawable(i);
}
array.recycle();
attributes.recycle();
initialize(context);
}
/** Create a key with the given top-left coordinate and extract its attributes from
* the XML parser.
* @param res resources associated with the caller's context
* @param parent the row that this key belongs to. The row must already be attached to
* a {@link Keyboard}.
* @param x the x coordinate of the top-left
* @param y the y coordinate of the top-left
* @param parser the XML parser containing the attributes for this key
*/
public Key(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
this(parent);
this.x = x;
this.y = y;
TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
com.android.internal.R.styleable.Keyboard);
width = getDimensionOrFraction(a,
com.android.internal.R.styleable.Keyboard_keyWidth,
keyboard.mDisplayWidth, parent.defaultWidth);
height = getDimensionOrFraction(a,
com.android.internal.R.styleable.Keyboard_keyHeight,
keyboard.mDisplayHeight, parent.defaultHeight);
gap = getDimensionOrFraction(a,
com.android.internal.R.styleable.Keyboard_horizontalGap,
keyboard.mDisplayWidth, parent.defaultHorizontalGap);
a.recycle();
a = res.obtainAttributes(Xml.asAttributeSet(parser),
com.android.internal.R.styleable.Keyboard_Key);
this.x += gap;
TypedValue codesValue = new TypedValue();
a.getValue(com.android.internal.R.styleable.Keyboard_Key_codes,
codesValue);
if (codesValue.type == TypedValue.TYPE_INT_DEC
|| codesValue.type == TypedValue.TYPE_INT_HEX) {
codes = new int[] { codesValue.data };
} else if (codesValue.type == TypedValue.TYPE_STRING) {
codes = parseCSV(codesValue.string.toString());
}
iconPreview = a.getDrawable(com.android.internal.R.styleable.Keyboard_Key_iconPreview);
if (iconPreview != null) {
iconPreview.setBounds(0, 0, iconPreview.getIntrinsicWidth(),
iconPreview.getIntrinsicHeight());
}
popupCharacters = a.getText(
com.android.internal.R.styleable.Keyboard_Key_popupCharacters);
popupResId = a.getResourceId(
com.android.internal.R.styleable.Keyboard_Key_popupKeyboard, 0);
repeatable = a.getBoolean(
com.android.internal.R.styleable.Keyboard_Key_isRepeatable, false);
modifier = a.getBoolean(
com.android.internal.R.styleable.Keyboard_Key_isModifier, false);
sticky = a.getBoolean(
com.android.internal.R.styleable.Keyboard_Key_isSticky, false);
edgeFlags = a.getInt(com.android.internal.R.styleable.Keyboard_Key_keyEdgeFlags, 0);
edgeFlags |= parent.rowEdgeFlags;
icon = a.getDrawable(
com.android.internal.R.styleable.Keyboard_Key_keyIcon);
if (icon != null) {
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
}
label = a.getText(com.android.internal.R.styleable.Keyboard_Key_keyLabel);
text = a.getText(com.android.internal.R.styleable.Keyboard_Key_keyOutputText);
if (codes == null && !TextUtils.isEmpty(label)) {
codes = new int[] { label.charAt(0) };
}
a.recycle();
}
/**
* Create a key with the given top-left coordinate and extract its attributes from
* the XML parser.
*
* @param res resources associated with the caller's context
* @param parent the row that this key belongs to. The row must already be attached to
* a {@link Keyboard}.
* @param x the x coordinate of the top-left
* @param y the y coordinate of the top-left
* @param parser the XML parser containing the attributes for this key
*/
public Key(@NonNull final Resources res,
@NonNull final Keyboard.Row parent,
final int x, final int y,
final XmlResourceParser parser) {
this(parent);
this.x = x;
this.y = y;
TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
width = getDimensionOrFraction(a,
R.styleable.Keyboard_keyWidth,
keyboard.mDisplayWidth, parent.defaultWidth);
height = getDimensionOrFraction(a,
R.styleable.Keyboard_keyHeight,
keyboard.mDisplayHeight, parent.defaultHeight);
gap = getDimensionOrFraction(a,
R.styleable.Keyboard_horizontalGap,
keyboard.mDisplayWidth, parent.defaultHorizontalGap);
a.recycle();
a = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
this.x += gap;
TypedValue codesValue = new TypedValue();
a.getValue(R.styleable.Keyboard_Key_codes, codesValue);
if (DEBUG) Log.i(TAG, "Key:" + codesValue);
if (codesValue.type == TypedValue.TYPE_INT_DEC
|| codesValue.type == TypedValue.TYPE_INT_HEX) {
codes = new int[]{codesValue.data};
} else if (codesValue.type == TypedValue.TYPE_STRING) {
codes = parseCSV(codesValue.string.toString());
}
iconPreview = a.getDrawable(R.styleable.Keyboard_Key_iconPreview);
if (iconPreview != null) {
iconPreview.setBounds(0, 0, iconPreview.getIntrinsicWidth(),
iconPreview.getIntrinsicHeight());
}
popupCharacters = a.getText(
R.styleable.Keyboard_Key_popupCharacters);
popupResId = a.getResourceId(
R.styleable.Keyboard_Key_popupKeyboard, 0);
repeatable = a.getBoolean(
R.styleable.Keyboard_Key_isRepeatable, false);
modifier = a.getBoolean(
R.styleable.Keyboard_Key_isModifier, false);
sticky = a.getBoolean(
R.styleable.Keyboard_Key_isSticky, false);
edgeFlags = a.getInt(R.styleable.Keyboard_Key_keyEdgeFlags, 0);
edgeFlags |= parent.rowEdgeFlags;
icon = a.getDrawable(
R.styleable.Keyboard_Key_keyIcon);
if (icon != null) {
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
}
label = a.getText(R.styleable.Keyboard_Key_keyLabel);
text = a.getText(R.styleable.Keyboard_Key_keyOutputText);
if (codes == null && !TextUtils.isEmpty(label)) {
codes = new int[]{label.charAt(0)};
}
a.recycle();
}