/// <summary> /// Loads an /// <see cref="Animation">Animation</see> /// object from a resource /// </summary> /// <param name="context">Application context used to access resources</param> /// <param name="id">The resource id of the animation to load</param> /// <returns>The animation object reference by the specified id</returns> /// <exception cref="android.content.res.Resources.NotFoundException">when the animation cannot be loaded /// </exception> public static android.view.animation.Animation loadAnimation(android.content.Context context, int id) { android.content.res.XmlResourceParser parser = null; try { parser = context.getResources().getAnimation(id); return(createAnimationFromXml(context, parser)); } catch (org.xmlpull.v1.XmlPullParserException ex) { android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("Can't load animation resource ID #0x" + Sharpen.Util.IntToHexString (id)); rnf.InnerException = ex; throw rnf; } catch (System.IO.IOException ex) { android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("Can't load animation resource ID #0x" + Sharpen.Util.IntToHexString (id)); rnf.InnerException = ex; throw rnf; } finally { if (parser != null) { parser.close(); } } }
/// <summary> /// Loads an /// <see cref="Animation">Animation</see> /// object from a resource /// </summary> /// <param name="context">Application context used to access resources</param> /// <param name="id">The resource id of the animation to load</param> /// <returns>The animation object reference by the specified id</returns> /// <exception cref="android.content.res.Resources.NotFoundException">when the animation cannot be loaded /// </exception> public static android.view.animation.Animation loadAnimation(android.content.Context context, int id) { android.content.res.XmlResourceParser parser = null; try { parser = context.getResources().getAnimation(id); return createAnimationFromXml(context, parser); } catch (org.xmlpull.v1.XmlPullParserException ex) { android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("Can't load animation resource ID #0x" + Sharpen.Util.IntToHexString (id)); rnf.InnerException = ex; throw rnf; } catch (System.IO.IOException ex) { android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("Can't load animation resource ID #0x" + Sharpen.Util.IntToHexString (id)); rnf.InnerException = ex; throw rnf; } finally { if (parser != null) { parser.close(); } } }
/// <exception cref="android.content.res.Resources.NotFoundException"></exception> internal virtual android.content.res.XmlResourceParser loadXmlResourceParser(string file, int id, int assetCookie, string type) { if (id != 0) { try { // These may be compiled... lock (mCachedXmlBlockIds) { // First see if this block is in our cache. int num = mCachedXmlBlockIds.Length; { for (int i = 0; i < num; i++) { if (mCachedXmlBlockIds[i] == id) { //System.out.println("**** REUSING XML BLOCK! id=" // + id + ", index=" + i); return mCachedXmlBlocks[i].newParser(); } } } // Not in the cache, create a new block and put it at // the next slot in the cache. android.content.res.XmlBlock block = mAssets.openXmlBlockAsset(assetCookie, file); if (block != null) { int pos = mLastCachedXmlBlockIndex + 1; if (pos >= num) { pos = 0; } mLastCachedXmlBlockIndex = pos; android.content.res.XmlBlock oldBlock = mCachedXmlBlocks[pos]; if (oldBlock != null) { oldBlock.close(); } mCachedXmlBlockIds[pos] = id; mCachedXmlBlocks[pos] = block; //System.out.println("**** CACHING NEW XML BLOCK! id=" // + id + ", index=" + pos); return block.newParser(); } } } catch (System.Exception e) { android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("File " + file + " from xml type " + type + " resource ID #0x" + Sharpen.Util.IntToHexString(id)); rnf.InnerException = e; throw rnf; } } throw new android.content.res.Resources.NotFoundException("File " + file + " from xml type " + type + " resource ID #0x" + Sharpen.Util.IntToHexString(id)); }
/// <exception cref="android.content.res.Resources.NotFoundException"></exception> internal virtual android.content.res.ColorStateList loadColorStateList(android.util.TypedValue value, int id) { // Log only framework resources int key = (value.assetCookie << 24) | value.data; android.content.res.ColorStateList csl; if (value.type >= android.util.TypedValue.TYPE_FIRST_COLOR_INT && value.type <= android.util.TypedValue .TYPE_LAST_COLOR_INT) { csl = mPreloadedColorStateLists.get(key); if (csl != null) { return csl; } csl = android.content.res.ColorStateList.valueOf(value.data); if (mPreloading) { mPreloadedColorStateLists.put(key, csl); } return csl; } csl = getCachedColorStateList(key); if (csl != null) { return csl; } csl = mPreloadedColorStateLists.get(key); if (csl != null) { return csl; } if (value.@string == null) { throw new android.content.res.Resources.NotFoundException("Resource is not a ColorStateList (color or path): " + value); } string file = [email protected](); if (file.EndsWith(".xml")) { try { android.content.res.XmlResourceParser rp = loadXmlResourceParser(file, id, value. assetCookie, "colorstatelist"); csl = android.content.res.ColorStateList.createFromXml(this, rp); rp.close(); } catch (System.Exception e) { android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("File " + file + " from color state list resource ID #0x" + Sharpen.Util.IntToHexString (id)); rnf.InnerException = e; throw rnf; } } else { throw new android.content.res.Resources.NotFoundException("File " + file + " from drawable resource ID #0x" + Sharpen.Util.IntToHexString(id) + ": .xml extension required"); } if (csl != null) { if (mPreloading) { mPreloadedColorStateLists.put(key, csl); } else { lock (mTmpValue) { //Log.i(TAG, "Saving cached color state list @ #" + // Integer.toHexString(key.intValue()) // + " in " + this + ": " + csl); mColorStateListCache.put(key, new [email protected]<android.content.res.ColorStateList >(csl)); } } } return csl; }
/// <exception cref="android.content.res.Resources.NotFoundException"></exception> internal virtual android.graphics.drawable.Drawable loadDrawable(android.util.TypedValue value, int id) { // Log only framework resources long key = (((long)value.assetCookie) << 32) | value.data; bool isColorDrawable = false; if (value.type >= android.util.TypedValue.TYPE_FIRST_COLOR_INT && value.type <= android.util.TypedValue .TYPE_LAST_COLOR_INT) { isColorDrawable = true; } android.graphics.drawable.Drawable dr = getCachedDrawable(isColorDrawable ? mColorDrawableCache : mDrawableCache, key); if (dr != null) { return dr; } android.graphics.drawable.Drawable.ConstantState cs = isColorDrawable ? sPreloadedColorDrawables .get(key) : sPreloadedDrawables.get(key); if (cs != null) { dr = cs.newDrawable(this); } else { if (value.type >= android.util.TypedValue.TYPE_FIRST_COLOR_INT && value.type <= android.util.TypedValue .TYPE_LAST_COLOR_INT) { dr = new android.graphics.drawable.ColorDrawable(value.data); } if (dr == null) { if (value.@string == null) { throw new android.content.res.Resources.NotFoundException("Resource is not a Drawable (color or path): " + value); } string file = [email protected](); // Log only framework resources if (file.EndsWith(".xml")) { try { android.content.res.XmlResourceParser rp = loadXmlResourceParser(file, id, value. assetCookie, "drawable"); dr = android.graphics.drawable.Drawable.createFromXml(this, rp); rp.close(); } catch (System.Exception e) { android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("File " + file + " from drawable resource ID #0x" + Sharpen.Util.IntToHexString (id)); rnf.InnerException = e; throw rnf; } } else { try { java.io.InputStream @is = mAssets.openNonAsset(value.assetCookie, file, android.content.res.AssetManager .ACCESS_STREAMING); // System.out.println("Opened file " + file + ": " + is); dr = android.graphics.drawable.Drawable.createFromResourceStream(this, value, @is , file, null); @is.close(); } catch (System.Exception e) { // System.out.println("Created stream: " + dr); android.content.res.Resources.NotFoundException rnf = new android.content.res.Resources .NotFoundException("File " + file + " from drawable resource ID #0x" + Sharpen.Util.IntToHexString (id)); rnf.InnerException = e; throw rnf; } } } } if (dr != null) { dr.setChangingConfigurations(value.changingConfigurations); cs = dr.getConstantState(); if (cs != null) { if (mPreloading) { if (isColorDrawable) { sPreloadedColorDrawables.put(key, cs); } else { sPreloadedDrawables.put(key, cs); } } else { lock (mTmpValue) { //Log.i(TAG, "Saving cached drawable @ #" + // Integer.toHexString(key.intValue()) // + " in " + this + ": " + cs); if (isColorDrawable) { mColorDrawableCache.put(key, new [email protected]<android.graphics.drawable.Drawable .ConstantState>(cs)); } else { mDrawableCache.put(key, new [email protected]<android.graphics.drawable.Drawable .ConstantState>(cs)); } } } } } return dr; }