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

Commit

Permalink
Clear projection menu selection if there isn't one selected (#2500)
Browse files Browse the repository at this point in the history
* Clear projection menu selection if there isn't one selected

* Unset video projection when exiting immersive Video mode

Co-authored-by: Manuel Martin <imanol.martin@gmail.com>
  • Loading branch information
MortimerGoro and keianhzo committed Jan 3, 2020
1 parent e6f4dda commit f2713d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.mozilla.vrbrowser.ui.widgets.menus.VideoProjectionMenuWidget.VIDEO_PROJECTION_NONE;

public class NavigationBarWidget extends UIWidget implements GeckoSession.NavigationDelegate,
GeckoSession.ProgressDelegate, GeckoSession.ContentDelegate, WidgetManagerDelegate.WorldClickListener,
WidgetManagerDelegate.UpdateListener, SessionChangeListener,
Expand Down Expand Up @@ -102,7 +104,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private BrightnessMenuWidget mBrightnessWidget;
private MediaControlsWidget mMediaControlsWidget;
private Media mFullScreenMedia;
private @VideoProjectionMenuWidget.VideoProjectionFlags Integer mAutoSelectedProjection;
private @VideoProjectionMenuWidget.VideoProjectionFlags int mAutoSelectedProjection = VIDEO_PROJECTION_NONE;
private HamburgerMenuWidget mHamburgerMenu;
private SendTabDialogWidget mSendTabDialog;
private TooltipWidget mPopUpNotification;
Expand Down Expand Up @@ -252,7 +254,7 @@ private void initialize(@NonNull Context aContext) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}

if (mAutoSelectedProjection != null) {
if (mAutoSelectedProjection != VIDEO_PROJECTION_NONE) {
enterVRVideo(mAutoSelectedProjection);
return;
}
Expand Down Expand Up @@ -698,6 +700,7 @@ private void exitVRVideo() {
boolean composited = mProjectionMenu.getPlacement().composited;
mProjectionMenu.getPlacement().copyFrom(mProjectionMenuPlacement);
mProjectionMenu.getPlacement().composited = composited;
mProjectionMenu.setSelectedProjection(VIDEO_PROJECTION_NONE);
mWidgetManager.updateWidget(mProjectionMenu);
closeFloatingMenus();
mWidgetManager.setControllersVisible(true);
Expand Down Expand Up @@ -870,11 +873,14 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {
}
AtomicBoolean autoEnter = new AtomicBoolean(false);
mAutoSelectedProjection = VideoProjectionMenuWidget.getAutomaticProjection(getSession().getCurrentUri(), autoEnter);
if (mAutoSelectedProjection != null && autoEnter.get()) {
if (mAutoSelectedProjection != VIDEO_PROJECTION_NONE && autoEnter.get()) {
mAutoEnteredVRVideo = true;
postDelayed(() -> enterVRVideo(mAutoSelectedProjection), 300);
} else {
mAutoEnteredVRVideo = false;
if (mProjectionMenu != null) {
mProjectionMenu.setSelectedProjection(mAutoSelectedProjection);
}
}
} else {
if (mIsInVRVideo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

public class VideoProjectionMenuWidget extends MenuWidget implements WidgetManagerDelegate.FocusChangeListener {

@IntDef(value = { VIDEO_PROJECTION_UNSUPPORTED, VIDEO_PROJECTION_3D_SIDE_BY_SIDE, VIDEO_PROJECTION_360,
@IntDef(value = { VIDEO_PROJECTION_NONE, 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_NONE = -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 @@ -128,27 +128,28 @@ private void handleClick(@VideoProjectionFlags int aVideoProjection) {

public void setSelectedProjection(@VideoProjectionFlags int aProjection) {
mSelectedProjection = aProjection;
IntStream.range(0, mItems.size())
int index = IntStream.range(0, mItems.size())
.filter(i -> ((ProjectionMenuItem)mItems.get(i)).projection == aProjection)
.findFirst()
.ifPresent(this::setSelectedItem);
.orElse(-1);
setSelectedItem(index);
}

public static @VideoProjectionFlags Integer getAutomaticProjection(String aURL, AtomicBoolean autoEnter) {
public static @VideoProjectionFlags int getAutomaticProjection(String aURL, AtomicBoolean autoEnter) {
if (aURL == null) {
return null;
return VIDEO_PROJECTION_NONE;
}

Uri uri = Uri.parse(aURL);
if (uri == null) {
return null;
return VIDEO_PROJECTION_NONE;
}

String projection = uri.getQueryParameter("mozVideoProjection");
if (projection == null) {
projection = uri.getQueryParameter("mozvideoprojection");
if (projection == null) {
return null;
return VIDEO_PROJECTION_NONE;
}
}
projection = projection.toLowerCase();
Expand All @@ -169,7 +170,7 @@ public void setSelectedProjection(@VideoProjectionFlags int aProjection) {
return VIDEO_PROJECTION_3D_SIDE_BY_SIDE;
}

return VIDEO_PROJECTION_UNSUPPORTED;
return VIDEO_PROJECTION_NONE;
}

@Override
Expand Down

0 comments on commit f2713d8

Please sign in to comment.