List of usage examples for android.util Xml asAttributeSet
public static AttributeSet asAttributeSet(XmlPullParser parser)
From source file:com.android.server.MountService.java
private void readStorageListLocked() { mVolumes.clear();// w w w. j a v a2 s. c om mVolumeStates.clear(); Resources resources = mContext.getResources(); int id = com.android.internal.R.xml.storage_list; XmlResourceParser parser = resources.getXml(id); AttributeSet attrs = Xml.asAttributeSet(parser); try { XmlUtils.beginDocument(parser, TAG_STORAGE_LIST); while (true) { XmlUtils.nextElement(parser); String element = parser.getName(); if (element == null) break; if (TAG_STORAGE.equals(element)) { TypedArray a = resources.obtainAttributes(attrs, com.android.internal.R.styleable.Storage); String path = a.getString(com.android.internal.R.styleable.Storage_mountPoint); int descriptionId = a.getResourceId(com.android.internal.R.styleable.Storage_storageDescription, -1); CharSequence description = a .getText(com.android.internal.R.styleable.Storage_storageDescription); boolean primary = a.getBoolean(com.android.internal.R.styleable.Storage_primary, false); boolean removable = a.getBoolean(com.android.internal.R.styleable.Storage_removable, false); boolean emulated = a.getBoolean(com.android.internal.R.styleable.Storage_emulated, false); int mtpReserve = a.getInt(com.android.internal.R.styleable.Storage_mtpReserve, 0); boolean allowMassStorage = a .getBoolean(com.android.internal.R.styleable.Storage_allowMassStorage, false); boolean allowMtp = a.getBoolean(com.android.internal.R.styleable.Storage_allowMtp, true); // resource parser does not support longs, so XML value is in megabytes long maxFileSize = a.getInt(com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L * 1024L; Slog.d(TAG, "got storage path: " + path + " description: " + description + " primary: " + primary + " removable: " + removable + " emulated: " + emulated + " mtpReserve: " + mtpReserve + " allowMassStorage: " + allowMassStorage + " maxFileSize: " + maxFileSize + " allowMtp: " + allowMtp); if (emulated) { // For devices with emulated storage, we create separate // volumes for each known user. mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false, true, mtpReserve, false, maxFileSize, null, allowMtp); final UserManagerService userManager = UserManagerService.getInstance(); for (UserInfo user : userManager.getUsers(false)) { createEmulatedVolumeForUserLocked(user.getUserHandle()); } } else { if (path == null || description == null) { Slog.e(TAG, "Missing storage path or description in readStorageList"); } else { final StorageVolume volume = new StorageVolume(new File(path), descriptionId, primary, removable, emulated, mtpReserve, allowMassStorage, maxFileSize, null, allowMtp); addVolumeLocked(volume); // Until we hear otherwise, treat as unmounted mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED); volume.setState(Environment.MEDIA_UNMOUNTED); } } a.recycle(); } } } catch (XmlPullParserException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { // Compute storage ID for each physical volume; emulated storage is // always 0 when defined. int index = isExternalStorageEmulated() ? 1 : 0; for (StorageVolume volume : mVolumes) { if (!volume.isEmulated()) { volume.setStorageId(index++); } } parser.close(); } }
From source file:org.kde.necessitas.ministro.ExtractStyle.java
private JSONObject extractItemStyle(int resourceId, String itemName, int textAppearance) { try {/*from w w w .ja va 2 s .co m*/ XmlResourceParser parser = m_context.getResources().getLayout(resourceId); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty } if (type != XmlPullParser.START_TAG) { return null; } AttributeSet attributes = Xml.asAttributeSet(parser); String name = parser.getName(); if (name.equals("TextView")) return extractTextAppearanceInformations("textViewStyle", itemName, attributes, textAppearance); if (name.equals("CheckedTextView")) return extractCheckedTextView(attributes, itemName); } catch (Exception e) { e.printStackTrace(); } return null; }