Reputation: 1688
I want to know how applications handle input from a touch screen. For example, if the user touch the coordinates x,y, how an opened (active in the foreground) application will know that the gadget (button for example) at the coordinates x,y must be clicked now?
Also, can I control the way by which apps handle the touch input using another app? I mean, I want to build an app that uses services
to control how other apps handle their inputs, of course this needs my app to have permission
to access other apps settings, but my question is, is it possible?
I have searched for how apps handle touch input, I found these results, which are useful, but not relevant to my case,
http://developer.android.com/training/gestures/index.html
How does Android device handle touch screen input?
Also, I know that any input hardware is controlled by HAL (Hardware Abstraction Layer)
in Android, also every input device has its own driver. But how apps handles the inputs coming from these devices?
Thank you.
Upvotes: 0
Views: 910
Reputation: 8487
There are several ways to handle touches in Android.
First with Buttons you can set a onClick()
method that will automatically be triggered when you touch the screen.
Another option is to attach a onTouchlistener
to your activity.
In this example a custom view class called "Example" with the id "exampleid" is getting attached to a "onTouchListener
Public class Example extends View implements View.onTouchListener {
public Example(Context context) {
Example exampleView = (Example) findViewById(R.id.exampleid); //This is how you set up a onTouch Listener.
gameView.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
//Do something when touched.
}
}
Upvotes: 1