1

I have an application which has a screen with list view. On this list view i am displaying different apps with their image and name in each row(using arraylist). Onclick of an app(in a row) it would launch that particular app. Now when there is an update to any app i want to show a badge on the image of the app. Can this be done?

I have the image stored as a bitmap. Is there any way i can add a badge to a bitmap(not a resource but obtained from web url) or any way to show the badge in a listview with an arraylist.

sundeep
  • 601
  • 1
  • 8
  • 21
  • See http://stackoverflow.com/questions/6044828/drawing-number-badge-like-iphone-in-android/6050064#6050064 and http://stackoverflow.com/questions/5569695/android-is-it-possible-to-update-a-imageview-imagebutton-with-a-number-to-show/5604787#5604787 if it can help you – ccheneson Dec 12 '13 at 14:35
  • @ccheneson here i am not using a relative layout. as i mentioned i am using a listview. There is no image view. – sundeep Dec 12 '13 at 14:38
  • The relative layout is used as a container for the image + the badge – ccheneson Dec 12 '13 at 14:42
  • sorry @ccheneson but my problem is not solved with the links you have pasted. I have gone through them before posting this question. My question is, is there any way i can add a badge to a bitmap(not a resource but obtained from web url) or any way to show the badge in a viewrow. – sundeep Dec 12 '13 at 14:49

2 Answers2

1

try this. You may need to amend the size options depending on the size of your image. I use this for 128x128 images.

public static Bitmap getOverlayedImage(Resources res, Drawable img1, Drawable img2) {
  float den = res.getDisplayMetrics().density;
  int dip = (int) (80 * den + 0.5f);
  int sz = (int) (128 * den + 0.5f);

  Drawable[] layers = new Drawable[2];
  layers[0] = img1;
  layers[1] = img2;

  LayerDrawable layerDrawable = new LayerDrawable(layers);
  layerDrawable.setLayerInset(1, dip, dip, 0, 00);

  Bitmap b = Bitmap.createBitmap(sz, sz, Bitmap.Config.ARGB_8888);
  layerDrawable.setBounds(0, 0, sz, sz);
  layerDrawable.draw(new Canvas(b));

  return b;
}

call it like this:

getOverlayedImage(getResources(), drawable1, drawable2);
Kuffs
  • 35,581
  • 10
  • 79
  • 92
  • here img1 has to be the image of my app and img2 is of badge ? what is the resource i have to pass? a bit confused with the parameters. – sundeep Dec 13 '13 at 07:33
  • Standard resources: http://developer.android.com/reference/android/content/Context.html#getResources() Drawable 1 is your image, drawable 2 is the image you would like overlayed. – Kuffs Dec 13 '13 at 07:49
  • sorry for the delay in accepting the answer. this solution worked for me. thanks – sundeep Dec 31 '13 at 05:59
0

There's a library that let's you attach a badge: https://github.com/jgilfelt/android-viewbadger

You can add the badge to the ImageView (or any other view you're using) that contains your image.

Bartek Filipowicz
  • 1,235
  • 7
  • 9
  • i am already using this project for in my project, but this is not serving my purpose currently. As i mentioned i am not using an imageview. I am using a viewrow and this project doesn't have any details regarding that. – sundeep Dec 12 '13 at 14:59
  • You mean it's a custom view where you paint the bitmap yourself? I'm not sure what do you mean by a viewrow. – Bartek Filipowicz Dec 12 '13 at 15:28