center and reset scale on page change - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Android development and PDF
  • Page:
  • 1

TOPIC: center and reset scale on page change

center and reset scale on page change 3 years 9 months ago #8313

  • rockycamacho
  • rockycamacho's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 15
  • Thank you received: 0
Hello,

I would like detect when a page has changed via flinging (not when the user has selected a thumbnail) and then reset the scale if it was zoomed.

Here is the code I tried:
Code on my fragment implementing PDFReaderListener
@Override
public void OnPageChanged(int pageno) {
pdfReader.resetScaleAndCenter(pageno);
}


Code on my custom pdfreader
public void resetScaleAndCenter(int pageno) {
m_view.vSetScale(m_view.vGetMinScale(), 0, 0);
m_view.vCenterPage(pageno);
}


This had a problem because it also triggered when the user selected a page from the thumb view.
Also sometimes it would jump to a different page. Ex. I would fling from page 2 to 3 but it would jump to page 24 instead.


Is there a better way to detect a page change caused by flinging? How do I solve the page jumping?

Thanks,
Rocky

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

center and reset scale on page change 3 years 9 months ago #8325

  • rockycamacho
  • rockycamacho's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 15
  • Thank you received: 0
Hello,

I have managed to detect the flinging to a page by modifying PDFView.java motionNormal method to store the current page on MotionEvent.ACTION_DOWN and then compare it to the page after MotionEvent.ACTION_UP.
I am able to perform scale and center but it still glitches sometimes by moving to a different page(often the last page). When I comment out the scale, it stops glitching. I think vSetScale is sometimes done after the center page.
//inside MotionEvent.ACTION_UP of motionNormal method..
final PDFPos pdfPos = vGetPos(m_w / 2, m_h / 2);
if(holdPos != null && pdfPos != null && holdPos.pageno != pdfPos.pageno) {
	m_view.vSetScale(m_view.vGetMinScale(), 0, 0);
	m_view.vCenterPage(pdfPos.pageno);
	holdPos = null;
}

My question is, how do I make it so that the code only does vSetScale AFTER vCenterPage?


Thanks,
Rocky

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

center and reset scale on page change 3 years 9 months ago #8327

  • rockycamacho
  • rockycamacho's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 15
  • Thank you received: 0
Hello,

I found a workaround. I used a timer to schedule m_view.vCenterPage(pageno); so that it gets called after vSetScale. It still moves to a random page but it now goes back to the correct page.

Thanks,
Rocky

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

  • Page:
  • 1
Powered by Kunena Forum