Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2948 - Updated Volume control delegate to have a function wher… #3500

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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();
}
}
Original file line number Diff line number Diff line change
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