List of usage examples for android.content.res XmlResourceParser getAttributeValue
public String getAttributeValue(String namespace, String name);
From source file:org.skt.runtime.api.PluginManager.java
/** * Load plugins from res/xml/plugins.xml *//*from www .jav a 2s . c om*/ public void loadPlugins() { int id = ctx.getResources().getIdentifier("plugins", "xml", ctx.getPackageName()); if (id == 0) { pluginConfigurationMissing(); } XmlResourceParser xml = ctx.getResources().getXml(id); int eventType = -1; String service = "", pluginClass = ""; boolean onload = false; PluginEntry entry = null; while (eventType != XmlResourceParser.END_DOCUMENT) { if (eventType == XmlResourceParser.START_TAG) { String strNode = xml.getName(); if (strNode.equals("plugin")) { service = xml.getAttributeValue(null, "name"); pluginClass = xml.getAttributeValue(null, "value"); // System.out.println("Plugin: "+name+" => "+value); onload = "true".equals(xml.getAttributeValue(null, "onload")); entry = new PluginEntry(service, pluginClass, onload); this.addService(entry); } else if (strNode.equals("url-filter")) { this.urlMap.put(xml.getAttributeValue(null, "value"), service); } } try { eventType = xml.next(); } catch (XmlPullParserException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.apache.cordova.api.PluginManager.java
/** * Load plugins from res/xml/config.xml//w w w. j av a2s.co m */ public void loadPlugins() { int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getClass().getPackage().getName()); 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")); } //What is this? else 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 (paramType.equals("service")) // check if it is using the older service param 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(); } } }
From source file:com.CrestronXPanelApp.CrestronXPanelApp.java
/** * Creates the fragments by parsing the layouts xml document *///from www. java2s. co m public void initializeFragments() { XmlResourceParser xr = getResources().getXml(R.xml.layouts); int eventType = XmlPullParser.END_DOCUMENT; try { eventType = xr.getEventType(); } catch (XmlPullParserException e) { throw new RuntimeException("Cannot parse the layouts file, no way to show"); } while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG && xr.getName().equals("item")) { int layout = xr.getAttributeResourceValue(null, "layout", 0); String name = xr.getAttributeValue(null, "title"); mFragments.add(new FragEntry(AppFragment.newInstance(layout), name)); } try { eventType = xr.next(); } catch (Exception e) { break; // TODO better handling here } } }
From source file:org.apache.cordova.CordovaWebView.java
/** * Load Cordova configuration from res/xml/cordova.xml. * Approved list of URLs that can be loaded into DroidGap * <access origin="http://server regexp" subdomains="true" /> * Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR) * <log level="DEBUG" />/*w ww . ja v a 2 s . c o m*/ */ private void loadConfiguration() { int id = getResources().getIdentifier("config", "xml", this.cordova.getActivity().getPackageName()); if (id == 0) { id = getResources().getIdentifier("cordova", "xml", this.cordova.getActivity().getPackageName()); Log.i("CordovaLog", "config.xml missing, reverting to cordova.xml"); } if (id == 0) { LOG.i("CordovaLog", "cordova.xml missing. Ignoring..."); return; } XmlResourceParser xml = getResources().getXml(id); int eventType = -1; while (eventType != XmlResourceParser.END_DOCUMENT) { if (eventType == XmlResourceParser.START_TAG) { String strNode = xml.getName(); if (strNode.equals("access")) { String origin = xml.getAttributeValue(null, "origin"); String subdomains = xml.getAttributeValue(null, "subdomains"); if (origin != null) { this.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0)); } } else if (strNode.equals("log")) { String level = xml.getAttributeValue(null, "level"); LOG.i("CordovaLog", "Found log level %s", level); if (level != null) { LOG.setLogLevel(level); } } else if (strNode.equals("preference")) { String name = xml.getAttributeValue(null, "name"); String value = xml.getAttributeValue(null, "value"); LOG.i("CordovaLog", "Found preference for %s=%s", name, value); Log.d("CordovaLog", "Found preference for " + name + "=" + value); // Save preferences in Intent this.cordova.getActivity().getIntent().putExtra(name, value); } } try { eventType = xml.next(); } catch (XmlPullParserException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // Init preferences if ("true".equals(this.getProperty("useBrowserHistory", "false"))) { this.useBrowserHistory = true; } else { this.useBrowserHistory = false; } if ("true".equals(this.getProperty("fullscreen", "false"))) { this.cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); this.cordova.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } }
From source file:com.bt.download.android.gui.Librarian.java
/** * This function returns an array of string in the following order: version name, label * @param apk// w w w .j ava2 s . c o m * @return */ private String[] parseApk(Apk apk) { try { String[] result = new String[3]; XmlResourceParser parser = apk.getAndroidManifest(); boolean manifestParsed = true; boolean applicationParsed = false; while (!manifestParsed || !applicationParsed) { int type = parser.next(); if (type == XmlPullParser.END_DOCUMENT) { break; } switch (type) { case XmlPullParser.START_TAG: String tagName = parser.getName(); if (tagName.equals("manifest")) { String versionName = parser.getAttributeValue("http://schemas.android.com/apk/res/android", "versionName"); if (versionName != null && versionName.startsWith("@")) { versionName = apk.getString(Integer.parseInt(versionName.substring(1))); } result[0] = versionName; manifestParsed = true; } if (tagName.equals("application")) { String label = parser.getAttributeValue("http://schemas.android.com/apk/res/android", "label"); if (label != null && label.startsWith("@")) { label = apk.getString(Integer.parseInt(label.substring(1))); } result[1] = label; applicationParsed = true; } break; } } parser.close(); return result; } catch (Throwable e) { return null; } }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
/** * Loads a dictionary or multiple separated dictionary * * @return returns array of dictionary resource ids *//* w w w .ja v a2 s. c o m*/ /* package */static int[] getDictionary(Resources res) { String packageName = LatinIME.class.getPackage().getName(); XmlResourceParser xrp = res.getXml(R.xml.dictionary); ArrayList<Integer> dictionaries = new ArrayList<Integer>(); try { int current = xrp.getEventType(); while (current != XmlResourceParser.END_DOCUMENT) { if (current == XmlResourceParser.START_TAG) { String tag = xrp.getName(); if (tag != null) { if (tag.equals("part")) { String dictFileName = xrp.getAttributeValue(null, "name"); dictionaries.add(res.getIdentifier(dictFileName, "raw", packageName)); } } } xrp.next(); current = xrp.getEventType(); } } catch (XmlPullParserException e) { Log.e(TAG, "Dictionary XML parsing failure"); } catch (IOException e) { Log.e(TAG, "Dictionary XML IOException"); } int count = dictionaries.size(); int[] dict = new int[count]; for (int i = 0; i < count; i++) { dict[i] = dictionaries.get(i); } return dict; }