Java Code Examples for org.xmlpull.v1.XmlSerializer#endTag()

The following examples show how to use org.xmlpull.v1.XmlSerializer#endTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobStore.java    From JobSchedulerCompat with MIT License 6 votes vote down vote up
/**
 * Write out a tag with data identifying this job's constraints. If the constraint isn't here it doesn't apply.
 */
private void writeConstraintsToXml(XmlSerializer out, JobStatus jobStatus) throws IOException {
    out.startTag(null, XML_TAG_PARAMS_CONSTRAINTS);
    if (jobStatus.needsAnyConnectivity()) {
        out.attribute(null, "connectivity", Boolean.toString(true));
    }
    if (jobStatus.needsMeteredConnectivity()) {
        out.attribute(null, "metered", Boolean.toString(true));
    }
    if (jobStatus.needsUnmeteredConnectivity()) {
        out.attribute(null, "unmetered", Boolean.toString(true));
    }
    if (jobStatus.needsNonRoamingConnectivity()) {
        out.attribute(null, "not-roaming", Boolean.toString(true));
    }
    if (jobStatus.hasIdleConstraint()) {
        out.attribute(null, "idle", Boolean.toString(true));
    }
    if (jobStatus.hasChargingConstraint()) {
        out.attribute(null, "charging", Boolean.toString(true));
    }
    if (jobStatus.hasBatteryNotLowConstraint()) {
        out.attribute(null, "battery-not-low", Boolean.toString(true));
    }
    out.endTag(null, XML_TAG_PARAMS_CONSTRAINTS);
}
 
Example 2
Source File: XmlUtils.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Flatten a double[] into an XmlSerializer.  The list can later be read back
 * with readThisDoubleArrayXml().
 *
 * @param val  The double array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out  XmlSerializer to write the array into.
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static final void writeDoubleArrayXml(double[] val, String name, XmlSerializer out)
		throws XmlPullParserException, java.io.IOException {

	if (val == null) {
		out.startTag(null, "null");
		out.endTag(null, "null");
		return;
	}

	out.startTag(null, "double-array");
	if (name != null) {
		out.attribute(null, "name", name);
	}

	final int N = val.length;
	out.attribute(null, "num", Integer.toString(N));

	for (int i = 0; i < N; i++) {
		out.startTag(null, "item");
		out.attribute(null, "value", Double.toString(val[i]));
		out.endTag(null, "item");
	}

	out.endTag(null, "double-array");
}
 
Example 3
Source File: XmlUtils.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Flatten an int[] into an XmlSerializer.  The list can later be read back
 * with readThisIntArrayXml().
 *
 * @param val  The int array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out  XmlSerializer to write the array into.
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static void writeIntArrayXml(int[] val, String name, XmlSerializer out)
        throws java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "int-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    for (int aVal : val) {
        out.startTag(null, "item");
        out.attribute(null, "value", Integer.toString(aVal));
        out.endTag(null, "item");
    }

    out.endTag(null, "int-array");
}
 
Example 4
Source File: XmlUtils.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
public static void writeSetXml(Set val, String name, XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {
    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "set");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    for (Object v : val) {
        writeValueXml(v, null, out);
    }

    out.endTag(null, "set");
}
 
Example 5
Source File: SerializerExample.java    From exificient with MIT License 6 votes vote down vote up
static void write(XmlSerializer xpp) throws IllegalArgumentException,
		IllegalStateException, IOException {
	xpp.startDocument(null, null);

	xpp.setPrefix("foo", "urn:foo"); // first prefix
	xpp.startTag("", "root");

	xpp.attribute("", "atRoot", "atValue");
	{
		xpp.comment("my comment");

		xpp.startTag("", "el1");
		xpp.text("el1 text");
		xpp.endTag("", "el1");
	}
	xpp.endTag("", "root");
	xpp.endDocument();
}
 
Example 6
Source File: XmlUtils.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
public static final void writeSetXml(Set val, String name, XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {
    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "set");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    for (Object v : val) {
        writeValueXml(v, null, out);
    }

    out.endTag(null, "set");
}
 
Example 7
Source File: XmlUtils.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
public static final void writeSetXml(Set val, String name, XmlSerializer out)
		throws XmlPullParserException, java.io.IOException {
	if (val == null) {
		out.startTag(null, "null");
		out.endTag(null, "null");
		return;
	}

	out.startTag(null, "set");
	if (name != null) {
		out.attribute(null, "name", name);
	}

	for (Object v : val) {
		writeValueXml(v, null, out);
	}

	out.endTag(null, "set");
}
 
Example 8
Source File: XmlUtils.java    From a with GNU General Public License v3.0 6 votes vote down vote up
public static void writeSetXml(Set val, String name, XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {
    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "set");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    for (Object v : val) {
        writeValueXml(v, null, out);
    }

    out.endTag(null, "set");
}
 
Example 9
Source File: ResArrayValue.java    From ratel with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeToResValuesXml(XmlSerializer serializer,
                                    ResResource res) throws IOException, AndrolibException {
    String type = getType();
    type = (type == null ? "" : type + "-") + "array";
    serializer.startTag(null, type);
    serializer.attribute(null, "name", res.getResSpec().getName());

    // lets check if we need to add formatted="false" to this array
    for (int i = 0; i < mItems.length; i++) {
        if (mItems[i].hasMultipleNonPositionalSubstitutions()) {
            serializer.attribute(null, "formatted", "false");
            break;
        }
    }

    // add <item>'s
    for (int i = 0; i < mItems.length; i++) {
        serializer.startTag(null, "item");
        serializer.text(mItems[i].encodeAsResXmlNonEscapedItemValue());
        serializer.endTag(null, "item");
    }
    serializer.endTag(null, type);
}
 
Example 10
Source File: XmlUtils.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Flatten a byte[] into an XmlSerializer.  The list can later be read back
 * with readThisByteArrayXml().
 *
 * @param val  The byte array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out  XmlSerializer to write the array into.
 * @see #writeMapXml
 * @see #writeValueXml
 */
public static void writeByteArrayXml(byte[] val, String name,
                                     XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "byte-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    StringBuilder sb = new StringBuilder(val.length * 2);
    for (int b : val) {
        int h = b >> 4;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
        h = b & 0xff;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
Example 11
Source File: XmlUtils.java    From XPrivacy with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Flatten an int[] into an XmlSerializer.  The list can later be read back
 * with readThisIntArrayXml().
 *
 * @param val The int array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static final void writeIntArrayXml(int[] val, String name,
        XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "int-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    for (int i=0; i<N; i++) {
        out.startTag(null, "item");
        out.attribute(null, "value", Integer.toString(val[i]));
        out.endTag(null, "item");
    }

    out.endTag(null, "int-array");
}
 
Example 12
Source File: ServicePropertiesSerializer.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the given metrics properties to the XMLStreamWriter.
 * 
 * @param xmlw
 *            the XMLStreamWriter to write to.
 * @param metrics
 *            the metrics properties to be written.
 * @param metricsName
 *            the type of metrics properties to be written (Hour or Minute)
 * @throws IOException
 *             if there is an error writing the service properties.
 * @throws IllegalStateException
 *             if there is an error writing the service properties.
 * @throws IllegalArgumentException
 *             if there is an error writing the service properties.
 */
private static void writeMetricsProperties(final XmlSerializer xmlw, final MetricsProperties metrics,
        final String metricsName) throws IllegalArgumentException, IllegalStateException, IOException {
    Utility.assertNotNull("metrics.Configuration", metrics.getMetricsLevel());

    // Metrics
    xmlw.startTag(Constants.EMPTY_STRING, metricsName);

    // Version
    Utility.serializeElement(xmlw, Constants.AnalyticsConstants.VERSION_ELEMENT, metrics.getVersion());

    // Enabled
    Utility.serializeElement(xmlw, Constants.AnalyticsConstants.ENABLED_ELEMENT,
            metrics.getMetricsLevel() != MetricsLevel.DISABLED ? Constants.TRUE : Constants.FALSE);

    if (metrics.getMetricsLevel() != MetricsLevel.DISABLED) {
        // Include APIs
        Utility.serializeElement(xmlw, Constants.AnalyticsConstants.INCLUDE_APIS_ELEMENT,
                metrics.getMetricsLevel() == MetricsLevel.SERVICE_AND_API ? Constants.TRUE : Constants.FALSE);
    }

    // Retention Policy
    writeRetentionPolicy(xmlw, metrics.getRetentionIntervalInDays());

    // end Metrics
    xmlw.endTag(Constants.EMPTY_STRING, metricsName);
}
 
Example 13
Source File: ResIdValue.java    From ratel with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeToResValuesXml(XmlSerializer serializer,
                                    ResResource res) throws IOException, AndrolibException {
    serializer.startTag(null, "item");
    serializer
            .attribute(null, "type", res.getResSpec().getType().getName());
    serializer.attribute(null, "name", res.getResSpec().getName());
    serializer.endTag(null, "item");
}
 
Example 14
Source File: XmlUtils.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Flatten an int[] into an XmlSerializer.  The list can later be read back
 * with readThisIntArrayXml().
 *
 * @param val  The int array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out  XmlSerializer to write the array into.
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static final void writeIntArrayXml(int[] val, String name,
										  XmlSerializer out)
		throws XmlPullParserException, java.io.IOException {

	if (val == null) {
		out.startTag(null, "null");
		out.endTag(null, "null");
		return;
	}

	out.startTag(null, "int-array");
	if (name != null) {
		out.attribute(null, "name", name);
	}

	final int N = val.length;
	out.attribute(null, "num", Integer.toString(N));

	for (int i = 0; i < N; i++) {
		out.startTag(null, "item");
		out.attribute(null, "value", Integer.toString(val[i]));
		out.endTag(null, "item");
	}

	out.endTag(null, "int-array");
}
 
Example 15
Source File: IntentFilterVerificationInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
public void writeToXml(XmlSerializer serializer) throws IOException {
    serializer.attribute(null, ATTR_PACKAGE_NAME, mPackageName);
    serializer.attribute(null, ATTR_STATUS, String.valueOf(mMainStatus));
    for (String str : mDomains) {
        serializer.startTag(null, TAG_DOMAIN);
        serializer.attribute(null, ATTR_DOMAIN_NAME, str);
        serializer.endTag(null, TAG_DOMAIN);
    }
}
 
Example 16
Source File: TaskRecord.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Saves this {@link TaskRecord} to XML using given serializer.
 */
void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
    if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);

    out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
    if (realActivity != null) {
        out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
    }
    out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
    if (origActivity != null) {
        out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
    }
    // Write affinity, and root affinity if it is different from affinity.
    // We use the special string "@" for a null root affinity, so we can identify
    // later whether we were given a root affinity or should just make it the
    // same as the affinity.
    if (affinity != null) {
        out.attribute(null, ATTR_AFFINITY, affinity);
        if (!affinity.equals(rootAffinity)) {
            out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
        }
    } else if (rootAffinity != null) {
        out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
    }
    out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
    out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
    out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
    out.attribute(null, ATTR_USERID, String.valueOf(userId));
    out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
    out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
    out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
    out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
    if (lastDescription != null) {
        out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
    }
    if (lastTaskDescription != null) {
        lastTaskDescription.saveToXml(out);
    }
    out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
    out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
    out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
    out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
    out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
    out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
    out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
    out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE,
            String.valueOf(mSupportsPictureInPicture));
    if (mLastNonFullscreenBounds != null) {
        out.attribute(
                null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
    }
    out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
    out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
    out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));

    if (affinityIntent != null) {
        out.startTag(null, TAG_AFFINITYINTENT);
        affinityIntent.saveToXml(out);
        out.endTag(null, TAG_AFFINITYINTENT);
    }

    if (intent != null) {
        out.startTag(null, TAG_INTENT);
        intent.saveToXml(out);
        out.endTag(null, TAG_INTENT);
    }

    final ArrayList<ActivityRecord> activities = mActivities;
    final int numActivities = activities.size();
    for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
        final ActivityRecord r = activities.get(activityNdx);
        if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
                ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
                        | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
                        activityNdx > 0) {
            // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
            break;
        }
        out.startTag(null, TAG_ACTIVITY);
        r.saveToXml(out);
        out.endTag(null, TAG_ACTIVITY);
    }
}
 
Example 17
Source File: XmlUtils.java    From ticdesign with Apache License 2.0 4 votes vote down vote up
/**
 * Flatten an object's value into an XmlSerializer.  The value can later
 * be read back with readThisValueXml().
 *
 * Currently supported value types are: null, String, Integer, Long,
 * Float, Double Boolean, Map, List.
 *
 * @param v The object to be flattened.
 * @param name Name attribute to include with this value's tag, or null
 *             for none.
 * @param out XmlSerializer to write the object into.
 * @param callback Handler for Object types not recognized.
 *
 * @see #writeMapXml
 * @see #writeListXml
 * @see #readValueXml
 */
private static final void writeValueXml(Object v, String name, XmlSerializer out,
        WriteMapCallback callback)  throws XmlPullParserException, java.io.IOException {
    String typeStr;
    if (v == null) {
        out.startTag(null, "null");
        if (name != null) {
            out.attribute(null, "name", name);
        }
        out.endTag(null, "null");
        return;
    } else if (v instanceof String) {
        out.startTag(null, "string");
        if (name != null) {
            out.attribute(null, "name", name);
        }
        out.text(v.toString());
        out.endTag(null, "string");
        return;
    } else if (v instanceof Integer) {
        typeStr = "int";
    } else if (v instanceof Long) {
        typeStr = "long";
    } else if (v instanceof Float) {
        typeStr = "float";
    } else if (v instanceof Double) {
        typeStr = "double";
    } else if (v instanceof Boolean) {
        typeStr = "boolean";
    } else if (v instanceof byte[]) {
        writeByteArrayXml((byte[])v, name, out);
        return;
    } else if (v instanceof int[]) {
        writeIntArrayXml((int[])v, name, out);
        return;
    } else if (v instanceof long[]) {
        writeLongArrayXml((long[])v, name, out);
        return;
    } else if (v instanceof double[]) {
        writeDoubleArrayXml((double[])v, name, out);
        return;
    } else if (v instanceof String[]) {
        writeStringArrayXml((String[])v, name, out);
        return;
    } else if (v instanceof boolean[]) {
        writeBooleanArrayXml((boolean[])v, name, out);
        return;
    } else if (v instanceof Map) {
        writeMapXml((Map)v, name, out);
        return;
    } else if (v instanceof List) {
        writeListXml((List) v, name, out);
        return;
    } else if (v instanceof Set) {
        writeSetXml((Set) v, name, out);
        return;
    } else if (v instanceof CharSequence) {
        // XXX This is to allow us to at least write something if
        // we encounter styled text...  but it means we will drop all
        // of the styling information. :(
        out.startTag(null, "string");
        if (name != null) {
            out.attribute(null, "name", name);
        }
        out.text(v.toString());
        out.endTag(null, "string");
        return;
    } else if (callback != null) {
        callback.writeUnknownObject(v, name, out);
        return;
    } else {
        throw new RuntimeException("writeValueXml: unable to write value " + v);
    }

    out.startTag(null, typeStr);
    if (name != null) {
        out.attribute(null, "name", name);
    }
    out.attribute(null, "value", v.toString());
    out.endTag(null, typeStr);
}
 
Example 18
Source File: XML_Util.java    From AndroidApp with Mozilla Public License 2.0 4 votes vote down vote up
public static String createNodeXmlBody(Map<String, String> tags, String changesetId, double lat, double lon) throws Exception {
    XmlSerializer xmlSerializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();

    if (tags == null) return null;
    /**
     *
     <osm>
     <node changeset="12" lat="..." lon="...">
     <tag k="note" v="Just a node"/>
     ...
     </node>
     </osm>
     */

    xmlSerializer.setOutput(writer);
    // start DOCUMENT
    xmlSerializer.startDocument("UTF-8", true);
    // open tag: <osm>
    xmlSerializer.startTag("", "osm");
    // open tag: <changeset>
    xmlSerializer.startTag("", "node");
    xmlSerializer.attribute("", "changeset", changesetId);
    xmlSerializer.attribute("", "lat", String.valueOf(lat));
    xmlSerializer.attribute("", "lon", String.valueOf(lon));

    //create tags
    for (Map.Entry<String, String> tag : tags.entrySet()) {
        xmlSerializer.startTag("", "tag");
        xmlSerializer.attribute("", "k", tag.getKey());
        xmlSerializer.attribute("", "v", tag.getValue());
        xmlSerializer.endTag("", "tag");
    }

    // close tag: </changeset>
    xmlSerializer.endTag("", "node");
    // close tag: </osm>
    xmlSerializer.endTag("", "osm");
    // end DOCUMENT
    xmlSerializer.endDocument();

    return writer.toString();
}
 
Example 19
Source File: AccessibilityNodeInfoDumper.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
private static void dumpNodeRec(AccessibilityNodeInfo node,
		XmlSerializer serializer, int index, int width, int height)
		throws IOException {
	serializer.startTag("", "node");
	if (!nafExcludedClass(node) && !nafCheck(node))
		serializer.attribute("", "NAF", Boolean.toString(true));
	serializer.attribute("", "index", Integer.toString(index));
	serializer.attribute("", "text", safeCharSeqToString(node.getText()));
	serializer.attribute("", "resource-id",
			safeCharSeqToString(node.getViewIdResourceName()));
	serializer.attribute("", "class",
			safeCharSeqToString(node.getClassName()));
	serializer.attribute("", "package",
			safeCharSeqToString(node.getPackageName()));
	serializer.attribute("", "content-desc",
			safeCharSeqToString(node.getContentDescription()));
	serializer.attribute("", "checkable",
			Boolean.toString(node.isCheckable()));
	serializer.attribute("", "checked", Boolean.toString(node.isChecked()));
	serializer.attribute("", "clickable",
			Boolean.toString(node.isClickable()));
	serializer.attribute("", "enabled", Boolean.toString(node.isEnabled()));
	serializer.attribute("", "focusable",
			Boolean.toString(node.isFocusable()));
	serializer.attribute("", "focused", Boolean.toString(node.isFocused()));
	serializer.attribute("", "scrollable",
			Boolean.toString(node.isScrollable()));
	serializer.attribute("", "long-clickable",
			Boolean.toString(node.isLongClickable()));
	serializer.attribute("", "password",
			Boolean.toString(node.isPassword()));
	serializer.attribute("", "selected",
			Boolean.toString(node.isSelected()));
	serializer.attribute("", "bounds", AccessibilityNodeInfoHelper
			.getVisibleBoundsInScreen(node, width, height).toShortString());
	int count = node.getChildCount();
	for (int i = 0; i < count; i++) {
		AccessibilityNodeInfo child = node.getChild(i);
		if (child != null) {
			if (child.isVisibleToUser()) {
				dumpNodeRec(child, serializer, i, width, height);
				child.recycle();
			} else {
				Log.i(LOGTAG,
						String.format("Skipping invisible child: %s",
								child.toString()));
			}
		} else {
			Log.i(LOGTAG, String.format("Null child %d/%d, parent: %s", i,
					count, node.toString()));
		}
	}
	serializer.endTag("", "node");
}
 
Example 20
Source File: ActivitySettings.java    From NetGuard with GNU General Public License v3.0 4 votes vote down vote up
private void xmlExport(OutputStream out) throws IOException {
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, "UTF-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    serializer.startTag(null, "netguard");

    serializer.startTag(null, "application");
    xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer);
    serializer.endTag(null, "application");

    serializer.startTag(null, "wifi");
    xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "wifi");

    serializer.startTag(null, "mobile");
    xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "mobile");

    serializer.startTag(null, "screen_wifi");
    xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "screen_wifi");

    serializer.startTag(null, "screen_other");
    xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "screen_other");

    serializer.startTag(null, "roaming");
    xmlExport(getSharedPreferences("roaming", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "roaming");

    serializer.startTag(null, "lockdown");
    xmlExport(getSharedPreferences("lockdown", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "lockdown");

    serializer.startTag(null, "apply");
    xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "apply");

    serializer.startTag(null, "notify");
    xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer);
    serializer.endTag(null, "notify");

    serializer.startTag(null, "filter");
    filterExport(serializer);
    serializer.endTag(null, "filter");

    serializer.startTag(null, "forward");
    forwardExport(serializer);
    serializer.endTag(null, "forward");

    serializer.endTag(null, "netguard");
    serializer.endDocument();
    serializer.flush();
}