Search in sources :

Example 56 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 57 with ColorStateList

use of android.content.res.ColorStateList in project XobotOS by xamarin.

the class TextView method getTextColors.

/**
     * Returns the TextView_textColor attribute from the
     * Resources.StyledAttributes, if set, or the TextAppearance_textColor
     * from the TextView_textAppearance attribute, if TextView_textColor
     * was not set directly.
     */
public static ColorStateList getTextColors(Context context, TypedArray attrs) {
    ColorStateList colors;
    colors = attrs.getColorStateList(com.android.internal.R.styleable.TextView_textColor);
    if (colors == null) {
        int ap = attrs.getResourceId(com.android.internal.R.styleable.TextView_textAppearance, -1);
        if (ap != -1) {
            TypedArray appearance;
            appearance = context.obtainStyledAttributes(ap, com.android.internal.R.styleable.TextAppearance);
            colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
            appearance.recycle();
        }
    }
    return colors;
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 58 with ColorStateList

use of android.content.res.ColorStateList in project XobotOS by xamarin.

the class Switch 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, com.android.internal.R.styleable.TextAppearance);
    ColorStateList colors;
    int ts;
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
    if (colors != null) {
        mTextColors = colors;
    } else {
        // If no color set in TextAppearance, default to the view's textColor
        mTextColors = getTextColors();
    }
    ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0);
    if (ts != 0) {
        if (ts != mTextPaint.getTextSize()) {
            mTextPaint.setTextSize(ts);
            requestLayout();
        }
    }
    int typefaceIndex, styleIndex;
    typefaceIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_typeface, -1);
    styleIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_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 59 with ColorStateList

use of android.content.res.ColorStateList in project android_frameworks_base by ResurrectionRemix.

the class Toast method makeText.

/**
     * Make a standard toast that just contains a text view.
     *
     * @param context  The context to use.  Usually your {@link android.app.Application}
     *                 or {@link android.app.Activity} object.
     * @param text     The text to show.  Can be formatted text.
     * @param duration How long to display the message.  Either {@link #LENGTH_SHORT} or
     *                 {@link #LENGTH_LONG}
     *
     */
public static Toast makeText(Context context, CharSequence text, @Duration int duration) {
    Toast result = new Toast(context);
    final ColorStateList textColor = RandomColorHelper.getToastTextColorList(tContext);
    LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
    TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
    tv.setText(text);
    tv.setTextColor(textColor);
    result.mNextView = v;
    result.mDuration = duration;
    return result;
}
Also used : LayoutInflater(android.view.LayoutInflater) ColorStateList(android.content.res.ColorStateList) View(android.view.View)

Example 60 with ColorStateList

use of android.content.res.ColorStateList in project android_frameworks_base by ResurrectionRemix.

the class TextView method applyCompoundDrawableTint.

private void applyCompoundDrawableTint() {
    if (mDrawables == null) {
        return;
    }
    if (mDrawables.mHasTint || mDrawables.mHasTintMode) {
        final ColorStateList tintList = mDrawables.mTintList;
        final PorterDuff.Mode tintMode = mDrawables.mTintMode;
        final boolean hasTint = mDrawables.mHasTint;
        final boolean hasTintMode = mDrawables.mHasTintMode;
        final int[] state = getDrawableState();
        for (Drawable dr : mDrawables.mShowing) {
            if (dr == null) {
                continue;
            }
            if (dr == mDrawables.mDrawableError) {
                // drawable tint to it.
                continue;
            }
            dr.mutate();
            if (hasTint) {
                dr.setTintList(tintList);
            }
            if (hasTintMode) {
                dr.setTintMode(tintMode);
            }
            // stateful before applying the tint, so let's try again.
            if (dr.isStateful()) {
                dr.setState(state);
            }
        }
    }
}
Also used : PorterDuff(android.graphics.PorterDuff) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList)

Aggregations

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