1

I am trying to understand the following drag and resize behavior on android, but am not being able to track down. I have the following window launched in multi window free form mode [scree shot below], where if I click just outside the edge (any of the 4 sides) the window can be resized. I am trying to intercept this whole gesture (touch/ click outside the window) and drag.

  1. I have tried setting a touch listener to the decorview obtained from the window and returning true from it to receive all further events related to this gesture.

        getWindow().getDecorView().setOnTouchListener(new View.OnTouchListener() {
        private static final String TAG = "DVTouchListener";
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            Log.d(TAG,"onTouch "+motionEvent);
            return true;
        }
    });
    

    But this only gets a ACTION_DOWN shortly followed by an ACTION_CANCEL (ACTION_CANCEL is received while the pointer is pressed and drag has not started even).

  2. I tried overriding the dispatchTouchEvent of the activity and return true from there to receive all the MotionEvents of the gesture however the same is observed there too. ACTION_DOWN followed by ACTION_CANCEL.

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
       Log.d(TAG,"dispatchTouchEvent "+ev.toString());
       //        return super.dispatchTouchEvent(ev);
       return true;
    }
    

    I am not being able to understand the behavior as my understanding of the touch propagation was

if Activity.dispatchTouchEvent() returns true then it’ll consume all the subsequent gesture events (MOVE/UP). Whereas on returning false it’ll never be called again for subsequent events.

Can someone provide any hint as how to tap the whole set of MotionEvents in the gesture, or at least explain the observed behavior. This is all because I am working on a specific use case where I need to limit the resizing ability to a single side of the window. enter image description here

Som
  • 83
  • 2
  • 9

1 Answers1

1

If you return true it means you WANT to parse all events, but still the top level View can grab all for itself and when it decides to it fires an ACTION_CANCEL for child views know that no further event will be received from the gesture. In your case, if you trying to listen from system view events it have all priority to consume all events (since it listens it first).

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • Is there any other level where I can intercept it at ? I thought dispatchTouchEvent was the 1st point of hit. Is there a way to listen to the system view events, like you have mentioned , from my application code. Thanks for helping out! – Som Jul 19 '18 at 18:26
  • 1
    No, only the Launcher application code receive higher events, if you want to allow multiscreen navigation only on your application you can mimic the functionality with a activity that holds resizeables fragments. – Marcos Vasconcelos Jul 19 '18 at 18:30