android.util.Xml Java Examples

The following examples show how to use android.util.Xml. 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: KeyboardBuilder.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
private void parseSpacer(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_SPACER, parser);
        if (DEBUG) startEndTag("<%s /> skipped", TAG_SPACER);
        return;
    }
    final TypedArray keyAttr = mResources.obtainAttributes(
            Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
    final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
    final Key spacer = new Key.Spacer(keyAttr, keyStyle, mParams, row);
    keyAttr.recycle();
    if (DEBUG) startEndTag("<%s />", TAG_SPACER);
    XmlParseUtils.checkEndTag(TAG_SPACER, parser);
    endKey(spacer);
}
 
Example #2
Source File: KeyboardBuilder.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
private KeyboardRow parseRowAttributes(final XmlPullParser parser)
        throws XmlPullParserException {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard);
    try {
        if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap)) {
            throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "horizontalGap");
        }
        if (keyboardAttr.hasValue(R.styleable.Keyboard_verticalGap)) {
            throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "verticalGap");
        }
        return new KeyboardRow(mResources, mParams, parser, mCurrentY);
    } finally {
        keyboardAttr.recycle();
    }
}
 
Example #3
Source File: VectorDrawable.java    From Mover with Apache License 2.0 6 votes vote down vote up
/** @hide */
static VectorDrawable create(Resources resources, int rid) {
  android.util.Log.i("SupportVectorDrawable", resources.getResourceEntryName(rid));

  try {
    final XmlPullParser parser = resources.getXml(rid);
    final AttributeSet attrs = Xml.asAttributeSet(parser);
    int type;
        while ((type=parser.next()) != XmlPullParser.START_TAG &&
        type != XmlPullParser.END_DOCUMENT) {
      // Empty loop
    }
    if (type != XmlPullParser.START_TAG) {
      throw new XmlPullParserException("No start tag found");
    }

    final VectorDrawable drawable = new VectorDrawable();
    drawable.mResourceName = resources.getResourceEntryName(rid);
    drawable.inflate(resources, parser, attrs);

    return drawable;
  } catch (XmlPullParserException | IOException e) {
    Log.e(LOGTAG, "parser error", e);
  }
    return null;
}
 
Example #4
Source File: KeyboardBuilder.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
private void parseSpacer(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_SPACER, parser);
        if (DEBUG) startEndTag("<%s /> skipped", TAG_SPACER);
        return;
    }
    final TypedArray keyAttr = mResources.obtainAttributes(
            Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
    final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
    final Key spacer = new Key.Spacer(keyAttr, keyStyle, mParams, row);
    keyAttr.recycle();
    if (DEBUG) startEndTag("<%s />", TAG_SPACER);
    XmlParseUtils.checkEndTag(TAG_SPACER, parser);
    endKey(spacer);
}
 
Example #5
Source File: KeyboardRow.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
public KeyboardRow(final Resources res, final KeyboardParams params,
        final XmlPullParser parser, final int y) {
    mParams = params;
    final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.Keyboard);
    mRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
            R.styleable.Keyboard_rowHeight, params.mBaseHeight, params.mDefaultRowHeight);
    keyboardAttr.recycle();
    final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.Keyboard_Key);
    mRowAttributesStack.push(new RowAttributes(
            keyAttr, params.mDefaultKeyWidth, params.mBaseWidth));
    keyAttr.recycle();

    mCurrentY = y;
    mCurrentX = 0.0f;
}
 
Example #6
Source File: LollipopDrawablesCompat.java    From RippleDrawable with MIT License 6 votes vote down vote up
/**
 * Create a drawable from an XML document using an optional {@link Resources.Theme}.
 * For more information on how to create resources in XML, see
 * <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
 */
public static Drawable createFromXml(Resources r, XmlPullParser parser, Resources.Theme theme) throws XmlPullParserException, IOException {
    AttributeSet attrs = Xml.asAttributeSet(parser);

    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
        // Empty loop
    }

    if (type != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("No start tag found");
    }

    Drawable drawable = createFromXmlInner(r, parser, attrs, theme);

    if (drawable == null) {
        throw new RuntimeException("Unknown initial tag: " + parser.getName());
    }

    return drawable;
}
 
Example #7
Source File: OverlayManagerSettings.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public static void restore(@NonNull final ArrayList<SettingsItem> table,
        @NonNull final InputStream is) throws IOException, XmlPullParserException {

    try (InputStreamReader reader = new InputStreamReader(is)) {
        table.clear();
        final XmlPullParser parser = Xml.newPullParser();
        parser.setInput(reader);
        XmlUtils.beginDocument(parser, TAG_OVERLAYS);
        int version = XmlUtils.readIntAttribute(parser, ATTR_VERSION);
        if (version != CURRENT_VERSION) {
            upgrade(version);
        }
        int depth = parser.getDepth();

        while (XmlUtils.nextElementWithin(parser, depth)) {
            switch (parser.getName()) {
                case TAG_ITEM:
                    final SettingsItem item = restoreRow(parser, depth + 1);
                    table.add(item);
                    break;
            }
        }
    }
}
 
Example #8
Source File: BluetoothXmlParser.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
public ConcurrentHashMap<UUID, Characteristic> parseCharacteristics() throws XmlPullParserException, IOException {
    String[] characteristicFiles = appContext.getAssets().list(Consts.DIR_CHARACTERISTIC);
    XmlPullParser parser = Xml.newPullParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
    characteristics = new ConcurrentHashMap<>();
    for (String fileName : characteristicFiles) {
        try {
            Characteristic charact = parseCharacteristic(parser, Consts.DIR_CHARACTERISTIC + File.separator
                    + fileName);
            characteristics.put(charact.getUuid(), charact);
        } catch (XmlPullParserException | IOException e) {
            e.printStackTrace();
        }
    }
    return characteristics;
}
 
Example #9
Source File: Keyboard.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void parseKeyboardAttributes(Resources res, XmlResourceParser parser) {
    TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), 
            com.android.internal.R.styleable.Keyboard);

    mDefaultWidth = getDimensionOrFraction(a,
            com.android.internal.R.styleable.Keyboard_keyWidth,
            mDisplayWidth, mDisplayWidth / 10);
    mDefaultHeight = getDimensionOrFraction(a,
            com.android.internal.R.styleable.Keyboard_keyHeight,
            mDisplayHeight, 50);
    mDefaultHorizontalGap = getDimensionOrFraction(a,
            com.android.internal.R.styleable.Keyboard_horizontalGap,
            mDisplayWidth, 0);
    mDefaultVerticalGap = getDimensionOrFraction(a,
            com.android.internal.R.styleable.Keyboard_verticalGap,
            mDisplayHeight, 0);
    mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE);
    mProximityThreshold = mProximityThreshold * mProximityThreshold; // Square it for comparison
    a.recycle();
}
 
Example #10
Source File: XmlUtils.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
/**
 * 转换Object到xml
 *
 * @param obj
 * @param useAnnotation
 * @return
 */
public static String toXml(Object obj, boolean useAnnotation) {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final XmlSerializer serializer = Xml.newSerializer();
    String result = null;
    try {
        serializer.setOutput(baos, UTF_8);
        serializer.startDocument(UTF_8, true);
        toXml(serializer, obj, useAnnotation);
        serializer.endDocument();
        baos.close();
        result = baos.toString(UTF_8);
    } catch (IOException e) {
        Log.d(TAG, e.getMessage());
    }
    return result;
}
 
Example #11
Source File: Keyboard.java    From libcommon with Apache License 2.0 6 votes vote down vote up
public Row(Resources res, @NonNull final  Keyboard parent, XmlResourceParser parser) {
	if (DEBUG) Log.v(TAG, "コンストラクタ:");
	this.parent = parent;
	TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
		R.styleable.Keyboard);
	defaultWidth = getDimensionOrFraction(a,
		R.styleable.Keyboard_keyWidth,
		parent.mDisplayWidth, parent.mDefaultWidth);
	defaultHeight = getDimensionOrFraction(a,
		R.styleable.Keyboard_keyHeight,
		parent.mDisplayHeight, parent.mDefaultHeight);
	defaultHorizontalGap = getDimensionOrFraction(a,
		R.styleable.Keyboard_horizontalGap,
		parent.mDisplayWidth, parent.mDefaultHorizontalGap);
	verticalGap = getDimensionOrFraction(a,
		R.styleable.Keyboard_verticalGap,
		parent.mDisplayHeight, parent.mDefaultVerticalGap);
	a.recycle();
	a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard_Row);
	rowEdgeFlags = a.getInt(R.styleable.Keyboard_Row_rowEdgeFlags, 0);
	mode = a.getResourceId(R.styleable.Keyboard_Row_keyboardMode, 0);
	a.recycle();
}
 
Example #12
Source File: KeyboardBuilder.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
private void parseKey(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_KEY, parser);
        if (DEBUG) startEndTag("<%s /> skipped", TAG_KEY);
        return;
    }
    final TypedArray keyAttr = mResources.obtainAttributes(
            Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
    final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
    final String keySpec = keyStyle.getString(keyAttr, R.styleable.Keyboard_Key_keySpec);
    if (TextUtils.isEmpty(keySpec)) {
        throw new ParseException("Empty keySpec", parser);
    }
    final Key key = new Key(keySpec, keyAttr, keyStyle, mParams, row);
    keyAttr.recycle();
    if (DEBUG) {
        startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"),
                key, Arrays.toString(key.getMoreKeys()));
    }
    XmlParseUtils.checkEndTag(TAG_KEY, parser);
    endKey(key);
}
 
Example #13
Source File: KeyboardBuilder.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
private KeyboardRow parseRowAttributes(final XmlPullParser parser)
        throws XmlPullParserException {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard);
    try {
        if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap)) {
            throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "horizontalGap");
        }
        if (keyboardAttr.hasValue(R.styleable.Keyboard_verticalGap)) {
            throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "verticalGap");
        }
        return new KeyboardRow(mResources, mParams, parser, mCurrentY);
    } finally {
        keyboardAttr.recycle();
    }
}
 
Example #14
Source File: WriteXML.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private String writeXml() {
	XmlSerializer serializer = Xml.newSerializer();
	StringWriter writer = new StringWriter();
	try {
		// Hard coded stuff
		serializer.setOutput(writer);
		serializer.startDocument("UTF-8", true);
		serializer.startTag("", "people");
		serializer.attribute("", "number", "1");
		serializer.startTag("", "person");
		serializer.attribute("", "date", "20100101");
		serializer.startTag("", "name");
		serializer.text("Jim Knopf");
		serializer.endTag("", "name");
		serializer.startTag("", "url");
		serializer.text("http://www.vogella.de");
		serializer.endTag("", "url");
		serializer.startTag("", "attribute");
		serializer.text("nice guy");
		serializer.endTag("", "attribute");
		serializer.endTag("", "person");
		serializer.endTag("", "people");
		serializer.endDocument();

	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	return writer.toString();
}
 
Example #15
Source File: AliasActivity.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private Intent parseAlias(XmlPullParser parser)
        throws XmlPullParserException, IOException {
    AttributeSet attrs = Xml.asAttributeSet(parser);
    
    Intent intent = null;
    
    int type;
    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
            && type != XmlPullParser.START_TAG) {
    }
    
    String nodeName = parser.getName();
    if (!"alias".equals(nodeName)) {
        throw new RuntimeException(
                "Alias meta-data must start with <alias> tag; found"
                + nodeName + " at " + parser.getPositionDescription());
    }
    
    int outerDepth = parser.getDepth();
    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
           && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        nodeName = parser.getName();
        if ("intent".equals(nodeName)) {
            Intent gotIntent = Intent.parseIntent(getResources(), parser, attrs);
            if (intent == null) intent = gotIntent;
        } else {
            XmlUtils.skipCurrentTag(parser);
        }
    }
    
    return intent;
}
 
Example #16
Source File: XmlLoaderTask.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
private FileFormat getFileFormat()
{
    InputStream is = FileUtils.getInputStream(list.getActivity(), uri);
    String prop = null;
    try
    {
        final XmlPullParser p = Xml.newPullParser();
        p.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        p.setInput(is, null);
        p.nextTag();
        if (p.getAttributeCount() > 0)
        {
            prop = p.getAttributeValue(0);
        }
    }
    catch (Exception e)
    {
        ViewUtils.Debug(this, "Can not define file format: " + e.getLocalizedMessage());
    }
    FileUtils.closeStream(is);

    if (prop != null && FormulaList.XML_MMT_SCHEMA.equals(prop))
    {
        return FileFormat.MMT;
    }
    else if (prop != null && FormulaList.XML_SM_SCHEMA.equals(prop))
    {
        return FileFormat.SMATH_STUDIO;
    }
    return FileFormat.INVALID;
}
 
Example #17
Source File: SpeechRate.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
public SpeechRate()
{
    try
    {
        _parser = Xml.newPullParser();
        _parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
    }
    catch (XmlPullParserException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #18
Source File: WeixinUtil.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
public static Map<String,String> decodeXml(String content) {
    try {
        Map<String, String> xml = new HashMap<>();
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(new StringReader(content));
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {

            String nodeName=parser.getName();
            switch (event) {
                case XmlPullParser.START_DOCUMENT:

                    break;
                case XmlPullParser.START_TAG:
                    if(!"xml".equals(nodeName)){
                        //实例化student对象
                        xml.put(nodeName,parser.nextText());
                    }
                    break;
                case XmlPullParser.END_TAG:
                    break;
            }
            event = parser.next();
        }
        return xml;
    } catch (Exception e) {
        Log.e("orion",e.toString());
    }
    return null;

}
 
Example #19
Source File: StackOverflowXmlParser.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
public List<Cell> parse(InputStream in) throws XmlPullParserException, IOException {
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(in, null);
        parser.nextTag();
        return readCells(parser);
    } finally {
        in.close();
    }
}
 
Example #20
Source File: InvariantDeviceProfile.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
private ArrayList<InvariantDeviceProfile> getPredefinedDeviceProfiles(Context context) {
    ArrayList<InvariantDeviceProfile> profiles = new ArrayList<>();
    try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
        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) && "profile".equals(parser.getName())) {
                TypedArray a = context.obtainStyledAttributes(
                        Xml.asAttributeSet(parser), R.styleable.InvariantDeviceProfile);
                int numRows = a.getInt(R.styleable.InvariantDeviceProfile_numRows, 0);
                int numColumns = a.getInt(R.styleable.InvariantDeviceProfile_numColumns, 0);
                float iconSize = a.getFloat(R.styleable.InvariantDeviceProfile_iconSize, 0);
                profiles.add(new InvariantDeviceProfile(
                        a.getString(R.styleable.InvariantDeviceProfile_name),
                        a.getFloat(R.styleable.InvariantDeviceProfile_minWidthDps, 0),
                        a.getFloat(R.styleable.InvariantDeviceProfile_minHeightDps, 0),
                        numRows,
                        numColumns,
                        a.getInt(R.styleable.InvariantDeviceProfile_numFolderRows, numRows),
                        a.getInt(R.styleable.InvariantDeviceProfile_numFolderColumns, numColumns),
                        a.getInt(R.styleable.InvariantDeviceProfile_minAllAppsPredictionColumns, numColumns),
                        iconSize,
                        a.getFloat(R.styleable.InvariantDeviceProfile_iconTextSize, 0),
                        a.getInt(R.styleable.InvariantDeviceProfile_numHotseatIcons, numColumns),
                        a.getFloat(R.styleable.InvariantDeviceProfile_hotseatIconSize, iconSize),
                        a.getResourceId(R.styleable.InvariantDeviceProfile_defaultLayoutId, 0)));
                a.recycle();
            }
        }
    } catch (IOException|XmlPullParserException e) {
        throw new RuntimeException(e);
    }
    return profiles;
}
 
Example #21
Source File: ActivityDns.java    From tracker-control-android with GNU General Public License v3.0 5 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");

    DateFormat df = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.US); // RFC 822

    try (Cursor cursor = DatabaseHelper.getInstance(this).getDns()) {
        int colTime = cursor.getColumnIndex("time");
        int colQName = cursor.getColumnIndex("qname");
        int colAName = cursor.getColumnIndex("aname");
        int colResource = cursor.getColumnIndex("resource");
        int colTTL = cursor.getColumnIndex("ttl");
        while (cursor.moveToNext()) {
            long time = cursor.getLong(colTime);
            String qname = cursor.getString(colQName);
            String aname = cursor.getString(colAName);
            String resource = cursor.getString(colResource);
            int ttl = cursor.getInt(colTTL);

            serializer.startTag(null, "dns");
            serializer.attribute(null, "time", df.format(time));
            serializer.attribute(null, "qname", qname);
            serializer.attribute(null, "aname", aname);
            serializer.attribute(null, "resource", resource);
            serializer.attribute(null, "ttl", Integer.toString(ttl));
            serializer.endTag(null, "dns");
        }
    }

    serializer.endTag(null, "netguard");
    serializer.endDocument();
    serializer.flush();
}
 
Example #22
Source File: GPXParser.java    From android-gpx-parser with Apache License 2.0 5 votes vote down vote up
public Gpx parse(InputStream in) throws XmlPullParserException, IOException {
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        parser.setInput(in, null);
        parser.nextTag();
        return readGpx(parser);
    } finally {
        in.close();
    }
}
 
Example #23
Source File: NavInflater.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Inflate a NavGraph from the given XML resource id.
 *
 * @param graphResId
 * @return
 */
@SuppressLint("ResourceType")
@NonNull
public NavGraph inflate(@NavigationRes int graphResId) {
    Resources res = mContext.getResources();
    XmlResourceParser parser = res.getXml(graphResId);
    final AttributeSet attrs = Xml.asAttributeSet(parser);
    try {
        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG
                && type != XmlPullParser.END_DOCUMENT) {
            // Empty loop
        }
        if (type != XmlPullParser.START_TAG) {
            throw new XmlPullParserException("No start tag found");
        }

        String rootElement = parser.getName();
        NavDestination destination = inflate(res, parser, attrs);
        if (!(destination instanceof NavGraph)) {
            throw new IllegalArgumentException("Root element <" + rootElement + ">"
                    + " did not inflate into a NavGraph");
        }
        return (NavGraph) destination;
    } catch (Exception e) {
        throw new RuntimeException("Exception inflating "
                + res.getResourceName(graphResId) + " line "
                + parser.getLineNumber(), e);
    } finally {
        parser.close();
    }
}
 
Example #24
Source File: KeyboardLayoutSet.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
private static int readScriptIdFromTagFeature(final Resources resources,
                                              final XmlPullParser parser) throws IOException, XmlPullParserException {
    final TypedArray featureAttr = resources.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.KeyboardLayoutSet_Feature);
    try {
        final int scriptId =
                featureAttr.getInt(R.styleable.KeyboardLayoutSet_Feature_supportedScript,
                        ScriptUtils.SCRIPT_UNKNOWN);
        XmlParseUtils.checkEndTag(TAG_FEATURE, parser);
        return scriptId;
    } finally {
        featureAttr.recycle();
    }
}
 
Example #25
Source File: KeyboardLayoutSet.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
private void parseKeyboardLayoutSetElement(final XmlPullParser parser)
        throws XmlPullParserException, IOException {
    final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.KeyboardLayoutSet_Element);
    try {
        XmlParseUtils.checkAttributeExists(a,
                R.styleable.KeyboardLayoutSet_Element_elementName, "elementName",
                TAG_ELEMENT, parser);
        XmlParseUtils.checkAttributeExists(a,
                R.styleable.KeyboardLayoutSet_Element_elementKeyboard, "elementKeyboard",
                TAG_ELEMENT, parser);
        XmlParseUtils.checkEndTag(TAG_ELEMENT, parser);

        final ElementParams elementParams = new ElementParams();
        final int elementName = a.getInt(
                R.styleable.KeyboardLayoutSet_Element_elementName, 0);
        elementParams.mKeyboardXmlId = a.getResourceId(
                R.styleable.KeyboardLayoutSet_Element_elementKeyboard, 0);
        elementParams.mProximityCharsCorrectionEnabled = a.getBoolean(
                R.styleable.KeyboardLayoutSet_Element_enableProximityCharsCorrection,
                false);
        elementParams.mSupportsSplitLayout = a.getBoolean(
                R.styleable.KeyboardLayoutSet_Element_supportsSplitLayout, false);
        elementParams.mAllowRedundantMoreKeys = a.getBoolean(
                R.styleable.KeyboardLayoutSet_Element_allowRedundantMoreKeys, true);
        mParams.mKeyboardLayoutSetElementIdToParamsMap.put(elementName, elementParams);
    } finally {
        a.recycle();
    }
}
 
Example #26
Source File: KeyboardLayoutSet.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private static int readScriptIdFromTagFeature(final Resources resources,
        final XmlPullParser parser) throws IOException, XmlPullParserException {
    final TypedArray featureAttr = resources.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.KeyboardLayoutSet_Feature);
    try {
        final int scriptId =
                featureAttr.getInt(R.styleable.KeyboardLayoutSet_Feature_supportedScript,
                        ScriptUtils.SCRIPT_UNKNOWN);
        XmlParseUtils.checkEndTag(TAG_FEATURE, parser);
        return scriptId;
    } finally {
        featureAttr.recycle();
    }
}
 
Example #27
Source File: Keyboard.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
private void parseKeyboardAttributes(Resources res, XmlResourceParser parser) {
    TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.Keyboard);

    mDefaultWidth = getDimensionOrFraction(a,
            R.styleable.Keyboard_keyWidth,
            mDisplayWidth, mDisplayWidth / 10);
    mDefaultHeight = Math.round(getDimensionOrFraction(a,
            R.styleable.Keyboard_keyHeight,
            mDisplayHeight, mDefaultHeight));
    mDefaultHorizontalGap = getDimensionOrFraction(a,
            R.styleable.Keyboard_horizontalGap,
            mDisplayWidth, 0);
    mDefaultVerticalGap = Math.round(getDimensionOrFraction(a,
            R.styleable.Keyboard_verticalGap,
            mDisplayHeight, 0));
    mHorizontalPad = getDimensionOrFraction(a,
            R.styleable.Keyboard_horizontalPad,
            mDisplayWidth, res.getDimension(R.dimen.key_horizontal_pad));
    mVerticalPad = getDimensionOrFraction(a,
            R.styleable.Keyboard_verticalPad,
            mDisplayHeight, res.getDimension(R.dimen.key_vertical_pad));
    mLayoutRows = a.getInteger(R.styleable.Keyboard_layoutRows, DEFAULT_LAYOUT_ROWS);
    mLayoutColumns = a.getInteger(R.styleable.Keyboard_layoutColumns, DEFAULT_LAYOUT_COLUMNS);
    if (mDefaultHeight == 0 && mKeyboardHeight > 0 && mLayoutRows > 0) {
        mDefaultHeight = mKeyboardHeight / mLayoutRows;
        //Log.i(TAG, "got mLayoutRows=" + mLayoutRows + ", mDefaultHeight=" + mDefaultHeight);
    }
    mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE);
    mProximityThreshold = mProximityThreshold * mProximityThreshold; // Square it for comparison
    a.recycle();
}
 
Example #28
Source File: KeyboardLayoutSet.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
private static int readScriptIdFromTagFeature(final Resources resources,
        final XmlPullParser parser) throws IOException, XmlPullParserException {
    final TypedArray featureAttr = resources.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.KeyboardLayoutSet_Feature);
    try {
        final int scriptId =
                featureAttr.getInt(R.styleable.KeyboardLayoutSet_Feature_supportedScript,
                        ScriptUtils.SCRIPT_UNKNOWN);
        XmlParseUtils.checkEndTag(TAG_FEATURE, parser);
        return scriptId;
    } finally {
        featureAttr.recycle();
    }
}
 
Example #29
Source File: ChangelogParserUtil.java    From changelog with Apache License 2.0 5 votes vote down vote up
static Changelog readChangeLogFile(Context context, int changelogXmlFileId, IAutoVersionNameFormatter autoVersionNameFormatter, IChangelogSorter sorter) throws Exception {
    Changelog changelog;

    try {
        XmlPullParser parser;

        String resourceType = context.getResources().getResourceTypeName(changelogXmlFileId);
        if (resourceType.equals("raw")) {
            InputStream in = context.getResources().openRawResource(changelogXmlFileId);
            parser = Xml.newPullParser();
            parser.setInput(in, null);
        } else if (resourceType.equals("xml")) {
            parser = context.getResources().getXml(changelogXmlFileId);
        } else
            throw new RuntimeException("Wrong changelog resource type, provide xml or raw resource!");

        // 1) Create Changelog object
        changelog = new Changelog();

        // 2) Parse file into Changelog object
        parseMainNode(parser, changelog, autoVersionNameFormatter);

        // 3) sort changelogs
        changelog.sort(sorter);
    } catch (XmlPullParserException xpe) {
        Log.d(Constants.DEBUG_TAG, "XmlPullParseException while parsing changelog file", xpe);
        throw xpe;
    } catch (IOException ioe) {
        Log.d(Constants.DEBUG_TAG, "IOException with changelog.xml", ioe);
        throw ioe;
    }

    return changelog;
}
 
Example #30
Source File: ApplicationListParser.java    From Stringlate with MIT License 5 votes vote down vote up
static boolean parseToXml(ApplicationList applications, OutputStream out) {
    XmlSerializer serializer = Xml.newSerializer();
    try {
        serializer.setOutput(out, "UTF-8");
        serializer.startTag(ns, "fdroid");

        for (ApplicationDetails app : applications) {
            serializer.startTag(ns, "application");

            writeTag(serializer, ID, app.getPackageName());
            writeTag(serializer, LAST_UPDATED, app.getLastUpdatedDateString());
            writeTag(serializer, NAME, app.getProjectName());
            writeTag(serializer, DESCRIPTION, app.getDescription());
            writeTag(serializer, ICON_URL, app.getIconUrl());
            writeTag(serializer, SOURCE_URL, app.getSourceCodeUrl());
            writeTag(serializer, WEB, app.getProjectWebUrl());
            writeTag(serializer, MAIL, app.getProjectMail());

            serializer.endTag(ns, "application");
        }
        serializer.endTag(ns, "fdroid");
        serializer.flush();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}