Example #1
0
			/// <summary>
			/// Return a StyledAttributes holding the attribute values in
			/// <var>set</var>
			/// that are listed in <var>attrs</var>.
			/// </summary>
			/// <remarks>
			/// Return a StyledAttributes holding the attribute values in
			/// <var>set</var>
			/// that are listed in <var>attrs</var>.  In addition, if the given
			/// AttributeSet specifies a style class (through the "style" attribute),
			/// that style will be applied on top of the base attributes it defines.
			/// <p>Be sure to call StyledAttributes.recycle() when you are done with
			/// the array.
			/// <p>When determining the final value of a particular attribute, there
			/// are four inputs that come into play:</p>
			/// <ol>
			/// <li> Any attribute values in the given AttributeSet.
			/// <li> The style resource specified in the AttributeSet (named
			/// "style").
			/// <li> The default style specified by <var>defStyleAttr</var> and
			/// <var>defStyleRes</var>
			/// <li> The base values in this theme.
			/// </ol>
			/// <p>Each of these inputs is considered in-order, with the first listed
			/// taking precedence over the following ones.  In other words, if in the
			/// AttributeSet you have supplied <code>&lt;Button
			/// textColor="#ff000000"&gt;</code>, then the button's text will
			/// <em>always</em> be black, regardless of what is specified in any of
			/// the styles.
			/// </remarks>
			/// <param name="set">The base set of attribute values.  May be null.</param>
			/// <param name="attrs">The desired attributes to be retrieved.</param>
			/// <param name="defStyleAttr">
			/// An attribute in the current theme that contains a
			/// reference to a style resource that supplies
			/// defaults values for the StyledAttributes.  Can be
			/// 0 to not look for defaults.
			/// </param>
			/// <param name="defStyleRes">
			/// A resource identifier of a style resource that
			/// supplies default values for the StyledAttributes,
			/// used only if defStyleAttr is 0 or can not be found
			/// in the theme.  Can be 0 to not look for defaults.
			/// </param>
			/// <returns>
			/// Returns a TypedArray holding an array of the attribute values.
			/// Be sure to call
			/// <see cref="TypedArray.recycle()">TypedArray.recycle()</see>
			/// when done with it.
			/// </returns>
			/// <seealso cref="Resources.obtainAttributes(android.util.AttributeSet, int[])">Resources.obtainAttributes(android.util.AttributeSet, int[])
			/// 	</seealso>
			/// <seealso cref="obtainStyledAttributes(int[])">obtainStyledAttributes(int[])</seealso>
			/// <seealso cref="obtainStyledAttributes(int, int[])">obtainStyledAttributes(int, int[])
			/// 	</seealso>
			public android.content.res.TypedArray obtainStyledAttributes(android.util.AttributeSet
				 set, int[] attrs, int defStyleAttr, int defStyleRes)
			{
				int len = attrs.Length;
				android.content.res.TypedArray array = this._enclosing.getCachedStyledAttributes(
					len);
				// XXX note that for now we only work with compiled XML files.
				// To support generic XML files we will need to manually parse
				// out the attributes from the XML file (applying type information
				// contained in the resources and such).
				android.content.res.XmlBlock.Parser parser = (android.content.res.XmlBlock.Parser
					)set;
				android.content.res.AssetManager.applyStyle(this.mTheme, defStyleAttr, defStyleRes
					, parser != null ? parser.mParseState : null, attrs, array.mData, array.mIndices
					);
				array.mRsrcs = attrs;
				array.mXml = parser;
				if (false)
				{
					int[] data = array.mData;
					java.io.Console.Out.println("Attributes:");
					string s = "  Attrs:";
					int i;
					for (i = 0; i < set.getAttributeCount(); i++)
					{
						s = s + " " + set.getAttributeName(i);
						int id = set.getAttributeNameResource(i);
						if (id != 0)
						{
							s = s + "(0x" + Sharpen.Util.IntToHexString(id) + ")";
						}
						s = s + "=" + set.getAttributeValue(i);
					}
					java.io.Console.Out.println(s);
					s = "  Found:";
					android.util.TypedValue value = new android.util.TypedValue();
					for (i = 0; i < attrs.Length; i++)
					{
						int d = i * android.content.res.AssetManager.STYLE_NUM_ENTRIES;
						value.type = data[d + android.content.res.AssetManager.STYLE_TYPE];
						value.data = data[d + android.content.res.AssetManager.STYLE_DATA];
						value.assetCookie = data[d + android.content.res.AssetManager.STYLE_ASSET_COOKIE];
						value.resourceId = data[d + android.content.res.AssetManager.STYLE_RESOURCE_ID];
						s = s + " 0x" + Sharpen.Util.IntToHexString(attrs[i]) + "=" + value;
					}
					java.io.Console.Out.println(s);
				}
				return array;
			}
Example #2
0
		public override void inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser
			 parser, android.util.AttributeSet attrs)
		{
			android.content.res.TypedArray a = r.obtainAttributes(attrs, [email protected]
				styleable.StateListDrawable);
			base.inflateWithAttributes(r, parser, a, [email protected]_visible
				);
			mStateListState.setVariablePadding(a.getBoolean([email protected]_variablePadding
				, false));
			mStateListState.setConstantSize(a.getBoolean([email protected]_constantSize
				, false));
			mStateListState.setEnterFadeDuration(a.getInt([email protected]_enterFadeDuration
				, 0));
			mStateListState.setExitFadeDuration(a.getInt([email protected]_exitFadeDuration
				, 0));
			setDither(a.getBoolean([email protected]_dither, DEFAULT_DITHER
				));
			a.recycle();
			int type;
			int innerDepth = parser.getDepth() + 1;
			int depth;
			while ((type = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT &&
				 ((depth = parser.getDepth()) >= innerDepth || type != org.xmlpull.v1.XmlPullParserClass.END_TAG
				))
			{
				if (type != org.xmlpull.v1.XmlPullParserClass.START_TAG)
				{
					continue;
				}
				if (depth > innerDepth || !parser.getName().Equals("item"))
				{
					continue;
				}
				int drawableRes = 0;
				int i;
				int j = 0;
				int numAttrs = attrs.getAttributeCount();
				int[] states = new int[numAttrs];
				for (i = 0; i < numAttrs; i++)
				{
					int stateResId = attrs.getAttributeNameResource(i);
					if (stateResId == 0)
					{
						break;
					}
					if (stateResId == [email protected])
					{
						drawableRes = attrs.getAttributeResourceValue(i, 0);
					}
					else
					{
						states[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
					}
				}
				states = android.util.StateSet.trimStateSet(states, j);
				android.graphics.drawable.Drawable dr;
				if (drawableRes != 0)
				{
					dr = r.getDrawable(drawableRes);
				}
				else
				{
					while ((type = parser.next()) == org.xmlpull.v1.XmlPullParserClass.TEXT)
					{
					}
					if (type != org.xmlpull.v1.XmlPullParserClass.START_TAG)
					{
						throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
							 ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable"
							);
					}
					dr = android.graphics.drawable.Drawable.createFromXmlInner(r, parser, attrs);
				}
				mStateListState.addStateSet(states, dr);
			}
			onStateChange(getState());
		}