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;
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
the class DaylightHeaderProvider method loadHeaders.
private void loadHeaders() throws XmlPullParserException, IOException {
mHeadersList = new ArrayList<DaylightHeaderInfo>();
InputStream in = null;
XmlPullParser parser = null;
try {
if (mHeaderName == null) {
if (DEBUG)
Log.i(TAG, "Load header pack config daylight_header.xml");
in = mRes.getAssets().open("daylight_header.xml");
} else {
int idx = mHeaderName.lastIndexOf(".");
String headerConfigFile = mHeaderName.substring(idx + 1) + ".xml";
if (DEBUG)
Log.i(TAG, "Load header pack config " + headerConfigFile);
in = mRes.getAssets().open(headerConfigFile);
}
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
parser = factory.newPullParser();
parser.setInput(in, "UTF-8");
loadResourcesFromXmlParser(parser);
} finally {
// Cleanup resources
if (parser instanceof XmlResourceParser) {
((XmlResourceParser) parser).close();
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
Aggregations