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

Fixes Bookmarks resizing issues #820

Merged
merged 3 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
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.widgets.dialogs.CrashDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.KeyboardWidget;
import org.mozilla.vrbrowser.ui.widgets.NavigationBarWidget;
import org.mozilla.vrbrowser.ui.widgets.RootWidget;
Expand All @@ -59,9 +58,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.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;
Expand Down Expand Up @@ -130,6 +131,7 @@ public void run() {
private LinkedList<Pair<Object, Float>> mBrightnessQueue;
private Pair<Object, Float> mCurrentBrightness;
private SearchEngineWrapper mSearchEngineWrapper;
private ArrayList<Widget> mResizableWidgets;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -161,6 +163,8 @@ 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) -> {
Expand Down Expand Up @@ -205,8 +209,6 @@ protected void initializeWorld() {

// Bookmarks panel
mBookmarksWidget = new BookmarksWidget(this);
mBookmarksWidget.setBrowserWidget(mBrowserWidget);
mBrowserWidget.setBookmarksWidget(mBookmarksWidget);

// Create Browser navigation widget
mNavigationBar = new NavigationBarWidget(this);
Expand All @@ -233,9 +235,11 @@ protected void initializeWorld() {
mTray = new TrayWidget(this);

// Add widget listeners
mTray.addListeners(new TrayListener[]{mBookmarksWidget, mNavigationBar});
mTray.addListeners(new TrayListener[]{mNavigationBar, mBookmarksWidget});
mBookmarksWidget.addListeners(new BookmarkListener[]{mBrowserWidget, mNavigationBar, mTray});

mResizableWidgets.addAll(Arrays.asList(mBrowserWidget, mBookmarksWidget));

addWidgets(Arrays.asList(mRootWidget, mBrowserWidget, mNavigationBar, mKeyboard, mTray, mBookmarksWidget));
}

Expand Down Expand Up @@ -562,12 +566,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(() -> {
Widget widget = mWidgets.get(aHandle);
if (widget != null) {
widget.handleResizeEvent(aWorldWidth, aWorldHeight);
} else {
Log.e(LOGTAG, "Failed to find widget for resize: " + aHandle);
}
mResizableWidgets.forEach(widget -> widget.handleResizeEvent(aWorldWidth, aWorldHeight));
});
}

Expand Down Expand Up @@ -912,8 +911,8 @@ public void setControllersVisible(final boolean aVisible) {
}

@Override
public void setBrowserSize(float targetWidth, float targetHeight) {
mBrowserWidget.resizeByMultiplier(targetWidth / targetHeight, 1.0f);
public void setWindowSize(float targetWidth, float targetHeight) {
mBrowserWidget.resizeByMultiplier(targetWidth / targetHeight, 1.0f);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@


public class BookmarksWidget extends UIWidget implements Application.ActivityLifecycleCallbacks,
WidgetManagerDelegate.UpdateListener, TrayListener, GeckoSession.NavigationDelegate {
TrayListener, GeckoSession.NavigationDelegate {

private static final String ABOUT_BLANK = "about:blank";

private BookmarksBinding mBinding;
private BookmarkAdapter mBookmarkAdapter;
private BookmarkListViewModel mBookmarkListModel;
private Widget mBrowserWidget;
private List<BookmarkListener> mBookmarkListeners;
private AudioEngine mAudio;
private int mSessionId;
Expand All @@ -75,7 +74,6 @@ private void initialize(Context aContext) {
mAudio = AudioEngine.fromContext(aContext);

((Application)getApplicationContext()).registerActivityLifecycleCallbacks(this);
mWidgetManager.addUpdateListener(this);
SessionStore.get().addNavigationListener(this);

LayoutInflater inflater = LayoutInflater.from(aContext);
Expand All @@ -88,6 +86,9 @@ private void initialize(Context aContext) {

mBookmarkListModel = new BookmarkListViewModel(((Application)getApplicationContext()));
subscribeUi(mBookmarkListModel.getBookmarks());

handleResizeEvent(SettingsStore.getInstance(getContext()).getBrowserWorldWidth(),
SettingsStore.getInstance(getContext()).getBrowserWorldHeight());
}

@Override
Expand All @@ -102,13 +103,6 @@ public void resizeByMultiplier(float aspect, float multiplier) {
handleResizeEvent(targetWidth, targetHeight);
}

@Override
public void handleResizeEvent(float aWorldWidth, float aWorldHeight) {
super.handleResizeEvent(aWorldWidth, aWorldHeight);

mBrowserWidget.handleResizeEvent(aWorldWidth, aWorldHeight);
}

public void addListeners(BookmarkListener... listeners) {
mBookmarkListeners.addAll(Arrays.asList(listeners));
}
Expand All @@ -128,9 +122,10 @@ private void notifyBookmarksHidden() {
@Override
public void releaseWidget() {
((Application)getApplicationContext()).unregisterActivityLifecycleCallbacks(this);
mWidgetManager.removeUpdateListener(this);
SessionStore.get().removeNavigationListener(this);

unstackSession();

super.releaseWidget();
}

Expand Down Expand Up @@ -200,10 +195,6 @@ public void onChanged(List<BookmarkEntity> bookmarkEntities) {
}
};

public void setBrowserWidget(Widget widget) {
mBrowserWidget = widget;
}

@Override
public void show() {
super.show();
Expand Down Expand Up @@ -241,6 +232,10 @@ public void hide(@HideFlags int aHideFlags) {
protected void onDismiss() {
super.onDismiss();

unstackSession();
}

private void unstackSession() {
if (SessionStore.get().getCurrentSessionId() == mSessionId) {
if (SessionStore.get().canGoBack()) {
SessionStore.get().goBack();
Expand Down Expand Up @@ -288,20 +283,6 @@ public void onActivityDestroyed(Activity activity) {

}

// UpdateListener

@Override
public void onWidgetUpdate(Widget aWidget) {
if (aWidget != mBrowserWidget || !mBrowserWidget.isVisible()) {
return;
}

mWidgetPlacement.worldWidth = aWidget.getPlacement().worldWidth;
mWidgetPlacement.width = aWidget.getPlacement().width;
mWidgetPlacement.height = aWidget.getPlacement().height;
mWidgetManager.updateWidget(this);
}

// TrayListener

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@


public class BrowserWidget extends UIWidget implements SessionStore.SessionChangeListener,
GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, WidgetManagerDelegate.UpdateListener,
BookmarkListener {
GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, BookmarkListener {

private static final String LOGTAG = "VRB";

Expand All @@ -46,8 +45,6 @@ public class BrowserWidget extends UIWidget implements SessionStore.SessionChang
private int mWidthBackup;
private int mHeightBackup;
private int mBorderWidth;
private BookmarksWidget mBookmarksWidget;
private float mMultiplier;
Runnable mFirstDrawCallback;
private boolean mIsInVRVideoMode;

Expand All @@ -59,7 +56,6 @@ public BrowserWidget(Context aContext, int aSessionId) {
SessionStore.get().addSessionChangeListener(this);
SessionStore.get().addPromptListener(this);
SessionStore.get().addContentListener(this);
mWidgetManager.addUpdateListener(this);
setFocusable(true);
GeckoSession session = SessionStore.get().getSession(mSessionId);
if (session != null) {
Expand All @@ -69,8 +65,6 @@ public BrowserWidget(Context aContext, int aSessionId) {
mWidgetPlacement = new WidgetPlacement(aContext);
initializeWidgetPlacement(mWidgetPlacement);

mMultiplier = 1.0f;

handleResizeEvent(SettingsStore.getInstance(getContext()).getBrowserWorldWidth(),
SettingsStore.getInstance(getContext()).getBrowserWorldHeight());
}
Expand Down Expand Up @@ -114,10 +108,6 @@ public void hide(@HideFlags int aHideFlag) {
clearFocus();
}

public void setBookmarksWidget(BookmarksWidget aWidget) {
mBookmarksWidget = aWidget;
}

public void pauseCompositor() {
if (mDisplay == null) {
return;
Expand Down Expand Up @@ -172,8 +162,6 @@ public void disableVRVideoMode() {

@Override
public void resizeByMultiplier(float aspect, float multiplier) {
mMultiplier = multiplier;

float worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
float worldHeight = worldWidth / aspect;
float area = worldWidth * worldHeight * multiplier;
Expand Down Expand Up @@ -309,7 +297,6 @@ public void releaseWidget() {
SessionStore.get().removeSessionChangeListener(this);
SessionStore.get().removePromptListener(this);
SessionStore.get().removeContentListener(this);
mWidgetManager.removeUpdateListener(this);
GeckoSession session = SessionStore.get().getSession(mSessionId);
if (session == null) {
return;
Expand Down Expand Up @@ -553,20 +540,6 @@ public void onBookmarksHidden() {
show();
}

// UpdateListener

@Override
public void onWidgetUpdate(Widget aWidget) {
if (aWidget != mBookmarksWidget || !mBookmarksWidget.isVisible()) {
return;
}

mWidgetPlacement.worldWidth = aWidget.getPlacement().worldWidth;
mWidgetPlacement.width = aWidget.getPlacement().width;
mWidgetPlacement.height = aWidget.getPlacement().height;
mWidgetManager.updateWidget(this);
}

// GeckoSession.ContentDelegate
@Override
public void onTitleChange(GeckoSession session, String title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,8 @@ private void exitVRVideo() {

private void setResizePreset(float aMultiplier) {
final float aspect = SettingsStore.getInstance(getContext()).getWindowAspect();
if (mBrowserWidget.isVisible()) {
mBrowserWidget.resizeByMultiplier(aspect, aMultiplier);

} else if (mBookmarksWidget.isVisible()) {
mBookmarksWidget.resizeByMultiplier(aspect, aMultiplier);
}
mBrowserWidget.resizeByMultiplier(aspect, aMultiplier);
mBookmarksWidget.resizeByMultiplier(aspect, aMultiplier);
}

public void showVoiceSearch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface WorldClickListener {
void popWorldBrightness(Object aKey);
void setTrayVisible(boolean visible);
void setControllersVisible(boolean visible);
void setBrowserSize(float targetWidth, float targetHeight);
void setWindowSize(float targetWidth, float targetHeight);
void keyboardDismissed();
void updateEnvironment();
void updatePointerColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private void setWindowSize(int newWindowWidth, int newWindowHeight, boolean doAp
SettingsStore.getInstance(getContext()).setWindowHeight(newWindowHeight);

if (doApply) {
mWidgetManager.setBrowserSize(newWindowWidth, newWindowHeight);
mWidgetManager.setWindowSize(newWindowWidth, newWindowHeight);
}
}

Expand Down