Java Code Examples for android.util.AttributeSet#getAttributeBooleanValue()

The following examples show how to use android.util.AttributeSet#getAttributeBooleanValue() . 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: DrawableUtils.java    From timecat with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: ColorStateListUtils.java    From timecat with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: ColorPickerPreference.java    From Hangar with GNU General Public License v3.0 5 votes vote down vote up
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);
	}
}
 
Example 4
Source File: Button.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 5
Source File: TimePreference.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: SeekBarPreference.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: AppPickerPreference.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 8
Source File: Switch.java    From Social with Apache License 2.0 5 votes vote down vote up
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);

    }
 
Example 9
Source File: RippleView.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: ColorPickerPreference.java    From WiFiKeyView with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 11
Source File: Switch.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
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);

	}
 
Example 12
Source File: Button.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 13
Source File: RippleView.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: Switch.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
@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);
		}
	});
}
 
Example 15
Source File: SkinLayoutInflaterFactory.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 16
Source File: Chip.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
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");
  }
}
 
Example 17
Source File: CheckBox.java    From MaterialDesignLibrary with Apache License 2.0 4 votes vote down vote up
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);
        }
	}
 
Example 18
Source File: Slider.java    From MoeGallery with GNU General Public License v3.0 4 votes vote down vote up
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());
        }

    }
 
Example 19
Source File: Slider.java    From meiShi with Apache License 2.0 4 votes vote down vote up
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());
        }

    }
 
Example 20
Source File: CheckBox.java    From meiShi with Apache License 2.0 4 votes vote down vote up
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);
        }
	}