I'm using a SurfaceHolder callback to give me access to a drawing surface, using this class
class Display extends Page.Surface
{
public Display(Context c)
{
super(c,screens);
}
// ------------------------------------------------------------
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
log("surface "+holder.getSurfaceFrame());
buildFrontPage(width,height);
show();
}
}
Where Page.Surface is a fairly standard extension of a SurfaceView, and implements SurfaceHolder.CallBack, like so:
// --------------------------------------------------------------------
static class Surface extends SurfaceView implements SurfaceHolder.Callback
{
SurfaceHolder holder;
public Pages pages;
public Surface(Context context, Pages screens)
{
super(context);
holder=getHolder();
holder.addCallback(this);
pages=screens;
}
// ----------------------------------------------------------------
public void show()
{
Canvas c=null;
try {
c = holder.lockCanvas(null);
synchronized (holder) {
if((c!=null) && (pages!=null)) pages.draw(c);
}
} finally {
if (c != null) {
holder.unlockCanvasAndPost(c);
}
}
}
I'm also trapping touchevents in my main activity, using this:
// -------------------------------------------
@Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
super.dispatchTouchEvent(ev);
screens.handleTouchEvent(ev);
return true;
}
All so far, so good, except that the values returned by ev.getX() and ev.getY() are absolute values - covering the whole surface of the tablet, and the canvas returned in the callback doesn't start until below the menu. This means that all of the getY values are off by the depth of the menu.
Is there any way I can find the point on the whole tablet surface at which my working canvas starts, so I can subtract it from the getY value?