pawcio1357
Lurker
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.
[HIGH]
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);
}
[/HIGH]
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.
[HIGH]
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);
}
}
[/HIGH]
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 devices, all of which have Tegra(2 or 3), 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 that when I do the exact same things on a canvas of a newly created bitmap and save the bitmap to file, the graphs are visible(on Tegra devices too). What might be the cause of the problem?
[HIGH]
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);
}
[/HIGH]
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.
[HIGH]
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);
}
}
[/HIGH]
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 devices, all of which have Tegra(2 or 3), 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 that when I do the exact same things on a canvas of a newly created bitmap and save the bitmap to file, the graphs are visible(on Tegra devices too). What might be the cause of the problem?