android.util.AttributeSet#getAttributeName ( )源码实例Demo

下面列出了android.util.AttributeSet#getAttributeName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sensordatacollector   文件: TextViewPreference.java
public TextViewPreference(Context context, AttributeSet attrs)
{
    super(context, attrs);

    for(int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        String val = attrs.getAttributeValue(i);

        if("title".equals(attr)) {
            this.title = context.getString(Integer.parseInt(val.substring(1)));
        }
        if("summary".equals(attr)) {
            this.description = context.getString(Integer.parseInt(val.substring(1)));
        }

        if("clickable".equals(attr) && "false".equals(val)) {
            this.setEnabled(false);
        }
    }
}
 
源代码2 项目: DevUtils   文件: AutoGridView.java
/**
 * Sets the numColumns based on the attributeset
 */
private void init(AttributeSet attrs) {
    // Read numColumns out of the AttributeSet
    int count = attrs.getAttributeCount();
    if (count > 0) {
        for (int i = 0; i < count; i++) {
            String name = attrs.getAttributeName(i);
            if (name != null && name.equals("numColumns")) {
                // Update columns
                this.numColumnsID = attrs.getAttributeResourceValue(i, 1);
                updateColumns();
                break;
            }
        }
    }
    Log.d(TAG, "numColumns set to: " + numColumns);
}
 
源代码3 项目: NightModel   文件: AttrUtils.java
public static List<Attr> getNightModelAttr(Object[] args, Resources resources) {
    List<Attr> nightModelAttrs = new ArrayList<>();
    if (args != null && args.length > 0) {
        for (Object obj: args) {
            if (obj instanceof AttributeSet) {
                AttributeSet attrs = (AttributeSet) obj;
                for (int i = 0; i < attrs.getAttributeCount(); i++)
                {
                    String attrName = attrs.getAttributeName(i);
                    String attrValue = attrs.getAttributeValue(i);
                    AttrType attrType = getSupportAttrType(attrName);
                    if (attrType == null) continue;

                    if (attrValue.startsWith("@")) {
                        String resourceName = attrType.getResourceName(attrValue, resources);
                        Attr attr = new Attr(resourceName, attrType);
                        nightModelAttrs.add(attr);
                    }
                }
            }
        }
    }
    return nightModelAttrs;
}
 
源代码4 项目: chameleon   文件: SkinLayoutInflater.java
/**
 * 检查控件的属性值是否有对主题属性的引用,如果有则需要换肤
 *
 * @param view
 * @param attrs
 * @return
 */
public boolean addElement(View view, AttributeSet attrs) {
    if (view == null) {
        return false;
    }
    SkinElement skinElement = new SkinElement(view);
    int count = attrs.getAttributeCount();
    for (int i = 0; i < count; i++) {
        String name = attrs.getAttributeName(i);
        String value = attrs.getAttributeValue(i);
        if (!TextUtils.isEmpty(value) && value.startsWith("?")) {
            try {
                String temp = value.substring(1);
                int attrId = Integer.parseInt(temp);
                skinElement.changeAttrs.put(name, attrId);
            } catch (Exception e) {

            }

        }

    }
    if (skinElement.changeAttrs.size() == 0) {
        return false;
    }
    skinElements.add(skinElement);
    return true;
}
 
源代码5 项目: WhereYouGo   文件: PreviewEditTextPreference.java
public PreviewEditTextPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    summaryTemplate = super.getSummary();

    for (int i = 0; i < attrs.getAttributeCount(); i++) {

        String attr = attrs.getAttributeName(i);
        String val = attrs.getAttributeValue(i);
        if (attr.equalsIgnoreCase("previewTemplate")) {
            previewTemplate = val;
        }
    }
}
 
源代码6 项目: WhereYouGo   文件: PreviewListPreference.java
public PreviewListPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    summaryTemplate = super.getSummary();

    for (int i = 0; i < attrs.getAttributeCount(); i++) {

        String attr = attrs.getAttributeName(i);
        String val = attrs.getAttributeValue(i);
        if (attr.equalsIgnoreCase("previewTemplate")) {
            previewTemplate = val;
        }
    }
}
 
源代码7 项目: styT   文件: NS_MOBILE_EXTRA.java
public NS_MOBILE_EXTRA(Context context, AttributeSet attrs) {
    super(context, attrs);
    setDialogLayoutResource(R.layout.preference_seekbar);

    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equalsIgnoreCase("pref_kind")) {
            prefKind = attrs.getAttributeValue(i);
            break;
        }
    }
}
 
源代码8 项目: relight   文件: WidgetInflaterFactory.java
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    if (!WidgetView.class.getName().equals(name)) {
        try {
            return createView(name, context, attrs);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    AppCompatActivity activity = ContextUtils.getAppCompatActivity(context);
    if (null == activity) {
        throw new IllegalStateException("please use AppCompatActivity context to inflate");
    }
    // create widget
    String widgetName = null;
    String params = null;
    int id = 0;
    int count = attrs.getAttributeCount();
    for (int i = 0; i < count; i++) {
        String attrName = attrs.getAttributeName(i);
        String attrValue = attrs.getAttributeValue(i);
        if ("widget".equals(attrName)) {
            widgetName = attrValue;
        } else if ("params".equals(attrName)) {
            params = attrValue;
        } else if ("id".equals(attrName)) {
            id = Integer.parseInt(attrValue.substring(1));
        }
    }
    Widget widget = WidgetInflateUtils.createWidget(widgetName, activity, activity.getLifecycle());
    WidgetInflateUtils.initWidgetWithParams(context, widget, params);
    View view = widget.render();
    view.setTag(widget);
    view.setId(id);
    return view;
}
 
源代码9 项目: WechatEnhancement   文件: RangePreference.java
public RangePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    setDialogLayoutResource(R.layout.preference_range);


    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equalsIgnoreCase("start")) {
            startKey = attrs.getAttributeValue(i);
        } else if (attr.equalsIgnoreCase("end")) {
            endKey = attrs.getAttributeValue(i);
        }
    }
}
 
源代码10 项目: ReadMark   文件: SkinAttrSupport.java
/**
 * 把这个View的属性中需要的(SkinType, entryName)对取出来(作为SkinAttr类)
 * @param context
 * @param attrs
 * @return
 */
public static List<SkinAttr> getAttrs(Context context, AttributeSet attrs) {
    //把background、src、textColor解析出来
    List<SkinAttr> result = new ArrayList<>();

    //开始解析所有属性
    int length = attrs.getAttributeCount();
    for (int i=0; i<length; i++){
        //获取属性名称
        String name = attrs.getAttributeName(i);
        //获取属性值
        String value = attrs.getAttributeValue(i);
        //Log.e(TAG, name + "  "+ value);

        //检查是否存在所需属性名称
        SkinType skinType = getTargetSkinType(name);

        //如果是所需要的属性名
        if(skinType != null){
            //获取属性值名称
            String resName = getResName(context, value);

            if(TextUtils.isEmpty(resName)){
                continue;
            }

            SkinAttr attr = new SkinAttr(resName, skinType);
            result.add(attr);
        }

    }
    return result;
}
 
源代码11 项目: stynico   文件: NS_MOBILE_EXTRA.java
public NS_MOBILE_EXTRA(Context context, AttributeSet attrs) {
    super(context, attrs);
    setDialogLayoutResource(R.layout.preference_seekbar);

    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equalsIgnoreCase("pref_kind")) {
            prefKind = attrs.getAttributeValue(i);
            break;
        }
    }
}
 
源代码12 项目: WeChatLuckyMoney   文件: RangePreference.java
public RangePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    setDialogLayoutResource(R.layout.preference_range);


    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equalsIgnoreCase("start")) {
            startKey = attrs.getAttributeValue(i);
        } else if (attr.equalsIgnoreCase("end")) {
            endKey = attrs.getAttributeValue(i);
        }
    }
}
 
源代码13 项目: ChangeSkin   文件: SkinAttrSupport.java
public static List<SkinAttr> getSkinAttrs(AttributeSet attrs, Context context)
{
    List<SkinAttr> skinAttrs = new ArrayList<SkinAttr>();
    SkinAttr skinAttr = null;
    for (int i = 0; i < attrs.getAttributeCount(); i++)
    {
        String attrName = attrs.getAttributeName(i);
        String attrValue = attrs.getAttributeValue(i);

        SkinAttrType attrType = getSupprotAttrType(attrName);
        if (attrType == null) continue;

        if (attrValue.startsWith("@"))
        {
            int id = Integer.parseInt(attrValue.substring(1));
            String entryName = context.getResources().getResourceEntryName(id);

            L.e("entryName = " + entryName);
            if (entryName.startsWith(SkinConfig.ATTR_PREFIX))
            {
                skinAttr = new SkinAttr(attrType, entryName);
                skinAttrs.add(skinAttr);
            }
        }
    }
    return skinAttrs;

}
 
源代码14 项目: ReadMark   文件: SkinAttrSupport.java
/**
 * 把这个View的属性中需要的(SkinType, entryName)对取出来(作为SkinAttr类)
 * @param context
 * @param attrs
 * @return
 */
public static List<SkinAttr> getAttrs(Context context, AttributeSet attrs) {
    //把background、src、textColor解析出来
    List<SkinAttr> result = new ArrayList<>();

    //开始解析所有属性
    int length = attrs.getAttributeCount();
    for (int i=0; i<length; i++){
        //获取属性名称
        String name = attrs.getAttributeName(i);
        //获取属性值
        String value = attrs.getAttributeValue(i);
        //Log.e(TAG, name + "  "+ value);

        //检查是否存在所需属性名称
        SkinType skinType = getTargetSkinType(name);

        //如果是所需要的属性名
        if(skinType != null){
            //获取属性值名称
            String resName = getResName(context, value);

            if(TextUtils.isEmpty(resName)){
                continue;
            }

            SkinAttr attr = new SkinAttr(resName, skinType);
            result.add(attr);
        }

    }
    return result;
}
 
源代码15 项目: Stringlate   文件: FontPreferenceCompat.java
private void loadFonts(Context context, @Nullable AttributeSet attrs) {
    _defaultValue = _fontValues[0];
    if (attrs != null) {
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            String attrName = attrs.getAttributeName(i);
            String attrValue = attrs.getAttributeValue(i);
            if (attrName.equalsIgnoreCase("defaultValue")) {
                if (attrValue.startsWith("@")) {
                    int resId = Integer.valueOf(attrValue.substring(1));
                    attrValue = getContext().getString(resId);
                }
                _defaultValue = attrValue;
                break;
            }
        }
    }

    Spannable[] fontText = new Spannable[_fontNames.length];
    for (int i = 0; i < _fontNames.length; i++) {
        fontText[i] = new SpannableString(_fontNames[i] + "\n" + _fontValues[i]);
        fontText[i].setSpan(new TypefaceSpan(_fontValues[i]), 0, _fontNames[i].length(), 0);
        fontText[i].setSpan(new RelativeSizeSpan(0.7f), _fontNames[i].length() + 1, fontText[i].length(), 0);

    }
    setDefaultValue(_defaultValue);
    setEntries(fontText);
    setEntryValues(_fontValues);
}
 
源代码16 项目: AndroidComponentPlugin   文件: PackageParser.java
private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
        AttributeSet attrs, int flags, String[] outError) throws IOException,
        XmlPullParserException {

    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG
            && type != XmlPullParser.END_DOCUMENT) {
        ;
    }

    if (type != XmlPullParser.START_TAG) {
        outError[0] = "No start tag found";
        return null;
    }
    if (DEBUG_PARSER)
        Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
    if (!parser.getName().equals("manifest")) {
        outError[0] = "No <manifest> tag";
        return null;
    }
    String pkgName = attrs.getAttributeValue(null, "package");
    if (pkgName == null || pkgName.length() == 0) {
        outError[0] = "<manifest> does not specify package";
        return null;
    }
    String nameError = validateName(pkgName, true);
    if (nameError != null && !"android".equals(pkgName)) {
        outError[0] = "<manifest> specifies bad package name \""
            + pkgName + "\": " + nameError;
        return null;
    }
    int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equals("installLocation")) {
            installLocation = attrs.getAttributeIntValue(i,
                    PARSE_DEFAULT_INSTALL_LOCATION);
            break;
        }
    }

    // Only search the tree when the tag is directly below <manifest>
    final int searchDepth = parser.getDepth() + 1;

    final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
            final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
            if (verifier != null) {
                verifiers.add(verifier);
            }
        }
    }

    return new PackageLite(pkgName.intern(), installLocation, verifiers);
}
 
源代码17 项目: AndroidComponentPlugin   文件: PackageParser.java
private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
        AttributeSet attrs, int flags, String[] outError) throws IOException,
        XmlPullParserException {

    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG
            && type != XmlPullParser.END_DOCUMENT) {
        ;
    }

    if (type != XmlPullParser.START_TAG) {
        outError[0] = "No start tag found";
        return null;
    }
    if (DEBUG_PARSER)
        Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
    if (!parser.getName().equals("manifest")) {
        outError[0] = "No <manifest> tag";
        return null;
    }
    String pkgName = attrs.getAttributeValue(null, "package");
    if (pkgName == null || pkgName.length() == 0) {
        outError[0] = "<manifest> does not specify package";
        return null;
    }
    String nameError = validateName(pkgName, true);
    if (nameError != null && !"android".equals(pkgName)) {
        outError[0] = "<manifest> specifies bad package name \""
            + pkgName + "\": " + nameError;
        return null;
    }
    int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equals("installLocation")) {
            installLocation = attrs.getAttributeIntValue(i,
                    PARSE_DEFAULT_INSTALL_LOCATION);
            break;
        }
    }

    // Only search the tree when the tag is directly below <manifest>
    final int searchDepth = parser.getDepth() + 1;

    final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
            final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
            if (verifier != null) {
                verifiers.add(verifier);
            }
        }
    }

    return new PackageLite(pkgName.intern(), installLocation, verifiers);
}
 
源代码18 项目: AndroidComponentPlugin   文件: PackageParser.java
private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
        AttributeSet attrs, int flags, String[] outError) throws IOException,
        XmlPullParserException {

    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG
            && type != XmlPullParser.END_DOCUMENT) {
        ;
    }

    if (type != XmlPullParser.START_TAG) {
        outError[0] = "No start tag found";
        return null;
    }
    if (DEBUG_PARSER)
        Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
    if (!parser.getName().equals("manifest")) {
        outError[0] = "No <manifest> tag";
        return null;
    }
    String pkgName = attrs.getAttributeValue(null, "package");
    if (pkgName == null || pkgName.length() == 0) {
        outError[0] = "<manifest> does not specify package";
        return null;
    }
    String nameError = validateName(pkgName, true);
    if (nameError != null && !"android".equals(pkgName)) {
        outError[0] = "<manifest> specifies bad package name \""
            + pkgName + "\": " + nameError;
        return null;
    }
    int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
    int versionCode = 0;
    int numFound = 0;
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equals("installLocation")) {
            installLocation = attrs.getAttributeIntValue(i,
                    PARSE_DEFAULT_INSTALL_LOCATION);
            numFound++;
        } else if (attr.equals("versionCode")) {
            versionCode = attrs.getAttributeIntValue(i, 0);
            numFound++;
        }
        if (numFound >= 2) {
            break;
        }
    }

    // Only search the tree when the tag is directly below <manifest>
    final int searchDepth = parser.getDepth() + 1;

    final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
            final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
            if (verifier != null) {
                verifiers.add(verifier);
            }
        }
    }

    return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
}
 
源代码19 项目: AndroidComponentPlugin   文件: PackageParser.java
private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
        AttributeSet attrs, int flags, String[] outError) throws IOException,
        XmlPullParserException {

    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG
            && type != XmlPullParser.END_DOCUMENT) {
        ;
    }

    if (type != XmlPullParser.START_TAG) {
        outError[0] = "No start tag found";
        return null;
    }
    if (DEBUG_PARSER)
        Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
    if (!parser.getName().equals("manifest")) {
        outError[0] = "No <manifest> tag";
        return null;
    }
    String pkgName = attrs.getAttributeValue(null, "package");
    if (pkgName == null || pkgName.length() == 0) {
        outError[0] = "<manifest> does not specify package";
        return null;
    }
    String nameError = validateName(pkgName, true);
    if (nameError != null && !"android".equals(pkgName)) {
        outError[0] = "<manifest> specifies bad package name \""
            + pkgName + "\": " + nameError;
        return null;
    }
    int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
    int versionCode = 0;
    int numFound = 0;
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attr = attrs.getAttributeName(i);
        if (attr.equals("installLocation")) {
            installLocation = attrs.getAttributeIntValue(i,
                    PARSE_DEFAULT_INSTALL_LOCATION);
            numFound++;
        } else if (attr.equals("versionCode")) {
            versionCode = attrs.getAttributeIntValue(i, 0);
            numFound++;
        }
        if (numFound >= 2) {
            break;
        }
    }

    // Only search the tree when the tag is directly below <manifest>
    final int searchDepth = parser.getDepth() + 1;

    final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
            final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
            if (verifier != null) {
                verifiers.add(verifier);
            }
        }
    }

    return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
}
 
源代码20 项目: ACDD   文件: PackageLite.java
private static boolean parseApplication(PackageLite packageLite,
                                        XmlPullParser xmlPullParser, AttributeSet attributeSet)
        throws Exception {
    int i;
    String str = packageLite.packageName;
    for (i = 0; i < attributeSet.getAttributeCount(); i++) {
        String attributeName = attributeSet.getAttributeName(i);
        if (attributeName.equals("name")) {
            packageLite.applicationClassName = buildClassName(str,
                    attributeSet.getAttributeValue(i));
        } else if (attributeName.equals("icon")) {
            packageLite.applicationIcon = attributeSet
                    .getAttributeResourceValue(i, 0);
        } else if (attributeName.equals("label")) {
            packageLite.applicationLabel = attributeSet
                    .getAttributeResourceValue(i, 0);
        } else if (attributeName.equals("description")) {
            packageLite.applicationDescription = attributeSet
                    .getAttributeResourceValue(i, 0);
        }
    }


    final int innerDepth = xmlPullParser.getDepth();

    int type;
    while ((type = xmlPullParser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || xmlPullParser.getDepth() > innerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = xmlPullParser.getName();
        if (tagName.equals("activity")) {

            parseComponentData(packageLite, xmlPullParser,
                    attributeSet, false);

        } else if (tagName.equals("receiver")) {

            parseComponentData(packageLite, xmlPullParser,
                    attributeSet, true);

        } else if (tagName.equals("service")) {

            parseComponentData(packageLite, xmlPullParser,
                    attributeSet, true);

        } else if (tagName.equals("provider")) {

            parseComponentData(packageLite, xmlPullParser,
                    attributeSet, false);

        } else if (tagName.equals("activity-alias")) {
        } else if (xmlPullParser.getName().equals("meta-data")) {

            packageLite.metaData = parseMetaData(xmlPullParser,
                    attributeSet, packageLite.metaData);


        } else if (tagName.equals("uses-library")) {
        } else if (tagName.equals("uses-package")) {
        } else {
        }
    }

    return true;
}