diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 83d3a5e3bb..44df81062b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -45,8 +45,7 @@ import org.mozilla.vrbrowser.telemetry.TelemetryWrapper; import org.mozilla.vrbrowser.ui.OffscreenDisplay; import org.mozilla.vrbrowser.ui.widgets.BookmarkListener; -import org.mozilla.vrbrowser.ui.widgets.BookmarksWidget; -import org.mozilla.vrbrowser.ui.widgets.BrowserWidget; +import org.mozilla.vrbrowser.ui.views.BookmarksView; import org.mozilla.vrbrowser.ui.widgets.KeyboardWidget; import org.mozilla.vrbrowser.ui.widgets.NavigationBarWidget; import org.mozilla.vrbrowser.ui.widgets.RootWidget; @@ -58,11 +57,11 @@ import org.mozilla.vrbrowser.ui.widgets.Widget; import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement; +import org.mozilla.vrbrowser.ui.widgets.WindowWidget; import org.mozilla.vrbrowser.ui.widgets.dialogs.CrashDialogWidget; import java.io.IOException; import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; @@ -112,14 +111,14 @@ public void run() { SwipeRunnable mLastRunnable; Handler mHandler = new Handler(); Runnable mAudioUpdateRunnable; - BrowserWidget mBrowserWidget; + WindowWidget mWindowWidget; RootWidget mRootWidget; KeyboardWidget mKeyboard; NavigationBarWidget mNavigationBar; CrashDialogWidget mCrashDialog; TopBarWidget mTopBar; TrayWidget mTray; - BookmarksWidget mBookmarksWidget; + BookmarksView mBookmarksView; PermissionDelegate mPermissionDelegate; LinkedList mWidgetUpdateListeners; LinkedList mPermissionListeners; @@ -131,7 +130,6 @@ public void run() { private LinkedList> mBrightnessQueue; private Pair mCurrentBrightness; private SearchEngineWrapper mSearchEngineWrapper; - private ArrayList mResizableWidgets; @Override protected void onCreate(Bundle savedInstanceState) { @@ -163,8 +161,6 @@ protected void onCreate(Bundle savedInstanceState) { mBrightnessQueue = new LinkedList<>(); mCurrentBrightness = Pair.create(null, 1.0f); - mResizableWidgets = new ArrayList<>(); - mWidgets = new HashMap<>(); mWidgetContainer = new FrameLayout(this); mWidgetContainer.getViewTreeObserver().addOnGlobalFocusChangeListener((oldFocus, newFocus) -> { @@ -198,30 +194,30 @@ protected void onCreate(Bundle savedInstanceState) { } protected void initializeWorld() { + // Bookmarks panel + mBookmarksView = new BookmarksView(this); + // Create browser widget if (SessionStore.get().getCurrentSession() == null) { int id = SessionStore.get().createSession(); SessionStore.get().setCurrentSession(id); } int currentSession = SessionStore.get().getCurrentSessionId(); - mBrowserWidget = new BrowserWidget(this, currentSession); - mPermissionDelegate.setParentWidgetHandle(mBrowserWidget.getHandle()); - - // Bookmarks panel - mBookmarksWidget = new BookmarksWidget(this); + mWindowWidget = new WindowWidget(this, currentSession); + mWindowWidget.setBookmarksView(mBookmarksView); + mPermissionDelegate.setParentWidgetHandle(mWindowWidget.getHandle()); // Create Browser navigation widget mNavigationBar = new NavigationBarWidget(this); - mNavigationBar.setBrowserWidget(mBrowserWidget); - mNavigationBar.setBookmarksWidget(mBookmarksWidget); + mNavigationBar.setBrowserWidget(mWindowWidget); // Create keyboard widget mKeyboard = new KeyboardWidget(this); - mKeyboard.setBrowserWidget(mBrowserWidget); + mKeyboard.setBrowserWidget(mWindowWidget); // Create the top bar mTopBar = new TopBarWidget(this); - mTopBar.setBrowserWidget(mBrowserWidget); + mTopBar.setBrowserWidget(mWindowWidget); // Empty widget just for handling focus on empty space mRootWidget = new RootWidget(this); @@ -235,12 +231,10 @@ protected void initializeWorld() { mTray = new TrayWidget(this); // Add widget listeners - mTray.addListeners(new TrayListener[]{mNavigationBar, mBookmarksWidget}); - mBookmarksWidget.addListeners(new BookmarkListener[]{mBrowserWidget, mNavigationBar, mTray}); - - mResizableWidgets.addAll(Arrays.asList(mBrowserWidget, mBookmarksWidget)); + mTray.addListeners(new TrayListener[]{mWindowWidget, mNavigationBar}); + mBookmarksView.addListeners(new BookmarkListener[]{mWindowWidget, mNavigationBar, mTray}); - addWidgets(Arrays.asList(mRootWidget, mBrowserWidget, mNavigationBar, mKeyboard, mTray, mBookmarksWidget)); + addWidgets(Arrays.asList(mRootWidget, mWindowWidget, mNavigationBar, mKeyboard, mTray)); } @Override @@ -296,7 +290,7 @@ protected void onDestroy() { // Remove all widget listeners mTray.removeAllListeners(); - mBookmarksWidget.removeAllListeners(); + mBookmarksView.removeAllListeners(); SessionStore.get().unregisterListeners(); super.onDestroy(); @@ -492,8 +486,8 @@ void handleMotionEvent(final int aHandle, final int aDevice, final boolean aPres Widget widget = mWidgets.get(aHandle); if (widget == null) { MotionEventGenerator.dispatch(mRootWidget, aDevice, aPressed, aX, aY); - } else if (widget == mBrowserWidget && mBrowserWidget.getBorderWidth() > 0) { - final int border = mBrowserWidget.getBorderWidth(); + } else if (widget == mWindowWidget && mWindowWidget.getBorderWidth() > 0) { + final int border = mWindowWidget.getBorderWidth(); MotionEventGenerator.dispatch(widget, aDevice, aPressed, aX - border, aY - border); } else { MotionEventGenerator.dispatch(widget, aDevice, aPressed, aX, aY); @@ -566,7 +560,7 @@ void handleAudioPose(float qx, float qy, float qz, float qw, float px, float py, @SuppressWarnings("unused") void handleResize(final int aHandle, final float aWorldWidth, final float aWorldHeight) { runOnUiThread(() -> { - mResizableWidgets.forEach(widget -> widget.handleResizeEvent(aWorldWidth, aWorldHeight)); + mWindowWidget.handleResizeEvent(aWorldWidth, aWorldHeight); }); } @@ -581,9 +575,9 @@ class PauseCompositorRunnable implements Runnable { @Override public void run() { synchronized (VRBrowserActivity.this) { - if (mBrowserWidget != null) { + if (mWindowWidget != null) { Log.d(LOGTAG, "About to pause Compositor"); - mBrowserWidget.pauseCompositor(); + mWindowWidget.pauseCompositor(); Log.d(LOGTAG, "Compositor Paused"); } done = true; @@ -624,8 +618,8 @@ void resumeGeckoViewCompositor() { TelemetryWrapper.uploadImmersiveToHistogram(); Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(() -> { - if (mBrowserWidget != null) { - mBrowserWidget.resumeCompositor(); + if (mWindowWidget != null) { + mWindowWidget.resumeCompositor(); Log.d(LOGTAG, "Compositor Resumed"); } }, 20); @@ -912,7 +906,7 @@ public void setControllersVisible(final boolean aVisible) { @Override public void setWindowSize(float targetWidth, float targetHeight) { - mBrowserWidget.resizeByMultiplier(targetWidth / targetHeight, 1.0f); + mWindowWidget.resizeByMultiplier(targetWidth / targetHeight, 1.0f); } @Override diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BookmarksWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/BookmarksView.java similarity index 62% rename from app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BookmarksWidget.java rename to app/src/common/shared/org/mozilla/vrbrowser/ui/views/BookmarksView.java index 016a953c34..165f54a89a 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BookmarksWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/BookmarksView.java @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mozilla.vrbrowser.ui.widgets; +package org.mozilla.vrbrowser.ui.views; import android.app.Activity; import android.app.Application; @@ -11,6 +11,8 @@ import android.os.Bundle; import android.util.AttributeSet; import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; import org.mozilla.geckoview.AllowOrDeny; import org.mozilla.geckoview.GeckoResult; @@ -19,12 +21,12 @@ import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.audio.AudioEngine; import org.mozilla.vrbrowser.browser.SessionStore; -import org.mozilla.vrbrowser.browser.SettingsStore; import org.mozilla.vrbrowser.databinding.BookmarksBinding; import org.mozilla.vrbrowser.db.entity.BookmarkEntity; import org.mozilla.vrbrowser.model.Bookmark; -import org.mozilla.vrbrowser.ui.callbacks.BookmarkClickCallback; import org.mozilla.vrbrowser.ui.adapters.BookmarkAdapter; +import org.mozilla.vrbrowser.ui.callbacks.BookmarkClickCallback; +import org.mozilla.vrbrowser.ui.widgets.BookmarkListener; import org.mozilla.vrbrowser.viewmodel.BookmarkListViewModel; import java.util.ArrayList; @@ -39,9 +41,8 @@ import static org.mozilla.gecko.GeckoAppShell.getApplicationContext; - -public class BookmarksWidget extends UIWidget implements Application.ActivityLifecycleCallbacks, - TrayListener, GeckoSession.NavigationDelegate { +public class BookmarksView extends FrameLayout implements Application.ActivityLifecycleCallbacks, + GeckoSession.NavigationDelegate { private static final String ABOUT_BLANK = "about:blank"; @@ -50,20 +51,18 @@ public class BookmarksWidget extends UIWidget implements Application.ActivityLif private BookmarkListViewModel mBookmarkListModel; private List mBookmarkListeners; private AudioEngine mAudio; - private int mSessionId; - private int mPreviousSessionId; - public BookmarksWidget(Context aContext) { + public BookmarksView(Context aContext) { super(aContext); initialize(aContext); } - public BookmarksWidget(Context aContext, AttributeSet aAttrs) { + public BookmarksView(Context aContext, AttributeSet aAttrs) { super(aContext, aAttrs); initialize(aContext); } - public BookmarksWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) { + public BookmarksView(Context aContext, AttributeSet aAttrs, int aDefStyle) { super(aContext, aAttrs, aDefStyle); initialize(aContext); } @@ -87,20 +86,7 @@ private void initialize(Context aContext) { mBookmarkListModel = new BookmarkListViewModel(((Application)getApplicationContext())); subscribeUi(mBookmarkListModel.getBookmarks()); - handleResizeEvent(SettingsStore.getInstance(getContext()).getBrowserWorldWidth(), - SettingsStore.getInstance(getContext()).getBrowserWorldHeight()); - } - - @Override - public void resizeByMultiplier(float aspect, float multiplier) { - float worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width); - float worldHeight = worldWidth / aspect; - float area = worldWidth * worldHeight * multiplier; - - float targetWidth = (float) Math.sqrt(area * aspect); - float targetHeight = (float) Math.sqrt(area / aspect); - - handleResizeEvent(targetWidth, targetHeight); + setVisibility(GONE); } public void addListeners(BookmarkListener... listeners) { @@ -119,16 +105,6 @@ private void notifyBookmarksHidden() { mBookmarkListeners.forEach(bookmarkListener -> bookmarkListener.onBookmarksHidden()); } - @Override - public void releaseWidget() { - ((Application)getApplicationContext()).unregisterActivityLifecycleCallbacks(this); - SessionStore.get().removeNavigationListener(this); - - unstackSession(); - - super.releaseWidget(); - } - private final BookmarkClickCallback mBookmarkClickCallback = new BookmarkClickCallback() { @Override public void onClick(Bookmark bookmark) { @@ -136,7 +112,7 @@ public void onClick(Bookmark bookmark) { mAudio.playSound(AudioEngine.Sound.CLICK); } - loadAndHide(bookmark.getUrl()); + SessionStore.get().loadUri(bookmark.getUrl()); } @Override @@ -149,19 +125,6 @@ public void onDelete(Bookmark bookmark) { } }; - @Override - protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { - Context context = getContext(); - aPlacement.visible = false; - aPlacement.worldWidth = WidgetPlacement.floatDimension(context, R.dimen.window_world_width); - aPlacement.width = SettingsStore.getInstance(getContext()).getWindowWidth(); - aPlacement.height = SettingsStore.getInstance(getContext()).getWindowHeight(); - aPlacement.anchorX = 0.5f; - aPlacement.anchorY = 0.0f; - aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.window_world_y); - aPlacement.translationZ = WidgetPlacement.unitFromMeters(context, R.dimen.bookmarks_world_z); - } - private void subscribeUi(LiveData> liveData) { // Update the list when the data changes liveData.observeForever(mBookmarkListObserver); @@ -196,53 +159,14 @@ public void onChanged(List bookmarkEntities) { }; @Override - public void show() { - super.show(); + public void setVisibility(int visibility) { + super.setVisibility(visibility); - mPreviousSessionId = SessionStore.get().getCurrentSessionId(); - if (SessionStore.get().isCurrentSessionPrivate()) { - mSessionId = SessionStore.get().createSession(true); + if (visibility == VISIBLE) { + notifyBookmarksShown(); } else { - mSessionId = SessionStore.get().createSession(); - } - SessionStore.get().stackSession(mSessionId); - - notifyBookmarksShown(); - - mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS); - } - - public void loadAndHide(String aURL) { - SessionStore.get().loadUri(aURL); - - hide(UIWidget.REMOVE_WIDGET); - } - - @Override - public void hide(@HideFlags int aHideFlags) { - super.hide(aHideFlags); - - notifyBookmarksHidden(); - - mWidgetManager.popWorldBrightness(this); - } - - @Override - protected void onDismiss() { - super.onDismiss(); - - unstackSession(); - } - - private void unstackSession() { - if (SessionStore.get().getCurrentSessionId() == mSessionId) { - if (SessionStore.get().canGoBack()) { - SessionStore.get().goBack(); - - } else if (SessionStore.get().canUnstackSession()) { - SessionStore.get().unstackSession(); - } + notifyBookmarksHidden(); } } @@ -283,29 +207,14 @@ public void onActivityDestroyed(Activity activity) { } - // TrayListener - - @Override - public void onBookmarksClicked() { - if (isVisible()) { - onDismiss(); - super.hide(UIWidget.REMOVE_WIDGET); - - } else { - show(); - } - } - // NavigationDelegate @Override public void onLocationChange(GeckoSession session, String url) { - int sessionId = SessionStore.get().getSessionId(session); - if ((mWidgetPlacement.visible && + if (getVisibility() == View.VISIBLE && url != null && - !url.equals(ABOUT_BLANK)) || - sessionId == mPreviousSessionId) { - hide(UIWidget.REMOVE_WIDGET); + !url.equals(ABOUT_BLANK)) { + notifyBookmarksHidden(); } } 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 c053bce0be..978c5f7cfa 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 @@ -19,18 +19,18 @@ import org.mozilla.geckoview.GeckoResult; import org.mozilla.geckoview.GeckoSession; import org.mozilla.geckoview.WebRequestError; -import org.mozilla.vrbrowser.*; +import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.audio.AudioEngine; import org.mozilla.vrbrowser.browser.Media; import org.mozilla.vrbrowser.browser.SessionStore; import org.mozilla.vrbrowser.browser.SettingsStore; import org.mozilla.vrbrowser.search.SearchEngineWrapper; -import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget; -import org.mozilla.vrbrowser.utils.AnimationHelper; import org.mozilla.vrbrowser.ui.views.CustomUIButton; import org.mozilla.vrbrowser.ui.views.NavigationURLBar; import org.mozilla.vrbrowser.ui.views.UIButton; import org.mozilla.vrbrowser.ui.views.UITextButton; +import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget; +import org.mozilla.vrbrowser.utils.AnimationHelper; import org.mozilla.vrbrowser.utils.UrlUtils; import java.util.ArrayList; @@ -59,7 +59,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga private ViewGroup mNavigationContainer; private ViewGroup mFullScreenModeContainer; private ViewGroup mResizeModeContainer; - private BrowserWidget mBrowserWidget; + private WindowWidget mWindowWidget; private boolean mIsLoading; private boolean mIsInFullScreenMode; private boolean mIsResizing; @@ -88,7 +88,6 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga private WidgetPlacement mProjectionMenuPlacement; private BrightnessMenuWidget mBrightnessWidget; private MediaControlsWidget mMediaControlsWidget; - private BookmarksWidget mBookmarksWidget; private Media mFullScreenMedia; private @VideoProjectionMenuWidget.VideoProjectionFlags Integer mAutoSelectedProjection; @@ -321,8 +320,7 @@ public void releaseWidget() { SessionStore.get().removeProgressListener(this); SessionStore.get().removeContentListener(this); SessionStore.get().removeSessionChangeListener(this); - mBrowserWidget = null; - mBookmarksWidget = null; + mWindowWidget = null; super.releaseWidget(); } @@ -344,26 +342,22 @@ protected void onDraw(Canvas canvas) { super.onDraw(canvas); } - public void setBrowserWidget(BrowserWidget aWidget) { + public void setBrowserWidget(WindowWidget aWidget) { if (aWidget != null) { mWidgetPlacement.parentHandle = aWidget.getHandle(); } - mBrowserWidget = aWidget; - } - - public void setBookmarksWidget(BookmarksWidget aWidget) { - mBookmarksWidget = aWidget; + mWindowWidget = aWidget; } private void setFullScreenSize() { - mSizeBeforeFullScreen.copyFrom(mBrowserWidget.getPlacement()); + mSizeBeforeFullScreen.copyFrom(mWindowWidget.getPlacement()); // Set browser fullscreen size float aspect = SettingsStore.getInstance(getContext()).getWindowAspect(); Media media = SessionStore.get().getFullScreenVideo(); if (media != null && media.getWidth() > 0 && media.getHeight() > 0) { aspect = (float)media.getWidth() / (float)media.getHeight(); } - mBrowserWidget.resizeByMultiplier(aspect,1.75f); + mWindowWidget.resizeByMultiplier(aspect,1.75f); } private void enterFullScreenMode() { @@ -371,7 +365,7 @@ private void enterFullScreenMode() { return; } - mBrowserWidget.setSaveResizeChanges(false); + mWindowWidget.setSaveResizeChanges(false); setFullScreenSize(); mWidgetManager.pushBackHandler(mFullScreenBackHandler); mIsInFullScreenMode = true; @@ -391,7 +385,7 @@ private void enterFullScreenMode() { mProjectionMenu.setDelegate((projection )-> { if (mIsInVRVideo) { // Reproject while reproducing VRVideo - mWidgetManager.showVRVideo(mBrowserWidget.getHandle(), projection); + mWidgetManager.showVRVideo(mWindowWidget.getHandle(), projection); closeFloatingMenus(); } else { enterVRVideo(projection); @@ -420,9 +414,9 @@ private void exitFullScreenMode() { } }, 50); - mBrowserWidget.getPlacement().copyFrom(mSizeBeforeFullScreen); - mWidgetManager.updateWidget(mBrowserWidget); - mBrowserWidget.setSaveResizeChanges(true); + mWindowWidget.getPlacement().copyFrom(mSizeBeforeFullScreen); + mWidgetManager.updateWidget(mWindowWidget); + mWindowWidget.setSaveResizeChanges(true); mIsInFullScreenMode = false; mWidgetManager.popBackHandler(mFullScreenBackHandler); @@ -484,13 +478,13 @@ private void enterVRVideo(@VideoProjectionMenuWidget.VideoProjectionFlags int aP if (mFullScreenMedia != null && mFullScreenMedia.getWidth() > 0 && mFullScreenMedia.getHeight() > 0) { final boolean resetBorder = aProjection == VideoProjectionMenuWidget.VIDEO_PROJECTION_360 || aProjection == VideoProjectionMenuWidget.VIDEO_PROJECTION_360_STEREO; - mBrowserWidget.enableVRVideoMode(mFullScreenMedia.getWidth(), mFullScreenMedia.getHeight(), resetBorder); + mWindowWidget.enableVRVideoMode(mFullScreenMedia.getWidth(), mFullScreenMedia.getHeight(), resetBorder); // Handle video resize while in VR video playback mFullScreenMedia.setResizeDelegate((width, height) -> { - mBrowserWidget.enableVRVideoMode(width, height, resetBorder); + mWindowWidget.enableVRVideoMode(width, height, resetBorder); }); } - mBrowserWidget.setVisible(false); + mWindowWidget.setVisible(false); closeFloatingMenus(); if (mProjectionMenu.getSelectedProjection() != VideoProjectionMenuWidget.VIDEO_PROJECTION_3D_SIDE_BY_SIDE) { @@ -499,7 +493,7 @@ private void enterVRVideo(@VideoProjectionMenuWidget.VideoProjectionFlags int aP if (mMediaControlsWidget == null) { mMediaControlsWidget = new MediaControlsWidget(getContext()); - mMediaControlsWidget.setParentWidget(mBrowserWidget.getHandle()); + mMediaControlsWidget.setParentWidget(mWindowWidget.getHandle()); mMediaControlsWidget.getPlacement().visible = false; mWidgetManager.addWidget(mMediaControlsWidget); mMediaControlsWidget.setBackHandler(this::exitVRVideo); @@ -508,7 +502,7 @@ private void enterVRVideo(@VideoProjectionMenuWidget.VideoProjectionFlags int aP mMediaControlsWidget.setMedia(mFullScreenMedia); mMediaControlsWidget.setProjectionSelectorEnabled(mAutoSelectedProjection == null); mWidgetManager.updateWidget(mMediaControlsWidget); - mWidgetManager.showVRVideo(mBrowserWidget.getHandle(), aProjection); + mWidgetManager.showVRVideo(mWindowWidget.getHandle(), aProjection); } private void exitVRVideo() { @@ -526,15 +520,14 @@ private void exitVRVideo() { mWidgetManager.setControllersVisible(true); this.setVisible(true); - mBrowserWidget.disableVRVideoMode(); - mBrowserWidget.setVisible(true); + mWindowWidget.disableVRVideoMode(); + mWindowWidget.setVisible(true); mMediaControlsWidget.setVisible(false); } private void setResizePreset(float aMultiplier) { final float aspect = SettingsStore.getInstance(getContext()).getWindowAspect(); - mBrowserWidget.resizeByMultiplier(aspect, aMultiplier); - mBookmarksWidget.resizeByMultiplier(aspect, aMultiplier); + mWindowWidget.resizeByMultiplier(aspect, aMultiplier); } public void showVoiceSearch() { @@ -740,7 +733,7 @@ public void onCrash(GeckoSession session) { // WidgetManagerDelegate.UpdateListener @Override public void onWidgetUpdate(Widget aWidget) { - if ((aWidget != mBrowserWidget && aWidget != mBookmarksWidget) || mIsResizing) { + if (aWidget != mWindowWidget || mIsResizing) { return; } @@ -958,30 +951,20 @@ public void onBookmarksClicked() { } } - private void finishWidgetResize() { - if (mBrowserWidget.isVisible()) { - mWidgetManager.finishWidgetResize(mBrowserWidget); + @Override + public void onPrivateBrowsingClicked() { - } else if (mBookmarksWidget.isVisible()) { - mWidgetManager.finishWidgetResize(mBookmarksWidget); - } } - private void startWidgetResize() { - if (mBrowserWidget.isVisible()) { - mWidgetManager.startWidgetResize(mBrowserWidget); + private void finishWidgetResize() { + mWidgetManager.finishWidgetResize(mWindowWidget); + } - } else if (mBookmarksWidget.isVisible()) { - mWidgetManager.startWidgetResize(mBookmarksWidget); - } + private void startWidgetResize() { + mWidgetManager.startWidgetResize(mWindowWidget); } private void updateWidget() { - if (mBrowserWidget.isVisible()) { - onWidgetUpdate(mBrowserWidget); - - } else if (mBookmarksWidget.isVisible()) { - onWidgetUpdate(mBookmarksWidget); - } + onWidgetUpdate(mWindowWidget); } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayListener.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayListener.java index c2d83f1267..ec4030620f 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayListener.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayListener.java @@ -2,4 +2,5 @@ public interface TrayListener { void onBookmarksClicked(); + void onPrivateBrowsingClicked(); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java index 29513ea0a5..aea6b8a649 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java @@ -80,8 +80,10 @@ private void initialize(Context aContext) { mAudio.playSound(AudioEngine.Sound.CLICK); } - SessionStore.get().switchPrivateMode(); + notifyPrivateBrowsingClicked(); view.requestFocusFromTouch(); + + SessionStore.get().switchPrivateMode(); }); mSettingsButton = findViewById(R.id.settingsButton); @@ -103,8 +105,8 @@ private void initialize(Context aContext) { mAudio.playSound(AudioEngine.Sound.CLICK); } - view.requestFocusFromTouch(); notifyBookmarksClicked(); + view.requestFocusFromTouch(); }); mAudio = AudioEngine.fromContext(aContext); @@ -181,6 +183,10 @@ private void notifyBookmarksClicked() { mTrayListeners.forEach(trayListener -> trayListener.onBookmarksClicked()); } + private void notifyPrivateBrowsingClicked() { + mTrayListeners.forEach(trayListener -> trayListener.onPrivateBrowsingClicked()); + } + @Override protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { Context context = getContext(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BrowserWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java similarity index 76% rename from app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BrowserWidget.java rename to app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java index 914801495a..5eb591d668 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BrowserWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java @@ -5,7 +5,6 @@ package org.mozilla.vrbrowser.ui.widgets; -import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; @@ -14,6 +13,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.Surface; +import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; @@ -25,11 +25,12 @@ import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.browser.SessionStore; import org.mozilla.vrbrowser.browser.SettingsStore; +import org.mozilla.vrbrowser.ui.views.BookmarksView; import org.mozilla.vrbrowser.ui.widgets.prompts.ChoicePromptWidget; -public class BrowserWidget extends UIWidget implements SessionStore.SessionChangeListener, - GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, BookmarkListener { +public class WindowWidget extends UIWidget implements SessionStore.SessionChangeListener, + GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, TrayListener, BookmarkListener { private static final String LOGTAG = "VRB"; @@ -48,8 +49,10 @@ public class BrowserWidget extends UIWidget implements SessionStore.SessionChang Runnable mFirstDrawCallback; private boolean mIsInVRVideoMode; private boolean mSaveResizeChanges; + private View mView; + private BookmarksView mBookmarksView; - public BrowserWidget(Context aContext, int aSessionId) { + public WindowWidget(Context aContext, int aSessionId) { super(aContext); mSessionId = aSessionId; mWidgetManager = (WidgetManagerDelegate) aContext; @@ -110,6 +113,50 @@ public void hide(@HideFlags int aHideFlag) { clearFocus(); } + @Override + protected void onDismiss() { + if (mView != null) { + if (SessionStore.get().canGoBack()) { + SessionStore.get().goBack(); + + } else if (SessionStore.get().canUnstackSession()) { + SessionStore.get().unstackSession(); + } + + unsetView(mView); + } + } + + public void setBookmarksView(BookmarksView view) { + mBookmarksView = view; + } + + public void setView(View view) { + pauseCompositor(); + mView = view; + removeView(view); + mView.setVisibility(VISIBLE); + addView(mView); + mWidgetPlacement.density = getContext().getResources().getDisplayMetrics().density; + mWidgetManager.updateWidget(this); + postInvalidate(); + mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS); + mWidgetManager.pushBackHandler(mBackHandler); + } + + public void unsetView(View view) { + if (mView != null && mView == view) { + mView = null; + removeView(view); + view.setVisibility(GONE); + resumeCompositor(); + mWidgetPlacement.density = 1.0f; + mWidgetManager.updateWidget(this); + mWidgetManager.popWorldBrightness(this); + mWidgetManager.popBackHandler(mBackHandler); + } + } + public void pauseCompositor() { if (mDisplay == null) { return; @@ -192,46 +239,56 @@ public void setSaveResizeChanges(boolean aSave) { @Override public void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final int aHeight) { - GeckoSession session = SessionStore.get().getSession(mSessionId); - if (session == null) { - return; - } - if (aTexture == null) { - setWillNotDraw(true); - return; - } - mWidth = aWidth; - mHeight = aHeight; - mTexture = aTexture; - aTexture.setDefaultBufferSize(aWidth, aHeight); - mSurface = new Surface(aTexture); - if (mDisplay == null) { - mDisplay = session.acquireDisplay(); + if (mView != null) { + super.setSurfaceTexture(aTexture, aWidth, aHeight); + } else { - Log.e(LOGTAG, "GeckoDisplay was not null in BrowserWidget.setSurfaceTexture()"); + GeckoSession session = SessionStore.get().getSession(mSessionId); + if (session == null) { + return; + } + if (aTexture == null) { + setWillNotDraw(true); + return; + } + mWidth = aWidth; + mHeight = aHeight; + mTexture = aTexture; + aTexture.setDefaultBufferSize(aWidth, aHeight); + mSurface = new Surface(aTexture); + if (mDisplay == null) { + mDisplay = session.acquireDisplay(); + } else { + Log.e(LOGTAG, "GeckoDisplay was not null in BrowserWidget.setSurfaceTexture()"); + } + callSurfaceChanged(); } - callSurfaceChanged(); } @Override public void setSurface(Surface aSurface, final int aWidth, final int aHeight, Runnable aFirstDrawCallback) { - GeckoSession session = SessionStore.get().getSession(mSessionId); - if (session == null) { - return; - } - mWidth = aWidth; - mHeight = aHeight; - mSurface = aSurface; - mFirstDrawCallback = aFirstDrawCallback; - if (mDisplay == null) { - mDisplay = session.acquireDisplay(); - } else { - Log.e(LOGTAG, "GeckoDisplay was not null in BrowserWidget.setSurfaceTexture()"); - } - if (mSurface != null) { - callSurfaceChanged(); + if (mView != null) { + super.setSurface(aSurface, aWidth, aHeight, aFirstDrawCallback); + } else { - mDisplay.surfaceDestroyed(); + GeckoSession session = SessionStore.get().getSession(mSessionId); + if (session == null) { + return; + } + mWidth = aWidth; + mHeight = aHeight; + mSurface = aSurface; + mFirstDrawCallback = aFirstDrawCallback; + if (mDisplay == null) { + mDisplay = session.acquireDisplay(); + } else { + Log.e(LOGTAG, "GeckoDisplay was not null in BrowserWidget.setSurfaceTexture()"); + } + if (mSurface != null) { + callSurfaceChanged(); + } else { + mDisplay.surfaceDestroyed(); + } } } @@ -241,6 +298,10 @@ private void callSurfaceChanged() { @Override public void resizeSurface(final int aWidth, final int aHeight) { + if (mView != null) { + super.resizeSurface(aWidth, aHeight); + } + mWidth = aWidth; mHeight = aHeight; if (mTexture != null) { @@ -261,24 +322,34 @@ public WidgetPlacement getPlacement() { @Override public void handleTouchEvent(MotionEvent aEvent) { - if (aEvent.getActionMasked() == MotionEvent.ACTION_UP) { - requestFocus(); - requestFocusFromTouch(); - } - GeckoSession session = SessionStore.get().getSession(mSessionId); - if (session == null) { - return; + if (mView != null) { + super.handleTouchEvent(aEvent); + + } else { + if (aEvent.getActionMasked() == MotionEvent.ACTION_UP) { + requestFocus(); + requestFocusFromTouch(); + } + GeckoSession session = SessionStore.get().getSession(mSessionId); + if (session == null) { + return; + } + session.getPanZoomController().onTouchEvent(aEvent); } - session.getPanZoomController().onTouchEvent(aEvent); } @Override public void handleHoverEvent(MotionEvent aEvent) { - GeckoSession session = SessionStore.get().getSession(mSessionId); - if (session == null) { - return; + if (mView != null) { + super.handleHoverEvent(aEvent); + + } else { + GeckoSession session = SessionStore.get().getSession(mSessionId); + if (session == null) { + return; + } + session.getPanZoomController().onMotionEvent(aEvent); } - session.getPanZoomController().onMotionEvent(aEvent); } @Override @@ -287,10 +358,10 @@ public void handleResizeEvent(float aWorldWidth, float aWorldHeight) { int defaultWidth = SettingsStore.getInstance(getContext()).getWindowWidth(); int defaultHeight = SettingsStore.getInstance(getContext()).getWindowHeight(); - float aspect = (float)defaultWidth / (float)defaultHeight; + float aspect = (float) defaultWidth / (float) defaultHeight; float worldHeight = worldWidth / aspect; - mWidgetPlacement.width = (int)((aWorldWidth * defaultWidth) / worldWidth) + mBorderWidth * 2; - mWidgetPlacement.height = (int)((aWorldHeight * defaultHeight) /worldHeight) + mBorderWidth * 2; + mWidgetPlacement.width = (int) ((aWorldWidth * defaultWidth) / worldWidth) + mBorderWidth * 2; + mWidgetPlacement.height = (int) ((aWorldHeight * defaultHeight) / worldHeight) + mBorderWidth * 2; mWidgetPlacement.worldWidth = aWorldWidth; mWidgetManager.updateWidget(this); @@ -345,11 +416,11 @@ public void setVisible(boolean aVisible) { } } - @SuppressLint("MissingSuperCall") @Override public void draw(Canvas aCanvas) { - // Nothing to do - + if (mView != null) { + super.draw(aCanvas); + } } // SessionStore.GeckoSessionChange @@ -540,14 +611,42 @@ public GeckoResult onPopupRequest(final GeckoSession session, final @Override public void onBookmarksShown() { - pauseCompositor(); - hide(UIWidget.REMOVE_WIDGET); + } @Override public void onBookmarksHidden() { - resumeCompositor(); - show(); + unsetView(mBookmarksView); + } + + // TrayListener + + @Override + public void onBookmarksClicked() { + if (mBookmarksView.getVisibility() == View.VISIBLE) { + SessionStore.get().unstackSession(); + + unsetView(mBookmarksView); + + } else { + int sessionId; + if (SessionStore.get().isCurrentSessionPrivate()) { + sessionId = SessionStore.get().createSession(true); + + } else { + sessionId = SessionStore.get().createSession(); + } + SessionStore.get().stackSession(sessionId); + + setView(mBookmarksView); + } + } + + @Override + public void onPrivateBrowsingClicked() { + if (mBookmarksView.getVisibility() == VISIBLE) { + SessionStore.get().unstackSession(); + } } // GeckoSession.ContentDelegate diff --git a/app/src/main/res/values/dimen.xml b/app/src/main/res/values/dimen.xml index 275d0988b6..6c59c1e70c 100644 --- a/app/src/main/res/values/dimen.xml +++ b/app/src/main/res/values/dimen.xml @@ -150,5 +150,4 @@ 64dp - -4.19 \ No newline at end of file