Search in sources :

Example 91 with ColorStateList

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

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 92 with ColorStateList

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

the class NotificationGuts method applyAuto.

private void applyAuto() {
    mSeekBar.setEnabled(!mAuto);
    final ColorStateList starTint = mAuto ? mActiveSliderTint : mInactiveSliderTint;
    final float alpha = mAuto ? mInactiveSliderAlpha : mActiveSliderAlpha;
    Drawable icon = mAutoButton.getDrawable().mutate();
    icon.setTintList(starTint);
    mAutoButton.setImageDrawable(icon);
    mSeekBar.setAlpha(alpha);
    if (mAuto) {
        mSeekBar.setProgress(mNotificationImportance);
        mImportanceSummary.setText(mContext.getString(R.string.notification_importance_user_unspecified));
        mImportanceTitle.setText(mContext.getString(R.string.user_unspecified_importance));
    } else {
        updateTitleAndSummary(mSeekBar.getProgress());
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList)

Example 93 with ColorStateList

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

the class GradientDrawable method updateStateFromTypedArray.

/**
     * Updates the constant state from the values in the typed array.
     */
private void updateStateFromTypedArray(TypedArray a) {
    final GradientState state = mGradientState;
    // Account for any configuration changes.
    state.mChangingConfigurations |= a.getChangingConfigurations();
    // Extract the theme attributes, if any.
    state.mThemeAttrs = a.extractThemeAttrs();
    state.mShape = a.getInt(R.styleable.GradientDrawable_shape, state.mShape);
    state.mDither = a.getBoolean(R.styleable.GradientDrawable_dither, state.mDither);
    if (state.mShape == RING) {
        state.mInnerRadius = a.getDimensionPixelSize(R.styleable.GradientDrawable_innerRadius, state.mInnerRadius);
        if (state.mInnerRadius == -1) {
            state.mInnerRadiusRatio = a.getFloat(R.styleable.GradientDrawable_innerRadiusRatio, state.mInnerRadiusRatio);
        }
        state.mThickness = a.getDimensionPixelSize(R.styleable.GradientDrawable_thickness, state.mThickness);
        if (state.mThickness == -1) {
            state.mThicknessRatio = a.getFloat(R.styleable.GradientDrawable_thicknessRatio, state.mThicknessRatio);
        }
        state.mUseLevelForShape = a.getBoolean(R.styleable.GradientDrawable_useLevel, state.mUseLevelForShape);
    }
    final int tintMode = a.getInt(R.styleable.GradientDrawable_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = Drawable.parseTintMode(tintMode, PorterDuff.Mode.SRC_IN);
    }
    final ColorStateList tint = a.getColorStateList(R.styleable.GradientDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }
    final int insetLeft = a.getDimensionPixelSize(R.styleable.GradientDrawable_opticalInsetLeft, state.mOpticalInsets.left);
    final int insetTop = a.getDimensionPixelSize(R.styleable.GradientDrawable_opticalInsetTop, state.mOpticalInsets.top);
    final int insetRight = a.getDimensionPixelSize(R.styleable.GradientDrawable_opticalInsetRight, state.mOpticalInsets.right);
    final int insetBottom = a.getDimensionPixelSize(R.styleable.GradientDrawable_opticalInsetBottom, state.mOpticalInsets.bottom);
    state.mOpticalInsets = Insets.of(insetLeft, insetTop, insetRight, insetBottom);
}
Also used : ColorStateList(android.content.res.ColorStateList) Paint(android.graphics.Paint)

Example 94 with ColorStateList

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

the class BitmapDrawable method updateStateFromTypedArray.

/**
     * Updates the constant state from the values in the typed array.
     */
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final Resources r = a.getResources();
    final BitmapState state = mBitmapState;
    // Account for any configuration changes.
    state.mChangingConfigurations |= a.getChangingConfigurations();
    // Extract the theme attributes, if any.
    state.mThemeAttrs = a.extractThemeAttrs();
    final int srcResId = a.getResourceId(R.styleable.BitmapDrawable_src, 0);
    if (srcResId != 0) {
        final Bitmap bitmap = BitmapFactory.decodeResource(r, srcResId);
        if (bitmap == null) {
            throw new XmlPullParserException(a.getPositionDescription() + ": <bitmap> requires a valid 'src' attribute");
        }
        state.mBitmap = bitmap;
    }
    state.mTargetDensity = r.getDisplayMetrics().densityDpi;
    final boolean defMipMap = state.mBitmap != null ? state.mBitmap.hasMipMap() : false;
    setMipMap(a.getBoolean(R.styleable.BitmapDrawable_mipMap, defMipMap));
    state.mAutoMirrored = a.getBoolean(R.styleable.BitmapDrawable_autoMirrored, state.mAutoMirrored);
    state.mBaseAlpha = a.getFloat(R.styleable.BitmapDrawable_alpha, state.mBaseAlpha);
    final int tintMode = a.getInt(R.styleable.BitmapDrawable_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN);
    }
    final ColorStateList tint = a.getColorStateList(R.styleable.BitmapDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }
    final Paint paint = mBitmapState.mPaint;
    paint.setAntiAlias(a.getBoolean(R.styleable.BitmapDrawable_antialias, paint.isAntiAlias()));
    paint.setFilterBitmap(a.getBoolean(R.styleable.BitmapDrawable_filter, paint.isFilterBitmap()));
    paint.setDither(a.getBoolean(R.styleable.BitmapDrawable_dither, paint.isDither()));
    setGravity(a.getInt(R.styleable.BitmapDrawable_gravity, state.mGravity));
    final int tileMode = a.getInt(R.styleable.BitmapDrawable_tileMode, TILE_MODE_UNDEFINED);
    if (tileMode != TILE_MODE_UNDEFINED) {
        final Shader.TileMode mode = parseTileMode(tileMode);
        setTileModeXY(mode, mode);
    }
    final int tileModeX = a.getInt(R.styleable.BitmapDrawable_tileModeX, TILE_MODE_UNDEFINED);
    if (tileModeX != TILE_MODE_UNDEFINED) {
        setTileModeX(parseTileMode(tileModeX));
    }
    final int tileModeY = a.getInt(R.styleable.BitmapDrawable_tileModeY, TILE_MODE_UNDEFINED);
    if (tileModeY != TILE_MODE_UNDEFINED) {
        setTileModeY(parseTileMode(tileModeY));
    }
    state.mTargetDensity = Drawable.resolveDensity(r, 0);
}
Also used : Bitmap(android.graphics.Bitmap) ColorStateList(android.content.res.ColorStateList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) Paint(android.graphics.Paint) Shader(android.graphics.Shader) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 95 with ColorStateList

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

the class GradientDrawable method updateGradientDrawableStroke.

private void updateGradientDrawableStroke(TypedArray a) {
    final GradientState st = mGradientState;
    // Account for any configuration changes.
    st.mChangingConfigurations |= a.getChangingConfigurations();
    // Extract the theme attributes, if any.
    st.mAttrStroke = a.extractThemeAttrs();
    // We have an explicit stroke defined, so the default stroke width
    // must be at least 0 or the current stroke width.
    final int defaultStrokeWidth = Math.max(0, st.mStrokeWidth);
    final int width = a.getDimensionPixelSize(R.styleable.GradientDrawableStroke_width, defaultStrokeWidth);
    final float dashWidth = a.getDimension(R.styleable.GradientDrawableStroke_dashWidth, st.mStrokeDashWidth);
    ColorStateList colorStateList = a.getColorStateList(R.styleable.GradientDrawableStroke_color);
    if (colorStateList == null) {
        colorStateList = st.mStrokeColors;
    }
    if (dashWidth != 0.0f) {
        final float dashGap = a.getDimension(R.styleable.GradientDrawableStroke_dashGap, st.mStrokeDashGap);
        setStroke(width, colorStateList, dashWidth, dashGap);
    } else {
        setStroke(width, colorStateList);
    }
}
Also used : ColorStateList(android.content.res.ColorStateList) Paint(android.graphics.Paint)

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