Search in sources :

Example 1 with DefaultTextSecondaryColorStateList

use of carbon.drawable.DefaultTextSecondaryColorStateList in project Carbon by ZieIony.

the class InputLayout method initInputLayout.

private void initInputLayout(AttributeSet attrs, int defStyleAttr) {
    View.inflate(getContext(), R.layout.carbon_inputlayout, this);
    errorTextView = (TextView) findViewById(R.id.carbon_error);
    errorTextView.setTextColor(new DefaultTextSecondaryColorStateList(getContext()));
    errorTextView.setValid(false);
    counterTextView = (TextView) findViewById(R.id.carbon_counter);
    counterTextView.setTextColor(new DefaultTextSecondaryColorStateList(getContext()));
    labelTextView = (TextView) findViewById(R.id.carbon_label);
    clearImageView = (ImageView) findViewById(R.id.carbon_clear);
    showPasswordImageView = (ImageView) findViewById(R.id.carbon_showPassword);
    if (isInEditMode())
        return;
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InputLayout, defStyleAttr, 0);
        for (int i = 0; i < a.getIndexCount(); i++) {
            int attr = a.getIndex(i);
            if (!isInEditMode() && attr == R.styleable.InputLayout_carbon_errorFontPath) {
                String path = a.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setErrorTypeface(typeface);
            } else if (attr == R.styleable.InputLayout_carbon_errorTextSize) {
                setErrorTextSize(a.getDimension(attr, 0));
            } else if (attr == R.styleable.InputLayout_carbon_errorFontFamily) {
                int textStyle = a.getInt(R.styleable.InputLayout_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
                setErrorTypeface(typeface);
            } else if (!isInEditMode() && attr == R.styleable.InputLayout_carbon_labelFontPath) {
                String path = a.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setLabelTypeface(typeface);
            } else if (attr == R.styleable.InputLayout_carbon_counterTextSize) {
                setCounterTextSize(a.getDimension(attr, 0));
            } else if (attr == R.styleable.InputLayout_carbon_labelFontFamily) {
                int textStyle = a.getInt(R.styleable.InputLayout_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
                setLabelTypeface(typeface);
            } else if (!isInEditMode() && attr == R.styleable.InputLayout_carbon_counterFontPath) {
                String path = a.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setCounterTypeface(typeface);
            } else if (attr == R.styleable.InputLayout_carbon_labelTextSize) {
                setLabelTextSize(a.getDimension(attr, 0));
            } else if (attr == R.styleable.InputLayout_carbon_counterFontFamily) {
                int textStyle = a.getInt(R.styleable.InputLayout_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
                setCounterTypeface(typeface);
            }
        }
        if (!isInEditMode())
            setError(a.getString(R.styleable.InputLayout_carbon_errorMessage));
        setMinCharacters(a.getInt(R.styleable.InputLayout_carbon_minCharacters, 0));
        setMaxCharacters(a.getInt(R.styleable.InputLayout_carbon_maxCharacters, Integer.MAX_VALUE));
        setLabelStyle(LabelStyle.values()[a.getInt(R.styleable.InputLayout_carbon_labelStyle, LabelStyle.Floating.ordinal())]);
        setLabel(a.getString(R.styleable.InputLayout_carbon_label));
        setRequired(a.getBoolean(R.styleable.InputLayout_carbon_required, false));
        setShowPasswordButtonEnabled(a.getBoolean(R.styleable.InputLayout_carbon_showPassword, false));
        setClearButtonEnabled(a.getBoolean(R.styleable.InputLayout_carbon_showClear, false));
        a.recycle();
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) DefaultTextSecondaryColorStateList(carbon.drawable.DefaultTextSecondaryColorStateList)

Aggregations

TypedArray (android.content.res.TypedArray)1 Typeface (android.graphics.Typeface)1 DefaultTextSecondaryColorStateList (carbon.drawable.DefaultTextSecondaryColorStateList)1