List of usage examples for android.content.res XmlResourceParser close
public void close();
From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java
/** * Loads an {@link Animator} object from a resource, context is for loading interpolator. *///from w w w.j a v a 2 s. c o m public static Animator loadAnimator(Context context, Resources resources, Theme theme, @AnimatorRes int id, float pathErrorScale) throws NotFoundException { Animator animator; XmlResourceParser parser = null; try { parser = resources.getAnimation(id); animator = createAnimatorFromXml(context, resources, theme, parser, pathErrorScale); return animator; } catch (XmlPullParserException ex) { Resources.NotFoundException rnf = new Resources.NotFoundException( "Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } catch (IOException ex) { Resources.NotFoundException rnf = new Resources.NotFoundException( "Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } finally { if (parser != null) parser.close(); } }
From source file:org.indywidualni.centrumfm.util.ChangeLog.java
/** * Read change log from XML resource file. * * @param resId Resource ID of the XML file to read the change log from. * @param full If this is {@code true} the full change log is returned. Otherwise only changes for * versions newer than the last version are returned. * @return A {@code SparseArray} containing {@link ReleaseItem}s representing the (partial) * change log.// w w w. java 2s. co m */ @SuppressWarnings("TryFinallyCanBeTryWithResources") protected final SparseArray<ReleaseItem> readChangeLogFromResource(int resId, boolean full) { XmlResourceParser xml = mContext.getResources().getXml(resId); try { return readChangeLog(xml, full); } finally { xml.close(); } }
From source file:android.support.transition.TransitionInflater.java
/** * Loads a {@link Transition} object from a resource * * @param resource The resource id of the transition to load * @return The loaded Transition object/*from w ww .j a v a 2 s .com*/ * @throws android.content.res.Resources.NotFoundException when the * transition cannot be loaded */ public Transition inflateTransition(int resource) { XmlResourceParser parser = mContext.getResources().getXml(resource); try { return createTransitionFromXml(parser, Xml.asAttributeSet(parser), null); } catch (XmlPullParserException e) { throw new InflateException(e.getMessage(), e); } catch (IOException e) { throw new InflateException(parser.getPositionDescription() + ": " + e.getMessage(), e); } finally { parser.close(); } }
From source file:com.givewaygames.transition.TransitionInflater.java
/** * Loads a {@link Transition} object from a resource * * @param resource The resource id of the transition to load * @return The loaded Transition object//from ww w .j a v a2s . c o m * @throws android.content.res.Resources.NotFoundException when the * transition cannot be loaded */ public Transition inflateTransition(int resource) { XmlResourceParser parser = mContext.getResources().getXml(resource); try { return createTransitionFromXml(parser, Xml.asAttributeSet(parser), null); } catch (XmlPullParserException e) { InflateException ex = new InflateException(e.getMessage()); ex.initCause(e); throw ex; } catch (IOException e) { InflateException ex = new InflateException(parser.getPositionDescription() + ": " + e.getMessage()); ex.initCause(e); throw ex; } finally { parser.close(); } }
From source file:android.support.transition.TransitionInflater.java
/** * Loads a {@link TransitionManager} object from a resource * * @param resource The resource id of the transition manager to load * @return The loaded TransitionManager object * @throws android.content.res.Resources.NotFoundException when the * transition manager cannot be loaded *///from ww w . j av a2 s . com public TransitionManager inflateTransitionManager(int resource, ViewGroup sceneRoot) { XmlResourceParser parser = mContext.getResources().getXml(resource); try { return createTransitionManagerFromXml(parser, Xml.asAttributeSet(parser), sceneRoot); } catch (XmlPullParserException e) { InflateException ex = new InflateException(e.getMessage()); ex.initCause(e); throw ex; } catch (IOException e) { InflateException ex = new InflateException(parser.getPositionDescription() + ": " + e.getMessage()); ex.initCause(e); throw ex; } finally { parser.close(); } }
From source file:com.actionbarsherlock.view.MenuInflater.java
/** * Inflate a menu hierarchy from the specified XML resource. Throws * {@link InflateException} if there is an error. * * @param menuRes Resource ID for an XML layout resource to load (e.g., * <code>R.menu.main_activity</code>) * @param menu The Menu to inflate into. The items and submenus will be * added to this Menu./* ww w.j av a2 s . co m*/ */ public void inflate(int menuRes, Menu menu) { XmlResourceParser parser = null; try { parser = mContext.getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs, menu); } catch (XmlPullParserException e) { throw new InflateException("Error inflating menu XML", e); } catch (IOException e) { throw new InflateException("Error inflating menu XML", e); } finally { if (parser != null) parser.close(); } }
From source file:android.support.v7.internal.view.SupportMenuInflater.java
/** * Inflate a menu hierarchy from the specified XML resource. Throws * {@link InflateException} if there is an error. * * @param menuRes Resource ID for an XML layout resource to load (e.g., * <code>R.menu.main_activity</code>) * @param menu The Menu to inflate into. The items and submenus will be * added to this Menu.//from ww w . j a v a2 s.c o m */ @Override public void inflate(int menuRes, Menu menu) { // If we're not dealing with a SupportMenu instance, let super handle if (!(menu instanceof SupportMenu)) { super.inflate(menuRes, menu); return; } XmlResourceParser parser = null; try { parser = mContext.getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs, menu); } catch (XmlPullParserException e) { throw new InflateException("Error inflating menu XML", e); } catch (IOException e) { throw new InflateException("Error inflating menu XML", e); } finally { if (parser != null) parser.close(); } }
From source file:com.entertailion.android.slideshow.utils.Utils.java
/** * Load the list of featured photo web sites from embedded XML file. * //from w ww . java 2 s.c om * @see res/xml/sites.xml * * @param context * @return */ public static ArrayList<SiteInfo> getSites(Context context) { ArrayList<SiteInfo> sites = new ArrayList<SiteInfo>(); XmlResourceParser parser = null; try { Resources r = context.getResources(); int resourceId = r.getIdentifier("sites", "xml", "com.entertailion.android.slideshow"); if (resourceId != 0) { parser = context.getResources().getXml(resourceId); // R.xml.sites parser.next(); int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { switch (eventType) { case XmlPullParser.START_DOCUMENT: break; case XmlPullParser.START_TAG: String tagName = parser.getName(); if (tagName.equalsIgnoreCase("site")) { String name = parser.getAttributeValue(null, "name"); String url = parser.getAttributeValue(null, "url"); sites.add(new SiteInfo(name, url)); } break; } } eventType = parser.next(); } } } catch (Exception e) { Log.e(LOG_TAG, "getSites", e); } finally { if (parser != null) { parser.close(); } } return sites; }
From source file:lewa.support.v7.internal.view.SupportMenuInflater.java
/** * Inflate a menu hierarchy from the specified XML resource. Throws * {@link InflateException} if there is an error. * * @param menuRes Resource ID for an XML layout resource to load (e.g., * <code>R.menu.main_activity</code>) * @param menu The Menu to inflate into. The items and submenus will be * added to this Menu./*from w w w .ja v a2s .co m*/ */ @Override public void inflate(int menuRes, Menu menu) { // If we're not dealing with a SupportMenu instance, let super handle if (!(menu instanceof SupportMenu)) { super.inflate(menuRes, menu); return; } XmlResourceParser parser = null; try { parser = mContext.getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs, menu); } catch (XmlPullParserException e) { throw new InflateException("Error inflating menu XML", e); } catch (IOException e) { throw new InflateException("Error inflating menu XML", e); } finally { if (parser != null) parser.close(); } }
From source file:com.actionbarsherlock.internal.view.menu.MenuInflaterImpl.java
/** * Inflate a menu hierarchy from the specified XML resource. Throws * {@link InflateException} if there is an error. * * @param menuRes Resource ID for an XML layout resource to load (e.g., * <code>R.menu.main_activity</code>) * @param menu The Menu to inflate into. The items and submenus will be * added to this Menu.//from ww w. j av a 2 s .c o m */ public void inflate(int menuRes, android.view.Menu menu) { if (!(menu instanceof MenuBuilder)) { mNativeMenuInflater.inflate(menuRes, menu); return; } MenuBuilder actionBarMenu = (MenuBuilder) menu; XmlResourceParser parser = null; try { parser = mContext.getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs, actionBarMenu); } catch (XmlPullParserException e) { throw new InflateException("Error inflating menu XML", e); } catch (IOException e) { throw new InflateException("Error inflating menu XML", e); } finally { if (parser != null) parser.close(); } }