use of android.content.res.XmlResourceParser in project android_frameworks_base by ParanoidAndroid.
the class InputManagerService method visitKeyboardLayoutsInPackage.
private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, String keyboardName, KeyboardLayoutVisitor visitor) {
Bundle metaData = receiver.metaData;
if (metaData == null) {
return;
}
int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
if (configResId == 0) {
Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS + "' on receiver " + receiver.packageName + "/" + receiver.name);
return;
}
CharSequence receiverLabel = receiver.loadLabel(pm);
String collection = receiverLabel != null ? receiverLabel.toString() : "";
try {
Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
XmlResourceParser parser = resources.getXml(configResId);
try {
XmlUtils.beginDocument(parser, "keyboard-layouts");
for (; ; ) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null) {
break;
}
if (element.equals("keyboard-layout")) {
TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.KeyboardLayout);
try {
String name = a.getString(com.android.internal.R.styleable.KeyboardLayout_name);
String label = a.getString(com.android.internal.R.styleable.KeyboardLayout_label);
int keyboardLayoutResId = a.getResourceId(com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, 0);
if (name == null || label == null || keyboardLayoutResId == 0) {
Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " + "attributes in keyboard layout " + "resource from receiver " + receiver.packageName + "/" + receiver.name);
} else {
String descriptor = KeyboardLayoutDescriptor.format(receiver.packageName, receiver.name, name);
if (keyboardName == null || name.equals(keyboardName)) {
visitor.visitKeyboardLayout(resources, descriptor, label, collection, keyboardLayoutResId);
}
}
} finally {
a.recycle();
}
} else {
Log.w(TAG, "Skipping unrecognized element '" + element + "' in keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name);
}
}
} finally {
parser.close();
}
} catch (Exception ex) {
Log.w(TAG, "Could not parse keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name, ex);
}
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ParanoidAndroid.
the class UsbSettingsManager method handlePackageUpdateLocked.
private boolean handlePackageUpdateLocked(String packageName, ActivityInfo aInfo, String metaDataName) {
XmlResourceParser parser = null;
boolean changed = false;
try {
parser = aInfo.loadXmlMetaData(mPackageManager, metaDataName);
if (parser == null)
return false;
XmlUtils.nextElement(parser);
while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
String tagName = parser.getName();
if ("usb-device".equals(tagName)) {
DeviceFilter filter = DeviceFilter.read(parser);
if (clearCompatibleMatchesLocked(packageName, filter)) {
changed = true;
}
} else if ("usb-accessory".equals(tagName)) {
AccessoryFilter filter = AccessoryFilter.read(parser);
if (clearCompatibleMatchesLocked(packageName, filter)) {
changed = true;
}
}
XmlUtils.nextElement(parser);
}
} catch (Exception e) {
Slog.w(TAG, "Unable to load component info " + aInfo.toString(), e);
} finally {
if (parser != null)
parser.close();
}
return changed;
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ParanoidAndroid.
the class SimpleInflater method inflate.
public void inflate(int menuRes) {
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs);
} catch (XmlPullParserException e) {
throw new InflateException("Error inflating menu XML", e);
} catch (IOException e) {
throw new InflateException("Error inflating menu XML", e);
} finally {
if (parser != null)
parser.close();
}
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ParanoidAndroid.
the class LayoutInflater_Delegate method parseInclude.
@LayoutlibDelegate
public static void parseInclude(LayoutInflater thisInflater, XmlPullParser parser, View parent, AttributeSet attrs) throws XmlPullParserException, IOException {
int type;
if (parent instanceof ViewGroup) {
final int layout = attrs.getAttributeResourceValue(null, "layout", 0);
if (layout == 0) {
final String value = attrs.getAttributeValue(null, "layout");
if (value == null) {
throw new InflateException("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
} else {
throw new InflateException("You must specifiy a valid layout " + "reference. The layout ID " + value + " is not valid.");
}
} else {
final XmlResourceParser childParser = thisInflater.getContext().getResources().getLayout(layout);
try {
final AttributeSet childAttrs = Xml.asAttributeSet(childParser);
while ((type = childParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty.
}
if (type != XmlPullParser.START_TAG) {
throw new InflateException(childParser.getPositionDescription() + ": No start tag found!");
}
final String childName = childParser.getName();
if (TAG_MERGE.equals(childName)) {
// Inflate all children.
thisInflater.rInflate(childParser, parent, childAttrs, false);
} else {
final View view = thisInflater.createViewFromTag(parent, childName, childAttrs);
final ViewGroup group = (ViewGroup) parent;
// We try to load the layout params set in the <include /> tag. If
// they don't exist, we will rely on the layout params set in the
// included XML file.
// During a layoutparams generation, a runtime exception is thrown
// if either layout_width or layout_height is missing. We catch
// this exception and set localParams accordingly: true means we
// successfully loaded layout params from the <include /> tag,
// false means we need to rely on the included layout params.
ViewGroup.LayoutParams params = null;
try {
// ---- START CHANGES
sIsInInclude = true;
// ---- END CHANGES
params = group.generateLayoutParams(attrs);
} catch (RuntimeException e) {
// ---- START CHANGES
sIsInInclude = false;
// ---- END CHANGES
params = group.generateLayoutParams(childAttrs);
} finally {
// ---- START CHANGES
sIsInInclude = false;
if (params != null) {
view.setLayoutParams(params);
}
}
// Inflate all children.
thisInflater.rInflate(childParser, view, childAttrs, true);
// Attempt to override the included layout's android:id with the
// one set on the <include /> tag itself.
TypedArray a = thisInflater.mContext.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, 0, 0);
int id = a.getResourceId(com.android.internal.R.styleable.View_id, View.NO_ID);
// While we're at it, let's try to override android:visibility.
int visibility = a.getInt(com.android.internal.R.styleable.View_visibility, -1);
a.recycle();
if (id != View.NO_ID) {
view.setId(id);
}
switch(visibility) {
case 0:
view.setVisibility(View.VISIBLE);
break;
case 1:
view.setVisibility(View.INVISIBLE);
break;
case 2:
view.setVisibility(View.GONE);
break;
}
group.addView(view);
}
} finally {
childParser.close();
}
}
} else {
throw new InflateException("<include /> can only be used inside of a ViewGroup");
}
final int currentDepth = parser.getDepth();
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) {
// Empty
}
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ParanoidAndroid.
the class AliasActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
XmlResourceParser parser = null;
try {
ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
parser = ai.loadXmlMetaData(getPackageManager(), ALIAS_META_DATA);
if (parser == null) {
throw new RuntimeException("Alias requires a meta-data field " + ALIAS_META_DATA);
}
Intent intent = parseAlias(parser);
if (intent == null) {
throw new RuntimeException("No <intent> tag found in alias description");
}
startActivity(intent);
finish();
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException("Error parsing alias", e);
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing alias", e);
} catch (IOException e) {
throw new RuntimeException("Error parsing alias", e);
} finally {
if (parser != null)
parser.close();
}
}
Aggregations