Search in sources :

Example 1 with ColorStateList

use of android.content.res.ColorStateList in project philm by chrisbanes.

the class DrawableTintUtils method createFromColorRes.

public static Drawable createFromColorRes(@NonNull Context context, @DrawableRes int drawableId, @ColorRes int colorId) {
    Drawable d = ContextCompat.getDrawable(context, drawableId);
    d = DrawableCompat.wrap(d.mutate());
    ColorStateList tint = AppCompatResources.getColorStateList(context, colorId);
    DrawableCompat.setTintList(d, tint);
    return d;
}
Also used : Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList)

Example 2 with ColorStateList

use of android.content.res.ColorStateList in project GreenDroid by cyrilmottier.

the class MapPinMapActivity method onCreate.

//@formatter:on
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setActionBarContentView(R.layout.map_pin);
    final MapView mapView = (MapView) findViewById(R.id.map_view);
    mapView.setBuiltInZoomControls(true);
    final Resources r = getResources();
    for (int i = 0; i < sAreas.length; i++) {
        final OverlayItem[] items = sAreas[i];
        ColorStateList pinCsl = createRandomColorStateList();
        ColorStateList dotCsl = createRandomColorStateList();
        BasicItemizedOverlay itemizedOverlay = new BasicItemizedOverlay(new MapPinDrawable(r, pinCsl, dotCsl));
        for (int j = 0; j < items.length; j++) {
            itemizedOverlay.addOverlay(items[j]);
        }
        mapView.getOverlays().add(itemizedOverlay);
    }
}
Also used : OverlayItem(com.google.android.maps.OverlayItem) MapView(com.google.android.maps.MapView) ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources) GeoPoint(com.google.android.maps.GeoPoint) MapPinDrawable(greendroid.graphics.drawable.MapPinDrawable)

Example 3 with ColorStateList

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

the class FastScroller method init.

private void init(Context context) {
    // Get both the scrollbar states drawables
    TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
    mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);
    mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
    mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
    mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);
    mScrollCompleted = true;
    getSectionsFromIndexer();
    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);
    mPaint.setTextSize(mOverlaySize / 2);
    ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    // to show mOverlayDrawable properly
    if (mList.getWidth() > 0 && mList.getHeight() > 0) {
        onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
    }
    mState = STATE_NONE;
    refreshDrawableState();
    ta.recycle();
    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mMatchDragPosition = context.getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;
    setScrollbarPosition(mList.getVerticalScrollbarPosition());
}
Also used : RectF(android.graphics.RectF) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 4 with ColorStateList

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

the class TextView method getTextColors.

/**
     * Returns the TextView_textColor attribute from the
     * TypedArray, 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 5 with ColorStateList

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

the class TextView method setTextAppearance.

/**
     * Sets the text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     */
public void setTextAppearance(Context context, int resid) {
    TypedArray appearance = context.obtainStyledAttributes(resid, com.android.internal.R.styleable.TextAppearance);
    int color;
    ColorStateList colors;
    int ts;
    color = appearance.getColor(com.android.internal.R.styleable.TextAppearance_textColorHighlight, 0);
    if (color != 0) {
        setHighlightColor(color);
    }
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
    if (colors != null) {
        setTextColor(colors);
    }
    ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0);
    if (ts != 0) {
        setRawTextSize(ts);
    }
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColorHint);
    if (colors != null) {
        setHintTextColor(colors);
    }
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColorLink);
    if (colors != null) {
        setLinkTextColor(colors);
    }
    String familyName;
    int typefaceIndex, styleIndex;
    familyName = appearance.getString(com.android.internal.R.styleable.TextAppearance_fontFamily);
    typefaceIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_typeface, -1);
    styleIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, -1);
    setTypefaceFromAttrs(familyName, typefaceIndex, styleIndex);
    final int shadowcolor = appearance.getInt(com.android.internal.R.styleable.TextAppearance_shadowColor, 0);
    if (shadowcolor != 0) {
        final float dx = appearance.getFloat(com.android.internal.R.styleable.TextAppearance_shadowDx, 0);
        final float dy = appearance.getFloat(com.android.internal.R.styleable.TextAppearance_shadowDy, 0);
        final float r = appearance.getFloat(com.android.internal.R.styleable.TextAppearance_shadowRadius, 0);
        setShadowLayer(r, dx, dy, shadowcolor);
    }
    if (appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps, false)) {
        setTransformationMethod(new AllCapsTransformationMethod(getContext()));
    }
    appearance.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)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