本文整理匯總了Java中org.xmlpull.v1.XmlPullParser.getDepth方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlPullParser.getDepth方法的具體用法?Java XmlPullParser.getDepth怎麽用?Java XmlPullParser.getDepth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.xmlpull.v1.XmlPullParser
的用法示例。
在下文中一共展示了XmlPullParser.getDepth方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: f
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
private static String f(XmlPullParser xmlPullParser) {
String str = "";
int depth = xmlPullParser.getDepth();
while (true) {
if (xmlPullParser.next() == 3 && xmlPullParser.getDepth() == depth) {
return str;
}
str = str + xmlPullParser.getText();
}
}
示例2: newFilter
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
@Override
public Filter newFilter(XmlPullParser parser)
throws IOException, XmlPullParserException {
Filter child = null;
int outerDepth = parser.getDepth();
while (XmlUtils.nextElementWithin(parser, outerDepth)) {
Filter filter = IntentFirewall.parseFilter(parser);
if (child == null) {
child = filter;
} else {
throw new XmlPullParserException(
"<not> tag can only contain a single child filter.", parser, null);
}
}
return new NotFilter(child);
}
示例3: inflateChildren
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
private void inflateChildren(XmlPullParser parser, Node node) throws IOException, XmlPullParserException {
final 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 tagName=parser.getName();
//創建當前標簽Node
Node view=createNodeFromTag(tagName);
if(view!=null&&node instanceof ViewGroup){
ViewGroup viewGroup= (ViewGroup) node;
//查找當前標簽其內是否還有其他標簽如果沒有就直接返回
inflateChildren(parser,view);
viewGroup.addNode(view);
}
}
}
示例4: inflateColorStateList
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
final int innerDepth = parser.getDepth() + 1;
int depth;
int type;
LinkedList<int[]> stateList = new LinkedList<>();
LinkedList<Integer> colorList = new LinkedList<>();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG || depth > innerDepth
|| !parser.getName().equals("item")) {
continue;
}
TypedArray a1 = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.color});
final int value = a1.getResourceId(0, Color.MAGENTA);
final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value);
a1.recycle();
TypedArray a2 = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.alpha});
final float alphaMod = a2.getFloat(0, 1.0f);
a2.recycle();
colorList.add(alphaMod != 1.0f
? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod))
: baseColor);
stateList.add(extractStateSet(attrs));
}
if (stateList.size() > 0 && stateList.size() == colorList.size()) {
int[] colors = new int[colorList.size()];
for (int i = 0; i < colorList.size(); i++) {
colors[i] = colorList.get(i);
}
return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors);
}
return null;
}
示例5: readFromXml
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
public FilterList readFromXml(XmlPullParser parser) throws IOException, XmlPullParserException {
int outerDepth = parser.getDepth();
while (XmlUtils.nextElementWithin(parser, outerDepth)) {
readChild(parser);
}
return this;
}
示例6: skipCurrentTag
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
public static void skipCurrentTag(XmlPullParser parser)
throws XmlPullParserException, IOException {
int outerDepth = parser.getDepth();
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG
|| parser.getDepth() > outerDepth)) {
}
}
示例7: nextElementWithin
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
public static boolean nextElementWithin(XmlPullParser parser, int outerDepth)
throws IOException, XmlPullParserException {
for (;;) {
int type = parser.next();
if (type == XmlPullParser.END_DOCUMENT
|| (type == XmlPullParser.END_TAG && parser.getDepth() == outerDepth)) {
return false;
}
if (type == XmlPullParser.START_TAG
&& parser.getDepth() == outerDepth + 1) {
return true;
}
}
}
示例8: skipCurrentTag
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
public static void skipCurrentTag(XmlPullParser parser)
throws XmlPullParserException, IOException {
int outerDepth = parser.getDepth();
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG
|| parser.getDepth() > outerDepth)) {
}
}
示例9: rInflate
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
/**
* Recursive method used to descend down the xml hierarchy and instantiate
* items, instantiate their children, and then call onFinishInflate().
*/
private void rInflate(XmlPullParser parser, T node, final AttributeSet attrs)
throws XmlPullParserException, IOException {
final 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;
}
if (onCreateCustomFromTag(parser, node, attrs)) {
continue;
}
if (DEBUG) Log.v(TAG, "Now inflating tag: " + parser.getName());
String name = parser.getName();
T item = createItemFromTag(parser, name, attrs);
if (DEBUG) Log.v(TAG, "Creating params from parent: " + node);
onAddChildItem(node, item);
if (DEBUG) Log.v(TAG, "-----> start inflating children");
rInflate(parser, item, attrs);
if (DEBUG) Log.v(TAG, "-----> done inflating children");
}
}
示例10: parseCurrentView
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
public static synchronized ArrayList<ViewItem> parseCurrentView() {
// File f = new File("/mnt/sdcard/dump.xml");
// if (f.exists()) f.delete();
ShellUtils.execCommand("uiautomator dump /mnt/sdcard/dump.xml", true, false);
String xml = MainActivity.Read_File("dump.xml").replace("\n", "");
ArrayList<ViewItem> itemList = new ArrayList<>();
ViewItem temp;
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(new StringReader(xml));
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String tagName = parser.getName();
switch (eventType) {
case XmlPullParser.START_TAG:
if (tagName.equals("node")) {
temp = new ViewItem();
//讀類名
String[] className = parser.getAttributeValue(null, "class").split("\\.");
temp.simpleClassName = className[className.length - 1];
//讀坐標
String bounds = parser.getAttributeValue(null, "bounds");
String[] temp_n = bounds.replaceFirst("\\[", "").split("\\]\\[");
String[] point = temp_n[0].split(",");
if (point.length == 2)
temp.bounds = new Point(Integer.valueOf(point[0]), Integer.valueOf(point[1]));
else
temp.bounds = new Point();
//讀寬高
point = bounds.split("\\]\\[")[1].split(",");
if (point.length == 2)
temp.wh = new Point(Integer.valueOf(point[0]) - temp.bounds.x, Integer.valueOf(point[1].replaceFirst("\\]", "")) - temp.bounds.y);
else
temp.wh = new Point();
//其他雜類信息
temp.id = itemList.size();
temp.level = parser.getDepth();
ViewItem vi = getLastTopLevelNode(itemList, temp.level - 1);
temp.parentId = (vi == null ? NO_PARENT : vi.id);
itemList.add(temp);
}
break;
}
eventType = parser.next();
}
} catch (Exception e) {
e.printStackTrace();
}
return itemList;
}
示例11: createAnimationFromXml
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
private static Animation createAnimationFromXml(Context c, XmlPullParser parser,
AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException {
Animation anim = null;
// Make sure we are on a start tag.
int type;
int depth = parser.getDepth();
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 (name.equals("set")) {
anim = new AnimationSet(c, attrs);
createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);
} else if (name.equals("alpha")) {
anim = new AlphaAnimation(c, attrs);
} else if (name.equals("scale")) {
anim = new ScaleAnimation(c, attrs);
} else if (name.equals("rotate")) {
anim = new RotateAnimation(c, attrs);
} else if (name.equals("translate")) {
anim = new TranslateAnimation(c, attrs);
} else {
try {
anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs);
} catch (Exception te) {
throw new RuntimeException("Unknown animation name: " + parser.getName() + " error:" + te.getMessage());
}
}
if (parent != null) {
parent.addAnimation(anim);
}
}
return anim;
}
示例12: event
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
public void event(XmlPullParser var1) throws XmlPullParserException, IOException {
int var2 = var1.getEventType();
switch(var2) {
case 0:
Boolean var3 = (Boolean)var1.getProperty("http://xmlpull.org/v1/doc/features.html#xmldecl-standalone");
this.startDocument(var1.getInputEncoding(), var3);
break;
case 1:
this.endDocument();
break;
case 2:
this.writeStartTag(var1);
break;
case 3:
this.endTag(var1.getNamespace(), var1.getName());
break;
case 4:
if(var1.getDepth() > 0) {
this.text(var1.getText());
} else {
this.ignorableWhitespace(var1.getText());
}
break;
case 5:
this.cdsect(var1.getText());
break;
case 6:
this.entityRef(var1.getName());
break;
case 7:
String var4 = var1.getText();
this.ignorableWhitespace(var4);
break;
case 8:
this.processingInstruction(var1.getText());
break;
case 9:
this.comment(var1.getText());
break;
case 10:
this.docdecl(var1.getText());
}
}
示例13: inflateDrawable
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
int layerAttrUseCount = 0;
int drawableUseCount = 0;
int space = STEP << 1;
//L,T,R,B,S,E,id
int[][] childLayersAttrs = new int[space][ATTRS.length];
Drawable[] drawables = new Drawable[space];
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
if (layerAttrUseCount >= childLayersAttrs.length) {
int[][] dstInt = new int[drawables.length + STEP][ATTRS.length];
System.arraycopy(childLayersAttrs, 0, dstInt, 0, childLayersAttrs.length);
childLayersAttrs = dstInt;
}
updateLayerAttrs(context, attrs, childLayersAttrs[layerAttrUseCount]);
layerAttrUseCount++;
Drawable drawable = getAttrDrawable(context, attrs, android.R.attr.drawable);
// If the layer doesn't have a drawable or unresolved theme
// attribute for a drawable, attempt to parse one from the child
// element.
if (drawable == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription()
+ ": <item> tag requires a 'drawable' attribute or "
+ "child tag defining a drawable");
}
drawable = createFromXmlInner(context, parser, attrs);
} else {
final ColorStateList cls = getTintColorList(context, attrs, R.attr.drawableTint);
if (cls != null) {
drawable = ThemeUtils.tintDrawable(drawable, cls, getTintMode(context, attrs, R.attr.drawableTintMode));
}
}
if (drawable != null) {
if (drawableUseCount >= drawables.length) {
Drawable[] dst = new Drawable[drawables.length + STEP];
System.arraycopy(drawables, 0, dst, 0, drawables.length);
drawables = dst;
}
drawables[drawableUseCount] = drawable;
drawableUseCount++;
}
}
if (drawables[0] == null || drawableUseCount != layerAttrUseCount) {
return null;
} else {
LayerDrawable layerDrawable = new LayerDrawable(drawables);
for (int i = 0; i < drawables.length; i++) {
int[] childLayersAttr = childLayersAttrs[i];
if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) {
layerDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]);
}
if (childLayersAttr[4] != 0) {
layerDrawable.setId(i, childLayersAttr[4]);
}
}
return layerDrawable;
}
}
示例14: getValueForPath
import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
/**
* Retrieves the value of an XPath from an XML stream.
*/
private static String getValueForPath(String xpath, Reader xml) throws XmlPullParserException, IOException
{
XmlPullParser parser = new MXParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(xml);
int depth = 1;
String[] splits = xpath.split("/");
int event = parser.getEventType();
while( event != XmlPullParser.END_DOCUMENT )
{
if( event == XmlPullParser.START_TAG && parser.getDepth() == depth )
{
String[] elemNames = splits[depth - 1].split("\\|");
for( int i = 0; i < elemNames.length; i++ )
{
if( parser.getName().equals(elemNames[i]) )
{
if( depth == splits.length )
{
if( parser.next() == XmlPullParser.TEXT )
{
return parser.getText();
}
else
{
return null;
}
}
else
{
depth++;
}
}
}
}
event = parser.next();
}
return null;
}