private void parseRequestFocus(XmlPullParser parser, View view) { int type; view.requestFocus(); int currentDepth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) { // Empty } }
void rInflate(XmlPullParser parser, View parent, AttributeSet attrs, bool finishInflate, bool inheritContext) { int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } string name = parser.getName(); if (TAG_REQUEST_FOCUS.Equals(name)) { parseRequestFocus(parser, parent); } else if (TAG_TAG.Equals(name)) { parseViewTag(parser, parent, attrs); } if (TAG_INCLUDE.Equals(name)) { if (parser.getDepth() == 0) { throw new Exception("<include /> cannot be the root element"); } parseInclude(parser, parent, attrs, inheritContext); } else if (TAG_MERGE.Equals(name)) { throw new Exception("<merge /> must be the root element"); } else { View view = createViewFromTag(parent, name, attrs, inheritContext); ViewGroup viewGroup = (ViewGroup)parent; ViewGroup.LayoutParams lparams = viewGroup.generateLayoutParams(attrs); rInflate(parser, view, attrs, true, true); viewGroup.addView(view, lparams); } } if (finishInflate) { parent.onFinishInflate(); } }
/* * Returns the parent element if available, null otherwise * * public Element getParentElement() { * return (parent instanceof Element) * ? ((Element) parent) * : null; * } */ /** * Builds the child elements from the given Parser. By overwriting * parse, an element can take complete control over parsing its * subtree. */ public override void parse(XmlPullParser parser) { for (int i = parser.getNamespaceCount(parser.getDepth() - 1); i < parser.getNamespaceCount(parser.getDepth()); i++) { setPrefix(parser.getNamespacePrefix(i), parser.getNamespaceUri(i)); } for (int i = 0; i < parser.getAttributeCount(); i++) { setAttribute(parser.getAttributeNamespace(i), // parser.getAttributePrefix (i), parser.getAttributeName(i), parser.getAttributeValue(i)); } // if (prefixMap == null) throw new RuntimeException ("!!"); init(); if (parser.isEmptyElementTag()) { parser.nextToken(); } else { parser.nextToken(); base.parse(parser); if (getChildCount() == 0) { addChild(IGNORABLE_WHITESPACE, ""); } } parser.require( XmlPullParser.END_TAG, getNamespace(), getName()); parser.nextToken(); }
private void parseViewTag(XmlPullParser parser, View view, AttributeSet attrs) { int type; //The below will be activated in the final version of Astoria. //TypedArray ta = mContext.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ViewTag); //int key = ta.getResourceId(com.android.internal.R.styleable.ViewTag_id, 0); //string value = ta.getText(com.android.internal.R.styleable.ViewTag_value); //view.setTag(key, value); //ta.recycle(); int currentDepth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) { // Empty } }
private void parseInclude(XmlPullParser parser, View parent, AttributeSet attrs, bool inheritContext) { int type; //if (parent.GetType().Equals(typeof(ViewGroup))) if (parent is ViewGroup) { int layout = attrs.getAttributeResourceValue(null, "layout", 0); //This should return resource value, not name if (layout == 0) { string value = attrs.getAttributeValue(null, "layout"); if (value == null) { throw new Exception("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />"); } else { throw new Exception("You must specifiy a valid layout " + "reference. The layout ID " + value + " is not valid."); } } else { XmlResourceParser childParser = getContext().getResources().getLayout(layout); try { AttributeSet childAttrs = Xml.asAttributeSet(childParser, mContext); while ((type = childParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty. } if (type != XmlPullParser.START_TAG) { throw new Exception(childParser.getPositionDescription() + ": No start tag found!"); } string childName = childParser.getName(); if (TAG_MERGE.Equals(childName)) { // Inflate all children. rInflate(childParser, parent, childAttrs, false, inheritContext); } else { View view = createViewFromTag(parent, childName, childAttrs, inheritContext); ViewGroup group = (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. ViewGroup.LayoutParams lparams = null; try { lparams = group.generateLayoutParams(attrs); } catch { lparams = group.generateLayoutParams(childAttrs); } finally { if (lparams != null) { view.setLayoutParams(lparams); } } // Inflate all children. rInflate(childParser, view, childAttrs, true, true); /* * // Attempt to override the included layout's android:id with the * // one set on the <include /> tag itself. * TypedArray a = mContext.obtainStyledAttributes(attrs, com.android.inner.R.styleable.View, 0, 0); * int id = a.getResourceId(com.android.inner.R.styleable.View_id, View.NO_ID); * // While we're at it, let's try to override android:visibility. * int visibility = a.getInt(com.android.inner.R.styleable.View_visibility, -1); * a.recycle(); * * if (id != View.NO_ID) * { * view.setId(id); * } * * switch (visibility) * { * case 0: * view.setVisibility(View.VISIBLE); * break; * case 1: * view.setVisibility(View.INVISIBLE); * break; * case 2: * view.setVisibility(View.GONE); * break; * } */ group.addView(view); } } finally { } } } else { throw new Exception("<include /> can only be used inside of a ViewGroup"); } int currentDepth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) { // Empty } }