mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-19 16:24:57 +00:00
Use current volume as the start value in the volume gesture
- Renamed some variables/classes to increase readability
This commit is contained in:
parent
9883a38698
commit
6e75d41956
@ -460,7 +460,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
public void initListeners() {
|
public void initListeners() {
|
||||||
super.initListeners();
|
super.initListeners();
|
||||||
|
|
||||||
MySimpleOnGestureListener listener = new MySimpleOnGestureListener();
|
PlayerGestureListener listener = new PlayerGestureListener();
|
||||||
gestureDetector = new GestureDetector(context, listener);
|
gestureDetector = new GestureDetector(context, listener);
|
||||||
gestureDetector.setIsLongpressEnabled(false);
|
gestureDetector.setIsLongpressEnabled(false);
|
||||||
getRootView().setOnTouchListener(listener);
|
getRootView().setOnTouchListener(listener);
|
||||||
@ -489,6 +489,8 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
|
|
||||||
volumeProgressBar.setMax(maxGestureLength);
|
volumeProgressBar.setMax(maxGestureLength);
|
||||||
brightnessProgressBar.setMax(maxGestureLength);
|
brightnessProgressBar.setMax(maxGestureLength);
|
||||||
|
|
||||||
|
setInitialGestureValues();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -799,6 +801,13 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
// Utils
|
// Utils
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
private void setInitialGestureValues() {
|
||||||
|
if (getAudioReactor() != null) {
|
||||||
|
final float currentVolumeNormalized = (float) getAudioReactor().getVolume() / getAudioReactor().getMaxVolume();
|
||||||
|
volumeProgressBar.setProgress((int) (volumeProgressBar.getMax() * currentVolumeNormalized));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showControlsThenHide() {
|
public void showControlsThenHide() {
|
||||||
if (queueVisible) return;
|
if (queueVisible) return;
|
||||||
@ -939,7 +948,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MySimpleOnGestureListener extends GestureDetector.SimpleOnGestureListener implements View.OnTouchListener {
|
private class PlayerGestureListener extends GestureDetector.SimpleOnGestureListener implements View.OnTouchListener {
|
||||||
private boolean isMoving;
|
private boolean isMoving;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -978,31 +987,30 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
return super.onDown(e);
|
return super.onDown(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean isPlayerGestureEnabled = PlayerHelper.isPlayerGestureEnabled(getApplicationContext());
|
private static final int MOVEMENT_THRESHOLD = 40;
|
||||||
|
|
||||||
|
private final boolean isPlayerGestureEnabled = PlayerHelper.isPlayerGestureEnabled(getApplicationContext());
|
||||||
private final int maxVolume = playerImpl.getAudioReactor().getMaxVolume();
|
private final int maxVolume = playerImpl.getAudioReactor().getMaxVolume();
|
||||||
|
|
||||||
private final int MOVEMENT_THRESHOLD = 40;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
public boolean onScroll(MotionEvent initialEvent, MotionEvent movingEvent, float distanceX, float distanceY) {
|
||||||
if (!isPlayerGestureEnabled) return false;
|
if (!isPlayerGestureEnabled) return false;
|
||||||
|
|
||||||
//noinspection PointlessBooleanExpression
|
//noinspection PointlessBooleanExpression
|
||||||
if (DEBUG && false) Log.d(TAG, "MainVideoPlayer.onScroll = " +
|
if (DEBUG && false) Log.d(TAG, "MainVideoPlayer.onScroll = " +
|
||||||
", e1.getRaw = [" + e1.getRawX() + ", " + e1.getRawY() + "]" +
|
", e1.getRaw = [" + initialEvent.getRawX() + ", " + initialEvent.getRawY() + "]" +
|
||||||
", e2.getRaw = [" + e2.getRawX() + ", " + e2.getRawY() + "]" +
|
", e2.getRaw = [" + movingEvent.getRawX() + ", " + movingEvent.getRawY() + "]" +
|
||||||
", distanceXy = [" + distanceX + ", " + distanceY + "]");
|
", distanceXy = [" + distanceX + ", " + distanceY + "]");
|
||||||
|
|
||||||
if (!isMoving && (
|
final boolean insideThreshold = Math.abs(movingEvent.getY() - initialEvent.getY()) <= MOVEMENT_THRESHOLD;
|
||||||
Math.abs(e2.getY() - e1.getY()) <= MOVEMENT_THRESHOLD
|
if (!isMoving && (insideThreshold || Math.abs(distanceX) > Math.abs(distanceY))
|
||||||
|| Math.abs(distanceX) > Math.abs(distanceY)
|
|| playerImpl.getCurrentState() == BasePlayer.STATE_COMPLETED) {
|
||||||
) || playerImpl.getCurrentState() == BasePlayer.STATE_COMPLETED)
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
isMoving = true;
|
isMoving = true;
|
||||||
|
|
||||||
if (e1.getX() > playerImpl.getRootView().getWidth() / 2) {
|
if (initialEvent.getX() > playerImpl.getRootView().getWidth() / 2) {
|
||||||
playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY);
|
playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY);
|
||||||
float currentProgressPercent =
|
float currentProgressPercent =
|
||||||
(float) playerImpl.getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength();
|
(float) playerImpl.getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength();
|
||||||
|
Loading…
Reference in New Issue
Block a user