From f3ada542aa91d0a2894ccb7557b001a86ebfa548 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Tue, 27 Aug 2019 19:52:55 +0200 Subject: [PATCH] Adds close button when in private mode and one window is left (#1680) --- .../vrbrowser/ui/widgets/TopBarWidget.java | 22 ++++++- .../mozilla/vrbrowser/ui/widgets/Windows.java | 1 + app/src/main/res/drawable/text_button.xml | 31 ++++++++++ .../main/res/drawable/text_button_private.xml | 31 ++++++++++ app/src/main/res/layout/top_bar.xml | 62 ++++++++++++------- app/src/main/res/values/strings.xml | 4 ++ app/src/main/res/values/styles.xml | 15 +++++ 7 files changed, 144 insertions(+), 22 deletions(-) create mode 100644 app/src/main/res/drawable/text_button.xml create mode 100644 app/src/main/res/drawable/text_button_private.xml diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TopBarWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TopBarWidget.java index 6202262ce..d9fdb59bb 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TopBarWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TopBarWidget.java @@ -7,6 +7,7 @@ import android.content.Context; import android.util.AttributeSet; +import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -16,15 +17,18 @@ import org.mozilla.vrbrowser.audio.AudioEngine; import org.mozilla.vrbrowser.browser.SessionChangeListener; import org.mozilla.vrbrowser.ui.views.UIButton; +import org.mozilla.vrbrowser.ui.views.UITextButton; public class TopBarWidget extends UIWidget implements SessionChangeListener, WidgetManagerDelegate.UpdateListener { private UIButton mCloseButton; private UIButton mMoveLeftButton; private UIButton mMoveRightButton; + private UITextButton mClearButton; private AudioEngine mAudio; private WindowWidget mAttachedWindow; private TopBarWidget.Delegate mDelegate; + private LinearLayout mMultiWindowControlsContainer; private boolean mVisible; public TopBarWidget(Context aContext) { @@ -51,6 +55,8 @@ public interface Delegate { private void initialize(Context aContext) { inflate(aContext, R.layout.top_bar, this); + mMultiWindowControlsContainer = findViewById(R.id.multiWindowControlsContainer); + mCloseButton = findViewById(R.id.closeWindowButton); mCloseButton.setOnClickListener(view -> { view.requestFocusFromTouch(); @@ -84,7 +90,16 @@ private void initialize(Context aContext) { } }); - + mClearButton = findViewById(R.id.clearButton); + mClearButton.setOnClickListener(view -> { + view.requestFocusFromTouch(); + if (mAudio != null) { + mAudio.playSound(AudioEngine.Sound.CLICK); + } + if (mDelegate != null) { + mDelegate.onCloseClicked(TopBarWidget.this); + } + }); mAudio = AudioEngine.fromContext(aContext); @@ -164,6 +179,11 @@ public void setVisible(boolean aIsVisible) { } } + public void setClearMode(boolean showClear) { + mMultiWindowControlsContainer.setVisibility(showClear ? GONE : VISIBLE); + mClearButton.setVisibility(showClear ? VISIBLE : GONE); + } + public void setDelegate(TopBarWidget.Delegate aDelegate) { mDelegate = aDelegate; } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java index f116c18ea..92fab8785 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java @@ -662,6 +662,7 @@ private void updateTopBars() { boolean visible = mFullscreenWindow == null && (windows.size() > 1 || isInPrivateMode()); for (WindowWidget window: windows) { window.getTopBar().setVisible(visible); + window.getTopBar().setClearMode((windows.size() == 1 && isInPrivateMode())); if (visible) { window.getTopBar().setMoveLeftButtonEnabled(window != leftWindow); window.getTopBar().setMoveRightButtonEnabled(window != rightWindow); diff --git a/app/src/main/res/drawable/text_button.xml b/app/src/main/res/drawable/text_button.xml new file mode 100644 index 000000000..29fcc68c3 --- /dev/null +++ b/app/src/main/res/drawable/text_button.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/text_button_private.xml b/app/src/main/res/drawable/text_button_private.xml new file mode 100644 index 000000000..0ae770fc7 --- /dev/null +++ b/app/src/main/res/drawable/text_button_private.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/top_bar.xml b/app/src/main/res/layout/top_bar.xml index 4b0eafbae..c2b9cb31d 100644 --- a/app/src/main/res/layout/top_bar.xml +++ b/app/src/main/res/layout/top_bar.xml @@ -1,26 +1,46 @@ - - - - - + android:layout_gravity="center" + android:gravity="center_horizontal"> + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5eb0d26a2..594eb3177 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -901,4 +901,8 @@ History + + + Clear diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index abba99d94..7fb9e77a4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -136,6 +136,21 @@ @drawable/main_button_icon_color_private + +