vSetX/vSetY don't work unless flinging first - 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: vSetX/vSetY don't work unless flinging first

vSetX/vSetY don't work unless flinging first 4 months 2 weeks ago #13943

  • arlomedia
  • arlomedia's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 43
  • Thank you received: 1
My app has several ways to programmatically scroll through documents, such as page up/down hotspots placed over the document. These call PDFSetX/PDFSetY methods that I've added to PDFLayoutView, which in turn call vSetPos in PDFLayout, which calls vSetX/vSetY in PDFLayout. vSetX/vSetY calls m_scroller.setFinalX/setFinalY.

However, on my Pixel C tablet running Android 8.1, setFinalX/setFinalY doesn't do anything unless the document has previously been flung, which calls PDFLayout.vFling. I think this is because the fling method sets a velocity in the scroller, which can be used by later calls to setFinalX/setFinalY. If setFinalX/setFinalY are called without flinging, the velocity is 0 and nothing happens.

I have replaced setFinalX/setFinalY with this code in my PDFLayout:

int startX = vGetX();
int startY = vGetY();
int distanceX = Math.round(x - startX);
int distanceY = 0;
m_scroller.startScroll(startX, startY, distanceX, distanceY);

int startX = vGetX();
int startY = vGetY();
int distanceX = 0;
int distanceY = Math.round(y - startY);
m_scroller.startScroll(startX, startY, distanceX, distanceY);

This is working for me. But maybe there is a better way to do it? And maybe you should make this change in a future release of PDFLayout?

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

vSetX/vSetY don't work unless flinging first 4 months 2 weeks ago #13951

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
Thanks for the feedback, we will evaluate it and if necessary we will add it.

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

vSetX/vSetY don't work unless flinging first 2 months 2 weeks ago #14071

  • arlomedia
  • arlomedia's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 43
  • Thank you received: 1
Another place you will see this problem is if you pinch-zoom the document. If you pinch-zoom without flinging first, the document will zoom from the top left corner, rather than from the middle of the zoom location. You can see this in the Radaee PDF Viewer app.

Unfortunately, I found that my fix posted above creates a new problem: calling vSetY immediately after vSetX aborts the x movement. So when zooming the document, the left position doesn't move, and when panning the document (1 finger drag) it will only pan in the y direction. So I made a new vSetXY method that combines the x and y movement into a single m_scroller.startScroll action. This solves both the zooming and panning problems for me.

You might find a more direct solution that doesn't require combining the vSetX and vSetY function calls into a single function call. But I need this approach in my code because I also added an animated movement option, by using the optional fifth argument of m_scroller.startScroll. So I'm now using this instead of vSetX and vSetY:
public void vSetXY(int x, int y, boolean animated) {
    if (x > m_tw - m_w) x = m_tw - m_w;
    if (x < 0) x = 0;
    if (y > m_th - m_h) y = m_th - m_h;
    if (y < 0) y = 0;
    int duration = (animated) ? 250 : 0 ;
    lastX = x; // this lets us get the new x while the scroll is still animating
    lastY = y; // this lets us get the new y while the scroll is still animating
    int startX = vGetX();
    int startY = vGetY();
    int distanceX = Math.round(x - startX);
    int distanceY = Math.round(y - startY);
    m_scroller.forceFinished(true);
    m_scroller.startScroll(startX, startY, distanceX, distanceY, duration);
}

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

vSetX/vSetY don't work unless flinging first 2 months 1 week ago #14093

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 846
  • Karma: 43
  • Thank you received: 12
it because, you have not invalidate the view.
here is codes in onTouchNone method of PDFLayoutView class:
case MotionEvent.ACTION_MOVE:
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;

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

vSetX/vSetY don't work unless flinging first 2 months 1 week ago #14094

  • arlomedia
  • arlomedia's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 43
  • Thank you received: 1
The PDFSetX/PDFSetY methods I added to PDFLayoutView do call invalidate() after calling vSetPos().

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

  • Page:
  • 1
Powered by Kunena Forum