Beispiel #1
0
		// do nothing here
		/// <summary>Decode a new Bitmap from an InputStream.</summary>
		/// <remarks>
		/// Decode a new Bitmap from an InputStream. This InputStream was obtained from
		/// resources, which we pass to be able to scale the bitmap accordingly.
		/// </remarks>
		public static android.graphics.Bitmap decodeResourceStream(android.content.res.Resources
			 res, android.util.TypedValue value, java.io.InputStream @is, android.graphics.Rect
			 pad, android.graphics.BitmapFactory.Options opts)
		{
			if (opts == null)
			{
				opts = new android.graphics.BitmapFactory.Options();
			}
			if (opts.inDensity == 0 && value != null)
			{
				int density = value.density;
				if (density == android.util.TypedValue.DENSITY_DEFAULT)
				{
					opts.inDensity = android.util.DisplayMetrics.DENSITY_DEFAULT;
				}
				else
				{
					if (density != android.util.TypedValue.DENSITY_NONE)
					{
						opts.inDensity = density;
					}
				}
			}
			if (opts.inTargetDensity == 0 && res != null)
			{
				opts.inTargetDensity = res.getDisplayMetrics().densityDpi;
			}
			return decodeStream(@is, pad, opts);
		}
Beispiel #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;
		}
Beispiel #3
0
		public override void inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser
			 parser, android.util.AttributeSet attrs)
		{
			base.inflate(r, parser, attrs);
			android.content.res.TypedArray a = r.obtainAttributes(attrs, [email protected].
				styleable.BitmapDrawable);
			int id = a.getResourceId([email protected]_src, 0);
			if (id == 0)
			{
				throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
					 ": <bitmap> requires a valid src attribute");
			}
			android.graphics.Bitmap bitmap = android.graphics.BitmapFactory.decodeResource(r, 
				id);
			if (bitmap == null)
			{
				throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
					 ": <bitmap> requires a valid src attribute");
			}
			mBitmapState.mBitmap = bitmap;
			setBitmap(bitmap);
			setTargetDensity(r.getDisplayMetrics());
			android.graphics.Paint paint = mBitmapState.mPaint;
			paint.setAntiAlias(a.getBoolean([email protected]_antialias
				, paint.isAntiAlias()));
			paint.setFilterBitmap(a.getBoolean([email protected]_filter
				, paint.isFilterBitmap()));
			paint.setDither(a.getBoolean([email protected]_dither, 
				paint.isDither()));
			setGravity(a.getInt([email protected]_gravity, android.view.Gravity
				.FILL));
			int tileMode = a.getInt([email protected]_tileMode, -1
				);
			if (tileMode != -1)
			{
				switch (tileMode)
				{
					case 0:
					{
						setTileModeXY(android.graphics.Shader.TileMode.CLAMP, android.graphics.Shader.TileMode
							.CLAMP);
						break;
					}

					case 1:
					{
						setTileModeXY(android.graphics.Shader.TileMode.REPEAT, android.graphics.Shader.TileMode
							.REPEAT);
						break;
					}

					case 2:
					{
						setTileModeXY(android.graphics.Shader.TileMode.MIRROR, android.graphics.Shader.TileMode
							.MIRROR);
						break;
					}
				}
			}
			a.recycle();
		}
Beispiel #4
0
		internal BitmapDrawable(android.graphics.drawable.BitmapDrawable.BitmapState state
			, android.content.res.Resources res)
		{
			mBitmapState = state;
			if (res != null)
			{
				mTargetDensity = res.getDisplayMetrics().densityDpi;
			}
			else
			{
				mTargetDensity = state.mTargetDensity;
			}
			setBitmap(state != null ? state.mBitmap : null);
		}
Beispiel #5
0
		internal void setNinePatchState(android.graphics.drawable.NinePatchDrawable.NinePatchState
			 state, android.content.res.Resources res)
		{
			mNinePatchState = state;
			mNinePatch = state.mNinePatch;
			mPadding = state.mPadding;
			mTargetDensity = res != null ? res.getDisplayMetrics().densityDpi : state.mTargetDensity;
			//noinspection PointlessBooleanExpression
			if (state.mDither != DEFAULT_DITHER)
			{
				// avoid calling the setter unless we need to, since it does a
				// lazy allocation of a paint
				setDither(state.mDither);
			}
			if (mNinePatch != null)
			{
				computeBitmapSize();
			}
		}