Beispiel #1
0
		/// <summary>
		/// Recursive method used to descend down the xml hierarchy and instantiate
		/// views, instantiate their children, and then call onFinishInflate().
		/// </summary>
		/// <remarks>
		/// Recursive method used to descend down the xml hierarchy and instantiate
		/// views, instantiate their children, and then call onFinishInflate().
		/// </remarks>
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual void rInflate(org.xmlpull.v1.XmlPullParser parser, android.view.View
			 parent, android.util.AttributeSet attrs, bool finishInflate)
		{
			int depth = parser.getDepth();
			int type;
			while (((type = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_TAG || parser
				.getDepth() > depth) && type != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT)
			{
				if (type != org.xmlpull.v1.XmlPullParserClass.START_TAG)
				{
					continue;
				}
				string name = parser.getName();
				if (TAG_REQUEST_FOCUS.Equals(name))
				{
					parseRequestFocus(parser, parent);
				}
				else
				{
					if (TAG_INCLUDE.Equals(name))
					{
						if (parser.getDepth() == 0)
						{
							throw new android.view.InflateException("<include /> cannot be the root element");
						}
						parseInclude(parser, parent, attrs);
					}
					else
					{
						if (TAG_MERGE.Equals(name))
						{
							throw new android.view.InflateException("<merge /> must be the root element");
						}
						else
						{
							if (TAG_1995.Equals(name))
							{
								android.view.View view = new android.view.LayoutInflater.BlinkLayout(mContext, attrs
									);
								android.view.ViewGroup viewGroup = (android.view.ViewGroup)parent;
								android.view.ViewGroup.LayoutParams @params = viewGroup.generateLayoutParams(attrs
									);
								rInflate(parser, view, attrs, true);
								viewGroup.addView(view, @params);
							}
							else
							{
								android.view.View view = createViewFromTag(parent, name, attrs);
								android.view.ViewGroup viewGroup = (android.view.ViewGroup)parent;
								android.view.ViewGroup.LayoutParams @params = viewGroup.generateLayoutParams(attrs
									);
								rInflate(parser, view, attrs, true);
								viewGroup.addView(view, @params);
							}
						}
					}
				}
			}
			if (finishInflate)
			{
				parent.onFinishInflate();
			}
		}
Beispiel #2
0
		/// <summary>Inflate a new view hierarchy from the specified XML node.</summary>
		/// <remarks>
		/// Inflate a new view hierarchy from the specified XML node. Throws
		/// <see cref="InflateException">InflateException</see>
		/// if there is an error.
		/// <p>
		/// <em><strong>Important</strong></em>&nbsp;&nbsp;&nbsp;For performance
		/// reasons, view inflation relies heavily on pre-processing of XML files
		/// that is done at build time. Therefore, it is not currently possible to
		/// use LayoutInflater with an XmlPullParser over a plain XML file at runtime.
		/// </remarks>
		/// <param name="parser">
		/// XML dom node containing the description of the view
		/// hierarchy.
		/// </param>
		/// <param name="root">
		/// Optional view to be the parent of the generated hierarchy (if
		/// <em>attachToRoot</em> is true), or else simply an object that
		/// provides a set of LayoutParams values for root of the returned
		/// hierarchy (if <em>attachToRoot</em> is false.)
		/// </param>
		/// <param name="attachToRoot">
		/// Whether the inflated hierarchy should be attached to
		/// the root parameter? If false, root is only used to create the
		/// correct subclass of LayoutParams for the root view in the XML.
		/// </param>
		/// <returns>
		/// The root View of the inflated hierarchy. If root was supplied and
		/// attachToRoot is true, this is root; otherwise it is the root of
		/// the inflated XML file.
		/// </returns>
		public virtual android.view.View inflate(org.xmlpull.v1.XmlPullParser parser, android.view.ViewGroup
			 root, bool attachToRoot)
		{
			lock (mConstructorArgs)
			{
				android.util.AttributeSet attrs = android.util.Xml.asAttributeSet(parser);
				android.content.Context lastContext = (android.content.Context)mConstructorArgs[0
					];
				mConstructorArgs[0] = mContext;
				android.view.View result = root;
				try
				{
					// Look for the root node.
					int type;
					while ((type = parser.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(parser.getPositionDescription() + ": No start tag found!"
							);
					}
					string name = parser.getName();
					if (TAG_MERGE.Equals(name))
					{
						if (root == null || !attachToRoot)
						{
							throw new android.view.InflateException("<merge /> can be used only with a valid "
								 + "ViewGroup root and attachToRoot=true");
						}
						rInflate(parser, root, attrs, false);
					}
					else
					{
						// Temp is the root view that was found in the xml
						android.view.View temp;
						if (TAG_1995.Equals(name))
						{
							temp = new android.view.LayoutInflater.BlinkLayout(mContext, attrs);
						}
						else
						{
							temp = createViewFromTag(root, name, attrs);
						}
						android.view.ViewGroup.LayoutParams @params = null;
						if (root != null)
						{
							// Create layout params that match root, if supplied
							@params = root.generateLayoutParams(attrs);
							if (!attachToRoot)
							{
								// Set the layout params for temp if we are not
								// attaching. (If we are, we use addView, below)
								temp.setLayoutParams(@params);
							}
						}
						// Inflate all children under temp
						rInflate(parser, temp, attrs, true);
						// We are supposed to attach all the views we found (int temp)
						// to root. Do that now.
						if (root != null && attachToRoot)
						{
							root.addView(temp, @params);
						}
						// Decide whether to return the root that was passed in or the
						// top view found in xml.
						if (root == null || !attachToRoot)
						{
							result = temp;
						}
					}
				}
				catch (org.xmlpull.v1.XmlPullParserException e)
				{
					android.view.InflateException ex = new android.view.InflateException(e.Message);
					ex.InnerException = e;
					throw ex;
				}
				catch (System.IO.IOException e)
				{
					android.view.InflateException ex = new android.view.InflateException(parser.getPositionDescription
						() + ": " + e.Message);
					ex.InnerException = e;
					throw ex;
				}
				finally
				{
					// Don't retain static reference on context.
					mConstructorArgs[0] = lastContext;
					mConstructorArgs[1] = null;
				}
				return result;
			}
		}