Hi,
my app has widgets that have an ImageView and a TextView. On the onUpdate() method of the WidgetProvider, I put a Bitmap inside the ImageView this way:
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.widget_btn);
Bitmap bitmap2 = BitmapManager.setColor(bitmap, red, green, blue);
views.setImageViewBitmap(R.id.image, bitmap2);
setColor() method is this:
public synchronized static Bitmap setColor(Bitmap org, float r, float g, float b)
{
sColorMatrix.setScale(r, g, b, 1);
sColorPaint.setColorFilter(new ColorMatrixColorFilter(sColorMatrix));
// RGB_565 is faster, but loses transparency
Bitmap ret = Bitmap.createBitmap(org.getWidth(), org.getHeight(), Bitmap.Config.ARGB_8888);
try{
sColorCanvas.setBitmap(ret);
//sColorCanvas.drawColor(Color.);
sColorCanvas.drawBitmap(org, 0, 0, sColorPaint);
} catch (Throwable t){
}
return ret;
}
The problem is that sometimes the widget throws a RuntimeException because somebody has recycled the Bitmap, and I don't know what to do. Some suggestions?
I can attach the stacktrace if it can be useful. Thank you!