Example usage for android.graphics.drawable GradientDrawable draw

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

Introduction

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

Prototype

@Override
    public void draw(Canvas canvas) 

Source Link

Usage

From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java

/**
 * Prparer le widget avec les lments fixes (nom, ligne, sens...)
 *//*from w  ww  .  j  ava  2s .c  o m*/
protected void prepareWidgetViewInit(final Context context, final RemoteViews views, final Favori favori) {
    views.setTextViewText(R.id.itemSymbole, favori.getLettre());

    // Uniquement pour 2.2 et sup
    if (Build.VERSION.SDK_INT > 7) {
        views.setTextColor(R.id.itemSymbole, favori.getCouleurTexte());
        views.setTextColor(R.id.itemTitle, favori.getCouleurTexte());
        views.setTextColor(R.id.itemDescription, favori.getCouleurTexte());

        final GradientDrawable gradientDrawable = ColorUtils.getGradiant(favori.getCouleurBackground());
        final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(bitmap);
        gradientDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        gradientDrawable.draw(canvas);
        views.setImageViewBitmap(R.id.widgetHeaderBackground, bitmap);
    }

    if (favori.getNomFavori() == null) {
        views.setTextViewText(R.id.itemTitle, favori.getNomArret());
        views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomSens()));
    } else {
        views.setTextViewText(R.id.itemTitle, favori.getNomArret());
        views.setTextViewText(R.id.itemDescription,
                FormatUtils.formatSens(favori.getNomArret(), favori.getNomSens()));
    }

    views.setViewVisibility(R.id.widgetLoading, View.GONE);
}

From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java

/**
 * Creates Bitmap for a Map marker depending on the magnitude of an earthquake
 * @param context from which call is being made
 * @param magnitude from 0 to 10 scale earthquake intensity
 * @return colorful oval of size depending on magnitude
 *//*from   w w w .  j a  v  a  2s  .c o  m*/
public static Bitmap getEarthquakeMarker(Context context, Double magnitude) {

    if (magnitude < 1) {
        magnitude = 1.0;
    }

    GradientDrawable oval;
    oval = (GradientDrawable) ContextCompat.getDrawable(context, R.drawable.marker);

    if (oval != null) {

        int STROKE_SIZE = 5;
        float DASH_WIDTH = 9f;
        float DASH_GAP = 3f;

        if (magnitude >= 3 && magnitude <= 5) {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.BLUE });
            oval.setStroke(STROKE_SIZE, Color.BLUE, DASH_WIDTH, DASH_GAP);
        } else if (magnitude > 5 && magnitude < 7) {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.YELLOW });
            oval.setStroke(STROKE_SIZE, Color.YELLOW, DASH_WIDTH, DASH_GAP);
        } else if (magnitude >= 7) {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.RED });
            oval.setStroke(STROKE_SIZE, Color.RED, DASH_WIDTH, DASH_GAP);
        } else {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.GREEN });
            oval.setStroke(STROKE_SIZE, Color.GREEN, DASH_WIDTH, DASH_GAP);
        }

        int diameter = (int) (oval.getIntrinsicWidth() * magnitude / 4);

        Canvas canvas = new Canvas();
        Bitmap icon = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);

        canvas.setBitmap(icon);
        oval.setBounds(0, 0, diameter, diameter);
        oval.draw(canvas);

        return icon;
    } else {
        return null;
    }
}

From source file:de.madvertise.android.sdk.MadView.java

/**
 * Draw the ad background for a text banner
 * // w  w w .j  ava 2  s . com
 * @param canvas
 * @param rectangle
 * @param backgroundColor
 * @param textColor
 */
private void drawTextBannerBackground(Canvas canvas, Rect rectangle, int backgroundColor, int shineColor) {
    Paint paint = new Paint();
    paint.setColor(backgroundColor);
    paint.setAntiAlias(true);
    canvas.drawRect(rectangle, paint);

    int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor),
            Color.blue(shineColor));
    int[] gradientColors = { upperColor, shineColor };
    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            gradientColors);

    int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top;
    gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop);
    gradientDrawable.draw(canvas);

    Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom);
    Paint shadowPaint = new Paint();
    shadowPaint.setColor(shineColor);
    canvas.drawRect(shadowRect, shadowPaint);
}

From source file:de.madvertise.android.sdk.MadvertiseView.java

/**
 * Draw the ad background for a text banner
 *
 * @param canvas/*from w  w w.  j a  va 2  s .  c om*/
 * @param rectangle
 * @param backgroundColor
 * @param mTextColor
 */
private void drawTextBannerBackground(final Canvas canvas, final Rect rectangle, final int backgroundColor,
        int shineColor) {
    Paint paint = new Paint();
    paint.setColor(backgroundColor);
    paint.setAntiAlias(true);
    canvas.drawRect(rectangle, paint);

    int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor),
            Color.blue(shineColor));
    int[] gradientColors = { upperColor, shineColor };
    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            gradientColors);

    int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top;
    gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop);
    gradientDrawable.draw(canvas);

    Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom);
    Paint shadowPaint = new Paint();
    shadowPaint.setColor(shineColor);
    canvas.drawRect(shadowRect, shadowPaint);
}