1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-25 01:20:34 +00:00

changed popup resizing

This commit is contained in:
Harshal Lele 2020-02-11 11:07:16 +05:30 committed by Stypox
parent 6b47df75a7
commit 9487b5367d
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23

View File

@ -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,17 @@ 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
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; isResizing = true;
} }
@ -1224,6 +1244,10 @@ public final class PopupVideoPlayer extends Service {
if (isResizing) { if (isResizing) {
isResizing = false; isResizing = false;
initPointerDistance = -1;
initFirstPointerX = initFirstPointerY = initSecPointerX = initSecPointerY = -1;
animateView(playerImpl.getResizingIndicator(), false, 100, 0); animateView(playerImpl.getResizingIndicator(), false, 100, 0);
playerImpl.changeState(playerImpl.getCurrentState()); playerImpl.changeState(playerImpl.getCurrentState());
} }
@ -1242,27 +1266,54 @@ public final class PopupVideoPlayer extends Service {
return false; return false;
} }
final float firstPointerX = event.getX(0); if(initPointerDistance != -1){
final float secondPointerX = event.getX(1);
final float diff = Math.abs(firstPointerX - secondPointerX); //get the movements of the fingers
if (firstPointerX > secondPointerX) { float firstPointerMoveX = event.getX(0) - initFirstPointerX;
// second pointer is the anchor (the leftmost pointer) float firstPointerMoveY = event.getY(0) - initFirstPointerY;
popupLayoutParams.x = (int) (event.getRawX() - diff); float secPointerMoveX = event.getX(1) - initSecPointerX;
} else { float secPointerMoveY = event.getY(1) - initSecPointerY;
// first pointer is the anchor //minimum threshold beyond which pinch gesture will work
popupLayoutParams.x = (int) event.getRawX(); 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(); checkPopupPositionBounds();
updateScreenSize(); updateScreenSize();
final int width = (int) Math.min(screenWidth, diff); final int width = (int) Math.min(screenWidth, newWidth);
updatePopupSize(width, -1); updatePopupSize(width, -1);
return true; return true;
} }
}
return false;
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Utils // Utils
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/