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

Commit

Permalink
Dismiss the projection menu when clicking on any other media button (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and MortimerGoro committed Nov 25, 2019
1 parent 45078e7 commit 986bf58
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ private void initialize(Context aContext) {
} else {
mMedia.play();
}

mMediaPlayButton.requestFocusFromTouch();
});

mMediaSeekBackButton.setOnClickListener(v -> {
mMedia.seek(Math.max(0, mMedia.getCurrentTime() - 10.0f));

mMediaSeekBackButton.requestFocusFromTouch();
});

mMediaSeekForwardButton.setOnClickListener(v -> {
Expand All @@ -98,6 +100,7 @@ private void initialize(Context aContext) {
t = Math.min(mMedia.getDuration(), t);
}
mMedia.seek(t);
mMediaSeekForwardButton.requestFocusFromTouch();
});

mMediaProjectionButton.setOnClickListener(v -> {
Expand All @@ -111,7 +114,12 @@ private void initialize(Context aContext) {
placement.rotationAxisY = 1.0f;
placement.rotation = (float) Math.toRadians(-7);
}
mProjectionMenu.getPlacement().visible = !mProjectionMenu.getPlacement().visible;
if (mProjectionMenu.isVisible()) {
mProjectionMenu.hide(KEEP_WIDGET);

} else {
mProjectionMenu.show(REQUEST_FOCUS);
}
mWidgetManager.updateWidget(mProjectionMenu);
});

Expand All @@ -122,13 +130,14 @@ private void initialize(Context aContext) {
mMedia.setMuted(true);
mVolumeControl.setVolume(0);
}
mMediaVolumeButton.requestFocusFromTouch();
});

mMediaBackButton.setOnClickListener(v -> {
if (mBackHandler != null) {
mBackHandler.run();
}

mMediaBackButton.requestFocusFromTouch();
});

mSeekBar.setDelegate(new MediaSeekBar.Delegate() {
Expand All @@ -137,6 +146,7 @@ public void onSeekDragStart() {
mPlayOnSeekEnd = mMedia.isPlaying();
mMediaSeekLabel.setVisibility(View.VISIBLE);
mMedia.pause();
mSeekBar.requestFocusFromTouch();
}

@Override
Expand Down Expand Up @@ -180,6 +190,7 @@ public void onSeekPreview(String aText, double aRatio) {
if (mMedia.isMuted()) {
mMedia.setMuted(false);
}
mVolumeControl.requestFocusFromTouch();
});

this.setOnHoverListener((v, event) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@

import android.content.Context;
import android.net.Uri;
import android.view.View;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.IntStream;

public class VideoProjectionMenuWidget extends MenuWidget {
public class VideoProjectionMenuWidget extends MenuWidget implements WidgetManagerDelegate.FocusChangeListener {

@IntDef(value = { VIDEO_PROJECTION_3D_SIDE_BY_SIDE, VIDEO_PROJECTION_360,
@IntDef(value = { VIDEO_PROJECTION_UNSUPPORTED, VIDEO_PROJECTION_3D_SIDE_BY_SIDE, VIDEO_PROJECTION_360,
VIDEO_PROJECTION_360_STEREO, VIDEO_PROJECTION_180,
VIDEO_PROJECTION_180_STEREO_LEFT_RIGHT, VIDEO_PROJECTION_180_STEREO_TOP_BOTTOM })
public @interface VideoProjectionFlags {}

public static final int VIDEO_PROJECTION_UNSUPPORTED = -1;
public static final int VIDEO_PROJECTION_3D_SIDE_BY_SIDE = 0;
public static final int VIDEO_PROJECTION_360 = 1;
public static final int VIDEO_PROJECTION_360_STEREO = 2;
Expand Down Expand Up @@ -61,6 +65,20 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.translationZ = 2.0f;
}

@Override
public void show(@ShowFlags int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.addFocusChangeListener(VideoProjectionMenuWidget.this);
}

@Override
public void hide(@HideFlags int aHideFlags) {
super.hide(aHideFlags);

mWidgetManager.removeFocusChangeListener(this);
}

public void setParentWidget(UIWidget aParent) {
mWidgetPlacement.parentHandle = aParent.getHandle();
}
Expand Down Expand Up @@ -151,6 +169,14 @@ public void setSelectedProjection(@VideoProjectionFlags int aProjection) {
return VIDEO_PROJECTION_3D_SIDE_BY_SIDE;
}

return -1;
return VIDEO_PROJECTION_UNSUPPORTED;
}

@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
if (!ViewUtils.isEqualOrChildrenOf(this, newFocus) && isVisible()) {
onDismiss();
}
}

}

0 comments on commit 986bf58

Please sign in to comment.