From 9487b5367d4f3cf1a78ffca34ca9024ef55c8f71 Mon Sep 17 00:00:00 2001 From: Harshal Lele Date: Tue, 11 Feb 2020 11:07:16 +0530 Subject: [PATCH 1/4] changed popup resizing --- .../newpipe/player/PopupVideoPlayer.java | 85 +++++++++++++++---- 1 file changed, 68 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 008aaaf9b..0cb1fe6c9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -41,6 +41,7 @@ import android.view.GestureDetector; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.WindowManager; import android.view.animation.AnticipateInterpolator; @@ -1010,6 +1011,14 @@ public final class PopupVideoPlayer extends Service { private boolean isMoving; private boolean isResizing; + //initial co-ordinates and distance between fingers + private double initPointerDistance = -1; + private float initFirstPointerX = -1; + private float initFirstPointerY = -1; + private float initSecPointerX = -1; + private float initSecPointerY = -1; + + @Override public boolean onDoubleTap(final MotionEvent e) { if (DEBUG) { @@ -1201,6 +1210,17 @@ public final class PopupVideoPlayer extends Service { playerImpl.hideControls(0, 0); animateView(playerImpl.getCurrentDisplaySeek(), false, 0, 0); animateView(playerImpl.getResizingIndicator(), true, 200, 0); + + //record co-ordinates of fingers + initFirstPointerX = event.getX(0); + initFirstPointerY = event.getY(0); + initSecPointerX = event.getX(1); + initSecPointerY = event.getY(1); + //record distance between fingers + float xDiff = event.getX(0) - event.getX(1); + float yDiff = event.getY(0) - event.getY(1); + initPointerDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff); + isResizing = true; } @@ -1224,6 +1244,10 @@ public final class PopupVideoPlayer extends Service { if (isResizing) { isResizing = false; + + initPointerDistance = -1; + initFirstPointerX = initFirstPointerY = initSecPointerX = initSecPointerY = -1; + animateView(playerImpl.getResizingIndicator(), false, 100, 0); playerImpl.changeState(playerImpl.getCurrentState()); } @@ -1242,25 +1266,52 @@ public final class PopupVideoPlayer extends Service { return false; } - final float firstPointerX = event.getX(0); - final float secondPointerX = event.getX(1); + if(initPointerDistance != -1){ + + //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 + float currentXDiff = event.getX(0) - event.getX(1); + float currentYDiff = event.getY(0) - event.getY(1); + double currentPointerDistance = Math.sqrt(currentXDiff * currentXDiff + currentYDiff * currentYDiff); + + //scale popup width + double scale = 1 + (currentPointerDistance - initPointerDistance)/ initPointerDistance; + + newWidth = (popupWidth * scale); + + //change co-ordinates of popup so the center stays at the same position + if(currentPointerDistance > initPointerDistance){ + popupLayoutParams.x -= (newWidth - popupWidth)/2; + } + else{ + popupLayoutParams.x += (popupWidth - newWidth)/2; + } + + initPointerDistance = currentPointerDistance; + + checkPopupPositionBounds(); + updateScreenSize(); + + final int width = (int) Math.min(screenWidth, newWidth); + updatePopupSize(width, -1); + + return true; + } - final float diff = Math.abs(firstPointerX - secondPointerX); - if (firstPointerX > secondPointerX) { - // second pointer is the anchor (the leftmost pointer) - popupLayoutParams.x = (int) (event.getRawX() - diff); - } else { - // first pointer is the anchor - popupLayoutParams.x = (int) event.getRawX(); } - - checkPopupPositionBounds(); - updateScreenSize(); - - final int width = (int) Math.min(screenWidth, diff); - updatePopupSize(width, -1); - - return true; + return false; } /*////////////////////////////////////////////////////////////////////////// From fe1889653e98b7fb55d24b03f9d4903e26b82278 Mon Sep 17 00:00:00 2001 From: Harshal Lele Date: Sun, 8 Mar 2020 12:10:06 +0530 Subject: [PATCH 2/4] made formatting changes --- .../newpipe/player/PopupVideoPlayer.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 0cb1fe6c9..e46aa94d6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -1217,9 +1217,8 @@ public final class PopupVideoPlayer extends Service { initSecPointerX = event.getX(1); initSecPointerY = event.getY(1); //record distance between fingers - float xDiff = event.getX(0) - event.getX(1); - float yDiff = event.getY(0) - event.getY(1); - initPointerDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff); + initPointerDistance = Math.hypot(event.getX(0) - event.getX(1), + event.getY(0) - event.getY(1)); isResizing = true; } @@ -1277,27 +1276,22 @@ public final class PopupVideoPlayer extends Service { int scaledTouchSlop = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop(); if(firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop || - secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop){ + secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) { double newWidth = popupWidth; //calculate current distance between the pointers - 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)); //scale popup width - double scale = 1 + (currentPointerDistance - initPointerDistance)/ initPointerDistance; + double scale = currentPointerDistance / initPointerDistance; newWidth = (popupWidth * scale); //change co-ordinates of popup so the center stays at the same position - if(currentPointerDistance > initPointerDistance){ - popupLayoutParams.x -= (newWidth - popupWidth)/2; - } - else{ - popupLayoutParams.x += (popupWidth - newWidth)/2; - } + popupLayoutParams.x += (popupWidth - newWidth)/2; + initPointerDistance = currentPointerDistance; From 46918ee9079f22e19b32f119fb6d454043f4efcc Mon Sep 17 00:00:00 2001 From: Harshal Lele Date: Mon, 9 Mar 2020 23:26:35 +0530 Subject: [PATCH 3/4] formatting changes --- .../java/org/schabi/newpipe/player/PopupVideoPlayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index e46aa94d6..71e0feac8 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -1265,7 +1265,7 @@ public final class PopupVideoPlayer extends Service { return false; } - if(initPointerDistance != -1){ + if (initPointerDistance != -1) { //get the movements of the fingers float firstPointerMoveX = event.getX(0) - initFirstPointerX; @@ -1275,8 +1275,8 @@ public final class PopupVideoPlayer extends Service { //minimum threshold beyond which pinch gesture will work int scaledTouchSlop = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop(); - if(firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop || - secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) { + if (firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop + || secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop) { double newWidth = popupWidth; From a50e430cd96ae508a66755678f21b318d00127f8 Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 10 Apr 2020 22:12:45 +0200 Subject: [PATCH 4/4] Fix checkstyle issues and improve code formatting Also calculate differently the moved distance of a pointer: use euclidean and not manhattan geometry --- .../newpipe/player/PopupVideoPlayer.java | 59 ++++++++----------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 71e0feac8..de9e9b746 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -1217,8 +1217,8 @@ public final class PopupVideoPlayer extends Service { initSecPointerX = event.getX(1); initSecPointerY = event.getY(1); //record distance between fingers - initPointerDistance = Math.hypot(event.getX(0) - event.getX(1), - event.getY(0) - event.getY(1)); + initPointerDistance = Math.hypot(initFirstPointerX - initSecPointerX, + initFirstPointerY - initSecPointerY); isResizing = true; } @@ -1245,7 +1245,10 @@ public final class PopupVideoPlayer extends Service { isResizing = false; initPointerDistance = -1; - initFirstPointerX = initFirstPointerY = initSecPointerX = initSecPointerY = -1; + initFirstPointerX = -1; + initFirstPointerY = -1; + initSecPointerX = -1; + initSecPointerY = -1; animateView(playerImpl.getResizingIndicator(), false, 100, 0); playerImpl.changeState(playerImpl.getCurrentState()); @@ -1261,49 +1264,33 @@ public final class PopupVideoPlayer extends Service { } private boolean handleMultiDrag(final MotionEvent event) { - if (event.getPointerCount() != 2) { - return false; - } + if (initPointerDistance != -1 && event.getPointerCount() == 2) { + // 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) { - - //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; + // minimum threshold beyond which pinch gesture will work + int minimumMove = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop(); + 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; + popupLayoutParams.x += (popupWidth - newWidth) / 2; checkPopupPositionBounds(); updateScreenSize(); - final int width = (int) Math.min(screenWidth, newWidth); - updatePopupSize(width, -1); - + updatePopupSize((int) Math.min(screenWidth, newWidth), -1); return true; } - } return false; }