Exemplo n.º 1
0
		/// <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;
		}
Exemplo n.º 2
0
		/// <summary>Create from inside an XML document.</summary>
		/// <remarks>
		/// Create from inside an XML document.  Called on a parser positioned at
		/// a tag in an XML document, tries to create a Drawable from that tag.
		/// Returns null if the tag is not a valid drawable.
		/// </remarks>
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public static android.graphics.drawable.Drawable createFromXmlInner(android.content.res.Resources
			 r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)
		{
			android.graphics.drawable.Drawable drawable;
			string name = parser.getName();
			if (name.Equals("selector"))
			{
				drawable = new android.graphics.drawable.StateListDrawable();
			}
			else
			{
				if (name.Equals("level-list"))
				{
					drawable = new android.graphics.drawable.LevelListDrawable();
				}
				else
				{
					if (name.Equals("layer-list"))
					{
						drawable = new android.graphics.drawable.LayerDrawable();
					}
					else
					{
						if (name.Equals("transition"))
						{
							drawable = new android.graphics.drawable.TransitionDrawable();
						}
						else
						{
							if (name.Equals("color"))
							{
								drawable = new android.graphics.drawable.ColorDrawable();
							}
							else
							{
								if (name.Equals("shape"))
								{
									drawable = new android.graphics.drawable.GradientDrawable();
								}
								else
								{
									if (name.Equals("scale"))
									{
										drawable = new android.graphics.drawable.ScaleDrawable();
									}
									else
									{
										if (name.Equals("clip"))
										{
											drawable = new android.graphics.drawable.ClipDrawable();
										}
										else
										{
											if (name.Equals("rotate"))
											{
												drawable = new android.graphics.drawable.RotateDrawable();
											}
											else
											{
												if (name.Equals("animated-rotate"))
												{
													drawable = new android.graphics.drawable.AnimatedRotateDrawable();
												}
												else
												{
													if (name.Equals("animation-list"))
													{
														drawable = new android.graphics.drawable.AnimationDrawable();
													}
													else
													{
														if (name.Equals("inset"))
														{
															drawable = new android.graphics.drawable.InsetDrawable();
														}
														else
														{
															if (name.Equals("bitmap"))
															{
																drawable = new android.graphics.drawable.BitmapDrawable(r);
																if (r != null)
																{
																	((android.graphics.drawable.BitmapDrawable)drawable).setTargetDensity(r.getDisplayMetrics
																		());
																}
															}
															else
															{
																if (name.Equals("nine-patch"))
																{
																	drawable = new android.graphics.drawable.NinePatchDrawable();
																	if (r != null)
																	{
																		((android.graphics.drawable.NinePatchDrawable)drawable).setTargetDensity(r.getDisplayMetrics
																			());
																	}
																}
																else
																{
																	throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
																		 ": invalid drawable tag " + name);
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			drawable.inflate(r, parser, attrs);
			return drawable;
		}