In my app, I have an activity that uses onTouchEvent() to calculate screen input. But on some phones, eg. Samsung Galaxy S4 the event is aborted in favor of GestureDetector, with the log message:
GestureDetector(23138): [Surface touch Event] Palm swipe start, x:565.0 m:450.0 s:54.0 TILT_TO_ZOOM_XVAR: 180.0
The problem disappears when the user turns Movements and Gestures off in the Android Phone Settings menu, but this is to hard to find to be convenient.
How can I disable this, without forcing the user to exit the app or change the phone settings?
I don't know if it works, but my first idea is requestDisallowInterceptTouchEvent() may help you ( http://developer.android.com/reference/android/view/ViewParent.html#requestDisallowInterceptTouchEvent%28boolean%29 ).
public boolean onTouch(View v, MotionEvent e) {
if(e.getAction() == MotionEvent.ACTION_DOWN){
viewPager.getParent().requestDisallowInterceptTouchEvent(true);
}
}
Related
Im trying to find touch area for android screen like how much area is covered by any finger,i know about event.getSize() method but its always gives me 0 output and pointerIndex is also 0. how can i find touch area for all android devices as further i also need to calculate touch pressure?
TRY THIS
final View view= findViewById(R.id.view);
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(context, "\"Touch coordinates : \" +\n" +
" String.valueOf(event.getX()) + \"x\" + String.valueOf(event.getY()", Toast.LENGTH_SHORT).show();
return true;
}
});
For your question regarding touch pressure. MotionEvent().getPressure(i) should return a value between 0 and 1 based on the "pressure" placed on the screen. In reality for capacitive screens it is the size of the capacitive object rather than literal pressure, but the concept is almost the same for fingers (fingers are squishy). Ranges higher than one may be returned depending on the calibration of the touchscreen.
If your screen is only returning 0 or 1, try testing on another device. Perhaps your screens driver simply does not return those values.Below link can be helpful for you
https://developer.android.com/reference/android/view/MotionEvent.html#getPressure(int)
http://android-er.blogspot.com/2014/05/get-touch-pressure.html
I am using an Android SurfaceView and listening for multi-touch events. I am able to detect multiple touches but it seems that the ACTION_POINTER_UP touch event is not getting fired. Here is a quick snip of my code.
public class GameView extends SurfaceView implements Runnable {
...
#Override
public boolean onTouchEvent(MotionEvent motionEvent) {
Log.i("pointer count", Integer.toString(motionEvent.getPointerCount()));
return true;
}
...
}
When I put 2 fingers on the screen the pointer count log out is 2. If I remove one of my fingers the pointer count log out is not 1 and stays at 2. It only goes to 1 if I move my finger that is still on the screen. Why is this and how to I firkin fix it? thanks!
EDIT
This problem occurs on my One Plus One and my friends Samsung Galaxy Note 2. It is interesting that when I put it on my Samsung Galaxy s4 the problem did not occur.
Do not use getAction() == MotionEvent.ACTION_POINTER_UP as the action will also contain the pointer index.
getActionMasked() will strip out this information, and could be used for comparison.
See http://developer.android.com/reference/android/view/MotionEvent.html#getActionMasked()
I have developed a game that shoots when player touches the screen by using onTouchListener for my custom SurfaceView and Thread.
But now I want to change the approach and instead of onTouchListener I added onTouchEvent to the SurfaceView o my Activity.
The problem is that I get some kind of offset when I click on the emulator.
Everything is working great, except that offset keeps appearing and I don't understand why.
Also let me mention that my app is running in landscape mode, maybe this is relevant.
I suspect that it isn't working properly because onTouchListener was added to the view and depended on it, but onTouchEvent doesn't depend on the view.
Also my view doesn't have any padding or margin properties, it is full-screen view (fill_parent).
Does anyone have any ideas on this?
I have done my application, and everything works correctly now, but i still do not know what the problem was.
After lots of debugging of my application the onTouchEvent returned random Y values that were always higher than the ones that the onTouchListener returned. And i am not sure why this is hapening since my view that recognizes the onTouchListener is a full-screen view.
So i figured out a way to get passed this by doing some math.
The first function that the android calls is the onTouch method which gives the correct values but just for one touch. I needed it to give right values even on the MotionEvent.ACTION_MOVE so i noticed that MotionEvent.ACTION_MOVE is actually doing correctly depending on the first touch recognized by the onTouchEvent.
So i just got the coordinate Y from the onTouch and the different coordinate with the offset from onTouchEvent calculated the difference and in every onTouchEvent from there, until the user lifts up their finger, i just subtract that difference and that gives me the correct value.
If anyone else has this problem, and doesn't know how to fix it, here is my code, maybe it will be helpful.
#Override
public boolean onTouchEvent(MotionEvent arg1) {
/*you can only touch when the thread is running*/
if(game.state() != STATE_PAUSE){
if(arg1.getAction() == MotionEvent.ACTION_DOWN){
coordinateX = arg1.getX();
coordinateY = arg1.getY();
differenceY = Math.abs(coordinateY - touchedY);
coordinateY = coordinateY - differenceY;
shootingIsOkay = true;
game.setDrawCircle(coordinateX,coordinateY);
}
if(arg1.getAction() == MotionEvent.ACTION_MOVE){
coordinateX = arg1.getX();
coordinateY = arg1.getY();
coordinateY = coordinateY - differenceY;
shootingIsOkay = true;
game.setDrawCircle(coordinateX,coordinateY);
}
if(arg1.getAction() == MotionEvent.ACTION_UP){
shootingIsOkay = false;
}
}
return false;
}
And the onTouch method that is called from the onTouchListener that depends on the view is just simple, here:
#Override
public boolean onTouch(View arg0, MotionEvent arg1) {
touchedY = arg1.getY();
return false;
}
If anyone knows how to fix this problem, please post your answer, i am very curious why this is happening
I have some buttons in my Android app which play a tone when pressed and stop playing when the button is released. I use code as below to implement this
private OnTouchListener dialTouch = new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if ( event.getAction() == MotionEvent.ACTION_DOWN)
{
//play tone
}
else if ( event.getAction() == MotionEvent.ACTION_UP)
{
// stop tone
}
}
}
However on a Samsung Galaxy 3 the palm swipe feature eg when taking a screenshot is triggering these MotionEvent.ACTION_DOWN events. Is there any way to ignore the palm swipe event in the code but still be able to generate the tone on press of the button.
Thanks
Hi there I know this is old, but did you even get it answered ? I really need to know how to turn off the palm sweep listener
I also want to know the Answer for this question.
Does android has any palm swipe listener itself , or we need to do this programatically by using our logic.
An experiment in learning Android is to detect two-finger presses. I have an app that changes a custom ImageView to a random pic on a touch. That works fine. I now want it to only change the picture when two or more fingers press. I have an IF statement to only randomize the picture if pointerCount>1. It doesn't do anything.
I have my ASUS Transformer TF101 connected to the PC. I have a simple custom ImageView with an onTouch event.
public boolean onTouchEvent(MotionEvent event) {
int number =event.getPointerCount();
if (number > 1){
*randomise pic*
I examine the value of 'number' during a debug step-through (Log.d doesn't work for me from this ASUS :() and it's always 1 no matter how many fingers I touch with.
Any ideas?
(X) return false;
(X) return super.onTouchEvent(event);
(O) return true;