diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java index 2e289f2ff..4886c0606 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java @@ -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, @@ -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; @@ -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; } @@ -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); @@ -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) { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/menus/VideoProjectionMenuWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/menus/VideoProjectionMenuWidget.java index 859c31d89..ab2091c99 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/menus/VideoProjectionMenuWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/menus/VideoProjectionMenuWidget.java @@ -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; @@ -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(); @@ -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