Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit c3c4c74

Browse files
Fixes #2948 - Updated Volume control delegate to have a function where clients can handle action cancelled event. (#3500)
1 parent 002aad0 commit c3c4c74

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/views/VolumeControl.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import android.annotation.SuppressLint;
44
import android.content.Context;
55
import android.util.AttributeSet;
6+
import android.util.Log;
67
import android.view.MotionEvent;
8+
import android.view.View;
79
import android.widget.FrameLayout;
810
import android.widget.SeekBar;
911

@@ -38,18 +40,19 @@ public VolumeControl(Context context, AttributeSet attrs, int defStyleAttr, int
3840
initialize();
3941
}
4042

41-
public interface Delegate {
42-
void onVolumeChange(double aVolume);
43-
}
44-
4543
@SuppressLint("ClickableViewAccessibility")
4644
private void initialize() {
4745
inflate(getContext(), R.layout.volume_control, this);
4846
mSeekBar = findViewById(R.id.volumeSeekBar);
4947
mSeekBar.setProgress(100);
5048
mSeekBar.setOnSeekBarChangeListener(this);
5149
mSeekBar.setOnTouchListener((v, event) -> {
52-
if (event.getAction() == MotionEvent.ACTION_UP) {
50+
51+
if ((event.getAction() == MotionEvent.ACTION_UP) || (event.getAction() == MotionEvent.ACTION_CANCEL)) {
52+
if ((event.getAction() == MotionEvent.ACTION_CANCEL) && (mDelegate != null)) {
53+
mDelegate.onSeekBarActionCancelled();
54+
}
55+
5356
return true;
5457
}
5558
return false;
@@ -60,7 +63,6 @@ public void setDelegate(Delegate aDelegate) {
6063
mDelegate = aDelegate;
6164
}
6265

63-
6466
public void setVolume(double aVolume) {
6567
mVolume = aVolume;
6668
if (!mTouching) {
@@ -101,4 +103,10 @@ public void onStartTrackingTouch(SeekBar seekBar) {
101103
public void onStopTrackingTouch(SeekBar seekBar) {
102104
mTouching = false;
103105
}
106+
107+
public interface Delegate {
108+
void onVolumeChange(double aVolume);
109+
110+
void onSeekBarActionCancelled();
111+
}
104112
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/MediaControlsWidget.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,23 @@ public void onSeekPreview(String aText, double aRatio) {
200200
}
201201
});
202202

203-
mVolumeControl.setDelegate(v -> {
204-
mMedia.setVolume(v);
205-
if (mMedia.isMuted()) {
206-
mMedia.setMuted(false);
203+
204+
mVolumeControl.setDelegate(new VolumeControl.Delegate() {
205+
206+
@Override
207+
public void onVolumeChange(double aVolume) {
208+
mMedia.setVolume(aVolume);
209+
if (mMedia.isMuted()) {
210+
mMedia.setMuted(false);
211+
}
212+
mVolumeControl.requestFocusFromTouch();
213+
}
214+
215+
@Override
216+
public void onSeekBarActionCancelled() {
217+
mHideVolumeSlider = true;
218+
startVolumeCtrlHandler();
207219
}
208-
mVolumeControl.requestFocusFromTouch();
209220
});
210221

211222

0 commit comments

Comments
 (0)