Example #1
0
		// Empty
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private void parseInclude(org.xmlpull.v1.XmlPullParser parser, android.view.View 
			parent, android.util.AttributeSet attrs)
		{
			int type;
			if (parent is android.view.ViewGroup)
			{
				int layout = attrs.getAttributeResourceValue(null, "layout", 0);
				if (layout == 0)
				{
					string value = attrs.getAttributeValue(null, "layout");
					if (value == null)
					{
						throw new android.view.InflateException("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />"
							);
					}
					else
					{
						throw new android.view.InflateException("You must specifiy a valid layout " + "reference. The layout ID "
							 + value + " is not valid.");
					}
				}
				else
				{
					android.content.res.XmlResourceParser childParser = getContext().getResources().getLayout
						(layout);
					try
					{
						android.util.AttributeSet childAttrs = android.util.Xml.asAttributeSet(childParser
							);
						while ((type = childParser.next()) != org.xmlpull.v1.XmlPullParserClass.START_TAG
							 && type != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT)
						{
						}
						// Empty.
						if (type != org.xmlpull.v1.XmlPullParserClass.START_TAG)
						{
							throw new android.view.InflateException(childParser.getPositionDescription() + ": No start tag found!"
								);
						}
						string childName = childParser.getName();
						if (TAG_MERGE.Equals(childName))
						{
							// Inflate all children.
							rInflate(childParser, parent, childAttrs, false);
						}
						else
						{
							android.view.View view = createViewFromTag(parent, childName, childAttrs);
							android.view.ViewGroup group = (android.view.ViewGroup)parent;
							// We try to load the layout params set in the <include /> tag. If
							// they don't exist, we will rely on the layout params set in the
							// included XML file.
							// During a layoutparams generation, a runtime exception is thrown
							// if either layout_width or layout_height is missing. We catch
							// this exception and set localParams accordingly: true means we
							// successfully loaded layout params from the <include /> tag,
							// false means we need to rely on the included layout params.
							android.view.ViewGroup.LayoutParams @params = null;
							try
							{
								@params = group.generateLayoutParams(attrs);
							}
							catch (java.lang.RuntimeException)
							{
								@params = group.generateLayoutParams(childAttrs);
							}
							finally
							{
								if (@params != null)
								{
									view.setLayoutParams(@params);
								}
							}
							// Inflate all children.
							rInflate(childParser, view, childAttrs, true);
							// Attempt to override the included layout's android:id with the
							// one set on the <include /> tag itself.
							android.content.res.TypedArray a = mContext.obtainStyledAttributes(attrs, [email protected]
								.styleable.View, 0, 0);
							int id = a.getResourceId([email protected]_id, android.view.View
								.NO_ID);
							// While we're at it, let's try to override android:visibility.
							int visibility = a.getInt([email protected]_visibility, -1);
							a.recycle();
							if (id != android.view.View.NO_ID)
							{
								view.setId(id);
							}
							switch (visibility)
							{
								case 0:
								{
									view.setVisibility(android.view.View.VISIBLE);
									break;
								}

								case 1:
								{
									view.setVisibility(android.view.View.INVISIBLE);
									break;
								}

								case 2:
								{
									view.setVisibility(android.view.View.GONE);
									break;
								}
							}
							group.addView(view);
						}
					}
					finally
					{
						childParser.close();
					}
				}
			}
			else
			{
				throw new android.view.InflateException("<include /> can only be used inside of a ViewGroup"
					);
			}
			int currentDepth = parser.getDepth();
			while (((type = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_TAG || parser
				.getDepth() > currentDepth) && type != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT
				)
			{
			}
		}
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());
		}