Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

Guide - PdfLayoutView in ViewPager 6 years 4 months ago #13173

  • ksnyers_ixor
  • ksnyers_ixor's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 4
  • Thank you received: 0
Hi,

In our application, we just want to show PDF documents inside a fragment. (no editing or any other actions, just scrolling and zooming)
I am currently trying to use the PDFLayoutView for this.
This seems to be working. (Is there a guide for this kind of integration? That would be handy. It is quite a pain to figure out if I am doing this correct right now)

The problem I am currently facing:
This fragment is contained inside a ViewPager.

The ViewPager should only switch page, when the PDFLayoutView has been completely scrolled to an edge.
I can not seem to find a way to accomplish this.
I have tried using a custom ViewGroup, implementing onInterceptTouchEvent, returning true,
and then passing onTouchEvent to PDFLayoutView first, only calling super, when the PDFLayoutView.onTouchEvent() returns false.
But this does not work.

How can I achieve this kind of behaviour?

Please Log in or Create an account to join the conversation.

Guide - PdfLayoutView in ViewPager 6 years 4 months ago #13176

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
I suggest you to look at the demo project, here you will find an example of a ViewPager.
Please check this class : PDFPagerAct.

Please Log in or Create an account to join the conversation.

Guide - PdfLayoutView in ViewPager 6 years 4 months ago #13178

  • ksnyers_ixor
  • ksnyers_ixor's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 4
  • Thank you received: 0
Hi Davide,

I see that the PDFViewPager allows to zoom in on a pdf page, and scroll the page completely, before switching to the second page.
This component makes use of PDFPageView, which I think handles the 'scroll to edge before viewpager scroll' behaviour.
However, the PDFLayoutView does not make use of PDFPageView.

So, based on PDFPageView, I created CustomPDFLayoutView, extending PDFLayoutView.
Overriding onTouchEvent
public class CustomPdfLayoutView extends PDFLayoutView {
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        try {
            if(this.onTouchZoom(event)) {
                this.getParent().requestDisallowInterceptTouchEvent(true);
                return true;
            } else {
                boolean bOK = this.onTouchNone(event);
                this.getParent().requestDisallowInterceptTouchEvent(bOK);
                return bOK;
            }
        } catch (Exception var3) {
            return false;
        }
    }
}

This allows me to scroll and zoom the pdf without scrolling the viewpager.
BUT, now the viewpager does not scroll anymore, whatsoever.

Please Log in or Create an account to join the conversation.

Guide - PdfLayoutView in ViewPager 6 years 4 months ago #13181

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
PDFLayoutView is not customized for the usage with a view pager, we suggest you to use PDFPageView along with PDFViewPager (for better handling of memory issues)

Please Log in or Create an account to join the conversation.

Guide - PdfLayoutView in ViewPager 6 years 4 months ago #13182

  • ksnyers_ixor
  • ksnyers_ixor's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 4
  • Thank you received: 0
Please have a look at the illustration for what we want to accomplish.

imgur.com/a/vjaug

We need a vertically scrolling PDF (so PDFLayoutView, not a PDFViewPager), That is contained inside a Fragment, which is contained inside our own, ViewPager.

We have managed to create this.
The issue we have, is that either
  • The PDFLayoutView is unable to scroll horizontally, because the ViewPager starts switching page
  • The PDFLayoutView is able to scroll and zoom in any way, but our ViewPager does not scroll anymore, when the PDF page is shown

What we need, is to have a way to let the PDFLayoutView handle touch events for scrolling and zooming
and when an edge is reached, our ViewPager should receive the touch events.

Is this in any way possible?

Please Log in or Create an account to join the conversation.

Last edit: by ksnyers_ixor. Reason: filesize of 261 KB is too big...

Guide - PdfLayoutView in ViewPager 6 years 4 months ago #13187

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
you have to return false in the onTouchNone method when you are in the left limit and you scroll.
In that way you pass the event to the ViewPager that will handle it.

You can do something like that :
private boolean onTouchNone(MotionEvent event)
	{
		if( m_status != STA_NONE ) return false;
		if( m_gesture.onTouchEvent(event) ) return true;
		switch(event.getActionMasked())
		{
		case MotionEvent.ACTION_DOWN:
            m_hold_x = event.getX();
            m_hold_y = event.getY();
            m_hold_docx = m_layout.vGetX();
            m_hold_docy = m_layout.vGetY();
            m_layout.vScrollAbort();
            invalidate();
            m_hold = true;
			break;
		case MotionEvent.ACTION_MOVE:
			if(m_hold_docx <= 0 && m_hold_docx + m_hold_x - event.getX() < 0) {
				Log.w("---test---","FLING x Viewpager");
				return false;
			}
            if(m_hold) {
                m_layout.vSetX((int) (m_hold_docx + m_hold_x - event.getX()));
                m_layout.vSetY((int) (m_hold_docy + m_hold_y - event.getY()));
                invalidate();
            }
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL:
            if(m_hold) {
                m_layout.vSetX((int) (m_hold_docx + m_hold_x - event.getX()));
                m_layout.vSetY((int) (m_hold_docy + m_hold_y - event.getY()));
                invalidate();
                m_layout.vMoveEnd();
                m_hold = false;
            }
			break;
		case MotionEvent.ACTION_POINTER_DOWN:
			if( event.getPointerCount() >= 2 )
			{
				m_status = STA_ZOOM;
				m_hold_x = (event.getX(0) + event.getX(1))/2;
				m_hold_y = (event.getY(0) + event.getY(1))/2;
				m_zoom_pos = m_layout.vGetPos( (int)m_hold_x, (int)m_hold_y );
				float dx = event.getX(0) - event.getX(1);
				float dy = event.getY(0) - event.getY(1);
				m_zoom_dis0 = Global.sqrtf(dx * dx + dy * dy);
				m_zoom_scale = m_layout.vGetZoom();
				m_status = STA_ZOOM;
				m_layout.vZoomStart();
                if(m_listener != null)
                    m_listener.OnPDFZoomStart();
			}
			break;
		}
		return true;
	}
The following user(s) said Thank You: ksnyers_ixor

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum