I am trying to set the temperature to fill the whole square of the notification icon. I have tried various settings and tweaks with the code and this is the best I can get it. I started off by creating some notification icons at the Android Assets Studio website and refer to them as ic_notification in their corresponding drawable folders. The PNG I created is a blank PNG where the 3.4 sits in it as seen in the picture, it is the black box in the picture.
I have run this on a Table (10.1" sized) and a small phone like the Samsung Galaxy S and the it stays the same size as in the picture below. I would like to fill the whole box not just the black box, covering the light blue part too. Can someone explain why it doesn't fill the whole screen, or how to get it to fill the whole screen?
The code I use is the following, parts[4] is the temperature taken from an array and degrees is the Fahrenheit or Celsius symbol depending on what the users selected in the settings. The icon gets set when the notification is build .setLargeIcon(drawableToBitmap(iconDrawable)) after the drawable is created.
BitmapDrawable iconDrawable = writeOnDrawable(R.drawable.ic_notification, parts[4] + degrees);
public BitmapDrawable writeOnDrawable(int drawableId, String text) {
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(),
drawableId).copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(bm.getWidth() / 3);
paint.setTextAlign(Align.CENTER);
Canvas canvas = new Canvas(bm);
//Log.e("log_etag", "Drawable Text " + text);
//Log.e("log_etag", "getWidth bitMap " + bm.getWidth());
//Log.e("log_etag", "Text Width " + text.length());
Rect bounds = new Rect();
float x = bm.getHeight() / 2, y = bm.getWidth() / 2;
// get text lenght
paint.getTextBounds(text, 0, text.length(), bounds);
// canvas.drawLine(0, y, canvas.getWidth(), y, paint); // Included
// to show vertical alignment
// canvas.drawLine(x, 0, x, canvas.getHeight(), paint); // Included
// to show horizontal alignment
// draw text
canvas.drawText(text, x, y + bounds.height() * 0.5f, paint);
return new BitmapDrawable(mContext.getResources(), bm);
}
And I use the following to convert to bitmap
public Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}