1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-16 13:50:49 +01:00

Fix checkstyle issues and improve code formatting

Also calculate differently the moved distance of a pointer: use euclidean and not manhattan geometry
This commit is contained in:
Stypox 2020-04-10 22:12:45 +02:00
parent 46918ee907
commit a50e430cd9
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23

View File

@ -1217,8 +1217,8 @@ public final class PopupVideoPlayer extends Service {
initSecPointerX = event.getX(1); initSecPointerX = event.getX(1);
initSecPointerY = event.getY(1); initSecPointerY = event.getY(1);
//record distance between fingers //record distance between fingers
initPointerDistance = Math.hypot(event.getX(0) - event.getX(1), initPointerDistance = Math.hypot(initFirstPointerX - initSecPointerX,
event.getY(0) - event.getY(1)); initFirstPointerY - initSecPointerY);
isResizing = true; isResizing = true;
} }
@ -1245,7 +1245,10 @@ public final class PopupVideoPlayer extends Service {
isResizing = false; isResizing = false;
initPointerDistance = -1; initPointerDistance = -1;
initFirstPointerX = initFirstPointerY = initSecPointerX = initSecPointerY = -1; initFirstPointerX = -1;
initFirstPointerY = -1;
initSecPointerX = -1;
initSecPointerY = -1;
animateView(playerImpl.getResizingIndicator(), false, 100, 0); animateView(playerImpl.getResizingIndicator(), false, 100, 0);
playerImpl.changeState(playerImpl.getCurrentState()); playerImpl.changeState(playerImpl.getCurrentState());
@ -1261,49 +1264,33 @@ public final class PopupVideoPlayer extends Service {
} }
private boolean handleMultiDrag(final MotionEvent event) { private boolean handleMultiDrag(final MotionEvent event) {
if (event.getPointerCount() != 2) { if (initPointerDistance != -1 && event.getPointerCount() == 2) {
return false; // get the movements of the fingers
} double firstPointerMove = Math.hypot(event.getX(0) - initFirstPointerX,
event.getY(0) - initFirstPointerY);
double secPointerMove = Math.hypot(event.getX(1) - initSecPointerX,
event.getY(1) - initSecPointerY);
if (initPointerDistance != -1) { // minimum threshold beyond which pinch gesture will work
int minimumMove = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop();
//get the movements of the fingers
float firstPointerMoveX = event.getX(0) - initFirstPointerX;
float firstPointerMoveY = event.getY(0) - initFirstPointerY;
float secPointerMoveX = event.getX(1) - initSecPointerX;
float secPointerMoveY = event.getY(1) - initSecPointerY;
//minimum threshold beyond which pinch gesture will work
int scaledTouchSlop = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop();
if (firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop
|| secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) {
double newWidth = popupWidth;
//calculate current distance between the pointers
double currentPointerDistance = Math.hypot(event.getX(0) - event.getX(1),
event.getY(0) - event.getY(1));
//scale popup width
double scale = currentPointerDistance / initPointerDistance;
newWidth = (popupWidth * scale);
//change co-ordinates of popup so the center stays at the same position
popupLayoutParams.x += (popupWidth - newWidth)/2;
if (Math.max(firstPointerMove, secPointerMove) > minimumMove) {
// calculate current distance between the pointers
double currentPointerDistance =
Math.hypot(event.getX(0) - event.getX(1),
event.getY(0) - event.getY(1));
// change co-ordinates of popup so the center stays at the same position
double newWidth = (popupWidth * currentPointerDistance / initPointerDistance);
initPointerDistance = currentPointerDistance; initPointerDistance = currentPointerDistance;
popupLayoutParams.x += (popupWidth - newWidth) / 2;
checkPopupPositionBounds(); checkPopupPositionBounds();
updateScreenSize(); updateScreenSize();
final int width = (int) Math.min(screenWidth, newWidth); updatePopupSize((int) Math.min(screenWidth, newWidth), -1);
updatePopupSize(width, -1);
return true; return true;
} }
} }
return false; return false;
} }