Knowledge Base - How to avoid page change during navigation if page is zoomed? (Deprecated)

Note: this class is deprecated

This article illustrate how to prevent the page navigation (
horizontal scroll) while the page is zoomed with the rendering mode set as double page.
Here you can find a class that extends
PDFViewDual class, it also supports RTOL:

@Deprecated
public class PDFViewDualExt extends PDFViewDual { protected boolean isRTL = false; Context context; public PDFViewDualExt(Context context, boolean isRTL) { super(context); this.context = context; this.isRTL = isRTL; } @Override protected boolean motionNormal(MotionEvent event) { super.motionNormal(event); try { switch (event.getActionMasked()) { case MotionEvent.ACTION_MOVE: if (m_status == STA_MOVING) { int x = m_scroller.getFinalX(); if (x + m_w > m_docw) x = m_docw - m_w; if (vGetScale() > vGetMinScale()) { try { if (Global.def_view == 6 && m_w > m_h && isLandscape()) { //dual page if (isRTL) { if ((m_pageno - 2 >= 0) && (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 { 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 (isRTL) { if ((m_pageno - 1) >= 0 && (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); } else { 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; m_scroller.setFinalX(x); if (m_listener != null) m_listener.OnPDFInvalidate(false); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (m_status == STA_MOVING) { int x = m_scroller.getFinalX(); if (x + m_w > m_docw) x = m_docw - m_w; if (vGetScale() > vGetMinScale()) { try { if (Global.def_view == 6 && m_w > m_h && isLandscape()) { //dual page if (isRTL) { if ((m_pageno - 2 >= 0) && (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 { 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 (isRTL) { if ((m_pageno - 1 >= 0) && (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); } else { 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; m_scroller.setFinalX(x); m_status = STA_NONE; vOnMoveEnd(x, m_scroller.getFinalY()); if (m_listener != null) m_listener.OnPDFInvalidate(false); } break; } } catch (Exception e) { e.printStackTrace(); } return true; } public boolean isLandscape() { return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; } @Override protected boolean vOnFling(float dx, float dy, float velocityX, float velocityY) { if (vGetScale() > vGetMinScale()) return true; return super.vOnFling(dx, dy, velocityX, velocityY); } /** * This override is to prevent scroller from stopping between two pages while searching */ @Override protected void vFindGoto() { if (m_pages == null) return; int pg = m_finder.find_get_page(); if (pg < 0 || pg >= m_doc.GetPageCount()) return; float pos[] = m_finder.find_get_pos(); if (pos == null) return; pos[0] = m_pages[pg].ToDIBX(pos[0]) + m_pages[pg].GetX(); pos[1] = m_pages[pg].ToDIBY(pos[1]) + m_pages[pg].GetY(); pos[2] = m_pages[pg].ToDIBX(pos[2]) + m_pages[pg].GetX(); pos[3] = m_pages[pg].ToDIBY(pos[3]) + m_pages[pg].GetY(); float x = m_scroller.getCurrX(); float y = m_scroller.getCurrY(); if (x > pos[0] - m_w / 8) x = pos[0] - m_w / 8; if (x < pos[2] - m_w * 7 / 8) x = pos[2] - m_w * 7 / 8; if (y > pos[1] - m_h / 8) y = pos[1] - m_h / 8; if (y < pos[3] - m_h * 7 / 8) y = pos[3] - m_h * 7 / 8; if (x > m_docw - m_w) x = m_docw - m_w; if (x < 0) x = 0; if (y > m_doch - m_h) y = m_doch - m_h; if (y < 0) y = 0; m_scroller.forceFinished(true); m_scroller.setFinalX((int) x); m_scroller.setFinalY((int) y); if (m_listener != null) m_listener.OnPDFInvalidate(false); /*center page after search*/ if (vGetScale() <= vGetMinScale()) { vCenterPage(pg); } } }

Applies To

RadaeePDF SDK for Android

Related Articles

Limit horizontal page change when a page is zoomed

Details

Created : 2015-02-10 15:31:14, Last Modified : 2017-05-12 09:43:20