0

Can some body help me with some understanding about onTouchListners?? I am new to android...and doing something more complex I guess..

1. I have a main Activity class which renders a list of 7 pdf files

2. there exists a PDF class which renders the selected item as a new pdf file(done using pdf renderer)

3. there exists a flip class to take care of flipping pages on touch

I am confused about, where to place the following method as it is never getting called if placed correctly and it shud help me deliver the next or previous pdf page..

public boolean onTouch(View v, MotionEvent event) {
         return gDetector.onTouchEvent(event);
   }

Thank u..

M S Gadag
  • 2,057
  • 1
  • 12
  • 15
Diya
  • 107
  • 1
  • 11

1 Answers1

0

Here is a simple explanation of how OnTouch works...

public boolean onTouch(View v, MotionEvent event) {

    int action = MotionEventCompat.getActionMasked(event);
    int pointerIndex = MotionEventCompat.getActionIndex(event);
    int x = (int)MotionEventCompat.getX(event,pointerIndex);
    int y = (int)MotionEventCompat.getY(event,pointerIndex);

    switch(action)
    {
    case MotionEvent.ACTION_DOWN:
        //
        // First finger was touched. Set "pointerIndex" to some value (lets say 0 or -1)
        // Save "pointerIndex" corresponding to this touched object.
        //
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        //
        // More finger touched when first finger is already touched.
        // Save "pointerIndex" corresponding to this touched object.
        //
        break;
    case MotionEvent.ACTION_MOVE:
        //
        // Finger with "pointerIndex" was moved.
        //
        break;
    case MotionEvent.ACTION_UP:
        //
        // The first touched finger went off.
        //
        break;
    case MotionEvent.ACTION_POINTER_UP:
        //
        // Finger with "pointerIndex" went off (other than first finger)
        //
        break;
    }
    return true;
}

I hope this helps.

Good Luck. :)

Hemendra Sharma
  • 1,063
  • 9
  • 21
  • Thank you for the above reference..but the issue is when i zoom imageview, the page gets zoomed along with that the page is either moved to the next page..the page is not held.. – Diya Dec 22 '14 at 05:58
  • I have implemented the flips using xml and the zoom using gestureListener both seem to be overriding...any suggestions plzz?? – Diya Dec 22 '14 at 05:59
  • In my PDF Renderer I have implemented the flips using xml and the zoom using gesture Listener, It has has following concern - When I zoom the page, it does not slide up, down, right or left correctly When I zoom the page and tap with two fingers close the page gets zoomed out and tap with two fingers far apart the page gets zoomed in leaving its actual co-ordinates.. – Diya Dec 24 '14 at 10:36