use of android.content.res.TypedArray in project PocketHub by pockethub.
the class AvatarLoader method getMaxAvatarSize.
private int getMaxAvatarSize(final Context context) {
int[] attrs = { android.R.attr.layout_height };
TypedArray array = context.getTheme().obtainStyledAttributes(R.style.AvatarXLarge, attrs);
// Passing default value of 100px, but it shouldn't resolve to default anyway.
int size = array.getLayoutDimension(0, 100);
array.recycle();
return size;
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class SimpleInflater method readItem.
public void readItem(AttributeSet attrs) {
TypedArray a = mContext.obtainStyledAttributes(attrs, com.android.internal.R.styleable.MenuItem);
// Inherit attributes from the group as default value
int itemId = a.getResourceId(R.styleable.MenuItem_android_id, 0);
final int category = a.getInt(R.styleable.MenuItem_android_menuCategory, 0);
final int order = a.getInt(R.styleable.MenuItem_android_orderInCategory, 0);
CharSequence itemTitle = a.getText(R.styleable.MenuItem_android_title);
CharSequence itemTitleCondensed = a.getText(R.styleable.MenuItem_android_titleCondensed);
int itemIconResId = a.getResourceId(R.styleable.MenuItem_android_icon, 0);
String itemAlphabeticShortcut = a.getString(R.styleable.MenuItem_android_alphabeticShortcut);
String itemNumericShortcut = a.getString(R.styleable.MenuItem_android_numericShortcut);
int itemCheckable = 0;
if (a.hasValue(R.styleable.MenuItem_android_checkable)) {
// Item has attribute checkable, use it
itemCheckable = a.getBoolean(R.styleable.MenuItem_android_checkable, false) ? 1 : 0;
}
boolean itemChecked = a.getBoolean(R.styleable.MenuItem_android_checked, false);
boolean itemVisible = a.getBoolean(R.styleable.MenuItem_android_visible, false);
boolean itemEnabled = a.getBoolean(R.styleable.MenuItem_android_enabled, false);
a.recycle();
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class TrustManagerService method getSettingsComponentName.
private ComponentName getSettingsComponentName(PackageManager pm, ResolveInfo resolveInfo) {
if (resolveInfo == null || resolveInfo.serviceInfo == null || resolveInfo.serviceInfo.metaData == null)
return null;
String cn = null;
XmlResourceParser parser = null;
Exception caughtException = null;
try {
parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, TrustAgentService.TRUST_AGENT_META_DATA);
if (parser == null) {
Slog.w(TAG, "Can't find " + TrustAgentService.TRUST_AGENT_META_DATA + " meta-data");
return null;
}
Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Drain preamble.
}
String nodeName = parser.getName();
if (!"trust-agent".equals(nodeName)) {
Slog.w(TAG, "Meta-data does not start with trust-agent tag");
return null;
}
TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.TrustAgent);
cn = sa.getString(com.android.internal.R.styleable.TrustAgent_settingsActivity);
sa.recycle();
} catch (PackageManager.NameNotFoundException e) {
caughtException = e;
} catch (IOException e) {
caughtException = e;
} catch (XmlPullParserException e) {
caughtException = e;
} finally {
if (parser != null)
parser.close();
}
if (caughtException != null) {
Slog.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
return null;
}
if (cn == null) {
return null;
}
if (cn.indexOf('/') < 0) {
cn = resolveInfo.serviceInfo.packageName + "/" + cn;
}
return ComponentName.unflattenFromString(cn);
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class AnimatorInflater method inferValueTypeOfKeyframe.
// When no value type is provided in keyframe, we need to infer the type from the value. i.e.
// if value is defined in the style of a color value, then the color type is returned.
// Otherwise, default float type is returned.
private static int inferValueTypeOfKeyframe(Resources res, Theme theme, AttributeSet attrs) {
int valueType;
TypedArray a;
if (theme != null) {
a = theme.obtainStyledAttributes(attrs, R.styleable.Keyframe, 0, 0);
} else {
a = res.obtainAttributes(attrs, R.styleable.Keyframe);
}
TypedValue keyframeValue = a.peekValue(R.styleable.Keyframe_value);
boolean hasValue = (keyframeValue != null);
// If not, fall back to default value type (i.e. float type).
if (hasValue && isColorType(keyframeValue.type)) {
valueType = VALUE_TYPE_COLOR;
} else {
valueType = VALUE_TYPE_FLOAT;
}
a.recycle();
return valueType;
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class AnimatorInflater method loadValues.
private static PropertyValuesHolder[] loadValues(Resources res, Theme theme, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
ArrayList<PropertyValuesHolder> values = null;
int type;
while ((type = parser.getEventType()) != XmlPullParser.END_TAG && type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
parser.next();
continue;
}
String name = parser.getName();
if (name.equals("propertyValuesHolder")) {
TypedArray a;
if (theme != null) {
a = theme.obtainStyledAttributes(attrs, R.styleable.PropertyValuesHolder, 0, 0);
} else {
a = res.obtainAttributes(attrs, R.styleable.PropertyValuesHolder);
}
String propertyName = a.getString(R.styleable.PropertyValuesHolder_propertyName);
int valueType = a.getInt(R.styleable.PropertyValuesHolder_valueType, VALUE_TYPE_UNDEFINED);
PropertyValuesHolder pvh = loadPvh(res, theme, parser, propertyName, valueType);
if (pvh == null) {
pvh = getPVH(a, valueType, R.styleable.PropertyValuesHolder_valueFrom, R.styleable.PropertyValuesHolder_valueTo, propertyName);
}
if (pvh != null) {
if (values == null) {
values = new ArrayList<PropertyValuesHolder>();
}
values.add(pvh);
}
a.recycle();
}
parser.next();
}
PropertyValuesHolder[] valuesArray = null;
if (values != null) {
int count = values.size();
valuesArray = new PropertyValuesHolder[count];
for (int i = 0; i < count; ++i) {
valuesArray[i] = values.get(i);
}
}
return valuesArray;
}
Aggregations