use of android.content.res.XmlResourceParser in project XobotOS by xamarin.
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 XobotOS by xamarin.
the class PowerProfile method readPowerValuesFromXml.
private void readPowerValuesFromXml(Context context) {
int id = com.android.internal.R.xml.power_profile;
XmlResourceParser parser = context.getResources().getXml(id);
boolean parsingArray = false;
ArrayList<Double> array = new ArrayList<Double>();
String arrayName = null;
try {
XmlUtils.beginDocument(parser, TAG_DEVICE);
while (true) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null)
break;
if (parsingArray && !element.equals(TAG_ARRAYITEM)) {
// Finish array
sPowerMap.put(arrayName, array.toArray(new Double[array.size()]));
parsingArray = false;
}
if (element.equals(TAG_ARRAY)) {
parsingArray = true;
array.clear();
arrayName = parser.getAttributeValue(null, ATTR_NAME);
} else if (element.equals(TAG_ITEM) || element.equals(TAG_ARRAYITEM)) {
String name = null;
if (!parsingArray)
name = parser.getAttributeValue(null, ATTR_NAME);
if (parser.next() == XmlPullParser.TEXT) {
String power = parser.getText();
double value = 0;
try {
value = Double.valueOf(power);
} catch (NumberFormatException nfe) {
}
if (element.equals(TAG_ITEM)) {
sPowerMap.put(name, value);
} else if (parsingArray) {
array.add(value);
}
}
}
}
if (parsingArray) {
sPowerMap.put(arrayName, array.toArray(new Double[array.size()]));
}
} catch (XmlPullParserException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
parser.close();
}
}
use of android.content.res.XmlResourceParser in project XobotOS by xamarin.
the class AutoText method init.
private void init(Resources r) {
XmlResourceParser parser = r.getXml(com.android.internal.R.xml.autotext);
StringBuilder right = new StringBuilder(RIGHT);
mTrie = new char[DEFAULT];
mTrie[TRIE_ROOT] = TRIE_NULL;
mTrieUsed = TRIE_ROOT + 1;
try {
XmlUtils.beginDocument(parser, "words");
String odest = "";
char ooff = 0;
while (true) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null || !(element.equals("word"))) {
break;
}
String src = parser.getAttributeValue(null, "src");
if (parser.next() == XmlPullParser.TEXT) {
String dest = parser.getText();
char off;
if (dest.equals(odest)) {
off = ooff;
} else {
off = (char) right.length();
right.append((char) dest.length());
right.append(dest);
}
add(src, off);
}
}
// Don't let Resources cache a copy of all these strings.
r.flushLayoutCache();
} catch (XmlPullParserException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
parser.close();
}
mText = right.toString();
}
use of android.content.res.XmlResourceParser in project XobotOS by xamarin.
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(int xmlResId) throws XmlPullParserException, IOException {
XmlResourceParser parser = getResources().getXml(xmlResId);
if (mInputContentType == null)
mInputContentType = new InputContentType();
mInputContentType.extras = new Bundle();
getResources().parseBundleExtras(parser, mInputContentType.extras);
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
the class ZoneGetter method readTimezonesToDisplay.
private static List<String> readTimezonesToDisplay(Context context) {
List<String> olsonIds = new ArrayList<String>();
try (XmlResourceParser xrp = context.getResources().getXml(R.xml.timezones)) {
while (xrp.next() != XmlResourceParser.START_TAG) {
continue;
}
xrp.next();
while (xrp.getEventType() != XmlResourceParser.END_TAG) {
while (xrp.getEventType() != XmlResourceParser.START_TAG) {
if (xrp.getEventType() == XmlResourceParser.END_DOCUMENT) {
return olsonIds;
}
xrp.next();
}
if (xrp.getName().equals(XMLTAG_TIMEZONE)) {
String olsonId = xrp.getAttributeValue(0);
olsonIds.add(olsonId);
}
while (xrp.getEventType() != XmlResourceParser.END_TAG) {
xrp.next();
}
xrp.next();
}
} catch (XmlPullParserException xppe) {
Log.e(TAG, "Ill-formatted timezones.xml file");
} catch (java.io.IOException ioe) {
Log.e(TAG, "Unable to read timezones.xml file");
}
return olsonIds;
}
Aggregations