2

I'm researching Mupdf library on Android. I compiled and ran the Sample successfully. It's really a great library. But now I have a problem with zooming the page when firing "Double tap" event.

First, I implemented my View to 'listen' double tap event :

public class MuPDFReaderView extends ReaderView implements GestureDetector.OnDoubleTapListener

Then, I overrode onDoubleTap() method :

@Override
public boolean onDoubleTap(MotionEvent e) {
    // TODO Auto-generated method stub
    MuPDFView pageView = (MuPDFView) getDisplayedView();
    pageView.setScale(1.5f);
    Log.e("double tap", "" + e.getDownTime());
    return false;
}

When double tap on page, I can see the "double tap" log in Logcat, but the page is not zoomed. What was I wrong here?

midhunhk
  • 5,560
  • 7
  • 52
  • 83
Phuc Tran
  • 7,555
  • 1
  • 39
  • 27

2 Answers2

1

I'm not sure why your attempt didn't worked, but here's another way to do it:

Instead of implementing the GestureDetector.OnDoubleTapListener on your View, implement it directly on the ReaderView you extended

public class ReaderView extends AdapterView<Adapter> implements 
    GestureDetector.OnGestureListener,
    GestureDetector.OnDoubleTapListener,
    ScaleGestureDetector.OnScaleGestureListener,
    Runnable { ... }

and then override the OnDoubleTap method like this

@Override
public boolean onDoubleTap(MotionEvent e) {

    float previousScale = mScale;
    mScale += (mScale == 1f) ? 2f : -2f;
    float factor = mScale/previousScale;

    View v = mChildViews.get(mCurrent);
    if (v != null) {
        // Work out the focus point relative to the view top left
        int viewFocusX = (int)e.getX() - (v.getLeft() + mXScroll);
        int viewFocusY = (int)e.getY() - (v.getTop() + mYScroll);
        // Scroll to maintain the focus point
        mXScroll += viewFocusX - viewFocusX * factor;
        mYScroll += viewFocusY - viewFocusY * factor;
        requestLayout();
    }

    return true;
}

Also you will have to override these 2 other methods

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    return false;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    return false;
}

Got this code from the Librelio Android example

https://github.com/libreliodev/android

Bruno
  • 543
  • 2
  • 7
  • 21
  • I added above methods to ReaderView class,but its not working Double click yet? when i add above code it says "The method onDoubleTap(MotionEvent) of type ReaderView must override or implement a supertype method" Do i have to add above method to somewhere else? – asliyanage Oct 09 '14 at 02:59
0

You need to handle this via ReaderView. Modify the scale and initiate request layout.

Ganesh Kanna
  • 2,269
  • 1
  • 19
  • 29