RadaeePDF.com :: Topic: center and reset scale on page change (1/1)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF

TOPIC: center and reset scale on page change

center and reset scale on page change 2 years 8 months ago #8313

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
The administrator has disabled public write access.

center and reset scale on page change 2 years 8 months ago #8325

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
The administrator has disabled public write access.

center and reset scale on page change 2 years 8 months ago #8327

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
The administrator has disabled public write access.
Powered by Kunena Forum