Search in sources :

Example 6 with ColorStateList

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

the class Switch method setSwitchTextAppearance.

/**
     * Sets the switch text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     *
     * @attr ref android.R.styleable#Switch_switchTextAppearance
     */
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);
    boolean allCaps = appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps, false);
    if (allCaps) {
        mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext());
        mSwitchTransformationMethod.setLengthChangesAllowed(true);
    } else {
        mSwitchTransformationMethod = null;
    }
    appearance.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) AllCapsTransformationMethod(android.text.method.AllCapsTransformationMethod)

Example 7 with ColorStateList

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

the class ColorStateListTest method testStateIsInList.

@SmallTest
public void testStateIsInList() throws Exception {
    ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
    int[] focusedState = { android.R.attr.state_focused };
    int focusColor = colorStateList.getColorForState(focusedState, R.color.failColor);
    assertEquals(mResources.getColor(R.color.testcolor1), focusColor);
}
Also used : ColorStateList(android.content.res.ColorStateList) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with ColorStateList

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

the class ColorStateListTest method testEmptyState.

@SmallTest
public void testEmptyState() throws Exception {
    ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
    int[] emptyState = {};
    int defaultColor = colorStateList.getColorForState(emptyState, mFailureColor);
    assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
}
Also used : ColorStateList(android.content.res.ColorStateList) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with ColorStateList

use of android.content.res.ColorStateList in project HoloEverywhere by Prototik.

the class TextView method setTextAppearance.

public static <T extends android.widget.TextView & FontStyleProvider> void setTextAppearance(T textView, TypedArray appearance) {
    int color = appearance.getColor(R.styleable.TextAppearance_android_textColorHighlight, 0);
    if (color != 0) {
        textView.setHighlightColor(color);
    }
    ColorStateList colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColor);
    if (colors != null) {
        textView.setTextColor(colors);
    }
    int ts = appearance.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0);
    if (ts != 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, ts);
    }
    colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColorHint);
    if (colors != null) {
        textView.setHintTextColor(colors);
    }
    colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColorLink);
    if (colors != null) {
        textView.setLinkTextColor(colors);
    }
    if (appearance.getBoolean(R.styleable.TextAppearance_android_textAllCaps, false)) {
        textView.setTransformationMethod(new AllCapsTransformationMethod(textView.getContext()));
    }
    Object[] font = parseFontStyle(appearance);
    textView.setFontStyle((String) font[2], (Integer) font[1] | ((Boolean) font[0] ? 0 : textView.getFontStyle()));
}
Also used : ColorStateList(android.content.res.ColorStateList) SuppressLint(android.annotation.SuppressLint) AllCapsTransformationMethod(org.holoeverywhere.text.AllCapsTransformationMethod)

Example 10 with ColorStateList

use of android.content.res.ColorStateList in project ElasticDownload by Tibolte.

the class VectorDrawable method updateStateFromTypedArray.

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;
    // Account for any configuration changes.
    state.mChangingConfigurations |= getChangingConfigurations(a);
    // Extract the theme attributes, if any.
    //TODO: will not support drawable theming yet (applies to tinting mainly)
    //state.mThemeAttrs = a.extractThemeAttrs();
    final int tintMode = a.getInt(R.styleable.VectorDrawable_vc_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = parseTintMode(tintMode, PorterDuff.Mode.SRC_IN);
    }
    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_vc_tint);
    if (tint != null) {
        state.mTint = tint;
    }
    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_vc_autoMirrored, state.mAutoMirrored);
    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_vc_viewportWidth, pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_vc_viewportHeight, pathRenderer.mViewportHeight);
    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires viewportHeight > 0");
    }
    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_android_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_android_height, pathRenderer.mBaseHeight);
    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires height > 0");
    }
    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_android_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);
    final String name = a.getString(R.styleable.VectorDrawable_android_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}
Also used : ColorStateList(android.content.res.ColorStateList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Paint(android.graphics.Paint)

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