Bug 884075 - Include a reason when hiding a toast. r=margaret
☠☠ backed out by 69d9290e58ee ☠ ☠
authorWes Johnston <wjohnston@mozilla.com>
Tue, 16 Jul 2013 01:33:06 -0700
changeset 138647 46f75b2f314c755bd04a66da99c85a0453aba5ec
parent 138646 59a25222200e6dce173a95f1c5332093f78a4f8d
child 138648 f1d3ac351fddbe202d0af0d3ed5e6b3f877c58a3
push id24964
push userryanvm@gmail.com
push dateTue, 16 Jul 2013 20:04:09 +0000
treeherdermozilla-central@fd10ead17ace [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs884075
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 884075 - Include a reason when hiding a toast. r=margaret
mobile/android/base/BrowserApp.java
mobile/android/base/widget/ButtonToast.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -1681,16 +1681,19 @@ abstract public class BrowserApp extends
                             getResources().getString(R.string.bookmark_added),
                             getResources().getString(R.string.bookmark_options),
                             null,
                             new ButtonToast.ToastListener() {
                                 @Override
                                 public void onButtonClicked() {
                                     showBookmarkDialog();
                                 }
+
+                                @Override
+                                public void onToastHidden(ButtonToast.ReasonHidden reason) { }
                             });
                         item.setIcon(R.drawable.ic_menu_bookmark_remove);
                     }
                 }
                 return true;
             case R.id.share:
                 shareCurrentUrl();
                 return true;
--- a/mobile/android/base/widget/ButtonToast.java
+++ b/mobile/android/base/widget/ButtonToast.java
@@ -42,16 +42,22 @@ public class ButtonToast {
     private final TextView mMessageView;
     private final Button mButton;
     private final Handler mHideHandler = new Handler();
 
     private final ToastListener mListener;
     private final LinkedList<Toast> mQueue = new LinkedList<Toast>();
     private Toast mCurrentToast;
 
+    public enum ReasonHidden {
+        CLICKED,
+        TIMEOUT,
+        STARTUP
+    }
+
     // State objects
     private static class Toast {
         public final CharSequence buttonMessage;
         public Drawable buttonDrawable;
         public final CharSequence message;
         public ToastListener listener;
 
         public Toast(CharSequence aMessage, CharSequence aButtonMessage,
@@ -60,38 +66,39 @@ public class ButtonToast {
             buttonMessage = aButtonMessage;
             buttonDrawable = aDrawable;
             listener = aListener;
         }
     }
 
     public interface ToastListener {
         void onButtonClicked();
+        void onToastHidden(ReasonHidden reason);
     }
 
     public ButtonToast(View view) {
         mView = view;
         mListener = null;
         mMessageView = (TextView) mView.findViewById(R.id.toast_message);
         mButton = (Button) mView.findViewById(R.id.toast_button);
         mButton.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
                         Toast t = mCurrentToast;
                         if (t == null)
                             return;
 
-                        hide(false);
+                        hide(false, ReasonHidden.CLICKED);
                         if (t.listener != null) {
                             t.listener.onButtonClicked();
                         }
                     }
                 });
 
-        hide(true);
+        hide(true, ReasonHidden.STARTUP);
     }
 
     public void show(boolean immediate, CharSequence message,
                      CharSequence buttonMessage, Drawable buttonDrawable,
                      ToastListener listener) {
         show(new Toast(message, buttonMessage, buttonDrawable, listener), immediate);
     }
 
@@ -118,22 +125,25 @@ public class ButtonToast {
 
         mView.clearAnimation();
         AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
         alpha.setDuration(duration);
         alpha.setFillAfter(true);
         mView.startAnimation(alpha);
     }
 
-    public void hide(boolean immediate) {
-        if (mButton.isPressed()) {
+    public void hide(boolean immediate, ReasonHidden reason) {
+        if (mButton.isPressed() && reason != ReasonHidden.CLICKED) {
             mHideHandler.postDelayed(mHideRunnable, TOAST_DURATION);
             return;
         }
 
+        if (mCurrentToast != null && mCurrentToast.listener != null) {
+            mCurrentToast.listener.onToastHidden(reason);
+        }
         mCurrentToast = null;
         mButton.setEnabled(false);
         mHideHandler.removeCallbacks(mHideRunnable);
         int duration = immediate ? 0 : mView.getResources().getInteger(android.R.integer.config_longAnimTime);
 
         mView.clearAnimation();
         if (immediate) {
             mView.setVisibility(View.GONE);
@@ -168,12 +178,12 @@ public class ButtonToast {
         if (t != null) {
             show(t, false);
         }
     }
 
     private Runnable mHideRunnable = new Runnable() {
         @Override
         public void run() {
-            hide(false);
+            hide(false, ReasonHidden.TIMEOUT);
         }
     };
 }