Search in sources :

Example 26 with ColorStateList

use of android.content.res.ColorStateList in project Jota-Text-Editor-old by jiro-aqua.

the class FastScroller method init.

private void init(Context context) {
    // Get both the scrollbar states drawables
    final Resources res = context.getResources();
    useThumbDrawable(context, res.getDrawable(// Jota Text Editor
    R.drawable.scrollbar_handle_accelerated_anim2));
    // Jota Text Editor
    //        mOverlayDrawable = res.getDrawable(
    //                com.android.internal.R.drawable.menu_submenu_background);
    mScrollCompleted = true;
    getSectionsFromIndexer();
    // Jota Text Editor
    //        mOverlaySize = context.getResources().getDimensionPixelSize(
    //                com.android.internal.R.dimen.fastscroll_overlay_size);
    //        mOverlayPos = new RectF();
    mScrollFade = new ScrollFade();
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Paint.Align.CENTER);
    // Jota Text Editor
    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary });
    ColorStateList textColor = ta.getColorStateList(ta.getIndex(0));
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mState = STATE_NONE;
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 27 with ColorStateList

use of android.content.res.ColorStateList in project Android-Switch-Demo-pre-4.0 by pellucide.

the class MySwitch method setSwitchTextAppearance.

/**
     * Sets the switch text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     */
public void setSwitchTextAppearance(Context context, int resid) {
    TypedArray appearance = context.obtainStyledAttributes(resid, R.styleable.mySwitchTextAppearanceAttrib);
    ColorStateList colors;
    int ts;
    colors = appearance.getColorStateList(R.styleable.mySwitchTextAppearanceAttrib_textColor);
    if (colors != null) {
        mTextColors = colors;
    } else {
        // If no color set in TextAppearance, default to the view's textColor
        mTextColors = getTextColors();
    }
    ts = appearance.getDimensionPixelSize(R.styleable.mySwitchTextAppearanceAttrib_textSize, 0);
    if (ts != 0) {
        if (ts != mTextPaint.getTextSize()) {
            mTextPaint.setTextSize(ts);
            requestLayout();
        }
    }
    int typefaceIndex, styleIndex;
    typefaceIndex = appearance.getInt(R.styleable.mySwitchTextAppearanceAttrib_typeface, -1);
    styleIndex = appearance.getInt(R.styleable.mySwitchTextAppearanceAttrib_textStyle, -1);
    setSwitchTypefaceByIndex(typefaceIndex, styleIndex);
    appearance.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 28 with ColorStateList

use of android.content.res.ColorStateList in project Genius-Android by qiujuer.

the class CheckBox method init.

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final Context context = getContext();
    final Resources resource = getResources();
    final float density = resource.getDisplayMetrics().density;
    final int baseSize = (int) (density * 2);
    if (attrs == null) {
        mMarkDrawable = new CircleCheckDrawable(resource.getColorStateList(R.color.g_default_check_box));
        setButtonDrawable(mMarkDrawable);
        return;
    }
    // Load attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckBox, defStyleAttr, defStyleRes);
    int borderSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gBorderSize, baseSize);
    int intervalSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gIntervalSize, baseSize);
    int markSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gMarkSize, -1);
    ColorStateList color = a.getColorStateList(R.styleable.CheckBox_gMarkColor);
    String fontFile = a.getString(R.styleable.CheckBox_gFont);
    a.recycle();
    if (color == null)
        color = resource.getColorStateList(R.color.g_default_check_box);
    boolean isCustom = true;
    if (markSize < 0) {
        markSize = (int) (density * 22);
        isCustom = false;
    }
    mMarkDrawable = new CircleCheckDrawable(color);
    mMarkDrawable.setBorderSize(borderSize);
    mMarkDrawable.setIntervalSize(intervalSize);
    mMarkDrawable.setMarkSize(markSize, isCustom);
    mMarkDrawable.inEditMode(isInEditMode());
    setButtonDrawable(mMarkDrawable);
    // Check for IDE preview render
    if (!this.isInEditMode()) {
        // Font
        if (fontFile != null && fontFile.length() > 0) {
            Typeface typeface = Ui.getFont(getContext(), fontFile);
            if (typeface != null)
                setTypeface(typeface);
        }
    }
}
Also used : Context(android.content.Context) CircleCheckDrawable(net.qiujuer.genius.ui.drawable.CircleCheckDrawable) Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources)

Example 29 with ColorStateList

use of android.content.res.ColorStateList in project Genius-Android by qiujuer.

the class EditText method init.

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    if (attrs == null)
        return;
    // Get the super padding top
    mTruePaddingTop = super.getPaddingTop();
    final Context context = getContext();
    final Resources resources = getResources();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EditText, defStyleAttr, defStyleRes);
    String fontFile = a.getString(R.styleable.EditText_gFont);
    int lineSize = a.getDimensionPixelSize(R.styleable.EditText_gLineSize, resources.getDimensionPixelSize(R.dimen.g_editText_lineSize));
    ColorStateList lineColor = a.getColorStateList(R.styleable.EditText_gLineColor);
    // Set HintProperty
    int titleModel = a.getInt(R.styleable.EditText_gHintTitle, 1);
    int titleTextSize = a.getDimensionPixelSize(R.styleable.EditText_gHintTitleTextSize, resources.getDimensionPixelSize(R.dimen.g_editText_hintTitleTextSize));
    int titlePaddingTop = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingTop, 0);
    int titlePaddingBottom = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingBottom, 0);
    int titlePaddingLeft = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingLeft, 0);
    int titlePaddingRight = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingRight, 0);
    a.recycle();
    // Init color
    if (lineColor == null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            lineColor = resources.getColorStateList(R.color.g_default_edit_view_line, null);
        } else {
            //noinspection deprecation
            lineColor = resources.getColorStateList(R.color.g_default_edit_view_line);
        }
    }
    if (!Ui.isHaveAttribute(attrs, "textColorHint") || getHintTextColors() == null) {
        ColorStateList hintColor;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            hintColor = resources.getColorStateList(R.color.g_default_edit_view_hint, null);
        } else {
            //noinspection deprecation
            hintColor = resources.getColorStateList(R.color.g_default_edit_view_hint);
        }
        setHintTextColor(hintColor);
    }
    // Set same values
    setLineSize(lineSize);
    setLineColor(lineColor);
    setHintTitleTextSize(titleTextSize);
    setHintTitleModel(titleModel);
    // check for IDE preview render
    if (!this.isInEditMode()) {
        // Set Font
        if (fontFile != null && fontFile.length() > 0) {
            Typeface typeface = Ui.getFont(context, fontFile);
            if (typeface != null)
                setTypeface(typeface);
        }
    }
    // Init background and title
    if (!Ui.isHaveAttribute(attrs, "background")) {
        initBackground();
    }
    initHintTitleText();
    // SetHintPadding
    setHintTitlePadding(titlePaddingLeft, titlePaddingTop, titlePaddingRight, titlePaddingBottom);
}
Also used : Context(android.content.Context) Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 30 with ColorStateList

use of android.content.res.ColorStateList in project Genius-Android by qiujuer.

the class Loading method init.

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final Context context = getContext();
    final Resources resource = getResources();
    if (attrs == null) {
        // default we init a circle style loading drawable
        setProgressStyle(STYLE_CIRCLE);
        return;
    }
    final float density = resource.getDisplayMetrics().density;
    // default size 2dp
    final int baseSize = (int) (density * 2);
    // Load attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Loading, defStyleAttr, defStyleRes);
    int bgLineSize = a.getDimensionPixelOffset(R.styleable.Loading_gBackgroundLineSize, baseSize);
    int fgLineSize = a.getDimensionPixelOffset(R.styleable.Loading_gForegroundLineSize, baseSize);
    // transparent color
    int bgColor = 0;
    ColorStateList colorStateList = a.getColorStateList(R.styleable.Loading_gBackgroundColor);
    if (colorStateList != null)
        bgColor = colorStateList.getDefaultColor();
    int fgColorId = a.getResourceId(R.styleable.Loading_gForegroundColor, R.array.g_default_loading_fg);
    int style = a.getInt(R.styleable.Loading_gProgressStyle, 1);
    boolean autoRun = a.getBoolean(R.styleable.Loading_gAutoRun, true);
    float progress = a.getFloat(R.styleable.Loading_gProgressFloat, 0);
    a.recycle();
    setProgressStyle(style);
    setAutoRun(autoRun);
    setProgress(progress);
    setBackgroundLineSize(bgLineSize);
    setForegroundLineSize(fgLineSize);
    setBackgroundColor(bgColor);
    // Check for IDE preview render
    if (!isInEditMode()) {
        String type = resource.getResourceTypeName(fgColorId);
        try {
            switch(type) {
                case "color":
                    setForegroundColor(resource.getColor(fgColorId));
                    break;
                case "array":
                    setForegroundColor(resource.getIntArray(fgColorId));
                    break;
                default:
                    setForegroundColor(resource.getIntArray(R.array.g_default_loading_fg));
                    break;
            }
        } catch (Exception e) {
            setForegroundColor(resource.getIntArray(R.array.g_default_loading_fg));
        }
    }
}
Also used : Context(android.content.Context) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources)

Aggregations

ColorStateList (android.content.res.ColorStateList)269 Paint (android.graphics.Paint)90 TypedArray (android.content.res.TypedArray)76 Drawable (android.graphics.drawable.Drawable)43 TextPaint (android.text.TextPaint)42 Resources (android.content.res.Resources)25 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)22 TypedValue (android.util.TypedValue)21 Context (android.content.Context)18 TextView (android.widget.TextView)18 SmallTest (android.test.suitebuilder.annotation.SmallTest)13 AllCapsTransformationMethod (android.text.method.AllCapsTransformationMethod)13 SuppressLint (android.annotation.SuppressLint)12 View (android.view.View)12 StateListDrawable (android.graphics.drawable.StateListDrawable)11 Nullable (android.annotation.Nullable)10 Bitmap (android.graphics.Bitmap)10 TextAppearanceSpan (android.text.style.TextAppearanceSpan)9 PorterDuff (android.graphics.PorterDuff)7 RippleDrawable (android.graphics.drawable.RippleDrawable)7