Get the real position for touch event

Started by
3 comments, last by _WeirdCat_ 8 years, 4 months ago

After switching to newer device i saw that, when i click something at the bottom of the screen it gives me the value of 480 even when the device height is 540.

it must be something with scaling, however i didin't find anything about that on the net

this is how i get screen dim:


void GetDisplaySize()
{
	WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
	Display display = wm.getDefaultDisplay();
	
	Point outSize = new Point();
	display.getSize(outSize);
   
	ScreenWidth  = outSize.x;
	ScreenHeight = outSize.y;

    
	Log.d("ANDRO_ASYNC","W: "+Integer.toString(ScreenWidth));
	Log.d("ANDRO_ASYNC","H: "+Integer.toString(ScreenHeight));
}

and how i get pointer location:


	        float X = event.getX(index);
	        float Y = event.getY(index);
Advertisement

Is it possible those missing 60 pixels are taken up by the hardware buttons (the back button and friends)?

I get my screen size from onSurfaceChanged from my GLSurfaceView (http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceChanged%28javax.microedition.khronos.opengles.GL10,%20int,%20int%29).

I don't know enough about WindowManager to know whether or not it'll include the built-in buttons in the dimensions it gives you.

i fogot to mention that the screen is horizontal, but that shouldn't matter, anyway your method doesn't work either (shows the same dimensions) additionally its called after glInit() method.

i just wonder how the heck could i scale the pointer position to the screen size.

the screen is definetly 960x540, because i even take a screenshot from opengl thread and when telling it to take pixels from that rect it shows whole screen, (yeah whole app is fullscreen) this means getrawx and getrawy return the same as getx and gety

worst part is x coordinate is good but not y (landscape)


Is it possible those missing 60 pixels are taken up by the hardware buttons (the back button and friends)?


That exactly whats going on. On my sh!#y HTC desire 610, the actually screen resolution is 800 x 480, however, when queried via the NDK it comes up 782 x 480, the HW buttons takes up the additional pixels.

There shoud be no need to scale, the value you are getting is the actual window surface size and the touch event will take that into effect.

i am not sure which surface it is since i have glsurfaceview (from java) and it claims that it has the same dimension as screen display. Maybe theres a way to find the handle to window of which touchpad event occurs and retreive width and height from that, because i am not quite willing to do calibration test on first run (you know there are quads draw in 4 corners of the screen and user is asked to touch them tongue.png <- this is my solution so far.)

tried something like that: super.getWindow().getWindowManager().getDefaultDisplay().getSize(outSize); but still it returns the screen size in pixels, not the thing that i want

This topic is closed to new replies.

Advertisement