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

Commit

Permalink
The volume slider from immersive mode remains displayed even after mo…
Browse files Browse the repository at this point in the history
…ving the pointer away - #2948

Fixes #2948 Updated change per Manuel that removed widget wide hover code for volume slider and moved it to volume button and slider respectively.  Fixes #2948
  • Loading branch information
daron-walters committed Apr 21, 2020
1 parent 58ba8ea commit d7cda4e
Showing 1 changed file with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import org.mozilla.telemetry.schedule.jobscheduler.TelemetryJobService;
import org.mozilla.vrbrowser.R;
import org.mozilla.geckoview.MediaElement;
import org.mozilla.vrbrowser.browser.Media;
Expand All @@ -22,6 +24,7 @@
import org.mozilla.vrbrowser.ui.views.VolumeControl;
import org.mozilla.vrbrowser.ui.widgets.menus.VideoProjectionMenuWidget;


public class MediaControlsWidget extends UIWidget implements MediaElement.Delegate {

private Media mMedia;
Expand All @@ -42,6 +45,10 @@ public class MediaControlsWidget extends UIWidget implements MediaElement.Delega
private boolean mPlayOnSeekEnd;
private Rect mOffsetViewBounds;
private VideoProjectionMenuWidget mProjectionMenu;
static long VOLUME_SLIDER_CHECK_DELAY = 1000;
private Handler mVolumeCtrlHandler = new Handler();
private boolean mHideVolumeSlider = false;
private Runnable mVolumeCtrlRunnable;

public MediaControlsWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -75,7 +82,12 @@ private void initialize(Context aContext) {
mMutedIcon = aContext.getDrawable(R.drawable.ic_icon_media_volume_muted);
mVolumeIcon = aContext.getDrawable(R.drawable.ic_icon_media_volume);
mOffsetViewBounds = new Rect();

mVolumeCtrlRunnable = () -> {
if ((mHideVolumeSlider) && (mVolumeControl.getVisibility() == View.VISIBLE)) {
mVolumeControl.setVisibility(View.INVISIBLE);
stopVolumeCtrlHandler();
}
};
mMediaPlayButton.setOnClickListener(v -> {
if (mMedia.isEnded()) {
mMedia.seek(0);
Expand Down Expand Up @@ -179,8 +191,8 @@ public void onSeekPreview(String aText, double aRatio) {
childView.getDrawingRect(mOffsetViewBounds);
MediaControlsWidget.this.offsetDescendantRectToMyCoords(childView, mOffsetViewBounds);

FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)mMediaSeekLabel.getLayoutParams();
params.setMarginStart(mOffsetViewBounds.left + (int)(aRatio * mOffsetViewBounds.width()) - mMediaSeekLabel.getMeasuredWidth() / 2);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mMediaSeekLabel.getLayoutParams();
params.setMarginStart(mOffsetViewBounds.left + (int) (aRatio * mOffsetViewBounds.width()) - mMediaSeekLabel.getMeasuredWidth() / 2);
mMediaSeekLabel.setLayoutParams(params);
}
});
Expand All @@ -193,36 +205,38 @@ public void onSeekPreview(String aText, double aRatio) {
mVolumeControl.requestFocusFromTouch();
});

this.setOnHoverListener((v, event) -> {
if (mMedia == null) {
return false;
}
if (event.getAction() == MotionEvent.ACTION_HOVER_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
float threshold = (float)MediaControlsWidget.this.getMeasuredWidth() * 0.65f;
boolean isVisible = mVolumeControl.getVisibility() == View.VISIBLE;
boolean makeVisible = event.getX() >= threshold;
if (isVisible != makeVisible) {
mVolumeControl.setVisibility(makeVisible ? View.VISIBLE : View.GONE);
}
} else if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT && !mMediaVolumeButton.isHovered() && this.isInTouchMode()) {
mVolumeControl.setVisibility(View.INVISIBLE);
}
return false;
});

mMediaVolumeButton.setOnHoverListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
float startY = v.getY();
float maxY = startY + v.getHeight();
//for this we only hide on the left side of volume button or outside y area of button
if ((event.getX() <= 0) || (!(event.getY() > startY && event.getY() < maxY))) {
mHideVolumeSlider = true;
startVolumeCtrlHandler();

} else {
mVolumeControl.setVisibility(View.VISIBLE);
mHideVolumeSlider = false;
stopVolumeCtrlHandler();
}
return false;
});

mMediaProjectionButton.setOnHoverListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
mVolumeControl.setVisibility(View.INVISIBLE);
mVolumeControl.setOnHoverListener((v, event) -> {
float startY = 0;
float maxY = startY + v.getHeight();
if ((event.getX() > 0 && event.getX() < v.getWidth()) && (event.getY() > startY && event.getY() < maxY)) {
mHideVolumeSlider = false;
stopVolumeCtrlHandler();
}
//for this we only hide on the right side of volume button or outside y area of button
else if ((event.getX() < 0) || (event.getX() >= v.getWidth()) || (!(event.getY() > startY && event.getY() < maxY))) {
mHideVolumeSlider = true;
startVolumeCtrlHandler();
}
return false;
});

}

@Override
Expand Down Expand Up @@ -322,7 +336,7 @@ public void onMetadataChange(MediaElement mediaElement, MediaElement.Metadata me
@Override
public void onLoadProgress(MediaElement mediaElement, MediaElement.LoadProgressInfo progressInfo) {
if (progressInfo.buffered != null) {
mSeekBar.setBuffered(progressInfo.buffered[progressInfo.buffered.length -1].end);
mSeekBar.setBuffered(progressInfo.buffered[progressInfo.buffered.length - 1].end);
}
}

Expand Down Expand Up @@ -353,4 +367,13 @@ public void onFullscreenChange(MediaElement mediaElement, boolean fullscreen) {
public void onError(MediaElement mediaElement, int code) {
}

private void startVolumeCtrlHandler() {
mVolumeCtrlHandler.postDelayed(mVolumeCtrlRunnable, VOLUME_SLIDER_CHECK_DELAY);
}

public void stopVolumeCtrlHandler() {
mVolumeCtrlHandler.removeCallbacks(mVolumeCtrlRunnable);
}


}

0 comments on commit d7cda4e

Please sign in to comment.