I have a problem with my android app which draws graphs of functions on a plane. To do this I use a custom View. The user can pan the coordinate system with touch. In the onDraw method, the coordinate system and the labels are drawn directly on the view's canvas, but the graphs themselves are buffered onto an additional bitmap(for performace reasons) - during the movement of the finger this bitmap is drawn onto the view's canvas translated so as to match the coordinate system, and the functions are redrawn only when the user releases the touch.
public void onDraw(Canvas canvas){
if (start) {
bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_4444);
hCanvas = new Canvas(bitmap);
start = false;
}
drawCoordinateSystem(canvas);
drawFunctions(canvas,bitmap,hCanvas);
}
In onTouch event listener I call invalidate(). There is a boolean "moving", which is set to true for ACTION_UP and to false for ACTION_DOWN.
public void drawFunctions(Canvas canvas,Bitmap bitmap,Canvas hCanvas){
if (moving) canvas.drawBitmap(bitmap,left+translateX,top+translateY,paint);
else {
hCanvas.drawColor(Color.TRANSPARENT,PorterDuff.Mode.CLEAR);
//code for drawing the functions on hCanvas
canvas.drawBitmap(bitmap,0,0,paint);
}
}
In ACTION_MOVE I calculate the translateX and translateY values appropriately.
Now where is the problem: If I compile the app for sdk 10, it works fine on all devices I tested it on(android 2.2-4.2 smartphones and tablets, virtual and physical). However, when I compile it for sdk 14, it works well for many devices, except for some tablets, where the coordinate system is drawn correctly, but somehow the bitmap containing the functions is not drawn on the view's canvas and the functions are not visible. The strange thing is, if I try to make a bitmap out of the view's canvas:
Bitmap bmp = this.getDrawingCache();
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
In the saved bitmap the functions are visible.
Another thing is - the issue occurs for i.a. Nexus 7, meanwhile on an AVD created with the preset Nexus 7 everything works fine.
What can be the problem?