当前位置: 首页>>代码示例>>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;未经允许,请勿转载。