/// <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><Button /// textColor="#ff000000"></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; }
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; } }
// 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 ) { } }
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; }