mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 01:20:34 +00:00
Merge pull request #3075 from harshlele/better-popup-resizing
Better popup resizing with pinch gestures
This commit is contained in:
commit
feab633e60
@ -41,6 +41,7 @@ import android.view.GestureDetector;
|
|||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.AnticipateInterpolator;
|
import android.view.animation.AnticipateInterpolator;
|
||||||
@ -1010,6 +1011,14 @@ public final class PopupVideoPlayer extends Service {
|
|||||||
private boolean isMoving;
|
private boolean isMoving;
|
||||||
private boolean isResizing;
|
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
|
@Override
|
||||||
public boolean onDoubleTap(final MotionEvent e) {
|
public boolean onDoubleTap(final MotionEvent e) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -1201,6 +1210,16 @@ public final class PopupVideoPlayer extends Service {
|
|||||||
playerImpl.hideControls(0, 0);
|
playerImpl.hideControls(0, 0);
|
||||||
animateView(playerImpl.getCurrentDisplaySeek(), false, 0, 0);
|
animateView(playerImpl.getCurrentDisplaySeek(), false, 0, 0);
|
||||||
animateView(playerImpl.getResizingIndicator(), true, 200, 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
|
||||||
|
initPointerDistance = Math.hypot(initFirstPointerX - initSecPointerX,
|
||||||
|
initFirstPointerY - initSecPointerY);
|
||||||
|
|
||||||
isResizing = true;
|
isResizing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1224,6 +1243,13 @@ public final class PopupVideoPlayer extends Service {
|
|||||||
|
|
||||||
if (isResizing) {
|
if (isResizing) {
|
||||||
isResizing = false;
|
isResizing = false;
|
||||||
|
|
||||||
|
initPointerDistance = -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());
|
||||||
}
|
}
|
||||||
@ -1238,30 +1264,36 @@ 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);
|
||||||
|
|
||||||
final float firstPointerX = event.getX(0);
|
// minimum threshold beyond which pinch gesture will work
|
||||||
final float secondPointerX = event.getX(1);
|
int minimumMove = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop();
|
||||||
|
|
||||||
final float diff = Math.abs(firstPointerX - secondPointerX);
|
if (Math.max(firstPointerMove, secPointerMove) > minimumMove) {
|
||||||
if (firstPointerX > secondPointerX) {
|
// calculate current distance between the pointers
|
||||||
// second pointer is the anchor (the leftmost pointer)
|
double currentPointerDistance =
|
||||||
popupLayoutParams.x = (int) (event.getRawX() - diff);
|
Math.hypot(event.getX(0) - event.getX(1),
|
||||||
} else {
|
event.getY(0) - event.getY(1));
|
||||||
// first pointer is the anchor
|
|
||||||
popupLayoutParams.x = (int) event.getRawX();
|
// 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();
|
checkPopupPositionBounds();
|
||||||
updateScreenSize();
|
updateScreenSize();
|
||||||
|
|
||||||
final int width = (int) Math.min(screenWidth, diff);
|
updatePopupSize((int) Math.min(screenWidth, newWidth), -1);
|
||||||
updatePopupSize(width, -1);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Utils
|
// Utils
|
||||||
|
Loading…
Reference in New Issue
Block a user