mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-19 00:04:56 +00:00
Merge branch 'popup_improvement' of https://github.com/karyogamy/NewPipe into size
This commit is contained in:
commit
989acce0a5
@ -92,6 +92,7 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
|||||||
public class PopupVideoPlayer extends Service {
|
public class PopupVideoPlayer extends Service {
|
||||||
private static final String TAG = ".PopupVideoPlayer";
|
private static final String TAG = ".PopupVideoPlayer";
|
||||||
private static final boolean DEBUG = BasePlayer.DEBUG;
|
private static final boolean DEBUG = BasePlayer.DEBUG;
|
||||||
|
private static final int SHUTDOWN_FLING_VELOCITY = 10000;
|
||||||
|
|
||||||
private static final int NOTIFICATION_ID = 40028922;
|
private static final int NOTIFICATION_ID = 40028922;
|
||||||
public static final String ACTION_CLOSE = "org.schabi.newpipe.player.PopupVideoPlayer.CLOSE";
|
public static final String ACTION_CLOSE = "org.schabi.newpipe.player.PopupVideoPlayer.CLOSE";
|
||||||
@ -303,7 +304,6 @@ public class PopupVideoPlayer extends Service {
|
|||||||
|
|
||||||
public void onVideoClose() {
|
public void onVideoClose() {
|
||||||
if (DEBUG) Log.d(TAG, "onVideoClose() called");
|
if (DEBUG) Log.d(TAG, "onVideoClose() called");
|
||||||
savePositionAndSize();
|
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,9 +574,7 @@ public class PopupVideoPlayer extends Service {
|
|||||||
private int initialPopupX, initialPopupY;
|
private int initialPopupX, initialPopupY;
|
||||||
private boolean isMoving;
|
private boolean isMoving;
|
||||||
|
|
||||||
private int onDownPopupWidth = 0;
|
|
||||||
private boolean isResizing;
|
private boolean isResizing;
|
||||||
private boolean isResizingRightSide;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDoubleTap(MotionEvent e) {
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
@ -603,27 +601,20 @@ public class PopupVideoPlayer extends Service {
|
|||||||
initialPopupY = windowLayoutParams.y;
|
initialPopupY = windowLayoutParams.y;
|
||||||
popupWidth = windowLayoutParams.width;
|
popupWidth = windowLayoutParams.width;
|
||||||
popupHeight = windowLayoutParams.height;
|
popupHeight = windowLayoutParams.height;
|
||||||
onDownPopupWidth = windowLayoutParams.width;
|
return super.onDown(e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress(MotionEvent e) {
|
public void onLongPress(MotionEvent e) {
|
||||||
if (DEBUG) Log.d(TAG, "onLongPress() called with: e = [" + e + "]");
|
if (DEBUG) Log.d(TAG, "onLongPress() called with: e = [" + e + "]");
|
||||||
playerImpl.showAndAnimateControl(-1, true);
|
updateScreenSize();
|
||||||
playerImpl.getLoadingPanel().setVisibility(View.GONE);
|
checkPositionBounds();
|
||||||
|
updatePopupSize((int) screenWidth, -1);
|
||||||
playerImpl.hideControls(0, 0);
|
|
||||||
animateView(playerImpl.getCurrentDisplaySeek(), false, 0, 0);
|
|
||||||
animateView(playerImpl.getResizingIndicator(), true, 200, 0);
|
|
||||||
|
|
||||||
isResizing = true;
|
|
||||||
isResizingRightSide = e.getRawX() > windowLayoutParams.x + (windowLayoutParams.width / 2f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||||
if (isResizing) return false;
|
if (isResizing) return super.onScroll(e1, e2, distanceX, distanceY);
|
||||||
|
|
||||||
if (playerImpl.getCurrentState() != BasePlayer.STATE_BUFFERING
|
if (playerImpl.getCurrentState() != BasePlayer.STATE_BUFFERING
|
||||||
&& (!isMoving || playerImpl.getControlsRoot().getAlpha() != 1f)) playerImpl.showControls(0);
|
&& (!isMoving || playerImpl.getControlsRoot().getAlpha() != 1f)) playerImpl.showControls(0);
|
||||||
@ -659,19 +650,33 @@ public class PopupVideoPlayer extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||||
|
if (Math.abs(velocityX) > SHUTDOWN_FLING_VELOCITY) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Popup close fling velocity= " + velocityX);
|
||||||
|
onVideoClose();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
gestureDetector.onTouchEvent(event);
|
gestureDetector.onTouchEvent(event);
|
||||||
if (event.getAction() == MotionEvent.ACTION_MOVE && isResizing && !isMoving) {
|
if (event.getPointerCount() == 2 && !isResizing) {
|
||||||
//if (DEBUG) Log.d(TAG, "onTouch() ACTION_MOVE > v = [" + v + "], e1.getRaw = [" + event.getRawX() + ", " + event.getRawY() + "]");
|
if (DEBUG) Log.d(TAG, "onTouch() 2 finger pointer detected, enabling resizing.");
|
||||||
int width;
|
playerImpl.showAndAnimateControl(-1, true);
|
||||||
if (isResizingRightSide) width = (int) event.getRawX() - windowLayoutParams.x;
|
playerImpl.getLoadingPanel().setVisibility(View.GONE);
|
||||||
else {
|
|
||||||
width = (int) (windowLayoutParams.width + (windowLayoutParams.x - event.getRawX()));
|
playerImpl.hideControls(0, 0);
|
||||||
if (width > minimumWidth) windowLayoutParams.x = initialPopupX - (width - onDownPopupWidth);
|
animateView(playerImpl.getCurrentDisplaySeek(), false, 0, 0);
|
||||||
}
|
animateView(playerImpl.getResizingIndicator(), true, 200, 0);
|
||||||
if (width <= maximumWidth && width >= minimumWidth) updatePopupSize(width, -1);
|
isResizing = true;
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_MOVE && !isMoving && isResizing) {
|
||||||
|
if (DEBUG) Log.d(TAG, "onTouch() ACTION_MOVE > v = [" + v + "], e1.getRaw = [" + event.getRawX() + ", " + event.getRawY() + "]");
|
||||||
|
return handleMultiDrag(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
@ -692,6 +697,29 @@ public class PopupVideoPlayer extends Service {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean handleMultiDrag(final MotionEvent event) {
|
||||||
|
if (event.getPointerCount() != 2) return false;
|
||||||
|
|
||||||
|
final float firstPointerX = event.getX(0);
|
||||||
|
final float secondPointerX = event.getX(1);
|
||||||
|
|
||||||
|
final float diff = Math.abs(firstPointerX - secondPointerX);
|
||||||
|
if (firstPointerX > secondPointerX) {
|
||||||
|
// second pointer is the anchor (the leftmost pointer)
|
||||||
|
windowLayoutParams.x = (int) (event.getRawX() - diff);
|
||||||
|
} else {
|
||||||
|
// first pointer is the anchor
|
||||||
|
windowLayoutParams.x = (int) event.getRawX();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkPositionBounds();
|
||||||
|
updateScreenSize();
|
||||||
|
|
||||||
|
final int width = (int) Math.min(screenWidth, diff);
|
||||||
|
updatePopupSize(width, -1);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user