Example usage for android.graphics.drawable GradientDrawable setStroke

List of usage examples for android.graphics.drawable GradientDrawable setStroke

Introduction

In this page you can find the example usage for android.graphics.drawable GradientDrawable setStroke.

Prototype

public void setStroke(int width, ColorStateList colorStateList) 

Source Link

Document

Set the stroke width and color state list for the drawable.

Usage

From source file:Main.java

public static Drawable cornerDrawable(final int bgColor, float[] cornerradius, int borderwidth,
        int bordercolor) {
    final GradientDrawable bg = new GradientDrawable();
    bg.setCornerRadii(cornerradius);/*from   w  ww  .j a  va  2 s  . com*/
    bg.setStroke(borderwidth, bordercolor);
    bg.setColor(bgColor);

    return bg;
}

From source file:Main.java

public static Drawable createDrawableBackground(int color, int cornerRadius, boolean hasBorder,
        int borderThickness, int borderColor) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    if (hasBorder)
        drawable.setStroke(borderThickness, borderColor);
    drawable.setCornerRadius(cornerRadius);
    drawable.setColor(color);//  w w w. ja  v a2s.c  om
    return drawable;
}

From source file:Main.java

public static GradientDrawable getDrawable(int radius, int fillColor, int width, int strokeColor) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setCornerRadius(radius);
    gradientDrawable.setColor(fillColor);
    gradientDrawable.setStroke(width, strokeColor);
    return gradientDrawable;
}

From source file:com.waz.zclient.ui.utils.ColorUtils.java

public static Drawable getButtonBackground(int borderColor, int fillColor, int strokeWidth, int cornerRadius) {
    int fillColorPressed = getPressColor(PRESSED_ALPHA, fillColor);
    int borderColorPressed = getPressColor(PRESSED_ALPHA, borderColor);

    GradientDrawable gradientDrawablePressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { fillColorPressed, fillColorPressed });
    gradientDrawablePressed.setStroke(strokeWidth, borderColorPressed);
    gradientDrawablePressed.setCornerRadius(cornerRadius);

    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { fillColor, fillColor });
    gradientDrawable.setStroke(strokeWidth, borderColor);
    gradientDrawable.setCornerRadius(cornerRadius);

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_pressed }, gradientDrawablePressed);
    states.addState(new int[] { android.R.attr.state_focused }, gradientDrawablePressed);
    states.addState(new int[] {}, gradientDrawable);

    return states;
}

From source file:Main.java

/**
 * Set the background of a {@link android.view.View} to the specified color, with a darker version of the
 * color as a border./*from  w  w  w  . ja v a  2s  .com*/
 */
public static void setViewBackground(View view, int color) {
    Resources r = view.getResources();

    Drawable currentDrawable = view.getBackground();
    GradientDrawable backgroundDrawable;
    if (currentDrawable != null && currentDrawable instanceof GradientDrawable) {
        // Reuse drawable
        backgroundDrawable = (GradientDrawable) currentDrawable;
    } else {
        backgroundDrawable = new GradientDrawable();
    }

    int darkenedColor = darkenColor(color);

    backgroundDrawable.setColor(color);
    backgroundDrawable.setStroke(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()),
            darkenedColor);

    view.setBackgroundDrawable(backgroundDrawable);
}

From source file:com.esri.android.ecologicalmarineunitexplorer.bottomsheet.BottomSheetFragment.java

/**
 * Build a stateful drawable for a given EMU
 * @param emuName String representing name
 * @return StateListDrawable responsive to selected, pressed, and enabled states
 *///from  w  w w. ja  va  2 s. c  o  m
private static StateListDrawable buildStateList(final int emuName) {
    final StateListDrawable stateListDrawable = new StateListDrawable();

    final GradientDrawable defaultShape = new GradientDrawable();
    final int color = Color.parseColor(EmuHelper.getColorForEMUCluster(emuName));
    defaultShape.setColor(color);

    final GradientDrawable selectedPressShape = new GradientDrawable();
    selectedPressShape.setColor(color);
    selectedPressShape.setStroke(5, Color.parseColor("#f4f442"));

    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape);

    return stateListDrawable;
}

From source file:com.fast.access.kam.widget.colorpicker.dashclockpicker.ColorPickerDialogDash.java

private static void setColorViewValue(View view, int color) {
    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        Resources res = imageView.getContext().getResources();

        Drawable currentDrawable = imageView.getDrawable();
        GradientDrawable colorChoiceDrawable;
        if (currentDrawable != null && currentDrawable instanceof GradientDrawable) {
            // Reuse drawable
            colorChoiceDrawable = (GradientDrawable) currentDrawable;
        } else {//from ww w. j a  v a 2  s .  c  om
            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, 1, res.getDisplayMetrics()),
                darkenedColor);
        imageView.setImageDrawable(colorChoiceDrawable);

    } else if (view instanceof TextView) {
        ((TextView) view).setTextColor(color);
    }
}

From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java

public static Drawable tintDrawable(GradientDrawable drawable, int fillColor, int strokeColor,
        int strokePixels) {
    drawable.setStroke(strokePixels, strokeColor);
    drawable.setColor(fillColor);//from   ww w  . ja va 2 s  . c o  m
    return drawable;
}

From source file:com.intirix.cloudpasswordmanager.pages.settings.SavePasswordOptionsViewHolder.java

private void addBorder(View view) {
    //use a GradientDrawable with only one color set, to make it a solid color
    GradientDrawable border = new GradientDrawable();
    border.setColor(0xFFFFFFFF); //white background
    border.setStroke(1, 0xFF000000); //black border with full opacity
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackgroundDrawable(border);
    } else {//from  w  w  w  .j av  a2  s. c om
        view.setBackground(border);
    }
}

From source file:com.intirix.cloudpasswordmanager.pages.settings.SavePasswordOptionsViewHolder.java

private void removeBorder(View view) {
    //use a GradientDrawable with only one color set, to make it a solid color
    GradientDrawable border = new GradientDrawable();
    border.setColor(0xFFFFFFFF); //white background
    border.setStroke(0, 0xFF000000); //black border with full opacity
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackgroundDrawable(border);
    } else {/*  w  w w.j  a  va2 s. c o  m*/
        view.setBackground(border);
    }
}