From 0e110cff80bbfc7dae590ed55855a6ecfc07fb1e Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Wed, 14 Nov 2018 22:39:50 -0800 Subject: [PATCH] wip --- .../mozilla/vrbrowser/VRBrowserActivity.java | 6 +- .../vrbrowser/ui/views/NavigationURLBar.java | 13 +++- .../vrbrowser/ui/widgets/BookmarksWidget.java | 57 ++++++++------ .../vrbrowser/ui/widgets/BrowserWidget.java | 6 +- .../ui/widgets/NavigationBarListener.java | 5 -- .../ui/widgets/NavigationBarWidget.java | 77 ++++++++----------- .../vrbrowser/ui/widgets/TrayListener.java | 3 - .../vrbrowser/ui/widgets/TrayWidget.java | 29 +------ 8 files changed, 81 insertions(+), 115 deletions(-) delete mode 100644 app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarListener.java diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 6400dc9b93..d398dd7b43 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -47,6 +47,7 @@ import org.mozilla.vrbrowser.ui.widgets.NavigationBarWidget; import org.mozilla.vrbrowser.ui.widgets.RootWidget; import org.mozilla.vrbrowser.ui.widgets.TopBarWidget; +import org.mozilla.vrbrowser.ui.widgets.TrayListener; import org.mozilla.vrbrowser.ui.widgets.TrayWidget; import org.mozilla.vrbrowser.ui.widgets.VideoProjectionMenuWidget; import org.mozilla.vrbrowser.ui.widgets.Widget; @@ -218,15 +219,13 @@ protected void initializeWorld() { // Create Tray mTray = new TrayWidget(this); - // Bookmarks panel mBookmarksWidget = new BookmarksWidget(this); mBookmarksWidget.setBrowserWidget(mBrowserWidget); // Add widget listeners - mTray.addListener(mBookmarksWidget); + mTray.addListeners(new TrayListener[]{mBookmarksWidget, mNavigationBar}); mBookmarksWidget.addListeners(new BookmarkListener[]{mBrowserWidget, mNavigationBar, mTray}); - mNavigationBar.addListener(mBookmarksWidget); addWidgets(Arrays.asList(mRootWidget, mBrowserWidget, mNavigationBar, mKeyboard, mTray, mBookmarksWidget)); } @@ -285,7 +284,6 @@ protected void onDestroy() { // Remove all widget listeners mTray.removeAllListeners(); mBookmarksWidget.removeAllListeners(); - mNavigationBar.removeAllListeners(); SessionStore.get().unregisterListeners(); super.onDestroy(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java index 6b022f8077..b9534a1663 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java @@ -71,6 +71,7 @@ public class NavigationURLBar extends FrameLayout { private NavigationUrlBinding mBinding; private BookmarkViewModel mBookmarkModel; private AudioEngine mAudio; + private boolean mUpdateBar; private Unit domainAutocompleteFilter(String text, InlineAutocompleteEditText view) { if (view != null) { @@ -162,6 +163,7 @@ private void initialize(Context aContext) { mBookmarkButton.setSoundEffectsEnabled(false); setURL(""); + mUpdateBar = true; // Prevent the URL TextEdit to get focus when user touches something outside of it setFocusable(true); @@ -172,6 +174,11 @@ public void setDelegate(NavigationURLBarDelegate delegate) { mDelegate = delegate; } + public void setUpdate(boolean update) { + mUpdateBar = update; + syncViews(); + } + private final NavigationBarCallback mNavigationBarCallback = new NavigationBarCallback() { @Override public void onBookmarkClick(Bookmark bookmark) { @@ -199,6 +206,10 @@ public void setHint(@StringRes int aHint) { } public void setURL(String aURL) { + if (!mUpdateBar) { + return; + } + // Setup model view for this URL if (mBookmarkModel != null) { mBookmarkModel.getObservableBookmark().removeObserver(mBookmarkObserver); @@ -308,7 +319,7 @@ public void showVoiceSearch(boolean enabled) { } private void syncViews() { - boolean showContainer = mIsInsecure || mIsLoading; + boolean showContainer = (mIsInsecure || mIsLoading) && mUpdateBar; int leftPadding = mDefaultURLLeftPadding; if (showContainer) { mURLLeftContainer.setVisibility(View.VISIBLE); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BookmarksWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BookmarksWidget.java index 9eea2a50dc..eb8c4224e4 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BookmarksWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BookmarksWidget.java @@ -12,6 +12,10 @@ import android.util.AttributeSet; import android.view.LayoutInflater; +import org.mozilla.geckoview.AllowOrDeny; +import org.mozilla.geckoview.GeckoResult; +import org.mozilla.geckoview.GeckoSession; +import org.mozilla.geckoview.WebRequestError; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.audio.AudioEngine; import org.mozilla.vrbrowser.browser.SessionStore; @@ -27,6 +31,8 @@ import java.util.Arrays; import java.util.List; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.databinding.DataBindingUtil; import androidx.lifecycle.LiveData; import androidx.lifecycle.Observer; @@ -35,7 +41,7 @@ public class BookmarksWidget extends UIWidget implements Application.ActivityLifecycleCallbacks, - WidgetManagerDelegate.UpdateListener, TrayListener, NavigationBarListener { + WidgetManagerDelegate.UpdateListener, TrayListener, GeckoSession.NavigationDelegate { private BookmarksBinding mBinding; private BookmarkAdapter mBookmarkAdapter; @@ -66,6 +72,7 @@ private void initialize(Context aContext) { ((Application)getApplicationContext()).registerActivityLifecycleCallbacks(this); mWidgetManager.addUpdateListener(this); + SessionStore.get().addNavigationListener(this); LayoutInflater inflater = LayoutInflater.from(aContext); @@ -79,10 +86,6 @@ private void initialize(Context aContext) { subscribeUi(mBookmarkListModel.getBookmarks()); } - public void addListener(BookmarkListener aListener) { - mBookmarkListeners.add(aListener); - } - public void addListeners(BookmarkListener... listeners) { mBookmarkListeners.addAll(Arrays.asList(listeners)); } @@ -92,21 +95,18 @@ public void removeAllListeners() { } private void notifyBookmarksShow() { - mBookmarkListeners.forEach(bookmarkListener -> { - bookmarkListener.onBookmarksShow(); - }); + mBookmarkListeners.forEach(bookmarkListener -> bookmarkListener.onBookmarksShow()); } private void notifyBookmarksHide() { - mBookmarkListeners.forEach(bookmarkListener -> { - bookmarkListener.onBookmarksHide(); - }); + mBookmarkListeners.forEach(bookmarkListener -> bookmarkListener.onBookmarksHide()); } @Override public void releaseWidget() { ((Application)getApplicationContext()).unregisterActivityLifecycleCallbacks(this); mWidgetManager.removeUpdateListener(this); + SessionStore.get().removeNavigationListener(this); super.releaseWidget(); } @@ -125,9 +125,8 @@ public void onClick(Bookmark bookmark) { mAudio.playSound(AudioEngine.Sound.CLICK); } - SessionStore.get().loadUri(bookmark.getUrl()); - notifyBookmarksShow(); hide(); + SessionStore.get().loadUri(bookmark.getUrl()); } @Override @@ -261,31 +260,41 @@ public void onBookmarksClicked() { toggle(); } + // NavigationDelegate + @Override - public void onHelpClicked() { - if (mWidgetPlacement.visible) { - hide(); - } + public void onLocationChange(GeckoSession session, String url) { + } @Override - public void onSettingsClicked() { + public void onCanGoBack(GeckoSession session, boolean canGoBack) { } @Override - public void onPrivateBrowsingClicked() { + public void onCanGoForward(GeckoSession session, boolean canGoForward) { + + } + + @Nullable + @Override + public GeckoResult onLoadRequest(@NonNull GeckoSession session, @NonNull LoadRequest request) { if (mWidgetPlacement.visible) { hide(); } + + return GeckoResult.ALLOW; } - // NavigationBarListener + @Nullable + @Override + public GeckoResult onNewSession(@NonNull GeckoSession session, @NonNull String uri) { + return null; + } @Override - public void onNavigationStarted() { - if (mWidgetPlacement.visible) { - hide(); - } + public GeckoResult onLoadError(GeckoSession session, String uri, WebRequestError error) { + return null; } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BrowserWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BrowserWidget.java index ecdc572c29..7512d0ee39 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BrowserWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/BrowserWidget.java @@ -14,21 +14,17 @@ 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; -import android.widget.FrameLayout; -import android.widget.LinearLayout; import org.mozilla.geckoview.AllowOrDeny; import org.mozilla.geckoview.GeckoDisplay; import org.mozilla.geckoview.GeckoResult; import org.mozilla.geckoview.GeckoSession; import org.mozilla.geckoview.GeckoSessionSettings; -import org.mozilla.vrbrowser.*; +import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.browser.SessionStore; import org.mozilla.vrbrowser.browser.SettingsStore; -import org.mozilla.vrbrowser.model.Bookmark; import org.mozilla.vrbrowser.ui.prompts.ChoicePromptWidget; diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarListener.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarListener.java deleted file mode 100644 index a4433a590c..0000000000 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarListener.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.mozilla.vrbrowser.ui.widgets; - -public interface NavigationBarListener { - void onNavigationStarted(); -} 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 9025aed684..0d75b29af7 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 @@ -34,7 +34,6 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -44,7 +43,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga WidgetManagerDelegate.UpdateListener, SessionStore.SessionChangeListener, NavigationURLBar.NavigationURLBarDelegate, VoiceSearchWidget.VoiceSearchDelegate, SharedPreferences.OnSharedPreferenceChangeListener, SuggestionsWidget.URLBarPopupDelegate, - BookmarkListener { + BookmarkListener, TrayListener { private static final String LOGTAG = "VRB"; @@ -84,9 +83,8 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga private SearchEngineWrapper mSearchEngineWrapper; private VideoProjectionMenuWidget mProjectionMenu; private WidgetPlacement mProjectionMenuPlacement; - private BrightnessMenuWidget mBrigthnessWidget; + private BrightnessMenuWidget mBrightnessWidget; private MediaControlsWidget mMediaControlsWidget; - private List mNavigationBarListeners; public NavigationBarWidget(Context aContext) { super(aContext); @@ -107,8 +105,6 @@ private void initialize(Context aContext) { mAppContext = aContext.getApplicationContext(); inflate(aContext, R.layout.navigation_bar, this); - mNavigationBarListeners = new ArrayList<>(); - mAudio = AudioEngine.fromContext(aContext); mBackButton = findViewById(R.id.backButton); mForwardButton = findViewById(R.id.forwardButton); @@ -140,7 +136,6 @@ else if (SessionStore.get().canUnstackSession()) if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.BACK); } - notifyNavigationStarted(); }); mForwardButton.setOnClickListener(v -> { @@ -149,7 +144,6 @@ else if (SessionStore.get().canUnstackSession()) if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } - notifyNavigationStarted(); }); mReloadButton.setOnClickListener(v -> { @@ -162,7 +156,6 @@ else if (SessionStore.get().canUnstackSession()) if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } - notifyNavigationStarted(); }); mHomeButton.setOnClickListener(v -> { @@ -171,7 +164,6 @@ else if (SessionStore.get().canUnstackSession()) if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } - notifyNavigationStarted(); }); mServoButton.setOnClickListener(v -> { @@ -239,12 +231,12 @@ else if (SessionStore.get().canUnstackSession()) if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } - boolean wasVisible = mBrigthnessWidget.isVisible(); + boolean wasVisible = mBrightnessWidget.isVisible(); closeFloatingMenus(); if (!wasVisible) { float anchor = 0.5f + (float)mBrightnessButton.getMeasuredWidth() / (float)NavigationBarWidget.this.getMeasuredWidth(); - mBrigthnessWidget.getPlacement().parentAnchorX = anchor; - mBrigthnessWidget.setVisible(true); + mBrightnessWidget.getPlacement().parentAnchorX = anchor; + mBrightnessWidget.setVisible(true); } }); @@ -309,22 +301,6 @@ else if (SessionStore.get().canUnstackSession()) updateServoButton(); } - public void addListener(NavigationBarListener aListener) { - mNavigationBarListeners.add(aListener); - } - - public void addListeners(NavigationBarListener... listeners) { - mNavigationBarListeners.addAll(Arrays.asList(listeners)); - } - - public void removeAllListeners() { - mNavigationBarListeners.clear(); - } - - private void notifyNavigationStarted() { - mNavigationBarListeners.forEach(navigationBarListener -> navigationBarListener.onNavigationStarted()); - } - @Override public void releaseWidget() { mWidgetManager.removeUpdateListener(this); @@ -387,13 +363,13 @@ private void enterFullScreenMode() { } }); } - if (mBrigthnessWidget == null) { - mBrigthnessWidget = new BrightnessMenuWidget(getContext()); - mBrigthnessWidget.setParentWidget(this); - mWidgetManager.addWidget(mBrigthnessWidget); + if (mBrightnessWidget == null) { + mBrightnessWidget = new BrightnessMenuWidget(getContext()); + mBrightnessWidget.setParentWidget(this); + mWidgetManager.addWidget(mBrightnessWidget); } closeFloatingMenus(); - mWidgetManager.pushWorldBrightness(mBrigthnessWidget, mBrigthnessWidget.getSelectedBrightness()); + mWidgetManager.pushWorldBrightness(mBrightnessWidget, mBrightnessWidget.getSelectedBrightness()); } private void exitFullScreenMode() { @@ -414,7 +390,7 @@ private void exitFullScreenMode() { mWidgetManager.setTrayVisible(true); closeFloatingMenus(); - mWidgetManager.popWorldBrightness(mBrigthnessWidget); + mWidgetManager.popWorldBrightness(mBrightnessWidget); } private void enterResizeMode() { @@ -444,12 +420,7 @@ private void exitResizeMode(boolean aCommitChanges) { } else { AnimationHelper.fadeIn(mNavigationContainer, AnimationHelper.FADE_ANIMATION_DURATION, null); } - AnimationHelper.fadeOut(mResizeModeContainer, 0, new Runnable() { - @Override - public void run() { - onWidgetUpdate(mBrowserWidget); - } - }); + AnimationHelper.fadeOut(mResizeModeContainer, 0, () -> onWidgetUpdate(mBrowserWidget)); mWidgetManager.popBackHandler(mResizeBackHandler); closeFloatingMenus(); } @@ -529,8 +500,8 @@ private void closeFloatingMenus() { if (mProjectionMenu != null) { mProjectionMenu.setVisible(false); } - if (mBrigthnessWidget != null) { - mBrigthnessWidget.setVisible(false); + if (mBrightnessWidget != null) { + mBrightnessWidget.setVisible(false); } } @@ -816,8 +787,6 @@ public void OnShowSearchPopup() { @Override public void onUrlBarEntered() { - notifyNavigationStarted(); - if (mPopup != null && mPopup.isVisible()) { mPopup.hide(); } @@ -879,6 +848,7 @@ public void onWorldClick() { } // URLBarPopupWidgetDelegate + @Override public void OnItemClicked(SuggestionsWidget.SuggestionItem item) { mURLBar.handleURLEdit(item.url); @@ -897,13 +867,30 @@ public void onBookmarksShow() { mURLBar.setBookmarks(true); mURLBar.setURL(""); mURLBar.setHint(R.string.about_bookmarks); + mURLBar.setUpdate(false); } @Override public void onBookmarksHide() { mResizeEnterButton.setEnabled(true); + mURLBar.setUpdate(true); mURLBar.setBookmarks(false); mURLBar.setURL(SessionStore.get().getCurrentUri()); mURLBar.setHint(R.string.search_placeholder); } + + // TrayListener + + @Override + public void onBookmarksClicked() { + if (mIsResizing) { + exitResizeMode(false); + + } else if (mIsInFullScreenMode) { + exitFullScreenMode(); + + } else if (mIsInVRVideo) { + exitVRVideo(); + } + } } 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 26f54eb84c..c2d83f1267 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,7 +2,4 @@ public interface TrayListener { void onBookmarksClicked(); - void onHelpClicked(); - void onSettingsClicked(); - 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 14f461266b..eec15c1e26 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 @@ -58,7 +58,6 @@ private void initialize(Context aContext) { onHelpButtonClicked(); view.requestFocusFromTouch(); - notifyHelpClicked(); }); mPrivateButton = findViewById(R.id.privateButton); @@ -69,7 +68,6 @@ private void initialize(Context aContext) { SessionStore.get().switchPrivateMode(); view.requestFocusFromTouch(); - notifyProvateBrowsingClicked(); }); mSettingsButton = findViewById(R.id.settingsButton); @@ -81,7 +79,6 @@ private void initialize(Context aContext) { toggleSettingsDialog(); if (isDialogOpened(mSettingsDialogHandle)) view.requestFocusFromTouch(); - notifySettingsClicked(); }); mBookmarksButton = findViewById(R.id.bookmarksButton); @@ -101,10 +98,6 @@ private void initialize(Context aContext) { SessionStore.get().addSessionChangeListener(this); } - public void addListener(TrayListener aListener) { - mTrayListeners.add(aListener); - } - public void addListeners(TrayListener... listeners) { mTrayListeners.addAll(Arrays.asList(listeners)); } @@ -114,27 +107,7 @@ public void removeAllListeners() { } private void notifyBookmarksClicked() { - mTrayListeners.forEach(trayListener -> { - trayListener.onBookmarksClicked(); - }); - } - - private void notifyHelpClicked() { - mTrayListeners.forEach(trayListener -> { - trayListener.onHelpClicked(); - }); - } - - private void notifySettingsClicked() { - mTrayListeners.forEach(trayListener -> { - trayListener.onSettingsClicked(); - }); - } - - private void notifyProvateBrowsingClicked() { - mTrayListeners.forEach(trayListener -> { - trayListener.onPrivateBrowsingClicked(); - }); + mTrayListeners.forEach(trayListener -> trayListener.onBookmarksClicked()); } @Override