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

Commit 3c90e7f

Browse files
authored
Fixes #2760 Fixes #2759 Fixes #2762 Notification fixes (#2769)
* Fix Popup notification position * Do not request focus for notifications * Just hide the popup notification when it times-out
1 parent fef9ed2 commit 3c90e7f

3 files changed

Lines changed: 37 additions & 26 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ protected void initializeWidgets() {
311311
public void onFocusedWindowChanged(@NonNull WindowWidget aFocusedWindow, @Nullable WindowWidget aPrevFocusedWindow) {
312312
attachToWindow(aFocusedWindow, aPrevFocusedWindow);
313313
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
314-
mNavigationBar.hideNotifications();
314+
mNavigationBar.hideAllNotifications();
315315
}
316316
@Override
317317
public void onWindowBorderChanged(@NonNull WindowWidget aChangeWindow) {
@@ -320,14 +320,14 @@ public void onWindowBorderChanged(@NonNull WindowWidget aChangeWindow) {
320320

321321
@Override
322322
public void onWindowsMoved() {
323-
mNavigationBar.hideNotifications();
323+
mNavigationBar.hideAllNotifications();
324324
updateWidget(mTray);
325325
}
326326

327327
@Override
328328
public void onWindowClosed() {
329329
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
330-
mNavigationBar.hideNotifications();
330+
mNavigationBar.hideAllNotifications();
331331
updateWidget(mTray);
332332
}
333333

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.mozilla.vrbrowser.ui.views.NavigationURLBar;
4343
import org.mozilla.vrbrowser.ui.views.UIButton;
4444
import org.mozilla.vrbrowser.ui.views.UITextButton;
45+
import org.mozilla.vrbrowser.ui.widgets.NotificationManager.Notification.NotificationPosition;
4546
import org.mozilla.vrbrowser.ui.widgets.dialogs.SelectionActionWidget;
4647
import org.mozilla.vrbrowser.ui.widgets.dialogs.SendTabDialogWidget;
4748
import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget;
@@ -377,7 +378,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
377378

378379
@Override
379380
public void detachFromWindow() {
380-
hideNotification();
381+
hideAllNotifications();
381382

382383
if (mAttachedWindow != null && mAttachedWindow.isResizing()) {
383384
exitResizeMode(ResizeAction.RESTORE_SIZE);
@@ -585,7 +586,7 @@ private void enterResizeMode() {
585586
}
586587
}
587588

588-
hideNotifications();
589+
hideAllNotifications();
589590

590591
// Update preset styles
591592
}
@@ -1030,7 +1031,10 @@ public void showPopUpsBlockedNotification() {
10301031
final int currentCount = mBlockedCount;
10311032
postDelayed(() -> {
10321033
if (currentCount == mBlockedCount) {
1033-
showNotification(POPUP_NOTIFICATION_ID, mBinding.navigationBarNavigation.urlBar.getPopUpButton(), R.string.popup_tooltip);
1034+
showNotification(POPUP_NOTIFICATION_ID,
1035+
mBinding.navigationBarNavigation.urlBar.getPopUpButton(),
1036+
NotificationManager.Notification.TOP,
1037+
R.string.popup_tooltip);
10341038
}
10351039
}, POP_UP_NOTIFICATION_DELAY);
10361040
}
@@ -1040,48 +1044,54 @@ public void hidePopUpsBlockedNotification() {
10401044
final int currentCount = mBlockedCount;
10411045
post(() -> {
10421046
if (currentCount == mBlockedCount) {
1043-
hideNotification();
1047+
hideNotification(POPUP_NOTIFICATION_ID);
10441048
}
10451049
});
10461050
}
10471051

1048-
public void hideNotifications() {
1049-
hidePopUpsBlockedNotification();
1050-
}
1051-
10521052
public void showTabAddedNotification() {
1053-
showNotification(TAB_ADDED_NOTIFICATION_ID, R.string.tab_added_notification);
1053+
showNotification(TAB_ADDED_NOTIFICATION_ID,
1054+
NotificationManager.Notification.BOTTOM,
1055+
R.string.tab_added_notification);
10541056
}
10551057

10561058
public void showTabSentNotification() {
1057-
showNotification(TAB_SENT_NOTIFICATION_ID, R.string.tab_sent_notification);
1059+
showNotification(TAB_SENT_NOTIFICATION_ID,
1060+
NotificationManager.Notification.BOTTOM,
1061+
R.string.tab_sent_notification);
10581062
}
10591063

10601064
public void showBookmarkAddedNotification() {
1061-
showNotification(BOOKMARK_ADDED_NOTIFICATION_ID, R.string.bookmarks_saved_notification);
1065+
showNotification(BOOKMARK_ADDED_NOTIFICATION_ID,
1066+
NotificationManager.Notification.BOTTOM,
1067+
R.string.bookmarks_saved_notification);
10621068
}
10631069

1064-
private void showNotification(int notificationId, UIButton button, int stringRes) {
1070+
private void showNotification(int notificationId, UIButton button, @NotificationPosition int position, int stringRes) {
10651071
NotificationManager.Notification notification = new NotificationManager.Builder(this)
10661072
.withView(button)
10671073
.withString(stringRes)
1068-
.withPosition(NotificationManager.Notification.BOTTOM)
1074+
.withPosition(position)
10691075
.withMargin(20.0f).build();
10701076
NotificationManager.show(notificationId, notification);
10711077
}
10721078

1073-
private void showNotification(int notificationId, int stringRes) {
1079+
private void showNotification(int notificationId, @NotificationPosition int position, int stringRes) {
10741080
NotificationManager.Notification notification = new NotificationManager.Builder(this)
10751081
.withString(stringRes)
1076-
.withPosition(NotificationManager.Notification.BOTTOM)
1082+
.withPosition(position)
10771083
.withMargin(20.0f).build();
10781084
NotificationManager.show(notificationId, notification);
10791085
}
10801086

1081-
private void hideNotification() {
1087+
public void hideAllNotifications() {
10821088
NotificationManager.hideAll();
10831089
}
10841090

1091+
private void hideNotification(int notificationId) {
1092+
NotificationManager.hide(notificationId);
1093+
}
1094+
10851095
private ConnectivityReceiver.Delegate mConnectivityDelegate = connected -> {
10861096
if (mMediaControlsWidget != null) {
10871097
mMediaControlsWidget.setVisible(connected && mMediaControlsWidget.isVisible());

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NotificationManager.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import android.view.View;
55

66
import androidx.annotation.DimenRes;
7+
import androidx.annotation.IntDef;
78
import androidx.annotation.LayoutRes;
89
import androidx.annotation.NonNull;
910
import androidx.annotation.StringRes;
1011

1112
import org.mozilla.gecko.util.ThreadUtils;
1213
import org.mozilla.vrbrowser.R;
1314
import org.mozilla.vrbrowser.ui.views.UIButton;
15+
import org.mozilla.vrbrowser.ui.widgets.NotificationManager.Notification.NotificationPosition;
1416

1517
import java.util.HashMap;
1618
import java.util.Iterator;
@@ -38,6 +40,8 @@ public NotificationData(@NonNull TooltipWidget view, @NonNull Notification notif
3840

3941
public static class Notification {
4042

43+
@IntDef(value = { MIDDLE, TOP, BOTTOM, LEFT, RIGHT})
44+
public @interface NotificationPosition {}
4145
public static final int MIDDLE = 0;
4246
public static final int TOP = 1;
4347
public static final int BOTTOM = 2;
@@ -49,7 +53,7 @@ public static class Notification {
4953
private String mString;
5054
private float mMargin;
5155
private float mZTranslation;
52-
private int mPositionFlags;
56+
private @NotificationPosition int mPositionFlags;
5357
private @DimenRes int mDensity;
5458
private @LayoutRes int mLayoutRes;
5559
private int mDuration;
@@ -76,7 +80,7 @@ public static class Builder {
7680
private String string;
7781
private float margin = 0.0f;
7882
private float zTranslation = 0.0f;
79-
private int positionFlags = Notification.MIDDLE;
83+
private @NotificationPosition int positionFlags = Notification.MIDDLE;
8084
private @DimenRes int density;
8185
private @LayoutRes int layoutRes = R.layout.library_notification;
8286
private int duration = DEFAULT_DURATION;
@@ -107,7 +111,7 @@ public Builder withMargin(float margin){
107111
return this;
108112
}
109113

110-
public Builder withPosition(int positionFlags) {
114+
public Builder withPosition(@NotificationPosition int positionFlags) {
111115
this.positionFlags = positionFlags;
112116
return this;
113117
}
@@ -150,14 +154,11 @@ public static void show(int notificationId, @NonNull Notification notification)
150154

151155
TooltipWidget notificationView = new TooltipWidget(notification.mParent.getContext(), notification.mLayoutRes);
152156

153-
notification.mParent.requestFocus();
154-
notification.mParent.requestFocusFromTouch();
155-
156157
setPlacement(notificationView, notification);
157158

158159
notificationView.setText(notification.mString);
159160
notificationView.setCurvedMode(false);
160-
notificationView.show(UIWidget.CLEAR_FOCUS);
161+
notificationView.show(UIWidget.KEEP_FOCUS);
161162

162163
if (notification.mView instanceof UIButton) {
163164
((UIButton)notification.mView).setNotificationMode(true);

0 commit comments

Comments
 (0)