當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。