use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
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 android_frameworks_base by ResurrectionRemix.
the class PowerProfile method readPowerValuesFromXml.
private void readPowerValuesFromXml(Context context) {
int id = com.android.internal.R.xml.power_profile;
final Resources resources = context.getResources();
XmlResourceParser parser = resources.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();
}
// Now collect other config variables.
int[] configResIds = new int[] { com.android.internal.R.integer.config_bluetooth_idle_cur_ma, com.android.internal.R.integer.config_bluetooth_rx_cur_ma, com.android.internal.R.integer.config_bluetooth_tx_cur_ma, com.android.internal.R.integer.config_bluetooth_operating_voltage_mv, com.android.internal.R.integer.config_wifi_idle_receive_cur_ma, com.android.internal.R.integer.config_wifi_active_rx_cur_ma, com.android.internal.R.integer.config_wifi_tx_cur_ma, com.android.internal.R.integer.config_wifi_operating_voltage_mv };
String[] configResIdKeys = new String[] { POWER_BLUETOOTH_CONTROLLER_IDLE, POWER_BLUETOOTH_CONTROLLER_RX, POWER_BLUETOOTH_CONTROLLER_TX, POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE, POWER_WIFI_CONTROLLER_IDLE, POWER_WIFI_CONTROLLER_RX, POWER_WIFI_CONTROLLER_TX, POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE };
for (int i = 0; i < configResIds.length; i++) {
String key = configResIdKeys[i];
// value in config.xml
if ((sPowerMap.containsKey(key) && (Double) sPowerMap.get(key) > 0)) {
continue;
}
int value = resources.getInteger(configResIds[i]);
if (value > 0) {
sPowerMap.put(key, (double) value);
}
}
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
the class MetaDataTest method checkMetaData.
private void checkMetaData(ComponentName cn, PackageItemInfo ci) throws IOException, XmlPullParserException {
assertNotNull("Unable to find component " + cn, ci);
Bundle md = ci.metaData;
assertNotNull("No meta data found", md);
assertEquals("foo", md.getString("com.android.frameworks.coretests.string"));
assertTrue(md.getBoolean("com.android.frameworks.coretests.boolean"));
assertEquals(100, md.getInt("com.android.frameworks.coretests.integer"));
assertEquals(0xff000000, md.getInt("com.android.frameworks.coretests.color"));
assertEquals((double) 1001, Math.floor(md.getFloat("com.android.frameworks.coretests.float") * 10 + .5));
assertEquals(R.xml.metadata, md.getInt("com.android.frameworks.coretests.reference"));
XmlResourceParser xml = ci.loadXmlMetaData(mContext.getPackageManager(), "com.android.frameworks.coretests.reference");
assertNotNull(xml);
int type;
while ((type = xml.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
}
assertEquals(XmlPullParser.START_TAG, type);
assertEquals("thedata", xml.getName());
// method 1: direct access
final String rawAttr = xml.getAttributeValue(null, "rawText");
assertEquals("some raw text", rawAttr);
// method 2: direct access of typed value
final int rawColorIntAttr = xml.getAttributeIntValue(null, "rawColor", 0);
assertEquals(0xffffff00, rawColorIntAttr);
final String rawColorStrAttr = xml.getAttributeValue(null, "rawColor");
assertEquals("#ffffff00", rawColorStrAttr);
// method 2: direct access of resource attribute
final String nameSpace = "http://schemas.android.com/apk/res/android";
final int colorIntAttr = xml.getAttributeIntValue(nameSpace, "color", 0);
assertEquals(0xffff0000, colorIntAttr);
final String colorStrAttr = xml.getAttributeValue(nameSpace, "color");
assertEquals("#ffff0000", colorStrAttr);
// method 3: styled access (borrowing an attr from view system here)
TypedArray a = mContext.obtainStyledAttributes(xml, android.R.styleable.TextView);
String styledAttr = a.getString(android.R.styleable.TextView_text);
assertEquals("text", styledAttr);
a.recycle();
xml.close();
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
the class AudioService method loadTouchSoundAssets.
private void loadTouchSoundAssets() {
XmlResourceParser parser = null;
// only load assets once.
if (!SOUND_EFFECT_FILES.isEmpty()) {
return;
}
loadTouchSoundAssetDefaults();
try {
parser = mContext.getResources().getXml(com.android.internal.R.xml.audio_assets);
XmlUtils.beginDocument(parser, TAG_AUDIO_ASSETS);
String version = parser.getAttributeValue(null, ATTR_VERSION);
boolean inTouchSoundsGroup = false;
if (ASSET_FILE_VERSION.equals(version)) {
while (true) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null) {
break;
}
if (element.equals(TAG_GROUP)) {
String name = parser.getAttributeValue(null, ATTR_GROUP_NAME);
if (GROUP_TOUCH_SOUNDS.equals(name)) {
inTouchSoundsGroup = true;
break;
}
}
}
while (inTouchSoundsGroup) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null) {
break;
}
if (element.equals(TAG_ASSET)) {
String id = parser.getAttributeValue(null, ATTR_ASSET_ID);
String file = parser.getAttributeValue(null, ATTR_ASSET_FILE);
int fx;
try {
Field field = AudioManager.class.getField(id);
fx = field.getInt(null);
} catch (Exception e) {
Log.w(TAG, "Invalid touch sound ID: " + id);
continue;
}
int i = SOUND_EFFECT_FILES.indexOf(file);
if (i == -1) {
i = SOUND_EFFECT_FILES.size();
SOUND_EFFECT_FILES.add(file);
}
SOUND_EFFECT_FILES_MAP[fx][0] = i;
} else {
break;
}
}
}
} catch (Resources.NotFoundException e) {
Log.w(TAG, "audio assets file not found", e);
} catch (XmlPullParserException e) {
Log.w(TAG, "XML parser exception reading touch sound assets", e);
} catch (IOException e) {
Log.w(TAG, "I/O exception reading touch sound assets", e);
} finally {
if (parser != null) {
parser.close();
}
}
}
use of android.content.res.XmlResourceParser in project android_frameworks_base by ResurrectionRemix.
the class VendorConfig method readVendorConfigs.
/**
* Read the vendor configuration file.
*
* @param context The content issuing the read
*
* @return An map pointing from vendor name to config
*
* @throws IOException
* @throws XmlPullParserException
*/
@NonNull
private static ArrayMap<String, VendorConfig> readVendorConfigs(@NonNull final Context context) throws IOException, XmlPullParserException {
try (XmlResourceParser parser = context.getResources().getXml(R.xml.vendorconfigs)) {
// Skip header
int parsingEvent;
do {
parsingEvent = parser.next();
} while (parsingEvent != XmlResourceParser.START_TAG);
ArrayList<VendorConfig> configs = readTagList(parser, VENDORS_TAG, VENDOR_TAG, new TagReader<VendorConfig>() {
public VendorConfig readTag(XmlPullParser parser, String tagName) throws XmlPullParserException, IOException {
return readVendorConfig(context, parser, tagName);
}
});
ArrayMap<String, VendorConfig> configMap = new ArrayMap<>(configs.size());
final int numConfigs = configs.size();
for (int i = 0; i < numConfigs; i++) {
VendorConfig config = configs.get(i);
configMap.put(config.name, config);
}
return configMap;
}
}
Aggregations