Skip to content

Commit

Permalink
Fixes #2948 - Updated Volume control delegate to have a function wher…
Browse files Browse the repository at this point in the history
…e clients can handle action cancelled event. (#3500)
  • Loading branch information
daron-walters committed Jun 15, 2020
1 parent 002aad0 commit c3c4c74
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Expand Up @@ -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;

Expand Down Expand Up @@ -38,18 +40,19 @@ 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);
mSeekBar = findViewById(R.id.volumeSeekBar);
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;
Expand All @@ -60,7 +63,6 @@ public void setDelegate(Delegate aDelegate) {
mDelegate = aDelegate;
}


public void setVolume(double aVolume) {
mVolume = aVolume;
if (!mTouching) {
Expand Down Expand Up @@ -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();
}
}
Expand Up @@ -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();
});


Expand Down

0 comments on commit c3c4c74

Please sign in to comment.