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

Commit

Permalink
Fixes #2375 Fixes #2564 Improve notification visibility (#2655)
Browse files Browse the repository at this point in the history
* Improve notification visibility/management

* Rebase fixes
  • Loading branch information
keianhzo authored Feb 5, 2020
1 parent b73b391 commit 6c51e61
Show file tree
Hide file tree
Showing 10 changed files with 419 additions and 98 deletions.
10 changes: 10 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,16 @@ public TrayWidget getTray() {
return mTray;
}

@Override
public NavigationBarWidget getNavigationBar() {
return mNavigationBar;
}

@Override
public Windows getWindows() {
return mWindows;
}

@Override
public void saveState() {
mWindows.saveState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ private void initialize(Context aContext) {

// Bookmarks
mBinding.bookmarkButton.setOnClickListener(v -> {
v.requestFocusFromTouch();
handleBookmarkClick();
});

Expand Down Expand Up @@ -392,7 +391,6 @@ public void setClickable(boolean clickable) {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
view.requestFocusFromTouch();

if (mDelegate != null) {
mDelegate.onVoiceSearchClicked();
Expand All @@ -415,7 +413,6 @@ public void setClickable(boolean clickable) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}

view.requestFocusFromTouch();
if (mDelegate != null) {
mDelegate.onPopUpButtonClicked();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
SharedPreferences.OnSharedPreferenceChangeListener, SuggestionsWidget.URLBarPopupDelegate,
TrayListener, WindowWidget.WindowListener {

private static final int NOTIFICATION_DURATION = 3000;
private static final int TAB_ADDED_NOTIFICATION_ID = 0;
private static final int TAB_SENT_NOTIFICATION_ID = 1;
private static final int BOOKMARK_ADDED_NOTIFICATION_ID = 2;
private static final int POPUP_NOTIFICATION_ID = 3;

private WindowViewModel mViewModel;
private NavigationBarBinding mBinding;
Expand All @@ -86,7 +89,6 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private @VideoProjectionMenuWidget.VideoProjectionFlags int mAutoSelectedProjection = VIDEO_PROJECTION_NONE;
private HamburgerMenuWidget mHamburgerMenu;
private SendTabDialogWidget mSendTabDialog;
private TooltipWidget mPopUpNotification;
private int mBlockedCount;
private Executor mUIThreadExecutor;

Expand Down Expand Up @@ -375,7 +377,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {

@Override
public void detachFromWindow() {
hideNotification(mBinding.navigationBarNavigation.urlBar.getPopUpButton());
hideNotification();

if (mAttachedWindow != null && mAttachedWindow.isResizing()) {
exitResizeMode(ResizeAction.RESTORE_SIZE);
Expand Down Expand Up @@ -1028,7 +1030,7 @@ public void showPopUpsBlockedNotification() {
final int currentCount = mBlockedCount;
postDelayed(() -> {
if (currentCount == mBlockedCount) {
showNotification(mBinding.navigationBarNavigation.urlBar.getPopUpButton(), R.string.popup_tooltip);
showNotification(POPUP_NOTIFICATION_ID, mBinding.navigationBarNavigation.urlBar.getPopUpButton(), R.string.popup_tooltip);
}
}, POP_UP_NOTIFICATION_DELAY);
}
Expand All @@ -1038,7 +1040,7 @@ public void hidePopUpsBlockedNotification() {
final int currentCount = mBlockedCount;
post(() -> {
if (currentCount == mBlockedCount) {
hideNotification(mBinding.navigationBarNavigation.urlBar.getPopUpButton());
hideNotification();
}
});
}
Expand All @@ -1047,37 +1049,37 @@ public void hideNotifications() {
hidePopUpsBlockedNotification();
}

private void showNotification(UIButton button, int stringRes) {
if (mPopUpNotification != null && mPopUpNotification.isVisible()) {
return;
}
public void showTabAddedNotification() {
showNotification(TAB_ADDED_NOTIFICATION_ID, R.string.tab_added_notification);
}

Rect offsetViewBounds = new Rect();
getDrawingRect(offsetViewBounds);
offsetDescendantRectToMyCoords(button, offsetViewBounds);

float ratio = WidgetPlacement.viewToWidgetRatio(getContext(), this);

mPopUpNotification = new TooltipWidget(getContext(), R.layout.library_notification);
mPopUpNotification.getPlacement().parentHandle = getHandle();
mPopUpNotification.getPlacement().anchorY = 0.0f;
mPopUpNotification.getPlacement().translationX = (getPaddingLeft() + offsetViewBounds.left + button.getWidth() / 2.0f) * ratio;
mPopUpNotification.getPlacement().translationY = ((offsetViewBounds.top - 60) * ratio);
mPopUpNotification.getPlacement().translationZ = 1.0f;
mPopUpNotification.getPlacement().density = WidgetPlacement.floatDimension(getContext(), R.dimen.tooltip_default_density);
mPopUpNotification.setText(stringRes);
mPopUpNotification.setCurvedMode(true);
mPopUpNotification.show(UIWidget.CLEAR_FOCUS);

postDelayed(() -> hideNotification(button), NOTIFICATION_DURATION);
public void showTabSentNotification() {
showNotification(TAB_SENT_NOTIFICATION_ID, R.string.tab_sent_notification);
}

private void hideNotification(UIButton button) {
if (mPopUpNotification != null) {
mPopUpNotification.hide(UIWidget.REMOVE_WIDGET);
mPopUpNotification = null;
}
button.setNotificationMode(false);
public void showBookmarkAddedNotification() {
showNotification(BOOKMARK_ADDED_NOTIFICATION_ID, R.string.bookmarks_saved_notification);
}

private void showNotification(int notificationId, UIButton button, int stringRes) {
NotificationManager.Notification notification = new NotificationManager.Builder(this)
.withView(button)
.withString(stringRes)
.withPosition(NotificationManager.Notification.BOTTOM)
.withMargin(20.0f).build();
NotificationManager.show(notificationId, notification);
}

private void showNotification(int notificationId, int stringRes) {
NotificationManager.Notification notification = new NotificationManager.Builder(this)
.withString(stringRes)
.withPosition(NotificationManager.Notification.BOTTOM)
.withMargin(20.0f).build();
NotificationManager.show(notificationId, notification);
}

private void hideNotification() {
NotificationManager.hideAll();
}

private ConnectivityReceiver.Delegate mConnectivityDelegate = connected -> {
Expand Down
Loading

0 comments on commit 6c51e61

Please sign in to comment.