Exemplo n.º 1
0
		/// <summary>Parse a name/value pair out of an XML tag holding that data.</summary>
		/// <remarks>
		/// Parse a name/value pair out of an XML tag holding that data.  The
		/// AttributeSet must be holding the data defined by
		/// <see cref="android.R.styleable.Extra">android.R.styleable.Extra</see>
		/// .  The following value types are supported:
		/// <ul>
		/// <li>
		/// <see cref="android.util.TypedValue.TYPE_STRING">android.util.TypedValue.TYPE_STRING
		/// 	</see>
		/// :
		/// <see cref="android.os.Bundle.putCharSequence(string, java.lang.CharSequence)">Bundle.putCharSequence()
		/// 	</see>
		/// <li>
		/// <see cref="android.util.TypedValue.TYPE_INT_BOOLEAN">android.util.TypedValue.TYPE_INT_BOOLEAN
		/// 	</see>
		/// :
		/// <see cref="android.os.Bundle.putCharSequence(string, java.lang.CharSequence)">Bundle.putBoolean()
		/// 	</see>
		/// <li>
		/// <see cref="android.util.TypedValue.TYPE_FIRST_INT">android.util.TypedValue.TYPE_FIRST_INT
		/// 	</see>
		/// -
		/// <see cref="android.util.TypedValue.TYPE_LAST_INT">android.util.TypedValue.TYPE_LAST_INT
		/// 	</see>
		/// :
		/// <see cref="android.os.Bundle.putCharSequence(string, java.lang.CharSequence)">Bundle.putBoolean()
		/// 	</see>
		/// <li>
		/// <see cref="android.util.TypedValue.TYPE_FLOAT">android.util.TypedValue.TYPE_FLOAT
		/// 	</see>
		/// :
		/// <see cref="android.os.Bundle.putCharSequence(string, java.lang.CharSequence)">Bundle.putFloat()
		/// 	</see>
		/// </ul>
		/// </remarks>
		/// <param name="tagName">
		/// The name of the tag these attributes come from; this is
		/// only used for reporting error messages.
		/// </param>
		/// <param name="attrs">The attributes from which to retrieve the name/value pair.</param>
		/// <param name="outBundle">The Bundle in which to place the parsed value.</param>
		/// <exception cref="org.xmlpull.v1.XmlPullParserException">If the attributes are not valid.
		/// 	</exception>
		public virtual void parseBundleExtra(string tagName, android.util.AttributeSet attrs
			, android.os.Bundle outBundle)
		{
			android.content.res.TypedArray sa = obtainAttributes(attrs, [email protected]
				.Extra);
			string name = sa.getString([email protected]_name);
			if (name == null)
			{
				sa.recycle();
				throw new org.xmlpull.v1.XmlPullParserException("<" + tagName + "> requires an android:name attribute at "
					 + attrs.getPositionDescription());
			}
			android.util.TypedValue v = sa.peekValue([email protected]_value
				);
			if (v != null)
			{
				if (v.type == android.util.TypedValue.TYPE_STRING)
				{
					java.lang.CharSequence cs = v.coerceToString();
					outBundle.putCharSequence(name, cs);
				}
				else
				{
					if (v.type == android.util.TypedValue.TYPE_INT_BOOLEAN)
					{
						outBundle.putBoolean(name, v.data != 0);
					}
					else
					{
						if (v.type >= android.util.TypedValue.TYPE_FIRST_INT && v.type <= android.util.TypedValue
							.TYPE_LAST_INT)
						{
							outBundle.putInt(name, v.data);
						}
						else
						{
							if (v.type == android.util.TypedValue.TYPE_FLOAT)
							{
								outBundle.putFloat(name, v.getFloat());
							}
							else
							{
								sa.recycle();
								throw new org.xmlpull.v1.XmlPullParserException("<" + tagName + "> only supports string, integer, float, color, and boolean at "
									 + attrs.getPositionDescription());
							}
						}
					}
				}
			}
			else
			{
				sa.recycle();
				throw new org.xmlpull.v1.XmlPullParserException("<" + tagName + "> requires an android:value or android:resource attribute at "
					 + attrs.getPositionDescription());
			}
			sa.recycle();
		}
Exemplo n.º 2
0
		internal virtual android.view.View createViewFromTag(android.view.View parent, string
			 name, android.util.AttributeSet attrs)
		{
			if (name.Equals("view"))
			{
				name = attrs.getAttributeValue(null, "class");
			}
			try
			{
				android.view.View view;
				if (mFactory2 != null)
				{
					view = mFactory2.onCreateView(parent, name, mContext, attrs);
				}
				else
				{
					if (mFactory != null)
					{
						view = mFactory.onCreateView(name, mContext, attrs);
					}
					else
					{
						view = null;
					}
				}
				if (view == null && mPrivateFactory != null)
				{
					view = mPrivateFactory.onCreateView(parent, name, mContext, attrs);
				}
				if (view == null)
				{
					if (-1 == name.IndexOf('.'))
					{
						view = onCreateView(parent, name, attrs);
					}
					else
					{
						view = createView(name, null, attrs);
					}
				}
				return view;
			}
			catch (android.view.InflateException e)
			{
				throw;
			}
			catch (java.lang.ClassNotFoundException e)
			{
				android.view.InflateException ie = new android.view.InflateException(attrs.getPositionDescription
					() + ": Error inflating class " + name);
				ie.InnerException = e;
				throw ie;
			}
			catch (System.Exception e)
			{
				android.view.InflateException ie = new android.view.InflateException(attrs.getPositionDescription
					() + ": Error inflating class " + name);
				ie.InnerException = e;
				throw ie;
			}
		}
Exemplo n.º 3
0
		/// <summary>Low-level function for instantiating a view by name.</summary>
		/// <remarks>
		/// Low-level function for instantiating a view by name. This attempts to
		/// instantiate a view class of the given <var>name</var> found in this
		/// LayoutInflater's ClassLoader.
		/// <p>
		/// There are two things that can happen in an error case: either the
		/// exception describing the error will be thrown, or a null will be
		/// returned. You must deal with both possibilities -- the former will happen
		/// the first time createView() is called for a class of a particular name,
		/// the latter every time there-after for that class name.
		/// </remarks>
		/// <param name="name">The full name of the class to be instantiated.</param>
		/// <param name="attrs">The XML attributes supplied for this instance.</param>
		/// <returns>View The newly instantiated view, or null.</returns>
		/// <exception cref="java.lang.ClassNotFoundException"></exception>
		/// <exception cref="android.view.InflateException"></exception>
		public android.view.View createView(string name, string prefix, android.util.AttributeSet
			 attrs)
		{
			System.Reflection.ConstructorInfo constructor = sConstructorMap.get(name);
			System.Type clazz = null;
			try
			{
				if (constructor == null)
				{
					// Class not found in the cache, see if it's real, and try to add it
					clazz = XobotOS.Runtime.Reflection.AsSubclass(mContext.getClassLoader().loadClass
						(prefix != null ? (prefix + name) : name), typeof(android.view.View));
					if (mFilter != null && clazz != null)
					{
						bool allowed = mFilter.onLoadClass(clazz);
						if (!allowed)
						{
							failNotAllowed(name, prefix, attrs);
						}
					}
					constructor = XobotOS.Runtime.Reflection.GetConstructor(clazz, mConstructorSignature
						);
					sConstructorMap.put(name, constructor);
				}
				else
				{
					// If we have a filter, apply it to cached constructor
					if (mFilter != null)
					{
						// Have we seen this name before?
						bool allowedState = mFilterMap.get(name);
						if (allowedState == null)
						{
							// New class -- remember whether it is allowed
							clazz = XobotOS.Runtime.Reflection.AsSubclass(mContext.getClassLoader().loadClass
								(prefix != null ? (prefix + name) : name), typeof(android.view.View));
							bool allowed = clazz != null && mFilter.onLoadClass(clazz);
							mFilterMap.put(name, allowed);
							if (!allowed)
							{
								failNotAllowed(name, prefix, attrs);
							}
						}
						else
						{
							if (allowedState.Equals(false))
							{
								failNotAllowed(name, prefix, attrs);
							}
						}
					}
				}
				object[] args = mConstructorArgs;
				args[1] = attrs;
				return (android.view.View)constructor.Invoke(args);
			}
			catch (java.lang.NoSuchMethodException e)
			{
				android.view.InflateException ie = new android.view.InflateException(attrs.getPositionDescription
					() + ": Error inflating class " + (prefix != null ? (prefix + name) : name));
				ie.InnerException = e;
				throw ie;
			}
			catch (System.InvalidCastException e)
			{
				// If loaded class is not a View subclass
				android.view.InflateException ie = new android.view.InflateException(attrs.getPositionDescription
					() + ": Class is not a View " + (prefix != null ? (prefix + name) : name));
				ie.InnerException = e;
				throw ie;
			}
			catch (java.lang.ClassNotFoundException e)
			{
				// If loadClass fails, we should propagate the exception.
				throw;
			}
			catch (System.Exception e)
			{
				android.view.InflateException ie = new android.view.InflateException(attrs.getPositionDescription
					() + ": Error inflating class " + (clazz == null ? "<unknown>" : clazz.FullName)
					);
				ie.InnerException = e;
				throw ie;
			}
		}
Exemplo n.º 4
0
		/// <summary>Throw an exception because the specified class is not allowed to be inflated.
		/// 	</summary>
		/// <remarks>Throw an exception because the specified class is not allowed to be inflated.
		/// 	</remarks>
		private void failNotAllowed(string name, string prefix, android.util.AttributeSet
			 attrs)
		{
			throw new android.view.InflateException(attrs.getPositionDescription() + ": Class not allowed to be inflated "
				 + (prefix != null ? (prefix + name) : name));
		}
Exemplo n.º 5
0
		public virtual android.view.View onCreateView(android.view.View parent, string name
			, android.content.Context context, android.util.AttributeSet attrs)
		{
			if (!"fragment".Equals(name))
			{
				return onCreateView(name, context, attrs);
			}
			string fname = attrs.getAttributeValue(null, "class");
			android.content.res.TypedArray a = context.obtainStyledAttributes(attrs, [email protected]
				.styleable.Fragment);
			if (fname == null)
			{
				fname = a.getString([email protected]_name);
			}
			int id = a.getResourceId([email protected]_id, android.view.View
				.NO_ID);
			string tag = a.getString([email protected]_tag);
			a.recycle();
			int containerId = parent != null ? parent.getId() : 0;
			if (containerId == android.view.View.NO_ID && id == android.view.View.NO_ID && tag
				 == null)
			{
				throw new System.ArgumentException(attrs.getPositionDescription() + ": Must specify unique android:id, android:tag, or have a parent with an id for "
					 + fname);
			}
			android.app.Fragment fragment = id != android.view.View.NO_ID ? mFragments.findFragmentById
				(id) : null;
			if (fragment == null && tag != null)
			{
				fragment = mFragments.findFragmentByTag(tag);
			}
			if (fragment == null && containerId != android.view.View.NO_ID)
			{
				fragment = mFragments.findFragmentById(containerId);
			}
			if (android.app.FragmentManagerImpl.DEBUG)
			{
				android.util.Log.v(TAG, "onCreateView: id=0x" + Sharpen.Util.IntToHexString(id) +
					 " fname=" + fname + " existing=" + fragment);
			}
			if (fragment == null)
			{
				fragment = android.app.Fragment.instantiate(this, fname);
				fragment.mFromLayout = true;
				fragment.mFragmentId = id != 0 ? id : containerId;
				fragment.mContainerId = containerId;
				fragment.mTag = tag;
				fragment.mInLayout = true;
				fragment.mFragmentManager = mFragments;
				fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
				mFragments.addFragment(fragment, true);
			}
			else
			{
				if (fragment.mInLayout)
				{
					throw new System.ArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x"
						 + Sharpen.Util.IntToHexString(id) + ", tag " + tag + ", or parent id 0x" + Sharpen.Util.IntToHexString
						(containerId) + " with another fragment for " + fname);
				}
				else
				{
					fragment.mInLayout = true;
					if (!fragment.mRetaining)
					{
						fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
					}
					mFragments.moveToState(fragment);
				}
			}
			if (fragment.mView == null)
			{
				throw new System.InvalidOperationException("Fragment " + fname + " did not create a view."
					);
			}
			if (id != 0)
			{
				fragment.mView.setId(id);
			}
			if (fragment.mView.getTag() == null)
			{
				fragment.mView.setTag(tag);
			}
			return fragment.mView;
		}