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

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

源代码1 项目: timecat   文件: DrawableUtils.java
/**
 * Extracts state_ attributes from an attribute set.
 *
 * @param attrs The attribute set.
 *
 * @return An array of state_ attributes.
 */
static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        if (stateResId == 0) {
            break;
        } else if (stateResId == android.R.attr.drawable || stateResId == android.R.attr.id || stateResId == R.attr.drawableTint || stateResId == R.attr.drawableTintMode) {
            // Ignore attributes from StateListDrawableItem and
            // AnimatedStateListDrawableItem.
            continue;
        } else {
            states[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
源代码2 项目: timecat   文件: ColorStateListUtils.java
protected static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        switch (stateResId) {
            case 0:
                break;
            case android.R.attr.color:
            case android.R.attr.alpha:
                // Ignore attributes from StateListDrawableItem and
                // AnimatedStateListDrawableItem.
                continue;
            default:
                states[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
源代码3 项目: WiFiKeyView   文件: ColorPickerPreference.java
private void init(Context context, AttributeSet attrs) {
    mDensity = getContext().getResources().getDisplayMetrics().density;
    setOnPreferenceClickListener(this);
    if (attrs != null) {
        mAlphaSliderEnabled = attrs.getAttributeBooleanValue(null, "alphaSlider", false);
        mHexValueEnabled = attrs.getAttributeBooleanValue(null, "hexValue", false);
    }
}
 
源代码4 项目: 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");
  }
}
 
源代码5 项目: NewFastFrame   文件: SkinLayoutInflaterFactory.java
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    //        获取是否应用换肤操作
    boolean hasApplySkin = attrs.getAttributeBooleanValue(NAME_PLACE, SKIN_FLAG, false);
    View view = appCompatActivity.getDelegate().createView(parent, name, context, attrs);
    if (view == null) {
        view = ViewProducer.createViewFromTag(context, name, attrs);
    }
    if (hasApplySkin) {
        return applySkin(context, view, attrs);
    }
    return view;
}
 
源代码6 项目: XERUNG   文件: Switch.java
@Override
protected void setAttributes(AttributeSet attrs) {
	super.setAttributes(attrs);
	if (!isInEditMode()) {
		getBackground().setAlpha(0);
	}
	iSchecked = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "checked", false);
	eventCheck = iSchecked;
	//添加监听器,如果点击了这个控件(不包括ball的区域),这个控件就开始判断是否是开启状态。
	setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			setChecked(iSchecked ? false : true);
		}
	});
	
	float size = 20;
	String thumbSize = attrs.getAttributeValue(MATERIALDESIGNXML, "thumbSize");
	if (thumbSize != null) {
		size = Utils.dipOrDpToFloat(thumbSize);
	}
	ball = new Ball(getContext());
	setThumbParams(size);
	addView(ball);
	// 给圆球添加监听器,点击圆球后就开始判断是否进入开启状态
	ball.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO 自动生成的方法存根
			setChecked(iSchecked ? false : true);
		}
	});
}
 
源代码7 项目: XERUNG   文件: RippleView.java
protected void setRippleAttributes(AttributeSet attrs) {
	/**
	 * 初始化按压时涟漪的颜色
	 * Set Ripple Color
	 * Color by resource
	 */
	int color = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"rippleColor",-1);
	if(color != -1){
		rippleColor = getResources().getColor(color);
		settedRippleColor = true;
	}else{
		// Color by hexadecimal
		int rColor = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1);// 16进制的颜色
		if(rColor != -1 && !isInEditMode()) {
			rippleColor = rColor;
			settedRippleColor = true;
		}
	}
	
	/**
	 * 初始化涟漪扩展的速度 
	 * init Ripple speed
	 */
	rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", rippleSpeed);
	
	/**
	 * 设定涟漪的响应时间
	 */
	clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "clickAfterRipple", clickAfterRipple);
}
 
源代码8 项目: MoeGallery   文件: Button.java
public Button(Context context, AttributeSet attrs) {
	super(context, attrs);
	setDefaultProperties();
	clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
			"animate", true);
	setAttributes(attrs);
	beforeBackground = backgroundColor;
	if (rippleColor == null)
		rippleColor = makePressColor();
}
 
源代码9 项目: MoeGallery   文件: Switch.java
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, 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
			int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
			if (background != -1)
				setBackgroundColor(background);
		}

		check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check",
				false);
		eventCheck = check;
		ball = new Ball(getContext());
		RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
				getResources()), Utils.dpToPx(20, getResources()));
		params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		ball.setLayoutParams(params);
		addView(ball);

	}
 
源代码10 项目: Hangar   文件: ColorPickerPreference.java
private void init(Context context, AttributeSet attrs) {
	mDensity = getContext().getResources().getDisplayMetrics().density;
	setOnPreferenceClickListener(this);
	if (attrs != null) {
		mAlphaSliderEnabled = attrs.getAttributeBooleanValue(null, "alphaSlider", false);
		mHexValueEnabled = attrs.getAttributeBooleanValue(null, "hexValue", false);
	}
}
 
源代码11 项目: XERUNG   文件: RippleView.java
protected void setRippleAttributes(AttributeSet attrs) {
	/**
	 * 初始化按压时涟漪的颜色
	 * Set Ripple Color
	 * Color by resource
	 */
	int color = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"rippleColor",-1);
	if(color != -1){
		rippleColor = getResources().getColor(color);
		settedRippleColor = true;
	}else{
		// Color by hexadecimal
		int rColor = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1);// 16进制的颜色
		if(rColor != -1 && !isInEditMode()) {
			rippleColor = rColor;
			settedRippleColor = true;
		}
	}
	
	/**
	 * 初始化涟漪扩展的速度 
	 * init Ripple speed
	 */
	rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", rippleSpeed);
	
	/**
	 * 设定涟漪的响应时间
	 */
	clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "clickAfterRipple", clickAfterRipple);
}
 
源代码12 项目: Social   文件: Switch.java
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, 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
            int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
            if (background != -1)
                setBackgroundColor(background);
        }

        check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check",
                false);
        eventCheck = check;
        ball = new Ball(getContext());
        RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
                getResources()), Utils.dpToPx(20, getResources()));
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        ball.setLayoutParams(params);
        addView(ball);

    }
 
源代码13 项目: GravityBox   文件: AppPickerPreference.java
public AppPickerPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = context;
    mResources = mContext.getResources();
    mDefaultSummaryText = (String) getSummary();
    mAppIconSizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40,
            mResources.getDisplayMetrics());
    mAppIconPreviewSizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60,
            mResources.getDisplayMetrics());
    mIconPickSizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50,
            mResources.getDisplayMetrics());
    mPackageManager = mContext.getPackageManager();
    mMode = MODE_APP;
    mAppInfo = new AppInfo();
    mAllowGravityBoxActions = true;

    if (attrs != null) {
        mIconPickerEnabled = attrs.getAttributeBooleanValue(null, "iconPickerEnabled", true);
        mNullItemEnabled = attrs.getAttributeBooleanValue(null, "nullItemEnabled", true);
        mForceCustomIcon = attrs.getAttributeBooleanValue(null, "forceCustomIcon", false);
        mAllowGravityBoxActions = attrs.getAttributeBooleanValue(null, "allowGravityBoxActions", true);
    }

    setDialogLayoutResource(R.layout.app_picker_preference);
    setPositiveButtonText(null);

    if (sIconPickerAdapter == null) {
        initializeIconPickerAdapter();
    }
}
 
源代码14 项目: 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();
}
 
源代码15 项目: GravityBox   文件: TimePreference.java
public TimePreference(Context ctxt, AttributeSet attrs) {
    super(ctxt, attrs);

    mDefaultSummaryText = (String) super.getSummary();
    if (attrs != null) {
        mTimerMode = attrs.getAttributeBooleanValue(null, "timerMode", false);
    }

    setPositiveButtonText(android.R.string.ok);
    setNegativeButtonText(android.R.string.cancel);
}
 
源代码16 项目: MaterialDesignLibrary   文件: Button.java
public Button(Context context, AttributeSet attrs) {
	super(context, attrs);
	setDefaultProperties();
	clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
			"animate", true);
	setAttributes(attrs);
	beforeBackground = backgroundColor;
	if (rippleColor == null)
		rippleColor = makePressColor();
}
 
源代码17 项目: meiShi   文件: 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 项目: 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);
        }
	}
 
源代码19 项目: MoeGallery   文件: Slider.java
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, 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
            int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
            if (background != -1)
                setBackgroundColor(background);
        }

        showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
                "showNumberIndicator", false);
        min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
        max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0);
        value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min);

        ball = new Ball(getContext());
        RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
                getResources()), Utils.dpToPx(20, getResources()));
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        ball.setLayoutParams(params);
        addView(ball);

        // Set if slider content number indicator
        // TODO
        if (showNumberIndicator) {
            numberIndicator = new NumberIndicator(getContext());
        }

    }
 
源代码20 项目: meiShi   文件: Slider.java
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, 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
            int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
            if (background != -1)
                setBackgroundColor(background);
        }

        showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
                "showNumberIndicator", false);
        min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
        max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0);
        value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min);

        ball = new Ball(getContext());
        RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
                getResources()), Utils.dpToPx(20, getResources()));
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        ball.setLayoutParams(params);
        addView(ball);

        // Set if slider content number indicator
        // TODO
        if (showNumberIndicator) {
            numberIndicator = new NumberIndicator(getContext());
        }

    }