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

Commit

Permalink
Fixes Bookmark resizing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Nov 23, 2018
1 parent a1f7bdc commit 7552029
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 61 deletions.
18 changes: 10 additions & 8 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.function.Consumer;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -130,6 +132,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 +164,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 @@ -235,6 +240,8 @@ protected void initializeWorld() {
mTray.addListeners(new TrayListener[]{mBookmarksWidget, mNavigationBar});
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 @@ -561,12 +568,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 @@ -911,8 +913,8 @@ public void setControllersVisible(final boolean aVisible) {
}

@Override
public void setBrowserSize(float targetWidth, float targetHeight) {
mBrowserWidget.setSize(targetWidth, targetHeight, 1.0f);
public void setWindowSize(float targetWidth, float targetHeight) {
mResizableWidgets.forEach(widget -> widget.setSize(targetWidth, targetHeight, 1.0f));
}

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


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

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

Expand Down Expand Up @@ -75,7 +75,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 +87,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 @@ -103,13 +105,6 @@ public void setSize(float windowWidth, float windowHeight, 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 @@ -129,9 +124,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 @@ -242,6 +238,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 @@ -289,20 +289,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 @@ -47,7 +46,6 @@ public class BrowserWidget extends UIWidget implements SessionStore.SessionChang
private int mHeightBackup;
private int mBorderWidth;
private BookmarksWidget mBookmarksWidget;
private float mMultiplier;
Runnable mFirstDrawCallback;

public BrowserWidget(Context aContext, int aSessionId) {
Expand All @@ -58,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 @@ -68,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 @@ -168,8 +163,6 @@ public void disableVRVideoMode() {

@Override
public void setSize(float windowWidth, float windowHeight, float multiplier) {
mMultiplier = multiplier;

float worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
float aspect = windowWidth / windowHeight;
float worldHeight = worldWidth / aspect;
Expand Down Expand Up @@ -306,7 +299,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 @@ -552,20 +544,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 @@ -490,18 +490,14 @@ private void exitVRVideo() {
}

private void setResizePreset(float aResizeMode) {
if (mBrowserWidget.isVisible()) {
mBrowserWidget.setSize(
SettingsStore.getInstance(getContext()).getWindowWidth(),
SettingsStore.getInstance(getContext()).getWindowHeight(),
aResizeMode);

} else if (mBookmarksWidget.isVisible()) {
mBookmarksWidget.setSize(
SettingsStore.getInstance(getContext()).getWindowWidth(),
SettingsStore.getInstance(getContext()).getWindowHeight(),
aResizeMode);
}
}

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 @@ -283,7 +283,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

0 comments on commit 7552029

Please sign in to comment.