-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Better popup resizing with pinch gestures #3075
Conversation
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.
Thank you for this useful contribution!
checkPopupPositionBounds(); | ||
updateScreenSize(); | ||
if(firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop || | ||
secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop){ |
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.
secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop){ | |
secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) { |
double currentPointerDistance = Math.sqrt(currentXDiff * currentXDiff + currentYDiff * currentYDiff); | ||
|
||
//scale popup width | ||
double scale = 1 + (currentPointerDistance - initPointerDistance)/ initPointerDistance; |
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.
This is algebraically equal to:
double scale = 1 + (currentPointerDistance - initPointerDistance)/ initPointerDistance; | |
double scale = currentPointerDistance / initPointerDistance; |
app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java
Outdated
Show resolved
Hide resolved
float currentXDiff = event.getX(0) - event.getX(1); | ||
float currentYDiff = event.getY(0) - event.getY(1); | ||
double currentPointerDistance = Math.sqrt(currentXDiff * currentXDiff + currentYDiff * currentYDiff); |
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.
There is the Java Math.hypot() function that does exactly this
float currentXDiff = event.getX(0) - event.getX(1); | |
float currentYDiff = event.getY(0) - event.getY(1); | |
double currentPointerDistance = Math.sqrt(currentXDiff * currentXDiff + currentYDiff * currentYDiff); | |
double currentPointerDistance = Math.hypot(event.getX(0) - event.getX(1), event.getY(0) - event.getY(1)); |
} | ||
else{ |
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.
} | |
else{ | |
} else { |
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.
Thank you, almost ready ;-)
When you are finished implementing these suggestions, could you provide another test apk, so that I can test on the latest changes? Thanks
if(firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop || | ||
secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) { |
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.
if(firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop || | |
secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) { | |
if (firstPointerMoveX > scaledTouchSlop || firstPointerMoveY > scaledTouchSlop | |
|| secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) { |
@@ -1082,25 +1105,47 @@ public boolean onTouch(View v, MotionEvent event) { | |||
private boolean handleMultiDrag(final MotionEvent event) { | |||
if (event.getPointerCount() != 2) return false; | |||
|
|||
final float firstPointerX = event.getX(0); | |||
final float secondPointerX = event.getX(1); | |||
if(initPointerDistance != -1){ |
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.
if(initPointerDistance != -1){ | |
if (initPointerDistance != -1) { |
I do prefer this behavior, but it seems that expanding isn't as smooth as it was with the weird "wherever your finger is" resize. When i drag the popup box to the right side of the screen and expand, it remains the same size until I'm finished resizing it, (or for about that amount of time anyway...), but it moves the box over to the left. For 4:3 video, you can see the black bars coming off the sides (why they need to be there at all for popup mode, i don't know, but it's an indicator that resizing is laggy) |
@harshlele There is a little glitch during popup scaling, in practice animation doesn't correctly follow the fingers movements |
Except this all working well. |
@Hubcapp @Oizaro im not sure how to solve that problem. i tried a few things but its always a bit stuttery. |
@Stypox is there like a linting test for the coding style so all these small coding style mistakes could be caught before I commit? APK: |
@harshlele running Android Studio code refactoring on the files you changed should do the trick |
I tested this once again and could not find problems. I can't reproduce the issue pointed out by @Oizaro, but even if the bug exists I don't think it is really a big problem, compared to how clunky popup resizing is now. |
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.
A few style issues, but this is ready :-D
//scale popup width | ||
double scale = currentPointerDistance / initPointerDistance; | ||
|
||
newWidth = (popupWidth * scale); |
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.
Remove the double newWidth = popupWidth;
declaration above and put it directly here:
newWidth = (popupWidth * scale); | |
double newWidth = popupWidth * scale; |
|
||
//change co-ordinates of popup so the center stays at the same position | ||
popupLayoutParams.x += (popupWidth - newWidth)/2; | ||
|
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.
Also remove some of these spaces and group similar/related statements toghether, to enhance readability
Also calculate differently the moved distance of a pointer: use euclidean and not manhattan geometry
2e59ed9
to
a50e430
Compare
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.
Thank you again for fixing this long-lasting issue! I pushed the style fixes myself, since they were very little changes, so this is now ready to be merged. I tested on Android 7.1, Android 4.4 and Android 10
The current popup window does resize with pinch gestures, but it's a bit weird. It resizes to the distance between the 2 fingers, and changes its position to one of the fingers. I changed it so that the window size scales to the pinch-in/out gesture and stays in the same position.
Fixes #515 fixes #2880 fixes #2918
APK:
app-debug.zip