- Posts: 4
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
Guide - PdfLayoutView in ViewPager
- ksnyers_ixor
- Topic Author
- Offline
- New Member
-
Less
More
IP: 192.168.0.71
8 years 3 months ago #13173
by ksnyers_ixor
Guide - PdfLayoutView in ViewPager was created by ksnyers_ixor
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?
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?
IP: 192.168.0.71
8 years 3 months ago #13176
by Davide
Replied by Davide on topic Guide - PdfLayoutView in ViewPager
Hi,
I suggest you to look at the demo project, here you will find an example of a ViewPager.
Please check this class : PDFPagerAct.
I suggest you to look at the demo project, here you will find an example of a ViewPager.
Please check this class : PDFPagerAct.
- ksnyers_ixor
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 4
- Thank you received: 0
IP: 192.168.0.71
8 years 3 months ago #13178
by ksnyers_ixor
Replied by ksnyers_ixor on topic Guide - PdfLayoutView in ViewPager
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
This allows me to scroll and zoom the pdf without scrolling the viewpager.
BUT, now the viewpager does not scroll anymore, whatsoever.
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
Code:
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.
IP: 192.168.0.71
8 years 3 months ago #13181
by Davide
Replied by Davide on topic Guide - PdfLayoutView in ViewPager
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)
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)
- ksnyers_ixor
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 4
- Thank you received: 0
IP: 192.168.0.71
8 years 3 months ago - 8 years 3 months ago #13182
by ksnyers_ixor
Replied by ksnyers_ixor on topic Guide - PdfLayoutView in ViewPager
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
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?
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?
Last edit: 8 years 3 months ago by ksnyers_ixor. Reason: filesize of 261 KB is too big...
IP: 192.168.0.71
8 years 3 months ago #13187
by Davide
Replied by Davide on topic Guide - PdfLayoutView in ViewPager
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 :
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 :
Code:
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;
}
Time to create page: 0.414 seconds