Bug 884075 - Use new getDrawable method in ButtonToasts. r=margaret
☠☠ backed out by f4a2d2218a29 ☠ ☠
authorWes Johnston <wjohnston@mozilla.com>
Tue, 16 Jul 2013 01:33:06 -0700
changeset 150931 59a25222200e6dce173a95f1c5332093f78a4f8d
parent 150930 2f2634b1f6951e7fee1eb7ccb2150dcba479a689
child 150932 46f75b2f314c755bd04a66da99c85a0453aba5ec
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [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 - Use new getDrawable method in ButtonToasts. r=margaret
mobile/android/base/BrowserApp.java
mobile/android/base/resources/values/dimens.xml
mobile/android/base/resources/values/styles.xml
mobile/android/base/widget/ButtonToast.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -1675,17 +1675,17 @@ abstract public class BrowserApp extends
                         tab.removeBookmark();
                         Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
                         item.setIcon(R.drawable.ic_menu_bookmark_add);
                     } else {
                         tab.addBookmark();
                         mToast.show(false,
                             getResources().getString(R.string.bookmark_added),
                             getResources().getString(R.string.bookmark_options),
-                            0,
+                            null,
                             new ButtonToast.ToastListener() {
                                 @Override
                                 public void onButtonClicked() {
                                     showBookmarkDialog();
                                 }
                             });
                         item.setIcon(R.drawable.ic_menu_bookmark_remove);
                     }
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -71,9 +71,10 @@
     <dimen name="tabs_tray_horizontal_height">156dp</dimen>
     <dimen name="text_selection_handle_width">47dp</dimen>
     <dimen name="text_selection_handle_height">58dp</dimen>
     <dimen name="text_selection_handle_shadow">11dp</dimen>
     <dimen name="validation_message_height">50dp</dimen>
     <dimen name="validation_message_margin_top">6dp</dimen>
     <dimen name="forward_default_offset">-13dip</dimen>
     <dimen name="addressbar_offset_left">32dp</dimen>
+    <dimen name="toast_button_padding">8dp</dimen>
 </resources>
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -501,17 +501,17 @@
         <item name="android:layout_width">0dp</item>
         <item name="android:layout_weight">1</item>
         <item name="android:layout_height">wrap_content</item>
         <item name="android:layout_gravity">center_vertical</item>
         <item name="android:textColor">#fff</item>
         <item name="android:textAppearance">?android:textAppearanceSmall</item>
         <item name="android:paddingTop">0dp</item>
         <item name="android:paddingBottom">0dp</item>
-        <item name="android:paddingLeft">8dp</item>
+        <item name="android:paddingLeft">@dimen/toast_button_padding</item>
         <item name="android:paddingRight">0dp</item>
         <item name="android:layout_marginTop">0dp</item>
         <item name="android:layout_marginBottom">0dp</item>
         <item name="android:layout_marginLeft">8dp</item>
         <item name="android:layout_marginRight">0dp</item>
     </style>
 
     <style name="ToastButton">
--- a/mobile/android/base/widget/ButtonToast.java
+++ b/mobile/android/base/widget/ButtonToast.java
@@ -13,56 +13,58 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.mozilla.gecko.widget;
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Handler;
 import android.text.TextUtils;
 import android.view.animation.Animation;
 import android.view.animation.AlphaAnimation;
 import android.view.View;
 import android.widget.Button;
 import android.widget.TextView;
 
 import java.util.LinkedList;
 
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.gfx.BitmapUtils;
 
 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 ToastListener mListener;
     private final LinkedList<Toast> mQueue = new LinkedList<Toast>();
     private Toast mCurrentToast;
 
     // State objects
     private static class Toast {
-        public final CharSequence token;
         public final CharSequence buttonMessage;
-        public final int buttonIcon;
+        public Drawable buttonDrawable;
         public final CharSequence message;
         public ToastListener listener;
 
-        public Toast(CharSequence aMessage, CharSequence aButtonMessage, int aIcon, ToastListener aListener) {
+        public Toast(CharSequence aMessage, CharSequence aButtonMessage,
+                     Drawable aDrawable, ToastListener aListener) {
             message = aMessage;
             buttonMessage = aButtonMessage;
-            buttonIcon = aIcon;
+            buttonDrawable = aDrawable;
             listener = aListener;
-            token = "";
         }
     }
 
     public interface ToastListener {
         void onButtonClicked();
     }
 
     public ButtonToast(View view) {
@@ -83,35 +85,35 @@ public class ButtonToast {
                         }
                     }
                 });
 
         hide(true);
     }
 
     public void show(boolean immediate, CharSequence message,
-                     CharSequence buttonMessage, int buttonIcon,
+                     CharSequence buttonMessage, Drawable buttonDrawable,
                      ToastListener listener) {
-        Toast t = new Toast(message, buttonMessage, buttonIcon, listener);
-        show(t, immediate);
+        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;
         }
 
         mCurrentToast = t;
         mButton.setEnabled(true);
 
         mMessageView.setText(t.message);
         mButton.setText(t.buttonMessage);
-        mButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, t.buttonIcon, 0);
+        mButton.setCompoundDrawablePadding(mView.getContext().getResources().getDimensionPixelSize(R.dimen.toast_button_padding));
+        mButton.setCompoundDrawablesWithIntrinsicBounds(null, null, t.buttonDrawable, null);
 
         mHideHandler.removeCallbacks(mHideRunnable);
         mHideHandler.postDelayed(mHideRunnable, TOAST_DURATION);
 
         mView.setVisibility(View.VISIBLE);
         int duration = immediate ? 0 : mView.getResources().getInteger(android.R.integer.config_longAnimTime);
 
         mView.clearAnimation();