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

In zoomed state stop fling gesture to next page

More
IP: 192.168.0.71 11 years 2 months ago #8363 by alex.temp
In zoomed state, I would like to stop fling gesture to next page unless the page is at the border of the page.
For standard version, how could I achieve this?
Thanks!!
More
11 years 1 month ago #8486 by alex.temp
Hi, I followed this post in knowledge base How to avoid page change during pan if zoom level>1.0?
I could stop going to next page when zoomed in portrait orientation, but not in landscape orientation.
After some debug, I found that the m_horz_dual[m_pageno] is null and throw a java.lang.NullPointerException.
Please help, thank you!

Below is the code I added in PDFViewDual class:, motionNormal and vOnFling
@Override
protected boolean motionNormal(MotionEvent event)
{
if (m_gesture.onTouchEvent(event)) return true;
switch (event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
if (m_status == STA_NONE)
{
m_scroller.forceFinished(true);
m_scroller.abortAnimation();
m_holdsx = m_scroller.getCurrX();
m_holdsy = m_scroller.getCurrY();
m_holdx = event.getX();
m_holdy = event.getY();
m_status = STA_MOVING;
}
break;
case MotionEvent.ACTION_MOVE:
if (m_status == STA_MOVING)
{
m_movex = event.getX();
m_movey = event.getY();
int x = (int) (m_holdsx + m_holdx - m_movex);
int y = (int) (m_holdsy + m_holdy - m_movey);
if (m_lock == 1 || m_lock == 3) x = (int) m_holdsx;
if (m_lock == 2 || m_lock == 3) y = (int) m_holdsy;
if (x + m_w > m_docw) x = m_docw - m_w;
if (vGetScale() > vGetMinScale())
{
try
{
if (Global.def_view == 6 && m_w > m_h && m_horz_dual[m_pageno])
{ //dual page
if ((m_pageno + 2 < m_pages.length) && x + m_w > m_pages[m_pageno + 2].m_x) x = m_pages[m_pageno + 2].m_x - m_w;
if (m_pageno > 0 && x <= (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w)) x = (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w);
}
else
{ //single page
if ((m_pageno + 1 < m_pages.length) && x + m_w > m_pages[m_pageno + 1].m_x) x = m_pages[m_pageno + 1].m_x - m_w;
if (m_pageno > 0 && x <= (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w)) x = (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (x < 0) x = 0;
if (y + m_h > m_doch) y = m_doch - m_h;
if (y < 0) y = 0;
m_scroller.setFinalX(x);
m_scroller.setFinalY(y);
if (m_listener != null) m_listener.OnPDFInvalidate(false);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (m_status == STA_MOVING)
{
m_movex = event.getX();
m_movey = event.getY();
int x = (int) (m_holdsx + m_holdx - m_movex);
int y = (int) (m_holdsy + m_holdy - m_movey);
if (m_lock == 1 || m_lock == 3) x = (int) m_holdsx;
if (m_lock == 2 || m_lock == 3) y = (int) m_holdsy;
if (x + m_w > m_docw) x = m_docw - m_w;

if (vGetScale() > vGetMinScale())
{
try
{
if (Global.def_view == 6 && m_w > m_h && m_horz_dual[m_pageno])
{ //dual page
if ((m_pageno + 2 < m_pages.length) && x + m_w > m_pages[m_pageno + 2].m_x) x = m_pages[m_pageno + 2].m_x - m_w;
if (m_pageno > 0 && x <= (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w)) x = (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w);
}
else
{ //single page
if ((m_pageno + 1 < m_pages.length) && x + m_w > m_pages[m_pageno + 1].m_x) x = m_pages[m_pageno + 1].m_x - m_w;
if (m_pageno > 0 && x <= (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w)) x = (m_pages[m_pageno - 1].m_x + m_pages[m_pageno - 1].m_w);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (x < 0) x = 0;
if (y + m_h > m_doch) y = m_doch - m_h;
if (y < 0) y = 0;
m_scroller.setFinalX(x);
m_scroller.setFinalY(y);
m_status = STA_NONE;
vOnMoveEnd(x, y);
if (m_listener != null) m_listener.OnPDFInvalidate(false);
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
if (event.getPointerCount() == 2 && m_status == STA_MOVING && m_lock != 5)
{
m_scroller.forceFinished(true);
m_scroller.abortAnimation();
m_holdx = (event.getX(0) + event.getX(1)) / 2;
m_holdy = (event.getY(0) + event.getY(1)) / 2;
float dx = event.getX(0) - event.getX(1);
float dy = event.getY(0) - event.getY(1);
m_zoom_pos = vGetPos((int) m_holdx, (int) m_holdy);
m_zoom_dis1 = FloatMath.sqrt(dx * dx + dy * dy);
m_zoom_dis2 = m_zoom_dis1;
m_zoom_scale = m_scale;
int cur = m_prange_start;
int cnt = m_prange_end;
while (cur < cnt)
{
m_pages[cur].CreateBmp();
m_thread.end_render(m_pages[cur]);
cur++;
}
m_drawbmp = true;
m_status = STA_ZOOM;
}
break;
}
return true;
}

@Override
protected boolean vOnFling(float dx, float dy, float velocityX, float velocityY)
{
float ddx = (velocityX < 0) ? -velocityX : velocityX;
float ddy = (velocityY < 0) ? -velocityY : velocityY;
if (ddx < ddy) return false;
if (dx < (m_w >> 2) && dx > -(m_w >> 2)) return false;
if (ddx < (m_w >> 1) && ddx > -(m_w >> 1)) return false;
if (vGetScale() > vGetMinScale()) return true;
int x = m_scroller.getCurrX();
int y = m_scroller.getCurrY();
if (x + m_w > m_docw) x = m_docw - m_w;
if (x < 0) x = 0;
if (y + m_h > m_doch) y = m_doch - m_h;
if (y < 0) y = 0;
int ccur = 0;
while (ccur < m_cells.length)
{
PDFCell cell = m_cells[ccur];
if (m_holdsx >= cell.left && m_holdsx < cell.right)
{
if (m_rtol)
{
if (dx > 0)
{
if (ccur < m_cells.length - 1)
{
int endx = m_cells[ccur + 1].right - m_w;
m_scroller.startScroll(x, y, endx - x, 0);
}
else
m_scroller.startScroll(x, y, -x, 0);
}
else
{
if (ccur > 0)
{
int endx = cell.right;
m_scroller.startScroll(x, y, endx - x, 0);
}
else
m_scroller.startScroll(x, y, m_cells[ccur].right - m_w, 0);
}
}
else
{
if (dx > 0)
{
if (ccur > 0)
{
int endx = m_cells[ccur - 1].right - m_w;
m_scroller.startScroll(x, y, endx - x, 0);
}
else
m_scroller.startScroll(x, y, -x, 0);
}
else
{
if (ccur < m_cells.length - 1)
{
int endx = cell.right;
m_scroller.startScroll(x, y, endx - x, 0);
}
else
m_scroller.startScroll(x, y, m_cells[ccur].right - m_w, 0);
}
}
return true;
}
ccur++;
}
return false;
}
More
11 years 1 month ago #8505 by nermeen
m_horz_dual is initialized during the open procedure...please check PDFReader.PDFOpen (case 6)...so it cannot be null...
More
11 years 1 month ago #8509 by alex.temp
Below is case 6, it passed null to initialize the m_horz_dual, should I change the null to something else to make it work? If yes, what it should be changed to? Thanks!
case 6:
{
PDFViewDual view = new PDFViewDual(this.getContext());
view.vSetLayoutPara(null, null, m_rtol);
m_view = view;
}
break;
More
11 years 1 month ago #8512 by nermeen
If you want to view your pages as a magazine (i.e. show first page as single and the rest as dual) then you can change Case 6 as:
Code:
case 6: { PDFViewDual view = new PDFViewDual(this.getContext()); boolean paras[] = new boolean[m_doc.GetPageCount()]; paras[0] = false; int cur = 1; while( cur < paras.length ) { paras[cur] = true; cur++; } view.vSetLayoutPara(null, paras, m_rtol); m_view = view; }
This way you wont have the exception,
If you want to keep the single page view, then you can remove the dependecy on m_horz_dual from the motionNormal method (as you wont be needing it)
More
11 years 1 month ago - 11 years 1 month ago #8513 by alex.temp
Thanks for your prompt reply! I removed the dependecy on m_horz_dual from the motionNormal method. It works only when the scale (value get from vGetScale()) is under around 1.7....
if it is zoomed larger than around 1.7, I could still change to the next page.
Please help.
Last edit: 11 years 1 month ago by alex.temp.
Time to create page: 0.424 seconds
Powered by Kunena Forum