use of android.content.res.XmlResourceParser in project platform_frameworks_base by android.
the class PreferenceManager method inflateFromIntent.
/**
* Inflates a preference hierarchy from the preference hierarchies of
* {@link Activity Activities} that match the given {@link Intent}. An
* {@link Activity} defines its preference hierarchy with meta-data using
* the {@link #METADATA_KEY_PREFERENCES} key.
* <p>
* If a preference hierarchy is given, the new preference hierarchies will
* be merged in.
*
* @param queryIntent The intent to match activities.
* @param rootPreferences Optional existing hierarchy to merge the new
* hierarchies into.
* @return The root hierarchy (if one was not provided, the new hierarchy's
* root).
*/
PreferenceScreen inflateFromIntent(Intent queryIntent, PreferenceScreen rootPreferences) {
final List<ResolveInfo> activities = queryIntentActivities(queryIntent);
final HashSet<String> inflatedRes = new HashSet<String>();
for (int i = activities.size() - 1; i >= 0; i--) {
final ActivityInfo activityInfo = activities.get(i).activityInfo;
final Bundle metaData = activityInfo.metaData;
if ((metaData == null) || !metaData.containsKey(METADATA_KEY_PREFERENCES)) {
continue;
}
// Need to concat the package with res ID since the same res ID
// can be re-used across contexts
final String uniqueResId = activityInfo.packageName + ":" + activityInfo.metaData.getInt(METADATA_KEY_PREFERENCES);
if (!inflatedRes.contains(uniqueResId)) {
inflatedRes.add(uniqueResId);
final Context context;
try {
context = mContext.createPackageContext(activityInfo.packageName, 0);
} catch (NameNotFoundException e) {
Log.w(TAG, "Could not create context for " + activityInfo.packageName + ": " + Log.getStackTraceString(e));
continue;
}
final PreferenceInflater inflater = new PreferenceInflater(context, this);
final XmlResourceParser parser = activityInfo.loadXmlMetaData(context.getPackageManager(), METADATA_KEY_PREFERENCES);
rootPreferences = (PreferenceScreen) inflater.inflate(parser, rootPreferences, true);
parser.close();
}
}
rootPreferences.onAttachedToHierarchy(this);
return rootPreferences;
}
use of android.content.res.XmlResourceParser in project platform_frameworks_base by android.
the class TextView method setInputExtras.
/**
* Set the extra input data of the text, which is the
* {@link EditorInfo#extras TextBoxAttribute.extras}
* Bundle that will be filled in when creating an input connection. The
* given integer is the resource ID of an XML resource holding an
* {@link android.R.styleable#InputExtras <input-extras>} XML tree.
*
* @see #getInputExtras(boolean)
* @see EditorInfo#extras
* @attr ref android.R.styleable#TextView_editorExtras
*/
public void setInputExtras(@XmlRes int xmlResId) throws XmlPullParserException, IOException {
createEditorIfNeeded();
XmlResourceParser parser = getResources().getXml(xmlResId);
mEditor.createInputContentTypeIfNeeded();
mEditor.mInputContentType.extras = new Bundle();
getResources().parseBundleExtras(parser, mEditor.mInputContentType.extras);
}
use of android.content.res.XmlResourceParser in project platform_frameworks_base by android.
the class XmlConfigSource method ensureInitialized.
private void ensureInitialized() {
synchronized (mLock) {
if (mInitialized) {
return;
}
try (XmlResourceParser parser = mContext.getResources().getXml(mResourceId)) {
parseNetworkSecurityConfig(parser);
mContext = null;
mInitialized = true;
} catch (Resources.NotFoundException | XmlPullParserException | IOException | ParserException e) {
throw new RuntimeException("Failed to parse XML configuration from " + mContext.getResources().getResourceEntryName(mResourceId), e);
}
}
}
use of android.content.res.XmlResourceParser in project platform_frameworks_base by android.
the class PrintServiceInfo method create.
/**
* Creates a new instance.
*
* @param resolveInfo The service resolve info.
* @param context Context for accessing resources.
* @return The created instance.
*/
public static PrintServiceInfo create(ResolveInfo resolveInfo, Context context) {
String settingsActivityName = null;
String addPrintersActivityName = null;
String advancedPrintOptionsActivityName = null;
XmlResourceParser parser = null;
PackageManager packageManager = context.getPackageManager();
parser = resolveInfo.serviceInfo.loadXmlMetaData(packageManager, PrintService.SERVICE_META_DATA);
if (parser != null) {
try {
int type = 0;
while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
type = parser.next();
}
String nodeName = parser.getName();
if (!TAG_PRINT_SERVICE.equals(nodeName)) {
Log.e(LOG_TAG, "Ignoring meta-data that does not start with " + TAG_PRINT_SERVICE + " tag");
} else {
Resources resources = packageManager.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
AttributeSet allAttributes = Xml.asAttributeSet(parser);
TypedArray attributes = resources.obtainAttributes(allAttributes, com.android.internal.R.styleable.PrintService);
settingsActivityName = attributes.getString(com.android.internal.R.styleable.PrintService_settingsActivity);
addPrintersActivityName = attributes.getString(com.android.internal.R.styleable.PrintService_addPrintersActivity);
advancedPrintOptionsActivityName = attributes.getString(com.android.internal.R.styleable.PrintService_advancedPrintOptionsActivity);
attributes.recycle();
}
} catch (IOException ioe) {
Log.w(LOG_TAG, "Error reading meta-data:" + ioe);
} catch (XmlPullParserException xppe) {
Log.w(LOG_TAG, "Error reading meta-data:" + xppe);
} catch (NameNotFoundException e) {
Log.e(LOG_TAG, "Unable to load resources for: " + resolveInfo.serviceInfo.packageName);
} finally {
if (parser != null) {
parser.close();
}
}
}
return new PrintServiceInfo(resolveInfo, settingsActivityName, addPrintersActivityName, advancedPrintOptionsActivityName);
}
use of android.content.res.XmlResourceParser in project cordova-android-chromeview by thedracle.
the class PluginManager method loadPlugins.
/**
* Load plugins from res/xml/config.xml
*/
public void loadPlugins() {
int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
if (id == 0) {
id = this.ctx.getActivity().getResources().getIdentifier("plugins", "xml", this.ctx.getActivity().getPackageName());
LOG.i(TAG, "Using plugins.xml instead of config.xml. plugins.xml will eventually be deprecated");
}
if (id == 0) {
this.pluginConfigurationMissing();
//We have the error, we need to exit without crashing!
return;
}
XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id);
int eventType = -1;
String service = "", pluginClass = "", paramType = "";
boolean onload = false;
boolean insideFeature = false;
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
String strNode = xml.getName();
//This is for the old scheme
if (strNode.equals("plugin")) {
service = xml.getAttributeValue(null, "name");
pluginClass = xml.getAttributeValue(null, "value");
Log.d(TAG, "<plugin> tags are deprecated, please use <features> instead. <plugin> will no longer work as of Cordova 3.0");
onload = "true".equals(xml.getAttributeValue(null, "onload"));
} else //What is this?
if (strNode.equals("url-filter")) {
this.urlMap.put(xml.getAttributeValue(null, "value"), service);
} else if (strNode.equals("feature")) {
//Check for supported feature sets aka. plugins (Accelerometer, Geolocation, etc)
//Set the bit for reading params
insideFeature = true;
service = xml.getAttributeValue(null, "name");
} else if (insideFeature && strNode.equals("param")) {
paramType = xml.getAttributeValue(null, "name");
if (// check if it is using the older service param
paramType.equals("service"))
service = xml.getAttributeValue(null, "value");
else if (paramType.equals("package") || paramType.equals("android-package"))
pluginClass = xml.getAttributeValue(null, "value");
else if (paramType.equals("onload"))
onload = "true".equals(xml.getAttributeValue(null, "value"));
}
} else if (eventType == XmlResourceParser.END_TAG) {
String strNode = xml.getName();
if (strNode.equals("feature") || strNode.equals("plugin")) {
PluginEntry entry = new PluginEntry(service, pluginClass, onload);
this.addService(entry);
//Empty the strings to prevent plugin loading bugs
service = "";
pluginClass = "";
insideFeature = false;
}
}
try {
eventType = xml.next();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations