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

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

源代码1 项目: xDrip   文件: ColorPicker.java
public ColorPicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    if (attrs != null) {
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            if (attrs.getAttributeName(i).equals("defaultValue")) {
                final String this_value = attrs.getAttributeValue(i);

                if (this_value.length() > 0) {
                    if (debug)
                        Log.d(TAG, "Attribute debug: " + i + " " + attrs.getAttributeName(i) + " " + this_value);
                    if (this_value.startsWith("@")) {
                        localDefaultValue = Color.parseColor(getStringResourceByName(this_value));
                    } else {
                        localDefaultValue = Color.parseColor(this_value);
                    }
                    localDefaultValue = Color.parseColor(attrs.getAttributeValue(i));
                    super.defaultColor = localDefaultValue;
                } else {
                    Log.w(TAG, "No default value for colorpicker");
                }
                break;
            }

        }
    }
}
 
源代码2 项目: ReadMark   文件: SkinAppCompatViewInflater.java
private View createViewFromTag(Context context, String name, AttributeSet attrs) {
    if (name.equals("view")) {
        name = attrs.getAttributeValue(null, "class");
    }

    try {
        mConstructorArgs[0] = context;
        mConstructorArgs[1] = attrs;

        if (-1 == name.indexOf('.')) {
            for (int i = 0; i < sClassPrefixList.length; i++) {
                final View view = createView(context, name, sClassPrefixList[i]);
                if (view != null) {
                    return view;
                }
            }
            return null;
        } else {
            return createView(context, name, null);
        }
    } catch (Exception e) {
        // We do not want to catch these, lets return null and let the actual LayoutInflater
        // try
        return null;
    } finally {
        // Don't retain references on context.
        mConstructorArgs[0] = null;
        mConstructorArgs[1] = null;
    }
}
 
源代码3 项目: GravityBox   文件: SeekBarPreference.java
public SeekBarPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs != null) {
        mMinimum = attrs.getAttributeIntValue(null, "minimum", 0);
        mMaximum = attrs.getAttributeIntValue(null, "maximum", 100);
        mInterval = attrs.getAttributeIntValue(null, "interval", 1);
        mDefaultValue = mMinimum;
        mMonitorBoxEnabled = attrs.getAttributeBooleanValue(null, "monitorBoxEnabled", false);
        mMonitorBoxUnit = attrs.getAttributeValue(null, "monitorBoxUnit");
    }

    mHandler = new Handler();
}
 
源代码4 项目: Android-plugin-support   文件: DynamicApkParser.java
private static String parsePackageNames(XmlPullParser parser, AttributeSet attrs)
        throws IOException, XmlPullParserException, DynamicApkParserException {
    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG
            && type != XmlPullParser.END_DOCUMENT) {
    }

    if (type != XmlPullParser.START_TAG) {
        throw new DynamicApkParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                "No start tag found");
    }
    if (!parser.getName().equals("manifest")) {
        throw new DynamicApkParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                "No <manifest> tag");
    }

    final String packageName = attrs.getAttributeValue(null, "package");
    if (!"android".equals(packageName)) {
        final String error = validateName(packageName, true, true);
        if (error != null) {
            throw new DynamicApkParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME,
                    "Invalid manifest package: " + error);
        }
    }

    return packageName.intern();
}
 
源代码5 项目: AndroidComponentPlugin   文件: PackageParser.java
private static String parsePackageName(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;
    }

    return pkgName.intern();
}
 
源代码6 项目: stynico   文件: ELABORATE_FEED_REPORT.java
public ELABORATE_FEED_REPORT(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;
        }
    }
}
 
源代码7 项目: AndroidWebServ   文件: FileBrowser.java
public FileBrowser(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    initFileBrowser(context);

    folderResId = attrs.getAttributeResourceValue(namespace, "folder_def", 0);
    folderParentResId = attrs
            .getAttributeResourceValue(namespace, "folder_parent", folderResId);
    fileResId = attrs.getAttributeResourceValue(namespace, "file_def", 0);
    String value = attrs.getAttributeValue(namespace, "display");
    if (value != null) {
        if (value.equals("file")) {
            display = DISPLAY_FILE;
        } else if (value.equals("folder")) {
            display = DISPLAY_FOLDER;
        }
    }
    isBackResp = attrs.getAttributeBooleanValue(namespace, "back_resp", false);
    isSort = attrs.getAttributeBooleanValue(namespace, "sort", true);

    // 动态扩展名属性
    int index = 1;
    while (true) {
        String extName = attrs.getAttributeValue(namespace, "ext_name" + index);
        int fileImageResId = attrs.getAttributeResourceValue(namespace, "ext_image" + index, 0);
        // 如果读取不到extName或fileImage属性时跳出循环
        if ("".equals(extName) || extName == null || fileImageResId == 0) {
            break;
        }
        extResIdMap.put(extName, fileImageResId);
        index++;
    }
}
 
源代码8 项目: 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;

}
 
源代码9 项目: material-components-android   文件: Chip.java
private void validateAttributes(@Nullable AttributeSet attributeSet) {
  if (attributeSet == null) {
    return;
  }
  if (attributeSet.getAttributeValue(NAMESPACE_ANDROID, "background") != null) {
    Log.w(TAG, "Do not set the background; Chip manages its own background drawable.");
  }
  if (attributeSet.getAttributeValue(NAMESPACE_ANDROID, "drawableLeft") != null) {
    throw new UnsupportedOperationException("Please set left drawable using R.attr#chipIcon.");
  }
  if (attributeSet.getAttributeValue(NAMESPACE_ANDROID, "drawableStart") != null) {
    throw new UnsupportedOperationException("Please set start drawable using R.attr#chipIcon.");
  }
  if (attributeSet.getAttributeValue(NAMESPACE_ANDROID, "drawableEnd") != null) {
    throw new UnsupportedOperationException("Please set end drawable using R.attr#closeIcon.");
  }
  if (attributeSet.getAttributeValue(NAMESPACE_ANDROID, "drawableRight") != null) {
    throw new UnsupportedOperationException("Please set end drawable using R.attr#closeIcon.");
  }
  if (!attributeSet.getAttributeBooleanValue(NAMESPACE_ANDROID, "singleLine", true)
      || (attributeSet.getAttributeIntValue(NAMESPACE_ANDROID, "lines", 1) != 1)
      || (attributeSet.getAttributeIntValue(NAMESPACE_ANDROID, "minLines", 1) != 1)
      || (attributeSet.getAttributeIntValue(NAMESPACE_ANDROID, "maxLines", 1) != 1)) {
    throw new UnsupportedOperationException("Chip does not support multi-line text");
  }

  if (attributeSet.getAttributeIntValue(
          NAMESPACE_ANDROID, "gravity", (Gravity.CENTER_VERTICAL | Gravity.START))
      != (Gravity.CENTER_VERTICAL | Gravity.START)) {
    Log.w(TAG, "Chip text must be vertically center and start aligned");
  }
}
 
源代码10 项目: document-viewer   文件: WidgetUtils.java
public static Boolean getBooleanAttribute(final Context context, final AttributeSet attrs, final String namespace,
        final String name, final Boolean defValue) {
    final int resId = attrs.getAttributeResourceValue(namespace, name, Integer.MIN_VALUE);
    if (resId != Integer.MIN_VALUE) {
        return context.getResources().getBoolean(resId);
    }
    String str = attrs.getAttributeValue(namespace, name);
    return str != null ? Boolean.valueOf(str) : defValue;
}
 
/**
 * Reads attribute values and initializes members
 * 
 * @param attrs attributes to read from
 */
private void readAttributes(AttributeSet attrs) {
	pawSetting = attrs.getAttributeValue(PIRATEBOX_NAMESPACE, "setting");
	isNumeric = attrs.getAttributeValue(ANDROID_NAMESPACE, "numeric") != null ? true : false;
	try {
		numericDivider = Long.valueOf(attrs.getAttributeValue(PIRATEBOX_NAMESPACE, "numericDivider"));
	}
	catch(Exception e) {
		numericDivider = null;
	}
}
 
源代码12 项目: WhereYouGo   文件: MapGeneratorFactory.java
/**
 * @param attributeSet A collection of attributes which includes the desired MapGenerator.
 * @return a new MapGenerator instance.
 */
public static MapGenerator createMapGenerator(AttributeSet attributeSet) {
    String mapGeneratorName = attributeSet.getAttributeValue(null, MAP_GENERATOR_ATTRIBUTE_NAME);
    if (mapGeneratorName == null) {
        return new DatabaseRenderer();
    }

    MapGeneratorInternal mapGeneratorInternal = MapGeneratorInternal.valueOf(mapGeneratorName);
    return MapGeneratorFactory.createMapGenerator(mapGeneratorInternal);
}
 
public String getAttributeStringValue(Context context1, AttributeSet attributeset, String namespace, String attributeName, String defaultString) {
    Resources resources = context1.getResources();
    String value = attributeset.getAttributeValue(namespace, attributeName);
    if (value == null) {
        return defaultString;
    } else {
        return stringByName(resources, value);
    }
}
 
源代码14 项目: NewFastFrame   文件: ViewProducer.java
static View createViewFromTag(Context context, String name, AttributeSet attrs) {
    if (name.equals("view")) {
        name = attrs.getAttributeValue(null, "class");
    }

    try {
        mConstructorArgs[0] = context;
        mConstructorArgs[1] = attrs;

        if (-1 == name.indexOf('.')) {
            for (int i = 0; i < sClassPrefixList.length; i++) {
                final View view = createView(context, name, sClassPrefixList[i]);
                if (view != null) {
                    return view;
                }
            }
            return null;
        } else {
            return createView(context, name, null);
        }
    } catch (Exception e) {
        // We do not want to catch these, lets return null and let the actual LayoutInflater
        // try
        return null;
    } finally {
        // Don't retain references on context.
        mConstructorArgs[0] = null;
        mConstructorArgs[1] = null;
    }
}
 
源代码15 项目: SecondScreen   文件: SeekBarPreference.java
private String getAttributeStringValue(AttributeSet attrs, String namespace, String name, String defaultValue) {
	String value = attrs.getAttributeValue(namespace, name);
	if(value == null)
		value = defaultValue;
	
	return value;
}
 
源代码16 项目: memetastic   文件: 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;
            }
        }
    }

    for (File file : getAdditionalFonts()) {
        _fontNames = appendToArray(_fontNames, file.getName().replace(".ttf", "").replace(".TTF", ""));
        _fontValues = appendToArray(_fontValues, file.getAbsolutePath());
    }

    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 TypefaceObjectSpan(typeface(getContext(), _fontValues[i], null)), 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);
}
 
源代码17 项目: MaterialDesignLibrary   文件: CheckBox.java
protected void setAttributes(AttributeSet attrs) {

		setBackgroundResource(R.drawable.background_checkbox);

		// Set size of view
		setMinimumHeight(Utils.dpToPx(48, getResources()));
		setMinimumWidth(Utils.dpToPx(48, getResources()));

		// Set background Color
		// Color by resource
		int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
				"background", -1);
		if (bacgroundColor != -1) {
			setBackgroundColor(getResources().getColor(bacgroundColor));
		} else {
			// Color by hexadecimal
			// Color by hexadecimal
			int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
			if (background != -1)
				setBackgroundColor(background);
		}

		final boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
				"check", false);
			post(new Runnable() {

				@Override
				public void run() {
					setChecked(check);
					setPressed(false);
					changeBackgroundColor(getResources().getColor(
							android.R.color.transparent));
				}
			});

		checkView = new Check(getContext());
        checkView.setId(View.generateViewId());
		RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
				getResources()), Utils.dpToPx(20, getResources()));
		params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		checkView.setLayoutParams(params);
		addView(checkView);

        // Adding text view to checkbox
        int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1);
        String text = null;

        if(textResource != -1) {
            text = getResources().getString(textResource);
        } else {
            text = attrs.getAttributeValue(ANDROIDXML, "text");
        }

        if(text != null) {
            params.removeRule(RelativeLayout.CENTER_IN_PARENT);
            params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
                    TextView textView = new TextView(getContext());
            RelativeLayout.LayoutParams textViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            textViewLayoutParams.addRule(RelativeLayout.RIGHT_OF, checkView.getId());
            textViewLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
            textViewLayoutParams.setMargins(10, 0, 0, 0);
            textView.setLayoutParams(textViewLayoutParams);
            textView.setText(text);

            addView(textView);
        }
	}
 
源代码18 项目: ploggy   文件: TimePickerPreference.java
/**
 * @param context
 * @param attrs
 */
public TimePickerPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        defaultValue = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "defaultValue");
        initialize();
}
 
源代码19 项目: MoeGallery   文件: CheckBox.java
protected void setAttributes(AttributeSet attrs) {

		setBackgroundResource(R.drawable.background_checkbox);

		// Set size of view
		setMinimumHeight(Utils.dpToPx(48, getResources()));
		setMinimumWidth(Utils.dpToPx(48, getResources()));

		// Set background Color
		// Color by resource
		int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
				"background", -1);
		if (bacgroundColor != -1) {
			setBackgroundColor(getResources().getColor(bacgroundColor));
		} else {
			// Color by hexadecimal
			// Color by hexadecimal
			int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
			if (background != -1)
				setBackgroundColor(background);
		}

		final boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
				"check", false);
			post(new Runnable() {

				@Override
				public void run() {
					setChecked(check);
					setPressed(false);
					changeBackgroundColor(getResources().getColor(
							android.R.color.transparent));
				}
			});

		checkView = new Check(getContext());
        checkView.setId(View.generateViewId());
		RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
				getResources()), Utils.dpToPx(20, getResources()));
		params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		checkView.setLayoutParams(params);
		addView(checkView);

        // Adding text view to checkbox
        int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1);
        String text = null;

        if(textResource != -1) {
            text = getResources().getString(textResource);
        } else {
            text = attrs.getAttributeValue(ANDROIDXML, "text");
        }

        if(text != null) {
            params.removeRule(RelativeLayout.CENTER_IN_PARENT);
            params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
                    TextView textView = new TextView(getContext());
            RelativeLayout.LayoutParams textViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            textViewLayoutParams.addRule(RelativeLayout.RIGHT_OF, checkView.getId());
            textViewLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
            textViewLayoutParams.setMargins(10, 0, 0, 0);
            textView.setLayoutParams(textViewLayoutParams);
            textView.setText(text);

            addView(textView);
        }
	}
 
源代码20 项目: V.FlyoutTest   文件: FragmentActivity.java
/**
 * Add support for inflating the &lt;fragment> tag.
 */
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
    if (!"fragment".equals(name)) {
        return super.onCreateView(name, context, attrs);
    }
    
    String fname = attrs.getAttributeValue(null, "class");
    TypedArray a =  context.obtainStyledAttributes(attrs, FragmentTag.Fragment);
    if (fname == null) {
        fname = a.getString(FragmentTag.Fragment_name);
    }
    int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID);
    String tag = a.getString(FragmentTag.Fragment_tag);
    a.recycle();

    if (!Fragment.isSupportFragmentClass(this, fname)) {
        // Invalid support lib fragment; let the device's framework handle it.
        // This will allow android.app.Fragments to do the right thing.
        return super.onCreateView(name, context, attrs);
    }
    
    View parent = null; // NOTE: no way to get parent pre-Honeycomb.
    int containerId = parent != null ? parent.getId() : 0;
    if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname);
    }

    // If we restored from a previous state, we may already have
    // instantiated this fragment from the state and should use
    // that instance instead of making a new one.
    Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = mFragments.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = mFragments.findFragmentById(containerId);
    }

    if (FragmentManagerImpl.DEBUG) Log.v(TAG, "onCreateView: id=0x"
            + Integer.toHexString(id) + " fname=" + fname
            + " existing=" + fragment);
    if (fragment == null) {
        fragment = Fragment.instantiate(this, fname);
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = mFragments;
        fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        mFragments.addFragment(fragment, true);

    } else if (fragment.mInLayout) {
        // A fragment already exists and it is not one we restored from
        // previous state.
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Duplicate id 0x" + Integer.toHexString(id)
                + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId)
                + " with another fragment for " + fname);
    } else {
        // This fragment was retained from a previous instance; get it
        // going now.
        fragment.mInLayout = true;
        // If this fragment is newly instantiated (either right now, or
        // from last saved state), then give it the attributes to
        // initialize itself.
        if (!fragment.mRetaining) {
            fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        }
        mFragments.moveToState(fragment);
    }

    if (fragment.mView == null) {
        throw new IllegalStateException("Fragment " + fname
                + " did not create a view.");
    }
    if (id != 0) {
        fragment.mView.setId(id);
    }
    if (fragment.mView.getTag() == null) {
        fragment.mView.setTag(tag);
    }
    return fragment.mView;
}