From f2ae7a28366acca4557eeb87849c3ee26fecf05c Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Wed, 18 Dec 2019 16:40:48 +0100 Subject: [PATCH 1/2] Clear projection menu selection if there isn't one selected --- .../ui/widgets/NavigationBarWidget.java | 11 ++++++++--- .../menus/VideoProjectionMenuWidget.java | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) 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 743526735..e35c315ef 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; } @@ -872,11 +874,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 From 4ca742e110cd65cdd00c75f48d2614e04e92b0a4 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Fri, 3 Jan 2020 13:17:39 +0100 Subject: [PATCH 2/2] Unset video projection when exiting immersive Video mode --- .../org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java | 1 + 1 file changed, 1 insertion(+) 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 e35c315ef..75d4d2024 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 @@ -702,6 +702,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);