当前位置: 首页>>代码示例>>Java>>正文


Java XmlResourceParser.getAttributeValue方法代码示例

本文整理汇总了Java中android.content.res.XmlResourceParser.getAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:Java XmlResourceParser.getAttributeValue方法的具体用法?Java XmlResourceParser.getAttributeValue怎么用?Java XmlResourceParser.getAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.res.XmlResourceParser的用法示例。


在下文中一共展示了XmlResourceParser.getAttributeValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private boolean init(@NonNull Resources resources) {
    try {
        XmlResourceParser parser = resources.getXml(R.xml.appfilter);
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                if (!"item".equals(parser.getName())) {
                    event = parser.next();
                    continue;
                }
                String drawable = parser.getAttributeValue(null, "drawable");
                if (TextUtils.isEmpty(drawable)) {
                    event = parser.next();
                    continue;
                }
                String component = parser.getAttributeValue(null, "component");
                if (TextUtils.isEmpty(component)) {
                    event = parser.next();
                    continue;
                }
                Matcher matcher = componentPattern.matcher(component);
                if (!matcher.matches()) {
                    event = parser.next();
                    continue;
                }
                dataList.add(new Bean(matcher.group(1), matcher.group(2), drawable));
            }
            event = parser.next();
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:homeii,项目名称:GxIconAndroid,代码行数:36,代码来源:AppfilterReader.java

示例2: getColorValue

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private Integer getColorValue(int attrIndex, XmlResourceParser parser) {
    // Modify the >>>
    String valueResource = parser.getAttributeValue(attrIndex);
    if(!TextUtils.isEmpty(valueResource) && valueResource.startsWith("?")){ // 引用主题属性
        valueResource = valueResource.replace("?", "@"); // 替换?
        int attr = context.getResources().getIdentifier(valueResource, "attr", context.getPackageName()); // 找出属性Id
        if(attr != 0){
            TypedArray array = context.obtainStyledAttributes(new int[]{attr}); //解析属性值
            return array.getColor(0, 0);
        }
    }
    // <<<

    int colorResource = parser.getAttributeResourceValue(attrIndex, 0);

    if (colorResource != 0) {
        return ContextCompat.getColor(context, colorResource);
    }

    try {
        return Color.parseColor(parser.getAttributeValue(attrIndex));
    } catch (Exception ignored) {
        return null;
    }
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:26,代码来源:TabParser.java

示例3: parseManifest

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
/**
 * parseManifest
 *
 * @param parser        parser
 * @param intentFilters intentFilters
 * @throws Exception e
 */
private static void parseManifest(XmlResourceParser parser, Map<String, IntentFilter> intentFilters)
        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("activity") || tagName.equals("receiver") || tagName.equals("service")) {
            String activityName = parser.getAttributeValue(ANDROID_RESOURCES, "name");
            if (activityName != null) {
                parseActivity(activityName, intentFilters, parser);
            }
        }
    }
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:29,代码来源:ApkManifestParser.java

示例4: getXmlAttribute

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
/**
 * Attempts to get the given attribute as a String resource first, and if it fails
 * returns the attribute as a simple String value.
 * @param xml
 * @param name
 * @return
 */
private String getXmlAttribute(XmlResourceParser xml, String name) {
    int resId = xml.getAttributeResourceValue(null, name, 0);
    if (resId == 0) {
        return xml.getAttributeValue(null, name);
    } else {
        return getString(resId);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:16,代码来源:AccountSetupBasics.java

示例5: getAttributeValue

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
/**
 * Return attribute value, attempting launcher-specific namespace first
 * before falling back to anonymous attribute.
 */
static String getAttributeValue(XmlResourceParser parser, String attribute) {
    String value = parser.getAttributeValue(
            "http://schemas.android.com/apk/res-auto/com.enrico.launcher3", attribute);
    if (value == null) {
        value = parser.getAttributeValue(null, attribute);
    }
    return value;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:13,代码来源:AutoInstallsLayout.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: getAttributes

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private String[] getAttributes(XmlResourceParser xmlParser, String[] attributesList) {
    int length = attributesList.length;
    String[] attributes = new String[length];
    for (int i = 0; i < length; i++) {
        String attributeValue = xmlParser.getAttributeValue(null, attributesList[i]);
        attributes[i] = AndroidResources.getResourceString(attributeValue);
    }
    return attributes;
}
 
开发者ID:android-gamecollection,项目名称:gamecollection,代码行数:10,代码来源:Games.java

示例9: getAttributeValue

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
/**
 * Return attribute value, attempting launcher-specific namespace first
 * before falling back to anonymous attribute.
 */
protected static String getAttributeValue(XmlResourceParser parser, String attribute) {
    String value = parser.getAttributeValue(
            "http://schemas.android.com/apk/res-auto/com.android.launcher3", attribute);
    if (value == null) {
        value = parser.getAttributeValue(null, attribute);
    }
    return value;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:13,代码来源:AutoInstallsLayout.java

示例10: readValidCertificates

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private Map<String, ArrayList<CallerInfo>> readValidCertificates(XmlResourceParser parser) {
    HashMap<String, ArrayList<CallerInfo>> validCertificates = new HashMap<>();
    try {
        int eventType = parser.next();
        while (eventType != XmlResourceParser.END_DOCUMENT) {
            if (eventType == XmlResourceParser.START_TAG
                    && parser.getName().equals("signing_certificate")) {

                String name = parser.getAttributeValue(null, "name");
                String packageName = parser.getAttributeValue(null, "package");
                boolean isRelease = parser.getAttributeBooleanValue(null, "release", false);
                String certificate = parser.nextText().replaceAll("\\s|\\n", "");

                CallerInfo info = new CallerInfo(name, packageName, isRelease);

                ArrayList<CallerInfo> infos = validCertificates.get(certificate);
                if (infos == null) {
                    infos = new ArrayList<>();
                    validCertificates.put(certificate, infos);
                }
                /*Log.v(TAG, "Adding allowed caller: " + info.name +
                        " package=" + info.packageName + " release=" + info.release +
                        " certificate=" + certificate);*/
                infos.add(info);
            }
            eventType = parser.next();
        }
    } catch (XmlPullParserException | IOException e) {
        Log.e(TAG, e + "Could not read allowed callers from XML.");
    }
    return validCertificates;
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:33,代码来源:PackageValidator.java

示例11: 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

示例12: init

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
protected boolean init(Resources resources) {
    if (isReadDone()) {
        return true;
    }
    if (resources == null) {
        return false;
    }

    if (mPackageName == null) {
        return false;
    }

    int resId = resources.getIdentifier(IconPackConfig.APPFIlTER,
            IconPackConfig.APPFILTERLOCATION, mPackageName);


    XmlResourceParser parser = resources.getXml(resId);
    try {
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                if (!IconPackConfig.APPFILTERXMLLABEL.equals(parser.getName())) {
                    event = parser.next();
                    continue;
                }
                IconPackBean bean = new IconPackBean();
                bean.drawable = parser.getAttributeValue(null, IconPackConfig.APPFILTERDRAWABLEELEMENT);
                if (TextUtils.isEmpty(bean.drawable)) {
                    event = parser.next();
                    continue;
                }
                if (bean.drawable.matches(".+?_\\d+")) {
                    bean.drawableNoSeq = bean.drawable.substring(0, bean.drawable.lastIndexOf('_'));
                } else {
                    bean.drawableNoSeq = bean.drawable;
                }
                String component = parser.getAttributeValue(null, IconPackConfig.APPFILTERCOMPONENTELEMENT);
                if (component == null) {
                    event = parser.next();
                    continue;
                }
                Matcher matcher = Pattern.compile("ComponentInfo\\{([^/]+?)/(.+?)\\}").matcher(component);
                if (matcher.matches()) {
                    bean.pkg = matcher.group(1);
                    bean.launcher = matcher.group(2);
                }

                if (!TextUtils.isEmpty(bean.launcher)) {
                    mAppFilterConfigMap.put(bean.launcher, bean);
                }
            }
            event = parser.next();
        }
        isReadDone = true;
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:uchiaitachipro,项目名称:icon_pack_loader,代码行数:62,代码来源:AppFilterReader.java

示例13: init

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
protected boolean init(Resources resources) {
    if (isReadDone()) {
        return true;
    }
    if (resources == null) {
        return false;
    }
    int resId = getFilterConfigId();
    XmlResourceParser parser = resources.getXml(resId);
    try {
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                if (!IconPackConfig.ICONPACKLABEL.equals(parser.getName())) {
                    event = parser.next();
                    continue;
                }
                Intent filter = new Intent();
                String action = parser.getAttributeValue(null,
                        IconPackConfig.ICONPACKACTIONELEMENT);
                if (TextUtils.isEmpty(action)) {
                    event = parser.next();
                    continue;
                }
                filter.setAction(action);
                String category = parser.getAttributeValue(null,
                        IconPackConfig.ICONPACKCATEGORYELEMENT);
                if (TextUtils.isEmpty(category)) {
                    event = parser.next();
                    continue;
                }
                filter.addCategory(category);

                mFilter.add(filter);
            }
            event = parser.next();
        }
        mDone = true;
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:uchiaitachipro,项目名称:icon_pack_loader,代码行数:45,代码来源:IconPackFilterReader.java

示例14: 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

示例15: getTitleValue

import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private String getTitleValue(int attrIndex, XmlResourceParser parser) {
    int titleResource = parser.getAttributeResourceValue(attrIndex, 0);

    if (titleResource != 0) {
        return context.getString(titleResource);
    }

    return parser.getAttributeValue(attrIndex);
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:10,代码来源:TabParser.java


注:本文中的android.content.res.XmlResourceParser.getAttributeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。