Java Code Examples for android.content.res.Resources#getXml()
The following examples show how to use
android.content.res.Resources#getXml() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyboardLayoutSet.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) { final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype); final int xmlId = getXmlId(resources, layoutSetName); final XmlResourceParser parser = resources.getXml(xmlId); try { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { // Bovinate through the XML stupidly searching for TAG_FEATURE, and read // the script Id from it. parser.next(); final String tag = parser.getName(); if (TAG_FEATURE.equals(tag)) { return readScriptIdFromTagFeature(resources, parser); } } } catch (final IOException | XmlPullParserException e) { throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e); } finally { parser.close(); } // If the tag is not found, then the default script is Latin. return ScriptUtils.SCRIPT_LATIN; }
Example 2
Source File: DefaultLayoutParser.java From LB-Launcher with Apache License 2.0 | 6 votes |
@Override public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException, IOException { // Folder contents come from an external XML resource final Partner partner = Partner.get(mPackageManager); if (partner != null) { final Resources partnerRes = partner.getResources(); final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER, "xml", partner.getPackageName()); if (resId != 0) { final XmlResourceParser partnerParser = partnerRes.getXml(resId); beginDocument(partnerParser, TAG_FOLDER); FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes)); return folderParser.parseAndAdd(partnerParser); } } return -1; }
Example 3
Source File: VectorDrawable.java From Mover with Apache License 2.0 | 6 votes |
/** @hide */ static VectorDrawable create(Resources resources, int rid) { android.util.Log.i("SupportVectorDrawable", resources.getResourceEntryName(rid)); try { final XmlPullParser parser = resources.getXml(rid); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } final VectorDrawable drawable = new VectorDrawable(); drawable.mResourceName = resources.getResourceEntryName(rid); drawable.inflate(resources, parser, attrs); return drawable; } catch (XmlPullParserException | IOException e) { Log.e(LOGTAG, "parser error", e); } return null; }
Example 4
Source File: DefaultLayoutParser.java From Trebuchet with GNU General Public License v3.0 | 6 votes |
@Override public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException, IOException { // Folder contents come from an external XML resource final Partner partner = Partner.get(mPackageManager); if (partner != null) { final Resources partnerRes = partner.getResources(); final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER, "xml", partner.getPackageName()); if (resId != 0) { final XmlResourceParser partnerParser = partnerRes.getXml(resId); beginDocument(partnerParser, TAG_FOLDER); FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes)); return folderParser.parseAndAdd(partnerParser); } } return -1; }
Example 5
Source File: KeyboardLayoutSet.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
private void parseKeyboardLayoutSet(final Resources res, final int resId) throws XmlPullParserException, IOException { final XmlResourceParser parser = res.getXml(resId); try { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { final int event = parser.next(); if (event == XmlPullParser.START_TAG) { final String tag = parser.getName(); if (TAG_KEYBOARD_SET.equals(tag)) { parseKeyboardLayoutSetContent(parser); } else { throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); } } } } finally { parser.close(); } }
Example 6
Source File: KeyboardLayoutSet.java From simple-keyboard with Apache License 2.0 | 6 votes |
private void parseKeyboardLayoutSet(final Resources res, final int resId) throws XmlPullParserException, IOException { final XmlResourceParser parser = res.getXml(resId); try { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { final int event = parser.next(); if (event == XmlPullParser.START_TAG) { final String tag = parser.getName(); if (TAG_KEYBOARD_SET.equals(tag)) { parseKeyboardLayoutSetContent(parser); } else { throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); } } } } finally { parser.close(); } }
Example 7
Source File: DefaultLayoutParser.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
@Override public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException, IOException { // Folder contents come from an external XML resource final Partner partner = Partner.get(mPackageManager); if (partner != null) { final Resources partnerRes = partner.getResources(); final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER, "xml", partner.getPackageName()); if (resId != 0) { final XmlResourceParser partnerParser = partnerRes.getXml(resId); beginDocument(partnerParser, TAG_FOLDER); FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes)); return folderParser.parseAndAdd(partnerParser); } } return -1; }
Example 8
Source File: IconPackHelper.java From DistroHopper with GNU General Public License v3.0 | 6 votes |
public void loadIconPack (String packageName) throws PackageManager.NameNotFoundException, IOException, XmlPullParserException { PackageManager pacMan = this.context.getPackageManager (); Resources res = pacMan.getResourcesForApplication (packageName); /*InputStream stream = res.getAssets ().open ("appfilter.xml"); XmlPullParser parser = XmlPullParserFactory.newInstance ().newPullParser (); parser.setInput (stream, "UTF-8");*/ int resId = res.getIdentifier ("appfilter", "xml", packageName); XmlPullParser parser = res.getXml (resId); this.name = packageName; this.iconPackLoaded = true; this.resources = res; this.parseXml (parser); }
Example 9
Source File: KeyboardLayoutSet.java From openboard with GNU General Public License v3.0 | 6 votes |
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) { final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype); final int xmlId = getXmlId(resources, layoutSetName); final XmlResourceParser parser = resources.getXml(xmlId); try { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { // Bovinate through the XML stupidly searching for TAG_FEATURE, and read // the script Id from it. parser.next(); final String tag = parser.getName(); if (TAG_FEATURE.equals(tag)) { return readScriptIdFromTagFeature(resources, parser); } } } catch (final IOException | XmlPullParserException e) { throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e); } finally { parser.close(); } // If the tag is not found, then the default script is Latin. return ScriptUtils.SCRIPT_LATIN; }
Example 10
Source File: KeyboardLayoutSet.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
private void parseKeyboardLayoutSet(final Resources res, final int resId) throws XmlPullParserException, IOException { final XmlResourceParser parser = res.getXml(resId); try { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { final int event = parser.next(); if (event == XmlPullParser.START_TAG) { final String tag = parser.getName(); if (TAG_KEYBOARD_SET.equals(tag)) { parseKeyboardLayoutSetContent(parser); } else { throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); } } } } finally { parser.close(); } }
Example 11
Source File: IconsManager.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
private void loadAllDrawables(String packageName) { mDrawables.clear(); XmlPullParser xpp; try { Resources res = mPackageManager.getResourcesForApplication(packageName); mCurrentIconPackRes = res; int resource = res.getIdentifier("drawable", "xml", packageName); if (resource < 0) { return; } xpp = res.getXml(resource); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xpp.getName().equals("item")) { String drawableName = xpp.getAttributeValue(null, "drawable"); if (!mDrawables.contains(drawableName) && getIdentifier(packageName, drawableName, true) > 0) { mDrawables.add(drawableName); } } } eventType = xpp.next(); } } catch (Exception e) { e.printStackTrace(); // fallback onto appfilter if drawable xml fails loadIconPack(packageName, true, mContext); } }
Example 12
Source File: ZenModeHelper.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private ZenModeConfig readDefaultConfig(Resources resources) { XmlResourceParser parser = null; try { parser = resources.getXml(R.xml.default_zen_mode_config); while (parser.next() != XmlPullParser.END_DOCUMENT) { final ZenModeConfig config = ZenModeConfig.readXml(parser); if (config != null) return config; } } catch (Exception e) { Log.w(TAG, "Error reading default zen mode config from resource", e); } finally { IoUtils.closeQuietly(parser); } return new ZenModeConfig(); }
Example 13
Source File: AppfilterReader.java From NanoIconPack with Apache License 2.0 | 5 votes |
private boolean init(@NonNull Resources resources) { try { XmlResourceParser parser = resources.getXml(R.xml.appfilter); int event = parser.getEventType(); while (event != XmlPullParser.END_DOCUMENT) { if (event == XmlPullParser.START_TAG) { if (!"item".equals(parser.getName())) { event = parser.next(); continue; } String drawable = parser.getAttributeValue(null, "drawable"); if (TextUtils.isEmpty(drawable)) { event = parser.next(); continue; } String component = parser.getAttributeValue(null, "component"); if (TextUtils.isEmpty(component)) { event = parser.next(); continue; } Matcher matcher = componentPattern.matcher(component); if (!matcher.matches()) { event = parser.next(); continue; } dataList.add(new Bean(matcher.group(1), matcher.group(2), drawable)); } event = parser.next(); } return true; } catch (Exception e) { e.printStackTrace(); } return false; }
Example 14
Source File: MdVectorDrawableCompat.java From android-md-core with Apache License 2.0 | 5 votes |
@Nullable public static VectorDrawableCompat create(@NonNull Context context, @DrawableRes int resId) { Resources res = context.getResources(); Resources.Theme theme = context.getTheme(); VectorDrawableCompat drawable = VectorDrawableCompat.create(res, resId, theme); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { try { XmlPullParser parser = res.getXml(resId); AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } TypedArray a = theme.obtainStyledAttributes(attrs, new int[]{ android.R.attr.tint }, 0, 0); int tintId = a.getResourceId(0, 0); a.recycle(); drawable.setTintList(MdCompat.getColorStateList(context, tintId)); } catch (Exception e) { Ln.d(e); } } return drawable; }
Example 15
Source File: XmlConfigSource.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private NetworkSecurityConfig.Builder parseDebugOverridesResource() throws IOException, XmlPullParserException, ParserException { Resources resources = mContext.getResources(); String packageName = resources.getResourcePackageName(mResourceId); String entryName = resources.getResourceEntryName(mResourceId); int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName); // No debug-overrides resource was found, nothing to parse. if (resId == 0) { return null; } NetworkSecurityConfig.Builder debugConfigBuilder = null; // Parse debug-overrides out of the _debug resource. try (XmlResourceParser parser = resources.getXml(resId)) { XmlUtils.beginDocument(parser, "network-security-config"); int outerDepth = parser.getDepth(); boolean seenDebugOverrides = false; while (XmlUtils.nextElementWithin(parser, outerDepth)) { if ("debug-overrides".equals(parser.getName())) { if (seenDebugOverrides) { throw new ParserException(parser, "Only one debug-overrides allowed"); } if (mDebugBuild) { debugConfigBuilder = parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { XmlUtils.skipCurrentTag(parser); } seenDebugOverrides = true; } else { XmlUtils.skipCurrentTag(parser); } } } return debugConfigBuilder; }
Example 16
Source File: DeviceActivity.java From SensorTag-CC2650 with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); Intent intent = getIntent(); // BLE mBtLeService = BluetoothLeService.getInstance(); mBluetoothDevice = intent.getParcelableExtra(EXTRA_DEVICE); mServiceList = new ArrayList<BluetoothGattService>(); mIsSensorTag2 = false; // Determine type of SensorTagGatt String deviceName = mBluetoothDevice.getName(); if ((deviceName.equals("SensorTag2")) ||(deviceName.equals("CC2650 SensorTag"))) { mIsSensorTag2 = true; } else mIsSensorTag2 = false; PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Log.i(TAG, "Preferences for: " + deviceName); // GUI mDeviceView = new DeviceView(); mSectionsPagerAdapter.addSection(mDeviceView, "Sensors"); HelpView hw = new HelpView(); hw.setParameters("help_device.html", R.layout.fragment_help, R.id.webpage); mSectionsPagerAdapter.addSection(hw, "Help"); mProfiles = new ArrayList<GenericBluetoothProfile>(); progressDialog = new ProgressDialog(DeviceActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setIndeterminate(true); progressDialog.setTitle("Discovering Services"); progressDialog.setMessage(""); progressDialog.setMax(100); progressDialog.setProgress(0); progressDialog.show(); // GATT database Resources res = getResources(); XmlResourceParser xpp = res.getXml(R.xml.gatt_uuid); new GattInfo(xpp); }
Example 17
Source File: XmlConfigSource.java From cwac-netsecurity with Apache License 2.0 | 4 votes |
private NetworkSecurityConfig.Builder parseDebugOverridesResource() throws IOException, XmlPullParserException, ParserException { Resources resources = mContext.getResources(); String packageName = resources.getResourcePackageName(mResourceId); String entryName = resources.getResourceEntryName(mResourceId); int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName); // No debug-overrides resource was found, nothing to parse. if (resId == 0) { return null; } NetworkSecurityConfig.Builder debugConfigBuilder = null; // Parse debug-overrides out of the _debug resource. XmlResourceParser parser=null; try { parser = resources.getXml(resId); XmlUtils.beginDocument(parser, "network-security-config"); int outerDepth = parser.getDepth(); boolean seenDebugOverrides = false; while (XmlUtils.nextElementWithin(parser, outerDepth)) { if ("debug-overrides".equals(parser.getName())) { if (seenDebugOverrides) { throw new ParserException(parser, "Only one debug-overrides allowed"); } if (mDebugBuild) { debugConfigBuilder = parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { XmlUtils.skipCurrentTag(parser); } seenDebugOverrides = true; } else { XmlUtils.skipCurrentTag(parser); } } } finally { if (parser!=null) parser.close(); } return debugConfigBuilder; }
Example 18
Source File: PanelMenuFragment.java From trekarta with GNU General Public License v3.0 | 4 votes |
/** * Parse the given XML file as a header description, adding each * parsed Header into the target list. * * @param resId The XML resource to load and parse. * @param target The list in which the parsed headers should be placed. */ @SuppressWarnings("ResourceType") private void loadHeadersFromResource(@MenuRes int resId, List<PanelMenuItem> target) { Resources resources = getResources(); try (XmlResourceParser parser = resources.getXml(resId)) { AttributeSet attrs = Xml.asAttributeSet(parser); int type; //noinspection StatementWithEmptyBody while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) { // Parse next until start tag is found } String nodeName = parser.getName(); if (!"menu".equals(nodeName)) { throw new RuntimeException("XML document must start with <menu> tag; found" + nodeName + " at " + parser.getPositionDescription()); } final int outerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } nodeName = parser.getName(); if ("item".equals(nodeName)) { PanelMenuItem item = new PanelMenuItem(getContext()); int[] set = { android.R.attr.id, android.R.attr.title, android.R.attr.icon, android.R.attr.checkable, android.R.attr.actionLayout }; TypedArray sa = getContext().obtainStyledAttributes(attrs, set); item.setItemId(sa.getResourceId(0, PanelMenuItem.HEADER_ID_UNDEFINED)); TypedValue tv = sa.peekValue(1); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { item.setTitle(tv.resourceId); } else { item.setTitle(tv.string); } } int iconRes = sa.getResourceId(2, 0); if (iconRes != 0) item.setIcon(iconRes); item.setCheckable(sa.getBoolean(3, false)); int actionRes = sa.getResourceId(4, 0); if (actionRes != 0) item.setActionView(actionRes); sa.recycle(); target.add(item); } else { XmlUtils.skipCurrentTag(parser); } } } catch (XmlPullParserException | IOException e) { throw new RuntimeException("Error parsing headers", e); } }
Example 19
Source File: DefaultXmlParser.java From clevertap-android-sdk with MIT License | 4 votes |
static HashMap<String, String> getDefaultsFromXml(Context context, int resourceId) { HashMap<String,String> defaultsMap = new HashMap<>(); try { Resources resources = context.getResources(); if (resources == null) { Log.e("ProductConfig", "Could not find the resources of the current context while trying to set defaults from an XML."); return defaultsMap; } XmlResourceParser xmlParser = resources.getXml(resourceId); String curTag = null; String key = null; String value = null; for (int eventType = xmlParser.getEventType(); eventType != XmlPullParser.END_DOCUMENT; eventType = xmlParser.next()) { if (eventType == XmlPullParser.START_TAG) { curTag = xmlParser.getName(); } else if (eventType != XmlPullParser.END_TAG) { if (eventType == XmlPullParser.TEXT && curTag != null) { byte tagType = -1; switch (curTag) { case XML_TAG_KEY: tagType = XML_TAG_TYPE_KEY; break; case XML_TAG_VALUE: tagType = XML_TAG_TYPE_VALUE; } switch (tagType) { case XML_TAG_TYPE_KEY: key = xmlParser.getText(); break; case XML_TAG_TYPE_VALUE: value = xmlParser.getText(); break; default: Log.w(LOG_TAG_PRODUCT_CONFIG, "Encountered an unexpected tag while parsing the defaults XML."); } } } else { if (xmlParser.getName().equals(XML_TAG_ENTRY)) { if (key != null && value != null) { defaultsMap.put(key, value); } else { Log.w(LOG_TAG_PRODUCT_CONFIG, "An entry in the defaults XML has an invalid key and/or value tag."); } key = null; value = null; } curTag = null; } } } catch (IOException | XmlPullParserException var11) { Log.e("ProductConfig", "Encountered an error while parsing the defaults XML file.", var11); } return defaultsMap; }
Example 20
Source File: TabConfig.java From opentasks with Apache License 2.0 | 3 votes |
/** * Loads a {@link TabConfig} from the given XML resource. * <p> * A tabconfig XML file must looke like this: * </p> * <p> * <pre> * <tabconfig xmlns="http://schema.dmfs.org/tasks" > * * <tab * id="@+id/tab1_id" * icon="@drawable/tab1_icon" * title="@string/tab1_title" /> * <tab * id="@+id/tab2_id" * icon="@drawable/tab2_icon" * title="@string/tab2_title" * visible="false"/> * </tabconfig> * </pre> * * @param context * A {@link Context}. * @param tabsResource * The resource id of an XML resource that contains the tabconfig. * * @return A {@link TabConfig} instance. * * @throws XmlPullParserException * @throws IOException * @throws XmlObjectPullParserException */ public static TabConfig load(Context context, int tabsResource) throws XmlPullParserException, IOException, XmlObjectPullParserException { Resources res = context.getResources(); XmlResourceParser parser = res.getXml(tabsResource); XmlObjectPull objectParser = new XmlObjectPull(parser, new AndroidParserContext(context, null)); TabConfig groupings = objectParser.pull(DESCRIPTOR, null, new XmlPath()); groupings.updateVisible(); return groupings; }