1

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?

fadden
  • 51,356
  • 5
  • 116
  • 166
user3660664
  • 237
  • 3
  • 8
  • By the time you're dealing with a Canvas you're already in relative coordinates. I believe you need to figure out the position of the View. – fadden Feb 03 '15 at 16:56
  • Yes. That's what I was asking: how do I find the location, on the whole tablet, of the canvas returned by a SurfaceView. I've just tried making it fullscreen; but the notifications bar at the top (where the clock etc are) is still present. – user3660664 Feb 04 '15 at 15:50
  • Perhaps http://stackoverflow.com/questions/2224844/how-to-get-the-absolute-coordinates-of-a-view ? – fadden Feb 04 '15 at 16:58
  • That's the one - getLocationOnScreen. Thank you very much. – user3660664 Feb 04 '15 at 18:22

0 Answers0