diff --git a/app/src/common/shared/org/mozilla/vrbrowser/PermissionDelegate.java b/app/src/common/shared/org/mozilla/vrbrowser/PermissionDelegate.java index a8a79a9907..fd87aee14b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/PermissionDelegate.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/PermissionDelegate.java @@ -204,4 +204,8 @@ public void reject() { } } } + + public boolean isPermissionDialogVisible() { + return mPermissionWidget != null && mPermissionWidget.isVisible(); + } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index c818257061..15365e5c1a 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -41,6 +41,7 @@ import org.mozilla.vrbrowser.ui.RootWidget; import org.mozilla.vrbrowser.ui.TopBarWidget; import org.mozilla.vrbrowser.ui.TrayWidget; +import org.mozilla.vrbrowser.ui.UIWidget; import java.io.IOException; import java.net.URISyntaxException; @@ -104,6 +105,7 @@ public void run() { LinkedList mBackHandlers; private boolean mIsPresentingImmersive = false; private Thread mUiThread; + private boolean isDimmed; @Override protected void onCreate(Bundle savedInstanceState) { @@ -123,6 +125,7 @@ protected void onCreate(Bundle savedInstanceState) { intentFilter.addAction(CrashReporterService.CRASH_ACTION); registerReceiver(mCrashReceiver, intentFilter, getString(R.string.app_permission_name), null); + isDimmed = false; mLastGesture = NoGesture; super.onCreate(savedInstanceState); @@ -794,9 +797,12 @@ public void popBackHandler(Runnable aRunnable) { @Override public void fadeOutWorld() { - if (SessionStore.get().isCurrentSessionPrivate() ^ + if (!isDimmed && (SessionStore.get().isCurrentSessionPrivate() ^ mNavigationBar.isInFocusMode() ^ - mTray.isSettingsDialogOpened()) { + mTray.isSettingsDialogOpened() ^ + mPermissionDelegate.isPermissionDialogVisible() ^ + (mCrashDialog != null && mCrashDialog.isVisible()))) { + isDimmed = true; queueRunnable(new Runnable() { @Override public void run() { @@ -808,9 +814,12 @@ public void run() { @Override public void fadeInWorld() { - if ((!SessionStore.get().isCurrentSessionPrivate() && + if (isDimmed && (!SessionStore.get().isCurrentSessionPrivate() && !mNavigationBar.isInFocusMode() && - !mTray.isSettingsDialogOpened())) { + !mTray.isSettingsDialogOpened() && + !mPermissionDelegate.isPermissionDialogVisible() && + !(mCrashDialog != null && mCrashDialog.isVisible()))) { + isDimmed = false; queueRunnable(new Runnable() { @Override public void run() { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/CrashDialogWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/CrashDialogWidget.java index b0aa2681e9..83d0fb1a85 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/CrashDialogWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/CrashDialogWidget.java @@ -15,10 +15,11 @@ import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.SessionStore; import org.mozilla.vrbrowser.SettingsStore; +import org.mozilla.vrbrowser.WidgetManagerDelegate; import org.mozilla.vrbrowser.WidgetPlacement; import org.mozilla.vrbrowser.audio.AudioEngine; -public class CrashDialogWidget extends UIWidget { +public class CrashDialogWidget extends UIWidget implements WidgetManagerDelegate.FocusChangeListener { private static final String LOGTAG = "VRB"; public interface CrashDialogDelegate { @@ -50,6 +51,8 @@ public CrashDialogWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) { private void initialize(Context aContext) { inflate(aContext, R.layout.crash_dialog, this); + mWidgetManager.addFocusChangeListener(this); + mLearnMoreButton = findViewById(R.id.learnMoreButton); mDontSendButton = findViewById(R.id.dontSendButton); mSendDataButton = findViewById(R.id.sendDataButton); @@ -69,7 +72,7 @@ public void onClick(View view) { SessionStore.get().loadUri(getContext().getString(R.string.crash_dialog_learn_more_url)); - hide(); + onDismiss(); } }); mDontSendButton.setOnClickListener(new OnClickListener() { @@ -79,7 +82,7 @@ public void onClick(View view) { mAudio.playSound(AudioEngine.Sound.CLICK); } - hide(); + onDismiss(); } }); mSendDataButton.setOnClickListener(new OnClickListener() { @@ -89,13 +92,13 @@ public void onClick(View view) { mAudio.playSound(AudioEngine.Sound.CLICK); } + hide(); + if(mCrashDialogDelegate != null) { mCrashDialogDelegate.onSendData(); } SettingsStore.getInstance(getContext()).setCrashReportingEnabled(mSendDataCheckBox.isChecked()); - - hide(); } }); @@ -113,6 +116,13 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mAudio = AudioEngine.fromContext(aContext); } + @Override + public void releaseWidget() { + mWidgetManager.removeFocusChangeListener(this); + + super.releaseWidget(); + } + @Override protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { aPlacement.visible = false; @@ -127,13 +137,28 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { } @Override - protected void onBackButton() { - hide(); - if (mDelegate != null) - mDelegate.onWidgetClosed(getHandle()); + public void show() { + super.show(); + + mWidgetManager.fadeOutWorld(); + } + + @Override + public void hide() { + super.hide(); + + mWidgetManager.fadeInWorld(); } public void setCrashDialogDelegate(CrashDialogDelegate aDelegate) { mCrashDialogDelegate = aDelegate; } + + // WidgetManagerDelegate.FocusChangeListener + @Override + public void onGlobalFocusChanged(View oldFocus, View newFocus) { + if (oldFocus == this && isVisible()) { + onDismiss(); + } + } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/DeveloperOptionsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/DeveloperOptionsWidget.java index 354672cbda..11874f2add 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/DeveloperOptionsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/DeveloperOptionsWidget.java @@ -10,7 +10,6 @@ import android.view.View; import android.widget.CompoundButton; import android.widget.RadioGroup; -import android.widget.TextView; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.SessionStore; @@ -78,7 +77,7 @@ public void onClick(View view) { mAudio.playSound(AudioEngine.Sound.CLICK); } - onBackButton(); + onDismiss(); } }); @@ -175,11 +174,21 @@ private void showRestartDialog() { if (widget == null) { widget = createChild(RestartDialogWidget.class, false); mRestartDialogHandle = widget.getHandle(); + widget.setDelegate(new Delegate() { + @Override + public void onDismiss() { + onRestartDialogDismissed(); + } + }); } widget.show(); } + private void onRestartDialogDismissed() { + show(); + } + private SwitchSetting.OnCheckedChangeListener mRemoteDebuggingListener = new SwitchSetting.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean value, boolean doApply) { @@ -198,6 +207,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean value, boole @Override public void onCheckedChanged(CompoundButton compoundButton, boolean value, boolean doApply) { setEnvOverride(value); + showRestartDialog(); } }; diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/KeyboardWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/KeyboardWidget.java index fd2169ddda..66914e4371 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/KeyboardWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/KeyboardWidget.java @@ -27,7 +27,6 @@ import org.mozilla.geckoview.GeckoSession; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.SessionStore; -import org.mozilla.vrbrowser.Widget; import org.mozilla.vrbrowser.WidgetManagerDelegate; import org.mozilla.vrbrowser.WidgetPlacement; import org.mozilla.vrbrowser.telemetry.TelemetryWrapper; @@ -173,7 +172,7 @@ public void onClick(View view) { mBackHandler = new Runnable() { @Override public void run() { - onBackButton(); + onDismiss(); } }; @@ -257,7 +256,7 @@ public void dismiss() { mPopupKeyboardLayer.setVisibility(View.GONE); } - protected void onBackButton() { + protected void onDismiss() { dismiss(); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/PermissionWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/PermissionWidget.java index a04a93ec5e..7ac333d8e6 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/PermissionWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/PermissionWidget.java @@ -109,6 +109,20 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { aPlacement.anchorY = 0.5f; } + @Override + public void show() { + super.show(); + + mWidgetManager.fadeOutWorld(); + } + + @Override + public void hide() { + super.hide(); + + mWidgetManager.fadeInWorld(); + } + public void showPrompt(String aUri, PermissionType aType, GeckoSession.PermissionDelegate.Callback aCallback) { int messageId; int iconId; @@ -180,14 +194,14 @@ private void handlePermissionResult(boolean aGranted) { } mPermissionCallback = null; - hide(); + onDismiss(); } // WidgetManagerDelegate.FocusChangeListener @Override public void onGlobalFocusChanged(View oldFocus, View newFocus) { - if (oldFocus == this) { - hide(); + if (oldFocus == this && isVisible()) { + onDismiss(); } } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/RestartDialogWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/RestartDialogWidget.java index 30febb6063..64c0106080 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/RestartDialogWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/RestartDialogWidget.java @@ -67,7 +67,7 @@ public void onClick(View view) { mAudio.playSound(AudioEngine.Sound.CLICK); } - onBackButton(); + onDismiss(); } }); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/SettingsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/SettingsWidget.java index b0f1381a38..a48084a4bf 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/SettingsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/SettingsWidget.java @@ -28,12 +28,11 @@ import java.util.Calendar; import java.util.GregorianCalendar; -public class SettingsWidget extends UIWidget { +public class SettingsWidget extends UIWidget implements WidgetManagerDelegate.FocusChangeListener { private static final String LOGTAG = "VRB"; private AudioEngine mAudio; - private int mRestartDialogHandle = -1; private int mDeveloperOptionsDialogHandle = -1; private TextView mBuildText; @@ -77,6 +76,8 @@ public SettingsWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) { private void initialize(Context aContext) { inflate(aContext, R.layout.settings, this); + mWidgetManager.addFocusChangeListener(this); + ImageButton cancelButton = findViewById(R.id.settingsCancelButton); cancelButton.setOnClickListener(new OnClickListener() { @@ -86,7 +87,7 @@ public void onClick(View v) { mAudio.playSound(AudioEngine.Sound.CLICK); } - onBackButton(); + onDismiss(); } }); @@ -189,6 +190,8 @@ public void onClick(View view) { @Override public void releaseWidget() { + mWidgetManager.removeFocusChangeListener(this); + super.releaseWidget(); } @@ -297,18 +300,6 @@ private String versionCodeToDate(final int aVersionCode) { return formatted; } - private void showRestartDialog() { - UIWidget widget = getChild(mRestartDialogHandle); - if (widget == null) { - widget = createChild(RestartDialogWidget.class, false); - mRestartDialogHandle = widget.getHandle(); - } - - widget.show(); - - hide(); - } - private void showDeveloperOptionsDialog() { hide(); @@ -316,26 +307,37 @@ private void showDeveloperOptionsDialog() { if (widget == null) { widget = createChild(DeveloperOptionsWidget.class, false); mDeveloperOptionsDialogHandle = widget.getHandle(); + widget.setDelegate(new Delegate() { + @Override + public void onDismiss() { + onDeveloperOptionsDialogDismissed(); + } + }); } widget.show(); } - @Override - public void toggle() { - super.toggle(); - - if (!isVisible()) - mWidgetManager.fadeInWorld(); - else - mWidgetManager.fadeOutWorld(); + private void onDeveloperOptionsDialogDismissed() { + show(); + mWidgetManager.fadeInWorld(); } + // WindowManagerDelegate.FocusChangeListener @Override - protected void onBackButton() { - super.onBackButton(); + public void onGlobalFocusChanged(View oldFocus, View newFocus) { + boolean dismiss = false; + UIWidget widget = getChild(mDeveloperOptionsDialogHandle); + if (widget != null && oldFocus == widget && widget.isVisible()) { + dismiss = true; - mWidgetManager.fadeInWorld(); + } else if (oldFocus == this && isVisible()) { + dismiss = true; + } + + if (dismiss) { + onDismiss(); + } } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/TrayWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/TrayWidget.java index 8631881df1..22ecb5d0e4 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/TrayWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/TrayWidget.java @@ -8,16 +8,15 @@ import android.content.Context; import android.util.AttributeSet; import android.view.View; + import org.mozilla.geckoview.GeckoSession; import org.mozilla.geckoview.GeckoSessionSettings; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.SessionStore; -import org.mozilla.vrbrowser.WidgetManagerDelegate; import org.mozilla.vrbrowser.WidgetPlacement; import org.mozilla.vrbrowser.audio.AudioEngine; -public class TrayWidget extends UIWidget implements SessionStore.SessionChangeListener, - WidgetManagerDelegate.FocusChangeListener { +public class TrayWidget extends UIWidget implements SessionStore.SessionChangeListener { private static final String LOGTAG = "VRB"; @@ -46,18 +45,17 @@ public TrayWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) { private void initialize(Context aContext) { inflate(aContext, R.layout.tray, this); - mWidgetManager.addFocusChangeListener(this); - mHelpButton = findViewById(R.id.helpButton); mHelpButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - view.requestFocusFromTouch(); if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } onHelpButtonClicked(); + + view.requestFocusFromTouch(); } }); @@ -65,12 +63,13 @@ public void onClick(View view) { mPrivateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - view.requestFocusFromTouch(); if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } SessionStore.get().switchPrivateMode(); + + view.requestFocusFromTouch(); } }); @@ -78,14 +77,14 @@ public void onClick(View view) { mSettingsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - if (!isChildVisible(mSettingsDialogHandle)) - view.requestFocusFromTouch(); - if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } - showSettingsDialog(); + toggleSettingsDialog(); + + if (isSettingsDialogOpened()) + view.requestFocusFromTouch(); } }); @@ -115,7 +114,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { @Override public void releaseWidget() { - mWidgetManager.removeFocusChangeListener(this); SessionStore.get().removeSessionChangeListener(this); super.releaseWidget(); @@ -152,14 +150,31 @@ public void onCurrentSessionChange(GeckoSession aSession, int aId) { mIsLastSessionPrivate = isPrivateMode; } - private void showSettingsDialog() { + private void toggleSettingsDialog() { UIWidget widget = getChild(mSettingsDialogHandle); if (widget == null) { widget = createChild(SettingsWidget.class, false); mSettingsDialogHandle = widget.getHandle(); + widget.setDelegate(new Delegate() { + @Override + public void onDismiss() { + onSettingsDialogDismissed(); + } + }); + } + + if (widget.isVisible()) { + widget.hide(); + mWidgetManager.fadeInWorld(); + + } else { + widget.show(); + mWidgetManager.fadeOutWorld(); } + } - widget.toggle(); + private void onSettingsDialogDismissed() { + mWidgetManager.fadeInWorld(); } @Override @@ -180,7 +195,11 @@ public void hide() { public boolean isSettingsDialogOpened() { - return isChildVisible(mSettingsDialogHandle); + UIWidget widget = getChild(mSettingsDialogHandle); + if (widget != null) { + return widget.isVisible(); + } + return false; } private void onHelpButtonClicked() { @@ -193,15 +212,4 @@ private void onHelpButtonClicked() { SessionStore.get().loadUri(getContext().getString(R.string.help_url)); } - - // WindowManagerDelegate.FocusChangeListener - @Override - public void onGlobalFocusChanged(View oldFocus, View newFocus) { - if (isSettingsDialogOpened()) { - UIWidget child = getChild(mSettingsDialogHandle); - if (child != null) { - child.toggle(); - } - } - } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/UIWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/UIWidget.java index 7abb81b212..4d0f1eacfd 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/UIWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/UIWidget.java @@ -27,6 +27,10 @@ public abstract class UIWidget extends FrameLayout implements Widget { private static final String LOGTAG = "VRB"; + public interface Delegate { + void onDismiss(); + } + private UISurfaceTextureRenderer mRenderer; private SurfaceTexture mTexture; protected int mHandle; @@ -36,11 +40,7 @@ public abstract class UIWidget extends FrameLayout implements Widget { protected int mInitialHeight; protected Runnable mBackHandler; protected HashMap mChildren; - protected UIWidgetDelegate mDelegate; - - public interface UIWidgetDelegate { - void onWidgetClosed(int aHandle); - } + protected Delegate mDelegate; public UIWidget(Context aContext) { super(aContext); @@ -69,11 +69,12 @@ private void initialize() { mBackHandler = new Runnable() { @Override public void run() { - onBackButton(); + onDismiss(); } }; } + protected abstract void initializeWidgetPlacement(WidgetPlacement aPlacement); @Override @@ -201,7 +202,7 @@ public ViewParent invalidateChildInParent(int[] aLocation, Rect aDirty) { return parent; } - public void setDelegate(UIWidgetDelegate aDelegate) { + public void setDelegate(Delegate aDelegate) { mDelegate = aDelegate; } @@ -250,15 +251,6 @@ public boolean isVisible() { return mWidgetPlacement.visible; } - public boolean isChildVisible(int aHandle) { - UIWidget widget = getChild(aHandle); - if (widget != null) { - return widget.isVisible(); - } - - return false; - } - protected T createChild(@NonNull Class aChildClassName) { return createChild(aChildClassName, true); } @@ -267,15 +259,9 @@ protected T createChild(@NonNull Class aChildClassName, try { Constructor constructor = aChildClassName.getConstructor(new Class[] { Context.class }); UIWidget child = (UIWidget) constructor.newInstance(new Object[] { getContext() }); - if (inheritPlacement) + if (inheritPlacement) { child.getPlacement().parentHandle = getHandle(); - child.setDelegate(new UIWidgetDelegate() { - - @Override - public void onWidgetClosed(int aHandle) { - onChildClosed(aHandle); - } - }); + } mChildren.put(child.mHandle, child); return aChildClassName.cast(child); @@ -292,29 +278,12 @@ protected T getChild(int aChildId) { return (T) mChildren.get(aChildId); } - protected void removeChild(int aChildId) { - UIWidget child = mChildren.get(aChildId); - if (child != null) { - child.hide(); - mChildren.remove(aChildId); - child.releaseWidget(); - } - } - - protected void removeAllChildren() { - for (UIWidget child : mChildren.values()) { - removeChild(child.mHandle); - } - mChildren.clear(); - } - - protected void onChildClosed(int aHandle) { - show(); - } - protected void onBackButton() { + protected void onDismiss() { hide(); - if (mDelegate != null) - mDelegate.onWidgetClosed(getHandle()); + + if (mDelegate != null) { + mDelegate.onDismiss(); + } } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/prompts/ChoicePromptWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/prompts/ChoicePromptWidget.java index 080486fe8f..8b91302748 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/prompts/ChoicePromptWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/prompts/ChoicePromptWidget.java @@ -171,7 +171,7 @@ public void releaseWidget() { } @Override - protected void onBackButton() { + protected void onDismiss() { hide(); if (mPromptDelegate != null) { @@ -401,7 +401,7 @@ public boolean onHover(View view, MotionEvent motionEvent) { // WidgetManagerDelegate.FocusChangeListener @Override public void onGlobalFocusChanged(View oldFocus, View newFocus) { - if (oldFocus == this) { + if (oldFocus == this && isVisible()) { if (mPromptDelegate != null) { mPromptDelegate.onDismissed(getDefaultChoices(mListItems)); }