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
1 changed files with 23 additions and 36 deletions

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;
}
if (initPointerDistance != -1) {
// get the movements of the fingers // get the movements of the fingers
float firstPointerMoveX = event.getX(0) - initFirstPointerX; double firstPointerMove = Math.hypot(event.getX(0) - initFirstPointerX,
float firstPointerMoveY = event.getY(0) - initFirstPointerY; event.getY(0) - initFirstPointerY);
float secPointerMoveX = event.getX(1) - initSecPointerX; double secPointerMove = Math.hypot(event.getX(1) - initSecPointerX,
float secPointerMoveY = event.getY(1) - initSecPointerY; event.getY(1) - initSecPointerY);
// minimum threshold beyond which pinch gesture will work // minimum threshold beyond which pinch gesture will work
int scaledTouchSlop = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop(); int minimumMove = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop();
if (firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop
|| secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) {
double newWidth = popupWidth;
if (Math.max(firstPointerMove, secPointerMove) > minimumMove) {
// calculate current distance between the pointers // calculate current distance between the pointers
double currentPointerDistance = Math.hypot(event.getX(0) - event.getX(1), double currentPointerDistance =
Math.hypot(event.getX(0) - event.getX(1),
event.getY(0) - event.getY(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 // change co-ordinates of popup so the center stays at the same position
popupLayoutParams.x += (popupWidth - newWidth)/2; 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;
} }