Search in sources :

Example 21 with ColorStateList

use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.

the class SkinCompatResources method getColorStateList.

public ColorStateList getColorStateList(int resId) {
    ColorStateList colorStateList = ContextCompat.getColorStateList(mAppContext, resId);
    if (isDefaultSkin) {
        return colorStateList;
    }
    String resName = mAppContext.getResources().getResourceEntryName(resId);
    int targetResId = mResources.getIdentifier(resName, "color", mSkinPkgName);
    return targetResId == 0 ? colorStateList : mResources.getColorStateList(targetResId);
}
Also used : ColorStateList(android.content.res.ColorStateList)

Example 22 with ColorStateList

use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.

the class SkinCompatBackgroundHelper method applySkin.

public void applySkin() {
    mBackgroundResId = checkResourceId(mBackgroundResId);
    if (mBackgroundResId == INVALID_ID) {
        return;
    }
    String typeName = mView.getResources().getResourceTypeName(mBackgroundResId);
    if ("color".equals(typeName)) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            int color = SkinCompatResources.getInstance().getColor(mBackgroundResId);
            mView.setBackgroundColor(color);
        } else {
            ColorStateList colorStateList = SkinCompatResources.getInstance().getColorStateList(mBackgroundResId);
            Drawable drawable = mView.getBackground();
            DrawableCompat.setTintList(drawable, colorStateList);
            ViewCompat.setBackground(mView, drawable);
        }
    } else if ("drawable".equals(typeName)) {
        Drawable drawable = SkinCompatResources.getInstance().getDrawable(mBackgroundResId);
        ViewCompat.setBackground(mView, drawable);
    } else if ("mipmap".equals(typeName)) {
        Drawable drawable = SkinCompatResources.getInstance().getMipmap(mBackgroundResId);
        ViewCompat.setBackground(mView, drawable);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList)

Example 23 with ColorStateList

use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.

the class SkinCompatTextHelper method applyTextColorResource.

private void applyTextColorResource() {
    mTextColorResId = checkResourceId(mTextColorResId);
    if (mTextColorResId == R.color.abc_primary_text_disable_only_material_light || mTextColorResId == R.color.abc_secondary_text_material_light) {
        return;
    }
    if (mTextColorResId != INVALID_ID) {
        ColorStateList color = SkinCompatResources.getInstance().getColorStateList(mTextColorResId);
        mView.setTextColor(color);
    }
}
Also used : ColorStateList(android.content.res.ColorStateList)

Example 24 with ColorStateList

use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.

the class SkinCompatTextHelper method applyTextColorHintResource.

private void applyTextColorHintResource() {
    mTextColorHintResId = checkResourceId(mTextColorHintResId);
    if (mTextColorHintResId == R.color.abc_hint_foreground_material_light) {
        return;
    }
    if (mTextColorHintResId != INVALID_ID) {
        ColorStateList color = SkinCompatResources.getInstance().getColorStateList(mTextColorHintResId);
        mView.setHintTextColor(color);
    }
}
Also used : ColorStateList(android.content.res.ColorStateList)

Example 25 with ColorStateList

use of android.content.res.ColorStateList in project platform_frameworks_base by android.

the class TextView method setTextAppearance.

/**
     * Sets the text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     *
     * @deprecated Use {@link #setTextAppearance(int)} instead.
     */
@Deprecated
public void setTextAppearance(Context context, @StyleRes int resId) {
    final TypedArray ta = context.obtainStyledAttributes(resId, R.styleable.TextAppearance);
    final int textColorHighlight = ta.getColor(R.styleable.TextAppearance_textColorHighlight, 0);
    if (textColorHighlight != 0) {
        setHighlightColor(textColorHighlight);
    }
    final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_textColor);
    if (textColor != null) {
        setTextColor(textColor);
    }
    final int textSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_textSize, 0);
    if (textSize != 0) {
        setRawTextSize(textSize);
    }
    final ColorStateList textColorHint = ta.getColorStateList(R.styleable.TextAppearance_textColorHint);
    if (textColorHint != null) {
        setHintTextColor(textColorHint);
    }
    final ColorStateList textColorLink = ta.getColorStateList(R.styleable.TextAppearance_textColorLink);
    if (textColorLink != null) {
        setLinkTextColor(textColorLink);
    }
    final String fontFamily = ta.getString(R.styleable.TextAppearance_fontFamily);
    final int typefaceIndex = ta.getInt(R.styleable.TextAppearance_typeface, -1);
    final int styleIndex = ta.getInt(R.styleable.TextAppearance_textStyle, -1);
    setTypefaceFromAttrs(fontFamily, typefaceIndex, styleIndex);
    final int shadowColor = ta.getInt(R.styleable.TextAppearance_shadowColor, 0);
    if (shadowColor != 0) {
        final float dx = ta.getFloat(R.styleable.TextAppearance_shadowDx, 0);
        final float dy = ta.getFloat(R.styleable.TextAppearance_shadowDy, 0);
        final float r = ta.getFloat(R.styleable.TextAppearance_shadowRadius, 0);
        setShadowLayer(r, dx, dy, shadowColor);
    }
    if (ta.getBoolean(R.styleable.TextAppearance_textAllCaps, false)) {
        setTransformationMethod(new AllCapsTransformationMethod(getContext()));
    }
    if (ta.hasValue(R.styleable.TextAppearance_elegantTextHeight)) {
        setElegantTextHeight(ta.getBoolean(R.styleable.TextAppearance_elegantTextHeight, false));
    }
    if (ta.hasValue(R.styleable.TextAppearance_letterSpacing)) {
        setLetterSpacing(ta.getFloat(R.styleable.TextAppearance_letterSpacing, 0));
    }
    if (ta.hasValue(R.styleable.TextAppearance_fontFeatureSettings)) {
        setFontFeatureSettings(ta.getString(R.styleable.TextAppearance_fontFeatureSettings));
    }
    ta.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) SpannedString(android.text.SpannedString) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) AllCapsTransformationMethod(android.text.method.AllCapsTransformationMethod)

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