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 Project: simple-keyboard Author: rkkr File: KeyboardRow.java License: Apache License 2.0 | 6 votes |
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 #2
Source Project: android_9.0.0_r45 Author: lulululbj File: OverlayManagerSettings.java License: Apache License 2.0 | 6 votes |
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 #3
Source Project: EFRConnect-android Author: SiliconLabs File: BluetoothXmlParser.java License: Apache License 2.0 | 6 votes |
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 #4
Source Project: android_9.0.0_r45 Author: lulululbj File: Keyboard.java License: Apache License 2.0 | 6 votes |
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 #5
Source Project: libcommon Author: saki4510t File: Keyboard.java License: Apache License 2.0 | 6 votes |
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 #6
Source Project: simple-keyboard Author: rkkr File: KeyboardBuilder.java License: Apache License 2.0 | 6 votes |
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 #7
Source Project: openboard Author: dslul File: KeyboardBuilder.java License: GNU General Public License v3.0 | 6 votes |
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 #8
Source Project: openboard Author: dslul File: KeyboardBuilder.java License: GNU General Public License v3.0 | 6 votes |
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 #9
Source Project: Cangol-appcore Author: Cangol File: XmlUtils.java License: Apache License 2.0 | 6 votes |
/** * 转换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 #10
Source Project: LokiBoard-Android-Keylogger Author: IceWreck File: KeyboardBuilder.java License: Apache License 2.0 | 6 votes |
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 #11
Source Project: RippleDrawable Author: ozodrukh File: LollipopDrawablesCompat.java License: MIT License | 6 votes |
/** * 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 #12
Source Project: simple-keyboard Author: rkkr File: KeyboardBuilder.java License: Apache License 2.0 | 6 votes |
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 #13
Source Project: Mover Author: Codetail File: VectorDrawable.java License: Apache License 2.0 | 6 votes |
/** @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 #14
Source Project: Stringlate Author: LonamiWebs File: ApplicationListParser.java License: MIT License | 5 votes |
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; } }
Example #15
Source Project: AOSP-Kayboard-7.1.2 Author: sergchil File: KeyboardLayoutSet.java License: Apache License 2.0 | 5 votes |
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 #16
Source Project: android-gpx-parser Author: ticofab File: GPXParser.java License: Apache License 2.0 | 5 votes |
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 #17
Source Project: android_9.0.0_r45 Author: lulululbj File: DefaultPermissionGrantPolicy.java License: Apache License 2.0 | 5 votes |
private @NonNull ArrayMap<String, List<DefaultPermissionGrant>> readDefaultPermissionExceptionsLocked() { File[] files = getDefaultPermissionFiles(); if (files == null) { return new ArrayMap<>(0); } ArrayMap<String, List<DefaultPermissionGrant>> grantExceptions = new ArrayMap<>(); // Iterate over the files in the directory and scan .xml files for (File file : files) { if (!file.getPath().endsWith(".xml")) { Slog.i(TAG, "Non-xml file " + file + " in " + file.getParent() + " directory, ignoring"); continue; } if (!file.canRead()) { Slog.w(TAG, "Default permissions file " + file + " cannot be read"); continue; } try ( InputStream str = new BufferedInputStream(new FileInputStream(file)) ) { XmlPullParser parser = Xml.newPullParser(); parser.setInput(str, null); parse(parser, grantExceptions); } catch (XmlPullParserException | IOException e) { Slog.w(TAG, "Error reading default permissions file " + file, e); } } return grantExceptions; }
Example #18
Source Project: android_9.0.0_r45 Author: lulululbj File: InstantAppRegistry.java License: Apache License 2.0 | 5 votes |
private static @Nullable UninstalledInstantAppState parseMetadataFile( @NonNull File metadataFile) { if (!metadataFile.exists()) { return null; } FileInputStream in; try { in = new AtomicFile(metadataFile).openRead(); } catch (FileNotFoundException fnfe) { Slog.i(LOG_TAG, "No instant metadata file"); return null; } final File instantDir = metadataFile.getParentFile(); final long timestamp = metadataFile.lastModified(); final String packageName = instantDir.getName(); try { XmlPullParser parser = Xml.newPullParser(); parser.setInput(in, StandardCharsets.UTF_8.name()); return new UninstalledInstantAppState( parseMetadata(parser, packageName), timestamp); } catch (XmlPullParserException | IOException e) { throw new IllegalStateException("Failed parsing instant" + " metadata file: " + metadataFile, e); } finally { IoUtils.closeQuietly(in); } }
Example #19
Source Project: ssj Author: hcmlab File: UtilTest.java License: GNU General Public License v3.0 | 5 votes |
@Test public void testXmlToStr() throws Exception { String str = "<ssj><test attr=\"val\">text</test><test attr=\"val2\">text2</test></ssj>"; Log.i("input: " + str); XmlPullParser xml = Xml.newPullParser(); xml.setInput(new StringReader(str)); xml.next(); Log.i("output: " + Util.xmlToString(xml)); }
Example #20
Source Project: Connect-SDK-Android-Core Author: ConnectSDK File: DLNANotifyParser.java License: Apache License 2.0 | 5 votes |
public JSONArray parse(InputStream in) throws XmlPullParserException, IOException, JSONException { try { XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(in, null); parser.nextTag(); return readPropertySet(parser); } finally { in.close(); } }
Example #21
Source Project: android_9.0.0_r45 Author: lulululbj File: AliasActivity.java License: Apache License 2.0 | 5 votes |
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 #22
Source Project: ssj Author: hcmlab File: SpeechRate.java License: GNU General Public License v3.0 | 5 votes |
public SpeechRate() { try { _parser = Xml.newPullParser(); _parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); } catch (XmlPullParserException e) { throw new RuntimeException(e); } }
Example #23
Source Project: android-common-utils Author: LightSun File: WeixinUtil.java License: Apache License 2.0 | 5 votes |
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 #24
Source Project: android_9.0.0_r45 Author: lulululbj File: NavInflater.java License: Apache License 2.0 | 5 votes |
/** * 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 #25
Source Project: openboard Author: dslul File: KeyboardLayoutSet.java License: GNU General Public License v3.0 | 5 votes |
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 #26
Source Project: openboard Author: dslul File: KeyboardLayoutSet.java License: GNU General Public License v3.0 | 5 votes |
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 #27
Source Project: Indic-Keyboard Author: smc File: KeyboardLayoutSet.java License: Apache License 2.0 | 5 votes |
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 #28
Source Project: hackerskeyboard Author: klausw File: Keyboard.java License: Apache License 2.0 | 5 votes |
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 #29
Source Project: tracker-control-android Author: OxfordHCC File: ActivityDns.java License: GNU General Public License v3.0 | 5 votes |
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 #30
Source Project: microMathematics Author: mkulesh File: XmlLoaderTask.java License: GNU General Public License v3.0 | 5 votes |
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; }