Java Code Examples for android.util.AttributeSet#getAttributeName()
The following examples show how to use
android.util.AttributeSet#getAttributeName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextViewPreference.java From sensordatacollector with GNU General Public License v2.0 | 6 votes |
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); } } }
Example 2
Source File: AttrUtils.java From NightModel with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: AutoGridView.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 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); }
Example 4
Source File: NS_MOBILE_EXTRA.java From styT with Apache License 2.0 | 5 votes |
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; } } }
Example 5
Source File: FontPreferenceCompat.java From Stringlate with MIT License | 5 votes |
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); }
Example 6
Source File: SkinAttrSupport.java From ReadMark with Apache License 2.0 | 5 votes |
/** * 把这个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; }
Example 7
Source File: SkinAttrSupport.java From ChangeSkin with Apache License 2.0 | 5 votes |
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; }
Example 8
Source File: RangePreference.java From WeChatLuckyMoney with Apache License 2.0 | 5 votes |
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); } } }
Example 9
Source File: NS_MOBILE_EXTRA.java From stynico with MIT License | 5 votes |
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; } } }
Example 10
Source File: SkinAttrSupport.java From ReadMark with Apache License 2.0 | 5 votes |
/** * 把这个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; }
Example 11
Source File: RangePreference.java From WechatEnhancement with GNU General Public License v3.0 | 5 votes |
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); } } }
Example 12
Source File: WidgetInflaterFactory.java From relight with Apache License 2.0 | 5 votes |
@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; }
Example 13
Source File: PreviewListPreference.java From WhereYouGo with GNU General Public License v3.0 | 5 votes |
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; } } }
Example 14
Source File: PreviewEditTextPreference.java From WhereYouGo with GNU General Public License v3.0 | 5 votes |
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; } } }
Example 15
Source File: SkinLayoutInflater.java From chameleon with Apache License 2.0 | 5 votes |
/** * 检查控件的属性值是否有对主题属性的引用,如果有则需要换肤 * * @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; }
Example 16
Source File: PackageParser.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
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); }
Example 17
Source File: PackageLite.java From ACDD with MIT License | 4 votes |
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; }
Example 18
Source File: PackageParser.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
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); }
Example 19
Source File: PackageParser.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
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); }
Example 20
Source File: PackageParser.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
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); }