0

I wrote the following code I cannot understand what is wrong with it. It is not capturing MotionEvent.ACTION_POINTER_DOWN.

 public boolean onTouch(View vk,MotionEvent me)
 {
 if(me.getActionMasked()==MotionEvent.ACTION_DOWN)
 {
 start_pinch=1;
 tv.setBackgroundResource(R.drawable.shape);
 }
 if(me.getActionMasked()==MotionEvent.ACTION_POINTER_DOWN)
 {
 Toast.makeText(MainActivity.this,""+start_pinch, 
 Toast.LENGTH_SHORT).show();
 }
 return true;
 }
Aditya
  • 57
  • 5
  • try: `int action = me.getActionMasked(); Log.d(TAG, MotionEvent.actionToString(action));` what do you see? – pskink Sep 27 '17 at 07:35
  • I tried as You said and It shows zero. while on printing MotionEvent.ACTION_POINTER_DOWN it shows 5 why is it? @pskink – Aditya Sep 27 '17 at 07:44
  • what does `MotionEvent.actionToString()` return? what do you see on the logcat? – pskink Sep 27 '17 at 07:45
  • I did not did it using the logcat i just used Toast. As this Log.d(TAG, MotionEvent.actionToString(action)); was showing an error. – Aditya Sep 27 '17 at 07:48
  • so do not use any toasts for debugging your code - use `Log.d` instead, more [here](https://developer.android.com/reference/android/util/Log.html) and [here](https://developer.android.com/studio/debug/am-logcat.html) – pskink Sep 27 '17 at 07:49
  • and? what do you see on the logcat? – pskink Sep 27 '17 at 07:53
  • MotionEvent.actionToString is producing something about the API level – Aditya Sep 27 '17 at 08:03
  • is producing what? it simply returns a string, did you pass that string to `Log.d` method? what do you see on the logcat then? – pskink Sep 27 '17 at 08:04
  • @pskink sorry for annoying. Ok it only returns ACTION_DOWN. Now what should I do ? – Aditya Sep 27 '17 at 08:20
  • touch down another finger – pskink Sep 27 '17 at 08:26
  • I dont know. It showed ACTION_POINTER_DOWN just once rest of the time it was showing ACTION_MOVE – Aditya Sep 27 '17 at 08:44
  • thats normal, so you have ACTION_POINTER_DOWN in your events, whats the problem then? what actually do you want to achieve in `onTouch` method? – pskink Sep 27 '17 at 08:45
  • I just want to do pinch zoom. but its producing action_move how is it possible to do so. So do I have to touch it very softly? why is it capturing ACTION_MOVE frequently rather than activating the ACTION_POINTER_DOWN event. – Aditya Sep 27 '17 at 08:50
  • see `MatrixGestureDetector` from [here](https://stackoverflow.com/a/21657145/2252830) – pskink Sep 27 '17 at 08:55
  • I actually could not understand it if you could add the simplified code which would work for my purpose. i would be very very thankful to you. @pskink – Aditya Sep 27 '17 at 09:03

1 Answers1

0

Requirement add return at method onTouch

Sample:

public boolean onTouch(View vk,MotionEvent me){
    if(me.getActionMasked()==MotionEvent.ACTION_DOWN){
        start_pinch=1;
        tv.setBackgroundResource(R.drawable.shape);
        return true;
    }
    if(me.getActionMasked()==MotionEvent.ACTION_POINTER_DOWN){
        Toast.makeText(MainActivity.this,""+start_pinch, 
        Toast.LENGTH_SHORT).show();
        return true;
    }

    return false;
}
Dungnbhut
  • 176
  • 5
  • Each pointer has a unique id that is assigned when it first goes down (indicated by ACTION_DOWN or ACTION_POINTER_DOWN). Maybe your event always call MotionEvent.ACTION_DOWN first. You can more event. https://developer.android.com/reference/android/view/MotionEvent.html – Dungnbhut Sep 27 '17 at 07:55
  • Actually, ACTION_DOWN should be invoked for the first touch. In case any other touches occur simultaneously or until ACTION_UP wasn't invoked - ACTION_POINTER_DOWN is used. – Mike Sep 27 '17 at 08:41