Bug 1015421 - Don't queue up ButtonToasts. r=margaret
authorWes Johnston <wjohnston@mozilla.com>
Mon, 02 Jun 2014 14:47:02 -0700
changeset 186262 5d9621220437aecf2155f88a847e0ff1fff74e49
parent 186204 4c520a1107b69acf6ed65e4124d4737cc9e9b600
child 186263 4c3e918570c0baaa1c92cfabb1c2a1f1592872cb
push id26885
push usercbook@mozilla.com
push dateTue, 03 Jun 2014 12:46:07 +0000
treeherdermozilla-central@b13d1d327c5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1015421
milestone32.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 1015421 - Don't queue up ButtonToasts. r=margaret
mobile/android/base/GeckoApp.java
mobile/android/base/widget/ButtonToast.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -494,20 +494,16 @@ public abstract class GeckoApp
 
         return super.onKeyDown(keyCode, event);
     }
 
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
 
-        if (mToast != null) {
-            mToast.onSaveInstanceState(outState);
-        }
-
         outState.putBoolean(SAVED_STATE_IN_BACKGROUND, isApplicationInBackground());
         outState.putString(SAVED_STATE_PRIVATE_SESSION, mPrivateBrowsingSession);
     }
 
     void handleClearHistory() {
         BrowserDB.clearHistory(getContentResolver());
     }
 
--- a/mobile/android/base/widget/ButtonToast.java
+++ b/mobile/android/base/widget/ButtonToast.java
@@ -33,23 +33,22 @@ public class ButtonToast {
     private final static String LOGTAG = "GeckoButtonToast";
 
     private final static int TOAST_DURATION = 5000;
 
     private final View mView;
     private final TextView mMessageView;
     private final Button mButton;
     private final Handler mHideHandler = new Handler();
-
-    private final LinkedList<Toast> mQueue = new LinkedList<Toast>();
     private Toast mCurrentToast;
 
     public enum ReasonHidden {
         CLICKED,
         TIMEOUT,
+        REPLACED,
         STARTUP
     }
 
     // State objects
     private static class Toast {
         public final CharSequence buttonMessage;
         public Drawable buttonDrawable;
         public final CharSequence message;
@@ -99,20 +98,20 @@ public class ButtonToast {
 
     public void show(boolean immediate, CharSequence message,
                      CharSequence buttonMessage, Drawable buttonDrawable,
                      ToastListener listener) {
         show(new Toast(message, buttonMessage, buttonDrawable, listener), immediate);
     }
 
     private void show(Toast t, boolean immediate) {
-        // If we're already showing a toast, add this one to the queue to show later
-        if (mView.getVisibility() == View.VISIBLE) {
-            mQueue.offer(t);
-            return;
+        // If we're already showing a toast, replace it with the new one by hiding the old one and quickly showing the new one.
+        if (mCurrentToast != null) {
+            hide(true, ReasonHidden.REPLACED);
+            immediate = true;
         }
 
         mCurrentToast = t;
         mButton.setEnabled(true);
 
         // Our toast is re-used, so we update all fields to clear any old values.
         mMessageView.setText(null != t.message ? t.message : "");
         mButton.setText(null != t.buttonMessage ? t.buttonMessage : "");
@@ -125,64 +124,43 @@ public class ButtonToast {
         int duration = immediate ? 0 : mView.getResources().getInteger(android.R.integer.config_longAnimTime);
 
         PropertyAnimator animator = new PropertyAnimator(duration);
         animator.attach(mView, PropertyAnimator.Property.ALPHA, 1.0f);
         animator.start();
     }
 
     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);
-            showNextInQueue();
         } else {
             // Using Android's animation frameworks will not correctly turn off clicking.
             // See bug 885717.
             PropertyAnimator animator = new PropertyAnimator(duration);
             animator.attach(mView, PropertyAnimator.Property.ALPHA, 0.0f);
             animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener () {
                 // If we are showing a toast and go in the background
                 // onAnimationEnd will be called when the app is restored
                 public void onPropertyAnimationEnd() {
                     mView.setVisibility(View.GONE);
-                    showNextInQueue();
                 }
                 public void onPropertyAnimationStart() { }
             });
             animator.start();
         }
     }
 
-    public void onSaveInstanceState(Bundle outState) {
-        // Add whatever toast we're currently showing to the front of the queue
-        if (mCurrentToast != null) {
-            mQueue.add(0, mCurrentToast);
-        }
-    }
-
-    private void showNextInQueue() {
-        Toast t = mQueue.poll();
-        if (t != null) {
-            show(t, false);
-        }
-    }
-
     private Runnable mHideRunnable = new Runnable() {
         @Override
         public void run() {
             hide(false, ReasonHidden.TIMEOUT);
         }
     };
 }