Search in sources :

Example 16 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project Signal-Android by WhisperSystems.

the class BubbleDrawableBuilder method create.

public Drawable create(Context context) {
    final GradientDrawable bubble = new GradientDrawable();
    final int radius = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
    final float[] radii = cornerBooleansToRadii(corners, radius);
    bubble.setColor(color);
    bubble.setCornerRadii(radii);
    if (!hasShadow) {
        return bubble;
    } else {
        final GradientDrawable shadow = new GradientDrawable();
        final int distance = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_shadow_distance);
        shadow.setColor(shadowColor);
        shadow.setCornerRadii(radii);
        final LayerDrawable layers = new LayerDrawable(new Drawable[] { shadow, bubble });
        layers.setLayerInset(1, 0, 0, 0, distance);
        return layers;
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 17 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project AndroidRubberIndicator by LyndonChin.

the class RubberIndicator method init.

private void init(AttributeSet attrs, int defStyle) {
    /** Get XML attributes */
    final TypedArray styledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.RubberIndicator, defStyle, 0);
    mSmallCircleColor = styledAttributes.getColor(R.styleable.RubberIndicator_smallCircleColor, DEFAULT_SMALL_CIRCLE_COLOR);
    mLargeCircleColor = styledAttributes.getColor(R.styleable.RubberIndicator_largeCircleColor, DEFAULT_LARGE_CIRCLE_COLOR);
    mOuterCircleColor = styledAttributes.getColor(R.styleable.RubberIndicator_outerCircleColor, DEFAULT_OUTER_CIRCLE_COLOR);
    styledAttributes.recycle();
    /** Initialize views */
    View rootView = inflate(getContext(), R.layout.rubber_indicator, this);
    mContainer = (LinearLayout) rootView.findViewById(R.id.container);
    mOuterCircle = (CircleView) rootView.findViewById(R.id.outer_circle);
    // Apply outer color to outerCircle and background shape
    View containerWrapper = rootView.findViewById(R.id.container_wrapper);
    mOuterCircle.setColor(mOuterCircleColor);
    GradientDrawable shape = (GradientDrawable) containerWrapper.getBackground();
    shape.setColor(mOuterCircleColor);
    /** values */
    mSmallCircleRadius = dp2px(SMALL_CIRCLE_RADIUS);
    mLargeCircleRadius = dp2px(LARGE_CIRCLE_RADIUS);
    mOuterCircleRadius = dp2px(OUTER_CIRCLE_RADIUS);
    /** animators */
    mPvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1, 0.8f, 1);
    mPvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 1, 0.8f, 1);
    mPvhScale = PropertyValuesHolder.ofFloat("scaleY", 1, 0.5f, 1);
    mPvhRotation = PropertyValuesHolder.ofFloat("rotation", 0);
    mSmallCirclePath = new Path();
    mPendingAnimations = new LinkedList<>();
    /** circle view list */
    mCircleViews = new ArrayList<>();
}
Also used : Path(android.graphics.Path) TypedArray(android.content.res.TypedArray) View(android.view.View) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 18 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project BoomMenu by Nightonke.

the class Ham method init.

@Override
public void init(int color) {
    Drawable backgroundDrawable = Util.getDrawable(this, R.drawable.piece_ham, null);
    ((GradientDrawable) backgroundDrawable).setColor(color);
    Util.setDrawable(this, backgroundDrawable);
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 19 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project BoomMenu by Nightonke.

the class Util method getOvalDrawable.

public static GradientDrawable getOvalDrawable(View view, int color) {
    GradientDrawable gradientDrawable = (GradientDrawable) getDrawable(view, R.drawable.shape_oval_normal);
    gradientDrawable.setColor(color);
    return gradientDrawable;
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 20 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project Signal-Android by WhisperSystems.

the class ColorPreference method setColorViewValue.

private static void setColorViewValue(View view, int color, boolean selected) {
    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        Resources res = imageView.getContext().getResources();
        Drawable currentDrawable = imageView.getDrawable();
        GradientDrawable colorChoiceDrawable;
        if (currentDrawable instanceof GradientDrawable) {
            // Reuse drawable
            colorChoiceDrawable = (GradientDrawable) currentDrawable;
        } else {
            colorChoiceDrawable = new GradientDrawable();
            colorChoiceDrawable.setShape(GradientDrawable.OVAL);
        }
        // Set stroke to dark version of color
        //      int darkenedColor = Color.rgb(
        //          Color.red(color) * 192 / 256,
        //          Color.green(color) * 192 / 256,
        //          Color.blue(color) * 192 / 256);
        colorChoiceDrawable.setColor(color);
        //      colorChoiceDrawable.setStroke((int) TypedValue.applyDimension(
        //          TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor);
        Drawable drawable = colorChoiceDrawable;
        if (selected) {
            BitmapDrawable checkmark = (BitmapDrawable) res.getDrawable(R.drawable.check);
            checkmark.setGravity(Gravity.CENTER);
            drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark });
        }
        imageView.setImageDrawable(drawable);
    } else if (view instanceof TextView) {
        ((TextView) view).setTextColor(color);
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Aggregations

GradientDrawable (android.graphics.drawable.GradientDrawable)163 Paint (android.graphics.Paint)19 Drawable (android.graphics.drawable.Drawable)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 SuppressLint (android.annotation.SuppressLint)18 View (android.view.View)18 TextView (android.widget.TextView)18 LayerDrawable (android.graphics.drawable.LayerDrawable)15 ImageView (android.widget.ImageView)14 LinearLayout (android.widget.LinearLayout)12 TypedArray (android.content.res.TypedArray)8 FrameLayout (android.widget.FrameLayout)6 TimeAnimator (android.animation.TimeAnimator)5 Typeface (android.graphics.Typeface)5 LayoutInflater (android.view.LayoutInflater)5 ViewGroup (android.view.ViewGroup)5 Attributes (com.cengalabs.flatui.Attributes)5 Resources (android.content.res.Resources)4 TextPaint (android.text.TextPaint)4 Button (android.widget.Button)4