-
-
Notifications
You must be signed in to change notification settings - Fork 78
Smooth scaling [3]: Enable smooth scaling #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| double fs = Math.sqrt(xfs * xfs + yfs * yfs); | ||
| if (Math.abs(1.0 - detector.getScaleFactor())<0.02) | ||
| consumed = false; | ||
| if (fs * 2< Math.abs(detector.getCurrentSpan() - detector.getPreviousSpan())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any idea why it was that way @gujjwal00 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is handling two separate issues:
- During scaling,
onScalecallback can be invoked by Android for very small amount of scaling factor. Returning false from these calls will cause them to accumulate. They are handled once they are large enough (± .02). This is whatconsumedis used for. This PR reduces the delta to ± .01 - Variables
inScaling,xInitialFocus,yInitialFocus,fsetc. and the check on line 68 are used to differentiate between 'Pinch' & 'Two-finger Swipe/Scroll'. For pinch gesture, focus shift (fs) would be less then the change in finger span (detector.getCurrentSpan() - detector.getPreviousSpan()). This PR removes this logic and lets Android differentiate between these gestures.
I think we can allow smooth scaling even if we want to keep the 2nd behavior. But there will always be edge cases because these two gestures can sometimes be ambiguous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, let me look more into this tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I was asking out of curiosity. If the new code works, I'm fine with it.
|
Root of the issue is that some two finger swipe gestures are interpreted as 'Pinch' & 'Scroll' both at the same time. Current scaling code tries to detect this and stops scaling if it thinks that gesture is 'Scroll' . That's why zooming is jerky. This PR removes that check from scaling code so that scaling is smoother for 'Pinch' gestures. On 'Scroll' side, we were triggering two-finger fling even if both fingers were moving in different directions. This PR adds a check to ignore such gestures so there should be less false-positive fling gestures (Arguably, this is more of a hack rather than a clean solution). IMO we can handle these gestures cleanly if we were to 'pan' on two-finger scroll but that's out of scope for this PR and I will defer that discussion to #58 . As for this PR, it is ready to merge. |
|
While scaling is super smooth now, this broke the two-finger fling gesture detection user for injecting cursor events LeftRightUpDown at https://github.com/bk138/multivnc/blob/master/android/app/src/main/java/com/coboltforge/dontmind/multivnc/VncCanvasActivity.java#L202 |
|
I have only made the detection more strict. Is it not working entirely for you? |
|
No two-finger fling at all anymore :-/ Using a Galaxy S7, Android 8.1. |
5d22bff to
df9331d
Compare
|
I'll have a look ASAP! Thanks! |
|
I tested with two other devices but it is working for me. I have removed changes related to fling detection from this PR. |
|
Still no luck: both two-finger fling and three-finger panning don't work with this branch, tested with a Galaxy S7 and a S10. Any idea where to tinker? |
|
Can you please try reverting commit df9331d ? Maybe Samsung has patched ScaleGestureDetector. |
df9331d to
a534835
Compare
|
Thanks for checking! I am guessing that
Can you please take a look? I have already taken too much of your time. |
|
This PR here now works much better in that fling gestures are now detected. However, I still get a minimal simultaneous scale as well, by ~ 10%. |
|
And smooth-scaling-alt works perfectly, at least for me 🎉 Do you want to change anything in that branch or is it ready to be merged? Thanks for the hard work, again! |
|
Glad to know its working! 🙂
Yeah, that is expected.
Let me just add few comments in the code. |
|
Closing in favor of #72 |
Related: #59
This PR removes the jerky behavior of scaling operation.