當前位置: 首頁>>代碼示例>>Java>>正文


Java XmlResourceParser.getName方法代碼示例

本文整理匯總了Java中android.content.res.XmlResourceParser.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlResourceParser.getName方法的具體用法?Java XmlResourceParser.getName怎麽用?Java XmlResourceParser.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.res.XmlResourceParser的用法示例。


在下文中一共展示了XmlResourceParser.getName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseAndAdd

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    final int groupDepth = parser.getDepth();
    int type;
    long addedId = -1;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > groupDepth) {
        if (type != XmlPullParser.START_TAG || addedId > -1) {
            continue;
        }
        final String fallback_item_name = parser.getName();
        if (TAG_FAVORITE.equals(fallback_item_name)) {
            addedId = mChildParser.parseAndAdd(parser);
        }
    }
    return addedId;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:19,代碼來源:DefaultLayoutParser.java

示例2: parseKeyboardLayoutSet

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private void parseKeyboardLayoutSet(final Resources res, final int resId)
        throws XmlPullParserException, IOException {
    final XmlResourceParser parser = res.getXml(resId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            final int event = parser.next();
            if (event == XmlPullParser.START_TAG) {
                final String tag = parser.getName();
                if (TAG_KEYBOARD_SET.equals(tag)) {
                    parseKeyboardLayoutSetContent(parser);
                } else {
                    throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET);
                }
            }
        }
    } finally {
        parser.close();
    }
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:20,代碼來源:KeyboardLayoutSet.java

示例3: parseAndAdd

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    final int groupDepth = parser.getDepth();
    int type;
    long addedId = -1;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > groupDepth) {
        if (type != XmlPullParser.START_TAG || addedId > -1) {
            continue;
        }
        final String fallback_item_name = parser.getName();
        if (TAG_FAVORITE.equals(fallback_item_name)) {
            addedId = mChildParser.parseAndAdd(parser);
        } else {
            Log.e(TAG, "Fallback groups can contain only favorites, found "
                    + fallback_item_name);
        }
    }
    return addedId;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:22,代碼來源:DefaultLayoutParser.java

示例4: parseActivity

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
 * parseActivity
 *
 * @param activityName  activityName
 * @param intentFilters intentFilters
 * @param parser        parser
 * @throws Exception e
 */
private static void parseActivity(String activityName, Map<String, IntentFilter> intentFilters,
                                  XmlResourceParser parser) throws Exception {
    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        String tagName = parser.getName();
        if (tagName == null) {
            continue;
        }

        if (tagName.equals("intent-filter")) {
            IntentFilter mFilter = new IntentFilter();
            intentFilters.put(activityName, mFilter);
            parseIntentFilter(mFilter, parser);
        }
    }
}
 
開發者ID:LiangMaYong,項目名稱:android-apkbox,代碼行數:30,代碼來源:ApkManifestParser.java

示例5: readScriptId

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) {
    final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX
            + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
    final int xmlId = getXmlId(resources, layoutSetName);
    final XmlResourceParser parser = resources.getXml(xmlId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            // Bovinate through the XML stupidly searching for TAG_FEATURE, and read
            // the script Id from it.
            parser.next();
            final String tag = parser.getName();
            if (TAG_FEATURE.equals(tag)) {
                return readScriptIdFromTagFeature(resources, parser);
            }
        }
    } catch (final IOException | XmlPullParserException e) {
        throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e);
    } finally {
        parser.close();
    }
    // If the tag is not found, then the default script is Latin.
    return ScriptUtils.SCRIPT_LATIN;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:24,代碼來源:KeyboardLayoutSet.java

示例6: getIcons

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private List<Cate> getIcons() {
    List<Cate> dataList = new ArrayList<>();
    Cate defCate = new Cate(null);
    XmlResourceParser parser = getResources().getXml(R.xml.drawable);
    try {
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                switch (parser.getName()) {
                    case "category":
                        dataList.add(new Cate(parser.getAttributeValue(null, "title")));
                        break;
                    case "item":
                        String iconName = parser.getAttributeValue(null, "drawable");
                        if (dataList.isEmpty()) {
                            defCate.pushIcon(iconName);
                        } else {
                            dataList.get(dataList.size() - 1).pushIcon(iconName);
                        }
                        break;
                }
            }
            event = parser.next();
        }
        if (!defCate.isEmpty()) {
            dataList.add(defCate);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return dataList;
}
 
開發者ID:by-syk,項目名稱:NanoIconPackLite,代碼行數:33,代碼來源:LiteIconActivityV2.java

示例7: parsePathStrategy

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private static PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException {
    SimplePathStrategy strat = new SimplePathStrategy(authority);
    XmlResourceParser in = context.getPackageManager().resolveContentProvider(authority, 128).loadXmlMetaData(context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
    if (in == null) {
        throw new IllegalArgumentException("Missing android.support.FILE_PROVIDER_PATHS meta-data");
    }
    while (true) {
        int type = in.next();
        if (type == 1) {
            return strat;
        }
        if (type == 2) {
            String tag = in.getName();
            String name = in.getAttributeValue(null, "name");
            String path = in.getAttributeValue(null, ATTR_PATH);
            File target = null;
            if (TAG_ROOT_PATH.equals(tag)) {
                target = buildPath(DEVICE_ROOT, path);
            } else if (TAG_FILES_PATH.equals(tag)) {
                target = buildPath(context.getFilesDir(), path);
            } else if (TAG_CACHE_PATH.equals(tag)) {
                target = buildPath(context.getCacheDir(), path);
            } else if (TAG_EXTERNAL.equals(tag)) {
                target = buildPath(Environment.getExternalStorageDirectory(), path);
            }
            if (target != null) {
                strat.addRoot(name, target);
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:32,代碼來源:FileProvider.java

示例8: readUuidData

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private void readUuidData(XmlResourceParser xpp) throws XmlPullParserException, IOException {
  xpp.next();
  String tagName = null;
  String uuid = null;
  String descr = null;
  int eventType = xpp.getEventType();

  while (eventType != XmlPullParser.END_DOCUMENT) {
    if (eventType == XmlPullParser.START_DOCUMENT) {
      // do nothing
    } else if (eventType == XmlPullParser.START_TAG) {
      tagName = xpp.getName();
      uuid = xpp.getAttributeValue(null, "uuid");
      descr = xpp.getAttributeValue(null, "descr");
    } else if (eventType == XmlPullParser.END_TAG) {
      // do nothing
    } else if (eventType == XmlPullParser.TEXT) {
      if (tagName.equalsIgnoreCase("item")) {
        if (!uuid.isEmpty()) {
          uuid = uuid.replace("0x", "");
          mNameMap.put(uuid, xpp.getText());
          mDescrMap.put(uuid, descr);
        }
      }
    }
    eventType = xpp.next();
  }
}
 
開發者ID:UDOOboard,項目名稱:UDOOBluLib-android,代碼行數:29,代碼來源:GattInfo.java

示例9: parseAndAdd

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
@Override
public long parseAndAdd(XmlResourceParser parser)
        throws XmlPullParserException, IOException {
    final String title;
    final int titleResId = getAttributeResourceValue(parser, ATTR_TITLE, 0);
    if (titleResId != 0) {
        title = mSourceRes.getString(titleResId);
    } else {
        title = mContext.getResources().getString(R.string.folder_name);
    }

    mValues.put(Favorites.TITLE, title);
    mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_FOLDER);
    mValues.put(Favorites.SPANX, 1);
    mValues.put(Favorites.SPANY, 1);
    mValues.put(Favorites._ID, mCallback.generateNewItemId());
    long folderId = mCallback.insertAndCheck(mDb, mValues);
    if (folderId < 0) {
        return -1;
    }

    final ContentValues myValues = new ContentValues(mValues);
    ArrayList<Long> folderItems = new ArrayList<Long>();

    int type;
    int folderDepth = parser.getDepth();
    int rank = 0;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > folderDepth) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        mValues.clear();
        mValues.put(Favorites.CONTAINER, folderId);
        mValues.put(Favorites.RANK, rank);

        TagParser tagParser = mFolderElements.get(parser.getName());
        if (tagParser != null) {
            final long id = tagParser.parseAndAdd(parser);
            if (id >= 0) {
                folderItems.add(id);
                rank++;
            }
        } else {
            throw new RuntimeException("Invalid folder item " + parser.getName());
        }
    }

    long addedId = folderId;

    // We can only have folders with >= 2 items, so we need to remove the
    // folder and clean up if less than 2 items were included, or some
    // failed to add, and less than 2 were actually added
    if (folderItems.size() < 2) {
        // Delete the folder
        Uri uri = Favorites.getContentUri(folderId);
        SqlArguments args = new SqlArguments(uri, null, null);
        mDb.delete(args.table, args.where, args.args);
        addedId = -1;

        // If we have a single item, promote it to where the folder
        // would have been.
        if (folderItems.size() == 1) {
            final ContentValues childValues = new ContentValues();
            copyInteger(myValues, childValues, Favorites.CONTAINER);
            copyInteger(myValues, childValues, Favorites.SCREEN);
            copyInteger(myValues, childValues, Favorites.CELLX);
            copyInteger(myValues, childValues, Favorites.CELLY);

            addedId = folderItems.get(0);
            mDb.update(Favorites.TABLE_NAME, childValues,
                    Favorites._ID + "=" + addedId, null);
        }
    }
    return addedId;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:77,代碼來源:AutoInstallsLayout.java

示例10: loadUiOptionsFromManifest

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private static int loadUiOptionsFromManifest(Activity activity) {
    int uiOptions = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);

        final String packageName = activity.getApplicationInfo().packageName;
        final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
        final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");

        int eventType = xml.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                String name = xml.getName();

                if ("application".equals(name)) {
                    //Check if the <application> has the attribute
                    if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        if ("uiOptions".equals(xml.getAttributeName(i))) {
                            uiOptions = xml.getAttributeIntValue(i, 0);
                            break; //out of for loop
                        }
                    }
                } else if ("activity".equals(name)) {
                    //Check if the <activity> is us and has the attribute
                    if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
                    Integer activityUiOptions = null;
                    String activityPackage = null;
                    boolean isOurActivity = false;

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        //We need both uiOptions and name attributes
                        String attrName = xml.getAttributeName(i);
                        if ("uiOptions".equals(attrName)) {
                            activityUiOptions = xml.getAttributeIntValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //out of for loop
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityUiOptions != null) && (activityPackage != null)) {
                            //Our activity, uiOptions specified, override with our value
                            uiOptions = activityUiOptions.intValue();
                        }
                    }
                    if (isOurActivity) {
                        //If we matched our activity but it had no logo don't
                        //do any more processing of the manifest
                        break;
                    }
                }
            }
            eventType = xml.nextToken();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions));
    return uiOptions;
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:71,代碼來源:ActionBarSherlockCompat.java

示例11: loadLogoFromManifest

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.
 * @return Logo resource ID.
 */
private static int loadLogoFromManifest(Activity activity) {
    int logo = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);

        final String packageName = activity.getApplicationInfo().packageName;
        final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
        final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");

        int eventType = xml.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                String name = xml.getName();

                if ("application".equals(name)) {
                    //Check if the <application> has the attribute
                    if (DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        if ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(i, 0);
                            break; //out of for loop
                        }
                    }
                } else if ("activity".equals(name)) {
                    //Check if the <activity> is us and has the attribute
                    if (DEBUG) Log.d(TAG, "Got <activity>");
                    Integer activityLogo = null;
                    String activityPackage = null;
                    boolean isOurActivity = false;

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        //We need both uiOptions and name attributes
                        String attrName = xml.getAttributeName(i);
                        if ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.intValue();
                        }
                    }
                    if (isOurActivity) {
                        //If we matched our activity but it had no logo don't
                        //do any more processing of the manifest
                        break;
                    }
                }
            }
            eventType = xml.nextToken();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
    return logo;
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:79,代碼來源:Utility4.java

示例12: loadLogoFromManifest

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.
 * @return Logo resource ID.
 */
public static int loadLogoFromManifest(Activity activity) {
    int logo = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);

        final String packageName = activity.getApplicationInfo().packageName;
        final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
        final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");

        int eventType = xml.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                String name = xml.getName();

                if ("application".equals(name)) {
                    //Check if the <application> has the attribute
                    if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        if ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(i, 0);
                            break; //out of for loop
                        }
                    }
                } else if ("activity".equals(name)) {
                    //Check if the <activity> is us and has the attribute
                    if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
                    Integer activityLogo = null;
                    String activityPackage = null;
                    boolean isOurActivity = false;

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        //We need both uiOptions and name attributes
                        String attrName = xml.getAttributeName(i);
                        if ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.intValue();
                        }
                    }
                    if (isOurActivity) {
                        //If we matched our activity but it had no logo don't
                        //do any more processing of the manifest
                        break;
                    }
                }
            }
            eventType = xml.nextToken();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
    return logo;
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:79,代碼來源:ResourcesCompat.java

示例13: parsePathStrategy

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
 * Parse and return {@link PathStrategy} for given authority as defined in
 * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}.
 *
 * @see #getPathStrategy(Context, String)
 */
private static PathStrategy parsePathStrategy(Context context, String authority)
        throws IOException, XmlPullParserException {
    final SimplePathStrategy strat = new SimplePathStrategy(authority);

    final ProviderInfo info = context.getPackageManager()
            .resolveContentProvider(authority, PackageManager.GET_META_DATA);
    final XmlResourceParser in = info.loadXmlMetaData(
            context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
    if (in == null) {
        throw new IllegalArgumentException(
                "Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
    }

    int type;
    while ((type = in.next()) != END_DOCUMENT) {
        if (type == START_TAG) {
            final String tag = in.getName();

            final String name = in.getAttributeValue(null, ATTR_NAME);
            String path = in.getAttributeValue(null, ATTR_PATH);

            File target = null;
            if (TAG_ROOT_PATH.equals(tag)) {
                target = DEVICE_ROOT;
            } else if (TAG_FILES_PATH.equals(tag)) {
                target = context.getFilesDir();
            } else if (TAG_CACHE_PATH.equals(tag)) {
                target = context.getCacheDir();
            } else if (TAG_EXTERNAL.equals(tag)) {
                target = Environment.getExternalStorageDirectory();
            } else if (TAG_EXTERNAL_FILES.equals(tag)) {
                File[] externalFilesDirs = getExternalFilesDirs(context, null);
                if (externalFilesDirs.length > 0) {
                    target = externalFilesDirs[0];
                }
            } else if (TAG_EXTERNAL_CACHE.equals(tag)) {
                File[] externalCacheDirs = getExternalCacheDirs(context);
                if (externalCacheDirs.length > 0) {
                    target = externalCacheDirs[0];
                }
            }

            if (target != null) {
                strat.addRoot(name, buildPath(target, path));
            }
        }
    }

    return strat;
}
 
開發者ID:roshakorost,項目名稱:Phial,代碼行數:57,代碼來源:FileProvider.java

示例14: parseAndAdd

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
@Override
public long parseAndAdd(XmlResourceParser parser)
        throws XmlPullParserException, IOException {
    final String title;
    final int titleResId = getAttributeResourceValue(parser, ATTR_TITLE, 0);
    if (titleResId != 0) {
        title = mSourceRes.getString(titleResId);
    } else {
        title = mContext.getResources().getString(R.string.folder_name);
    }

    mValues.put(Favorites.TITLE, title);
    mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_FOLDER);
    mValues.put(Favorites.SPANX, 1);
    mValues.put(Favorites.SPANY, 1);
    mValues.put(Favorites._ID, mCallback.generateNewItemId());
    long folderId = mCallback.insertAndCheck(mDb, mValues);
    if (folderId < 0) {
        if (LOGD) Log.e(TAG, "Unable to add folder");
        return -1;
    }

    final ContentValues myValues = new ContentValues(mValues);
    ArrayList<Long> folderItems = new ArrayList<Long>();

    int type;
    int folderDepth = parser.getDepth();
    int rank = 0;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > folderDepth) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        mValues.clear();
        mValues.put(Favorites.CONTAINER, folderId);
        mValues.put(Favorites.RANK, rank);

        TagParser tagParser = mFolderElements.get(parser.getName());
        if (tagParser != null) {
            final long id = tagParser.parseAndAdd(parser);
            if (id >= 0) {
                folderItems.add(id);
                rank++;
            }
        } else {
            throw new RuntimeException("Invalid folder item " + parser.getName());
        }
    }

    long addedId = folderId;

    // We can only have folders with >= 2 items, so we need to remove the
    // folder and clean up if less than 2 items were included, or some
    // failed to add, and less than 2 were actually added
    if (folderItems.size() < 2) {
        // Delete the folder
        Uri uri = Favorites.getContentUri(folderId);
        SqlArguments args = new SqlArguments(uri, null, null);
        mDb.delete(args.table, args.where, args.args);
        addedId = -1;

        // If we have a single item, promote it to where the folder
        // would have been.
        if (folderItems.size() == 1) {
            final ContentValues childValues = new ContentValues();
            copyInteger(myValues, childValues, Favorites.CONTAINER);
            copyInteger(myValues, childValues, Favorites.SCREEN);
            copyInteger(myValues, childValues, Favorites.CELLX);
            copyInteger(myValues, childValues, Favorites.CELLY);

            addedId = folderItems.get(0);
            mDb.update(Favorites.TABLE_NAME, childValues,
                    Favorites._ID + "=" + addedId, null);
        }
    }
    return addedId;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:78,代碼來源:AutoInstallsLayout.java

示例15: loadFromXml

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private void loadFromXml(int resourceId) {
    XmlResourceParser parser = getContext().getResources().getXml(
            resourceId);
    try {
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_DOCUMENT) {

            } else if (eventType == XmlPullParser.START_TAG) {
                String name = parser.getName();
                if (!TextUtils.isEmpty(name) && name.equals("animation-list")) {
                    int size = parser.getAttributeCount();
                    for (int i = 0; i < size; i++) {
                        if (parser.getAttributeName(i).equals(
                                "oneshot")) {
                            mLoop = !parser.getAttributeBooleanValue(
                                    i, true);
                        }
                    }
                }
                if (parser.getName().equals("item")) {
                    for (int i = 0; i < parser.getAttributeCount(); i++) {
                        if (parser.getAttributeName(i).equals(
                                "drawable")) {
                            int resId = Integer.parseInt(parser
                                    .getAttributeValue(i)
                                    .substring(1));
                            if (resId != 0)
                                mRes.add(resId);
                        } else if (parser.getAttributeName(i)
                                .equals("duration")) {
                            duration = parser.getAttributeIntValue(
                                    i, 1000);
                        }
                    }
                }
            } else if (eventType == XmlPullParser.END_TAG) {
            } else if (eventType == XmlPullParser.TEXT) {
            }
            eventType = parser.next();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e2) {
        e2.printStackTrace();
    }
}
 
開發者ID:ronghao,項目名稱:FrameAnimationView,代碼行數:48,代碼來源:FrameAnimView.java


注:本文中的android.content.res.XmlResourceParser.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。