diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/VolumeControl.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/VolumeControl.java index 04b277907..ac8b3ad9f 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/VolumeControl.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/VolumeControl.java @@ -3,7 +3,9 @@ import android.annotation.SuppressLint; import android.content.Context; import android.util.AttributeSet; +import android.util.Log; import android.view.MotionEvent; +import android.view.View; import android.widget.FrameLayout; import android.widget.SeekBar; @@ -38,10 +40,6 @@ public VolumeControl(Context context, AttributeSet attrs, int defStyleAttr, int initialize(); } - public interface Delegate { - void onVolumeChange(double aVolume); - } - @SuppressLint("ClickableViewAccessibility") private void initialize() { inflate(getContext(), R.layout.volume_control, this); @@ -49,7 +47,12 @@ private void initialize() { mSeekBar.setProgress(100); mSeekBar.setOnSeekBarChangeListener(this); mSeekBar.setOnTouchListener((v, event) -> { - if (event.getAction() == MotionEvent.ACTION_UP) { + + if ((event.getAction() == MotionEvent.ACTION_UP) || (event.getAction() == MotionEvent.ACTION_CANCEL)) { + if ((event.getAction() == MotionEvent.ACTION_CANCEL) && (mDelegate != null)) { + mDelegate.onSeekBarActionCancelled(); + } + return true; } return false; @@ -60,7 +63,6 @@ public void setDelegate(Delegate aDelegate) { mDelegate = aDelegate; } - public void setVolume(double aVolume) { mVolume = aVolume; if (!mTouching) { @@ -101,4 +103,10 @@ public void onStartTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) { mTouching = false; } + + public interface Delegate { + void onVolumeChange(double aVolume); + + void onSeekBarActionCancelled(); + } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/MediaControlsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/MediaControlsWidget.java index af0e78c31..2d22dff17 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/MediaControlsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/MediaControlsWidget.java @@ -200,12 +200,23 @@ public void onSeekPreview(String aText, double aRatio) { } }); - mVolumeControl.setDelegate(v -> { - mMedia.setVolume(v); - if (mMedia.isMuted()) { - mMedia.setMuted(false); + + mVolumeControl.setDelegate(new VolumeControl.Delegate() { + + @Override + public void onVolumeChange(double aVolume) { + mMedia.setVolume(aVolume); + if (mMedia.isMuted()) { + mMedia.setMuted(false); + } + mVolumeControl.requestFocusFromTouch(); + } + + @Override + public void onSeekBarActionCancelled() { + mHideVolumeSlider = true; + startVolumeCtrlHandler(); } - mVolumeControl.requestFocusFromTouch(); });