From 105bd17f0b91f82d0be8c144dddba1daa6cf328f Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Thu, 29 Aug 2019 22:55:18 +0200 Subject: [PATCH] Hide notification if tray is detached or hidden (#1708) --- .../vrbrowser/ui/widgets/TrayWidget.java | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java index 0859fba81..475e929ae 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java @@ -8,7 +8,6 @@ import android.animation.Animator; import android.animation.ValueAnimator; import android.content.Context; -import android.graphics.PointF; import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; @@ -281,6 +280,8 @@ public void show(@ShowFlags int aShowFlags) { @Override public void hide(@HideFlags int aHideFlags) { + ThreadUtils.postToUiThread(hideBookmarkNotification); + if (mWidgetPlacement.visible) { mWidgetPlacement.visible = false; if (aHideFlags == REMOVE_WIDGET) { @@ -293,6 +294,8 @@ public void hide(@HideFlags int aHideFlags) { @Override public void detachFromWindow() { + ThreadUtils.postToUiThread(hideBookmarkNotification); + if (mSessionStack != null) { mSessionStack.removeSessionChangeListener(this); mSessionStack = null; @@ -460,35 +463,45 @@ public void onBookmarksUpdated() { @Override public void onBookmarkAdded() { mBookmarksButton.setNotificationMode(true); - ThreadUtils.postToUiThread(() -> { - if (mLibraryNotification != null && mLibraryNotification.isVisible()) { - return; - } + ThreadUtils.postToUiThread(showBookmarkNotification); + } + }; - Rect offsetViewBounds = new Rect(); - getDrawingRect(offsetViewBounds); - offsetDescendantRectToMyCoords(mBookmarksButton, offsetViewBounds); - - float ratio = WidgetPlacement.viewToWidgetRatio(getContext(), TrayWidget.this); - - mLibraryNotification = new TooltipWidget(getContext(), R.layout.library_notification); - mLibraryNotification.getPlacement().parentHandle = getHandle(); - mLibraryNotification.getPlacement().anchorY = 0.0f; - mLibraryNotification.getPlacement().translationX = (offsetViewBounds.left + mBookmarksButton.getWidth() / 2.0f) * ratio; - mLibraryNotification.getPlacement().translationY = ((offsetViewBounds.top - 60) * ratio); - mLibraryNotification.getPlacement().translationZ = 25.0f; - mLibraryNotification.getPlacement().density = 3.0f; - mLibraryNotification.setText(R.string.bookmarks_saved_notification); - mLibraryNotification.setCurvedMode(false); - mLibraryNotification.show(UIWidget.CLEAR_FOCUS); - - ThreadUtils.postDelayedToUiThread(() -> { - if (mLibraryNotification != null) { - mLibraryNotification.hide(UIWidget.REMOVE_WIDGET); - } - mBookmarksButton.setNotificationMode(false); - }, LIBRARY_NOTIFICATION_DURATION); - }); + private Runnable showBookmarkNotification = new Runnable() { + @Override + public void run() { + if (mLibraryNotification != null && mLibraryNotification.isVisible()) { + return; + } + + Rect offsetViewBounds = new Rect(); + getDrawingRect(offsetViewBounds); + offsetDescendantRectToMyCoords(mBookmarksButton, offsetViewBounds); + + float ratio = WidgetPlacement.viewToWidgetRatio(getContext(), TrayWidget.this); + + mLibraryNotification = new TooltipWidget(getContext(), R.layout.library_notification); + mLibraryNotification.getPlacement().parentHandle = getHandle(); + mLibraryNotification.getPlacement().anchorY = 0.0f; + mLibraryNotification.getPlacement().translationX = (offsetViewBounds.left + mBookmarksButton.getWidth() / 2.0f) * ratio; + mLibraryNotification.getPlacement().translationY = ((offsetViewBounds.top - 60) * ratio); + mLibraryNotification.getPlacement().translationZ = 25.0f; + mLibraryNotification.getPlacement().density = 3.0f; + mLibraryNotification.setText(R.string.bookmarks_saved_notification); + mLibraryNotification.setCurvedMode(false); + mLibraryNotification.show(UIWidget.CLEAR_FOCUS); + + ThreadUtils.postDelayedToUiThread(hideBookmarkNotification, LIBRARY_NOTIFICATION_DURATION); + } + }; + + private Runnable hideBookmarkNotification = new Runnable() { + @Override + public void run() { + if (mLibraryNotification != null) { + mLibraryNotification.hide(UIWidget.REMOVE_WIDGET); + } + mBookmarksButton.setNotificationMode(false); } };