Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay So thanks to Gabe here and numerous blogs on this, I have found a solution to my question!</p> <p><strong>First I initialized my variables in the "Activity" class</strong></p> <pre><code>int GLOBAL_TOUCH_POSITION_X = 0; int GLOBAL_TOUCH_CURRENT_POSITION_X = 0; </code></pre> <p><strong>Next, Inside the onCreate():</strong></p> <pre><code>//Two-Finger Drag Gesture detection RelativeLayout TextLoggerLayout = (RelativeLayout)findViewById(R.id.ActivityrView); TextLoggerLayout.setOnTouchListener( new RelativeLayout.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent m) { handleTouch(m); return true; } }); </code></pre> <p><strong>Now define the function handleTouch(m) as follows</strong>, it outputs the current position of the "Two-finger-touch" along with the initial position of the touch:</p> <pre><code>void handleTouch(MotionEvent m){ //Number of touches int pointerCount = m.getPointerCount(); if(pointerCount == 2){ int action = m.getActionMasked(); int actionIndex = m.getActionIndex(); String actionString; TextView tv = (TextView) findViewById(R.id.testDiffText); switch (action) { case MotionEvent.ACTION_DOWN: GLOBAL_TOUCH_POSITION_X = (int) m.getX(1); actionString = "DOWN"+" current "+GLOBAL_TOUCH_CURRENT_POSITION_X+" prev "+GLOBAL_TOUCH_POSITION_X; tv.setText(actionString); break; case MotionEvent.ACTION_UP: GLOBAL_TOUCH_CURRENT_POSITION_X = 0; actionString = "UP"+" current "+GLOBAL_TOUCH_CURRENT_POSITION_X+" prev "+GLOBAL_TOUCH_POSITION_X; tv.setText(actionString); break; case MotionEvent.ACTION_MOVE: GLOBAL_TOUCH_CURRENT_POSITION_X = (int) m.getX(1); int diff = GLOBAL_TOUCH_POSITION_X-GLOBAL_TOUCH_CURRENT_POSITION_X; actionString = "Diff "+diff+" current "+GLOBAL_TOUCH_CURRENT_POSITION_X+" prev "+GLOBAL_TOUCH_POSITION_X; tv.setText(actionString); break; case MotionEvent.ACTION_POINTER_DOWN: GLOBAL_TOUCH_POSITION_X = (int) m.getX(1); actionString = "DOWN"+" current "+GLOBAL_TOUCH_CURRENT_POSITION_X+" prev "+GLOBAL_TOUCH_POSITION_X; tv.setText(actionString); break; default: actionString = ""; } pointerCount = 0; } else { GLOBAL_TOUCH_POSITION_X = 0; GLOBAL_TOUCH_CURRENT_POSITION_X = 0; } } </code></pre> <p>There you have it! The "Two-finger-drag" gesture finally implemented. Looks, like I can wrte a tiny blog post on it as well!! :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload