List of usage examples for android.graphics.drawable GradientDrawable getIntrinsicWidth
@Override public int getIntrinsicWidth()
From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java
/** * @param context context used to get resources * @param resourceID drawable resource ID to a GradientDrawable * @param fillColor fill color to apply to drawable * @param strokeColor stroke color to apply to drawable * @param strokePx width of stroke/*from w w w . jav a 2s . c o m*/ * @return a Bitmap of the drawable */ public static Bitmap gradientDrawableToBitmap(Context context, int resourceID, int fillColor, int strokeColor, int strokePx) { Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceID, null); GradientDrawable gradient = (GradientDrawable) drawable; int w = 1, h = 1; if (gradient != null) { w = gradient.getIntrinsicWidth(); h = gradient.getIntrinsicHeight(); } Drawable tinted = tintDrawable(gradient, fillColor, strokeColor, strokePx); return drawableToBitmap(context, tinted, w, h, true); }
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 ww . j a va 2s . c om*/ 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; } }