Bug 970247 - Stub the ButtonToast view (r=wesj)
☠☠ backed out by 400b0e44fbc0 ☠ ☠
authorLucas Rocha <lucasr@mozilla.com>
Wed, 12 Feb 2014 15:40:39 +0000
changeset 185615 03bf10b236ea5cf06e224ebd9e3268e67b9af9f4
parent 185614 e30953666622062ee0d1f5cf03c1822188442111
child 185616 c95d496bb2702c3786c8b9b900e62ea42382bf96
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs970247
milestone30.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 970247 - Stub the ButtonToast view (r=wesj)
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoApp.java
mobile/android/base/resources/layout/button_toast.xml
mobile/android/base/resources/layout/gecko_app.xml
mobile/android/base/resources/layout/web_app.xml
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -2252,17 +2252,17 @@ abstract public class BrowserApp extends
             tab = Tabs.getInstance().getSelectedTab();
             if (tab != null) {
                 if (item.isChecked()) {
                     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,
+                    getButtonToast().show(false,
                         getResources().getString(R.string.bookmark_added),
                         getResources().getString(R.string.bookmark_options),
                         null,
                         new ButtonToast.ToastListener() {
                             @Override
                             public void onButtonClicked() {
                                 showBookmarkDialog();
                             }
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -88,16 +88,17 @@ import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.OrientationEventListener;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.TextureView;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.ViewStub;
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.AbsoluteLayout;
 import android.widget.FrameLayout;
 import android.widget.ListView;
 import android.widget.RelativeLayout;
 import android.widget.SimpleAdapter;
 import android.widget.TextView;
@@ -816,25 +817,36 @@ public abstract class GeckoApp
                 } else {
                     toast = Toast.makeText(GeckoApp.this, message, Toast.LENGTH_SHORT);
                 }
                 toast.show();
             }
         });
     }
 
+    protected ButtonToast getButtonToast() {
+        if (mToast != null) {
+            return mToast;
+        }
+
+        ViewStub toastStub = (ViewStub) findViewById(R.id.toast);
+        mToast = new ButtonToast(toastStub.inflate());
+
+        return mToast;
+    }
+
     void showButtonToast(final String message, final String buttonText,
                          final String buttonIcon, final String buttonId) {
         BitmapUtils.getDrawable(GeckoApp.this, buttonIcon, new BitmapUtils.BitmapLoader() {
             public void onBitmapFound(final Drawable d) {
 
                 ThreadUtils.postToUiThread(new Runnable() {
                     @Override
                     public void run() {
-                        mToast.show(false, message, buttonText, d, new ButtonToast.ToastListener() {
+                        getButtonToast().show(false, message, buttonText, d, new ButtonToast.ToastListener() {
                             @Override
                             public void onButtonClicked() {
                                 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Toast:Click", buttonId));
                             }
 
                             @Override
                             public void onToastHidden(ButtonToast.ReasonHidden reason) {
                                 if (reason == ButtonToast.ReasonHidden.TIMEOUT) {
@@ -1243,18 +1255,16 @@ public abstract class GeckoApp
         mOrientation = getResources().getConfiguration().orientation;
 
         setContentView(getLayout());
 
         // Set up Gecko layout.
         mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
         mMainLayout = (RelativeLayout) findViewById(R.id.main_layout);
 
-        mToast = new ButtonToast(findViewById(R.id.toast));
-
         // Determine whether we should restore tabs.
         mShouldRestore = getSessionRestoreState(savedInstanceState);
         if (mShouldRestore && savedInstanceState != null) {
             boolean wasInBackground =
                 savedInstanceState.getBoolean(SAVED_STATE_IN_BACKGROUND, false);
 
             // Don't log OOM-kills if only one activity was destroyed. (For example
             // from "Don't keep activities" on ICS)
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/layout/button_toast.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/toast"
+              style="@style/Toast">
+
+    <TextView android:id="@+id/toast_message"
+              style="@style/ToastMessage" />
+
+    <ImageView android:id="@+id/toast_divider"
+               style="@style/ToastDivider" />
+
+    <Button android:id="@+id/toast_button"
+            style="@style/ToastButton" />
+
+</LinearLayout>
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -93,23 +93,13 @@
                                                     android:layout_height="fill_parent"
                                                     android:layout_width="fill_parent"
                                                     style="@style/GeckoActionBar"/>
 
         </org.mozilla.gecko.widget.GeckoViewFlipper>
 
     </view>
 
-    <LinearLayout android:id="@+id/toast"
-                  style="@style/Toast">
-
-        <TextView android:id="@+id/toast_message"
-                  style="@style/ToastMessage" />
-
-        <ImageView android:id="@+id/toast_divider"
-                   style="@style/ToastDivider" />
-
-        <Button android:id="@+id/toast_button"
-                style="@style/ToastButton" />
-
-    </LinearLayout>
+    <ViewStub android:id="@+id/toast"
+              android:layout="@layout/button_toast"
+              style="@style/Toast"/>
 
 </RelativeLayout>
--- a/mobile/android/base/resources/layout/web_app.xml
+++ b/mobile/android/base/resources/layout/web_app.xml
@@ -48,23 +48,13 @@
                          android:layout_alignParentBottom="true"
                          android:paddingBottom="30dip"
                          android:visibility="gone"/>
 
         </RelativeLayout>
 
     </RelativeLayout>
 
-    <LinearLayout android:id="@+id/toast"
-                  style="@style/Toast">
-
-        <TextView android:id="@+id/toast_message"
-                  style="@style/ToastMessage" />
-
-        <ImageView android:id="@+id/toast_divider"
-                   style="@style/ToastDivider" />
-
-        <Button android:id="@+id/toast_button"
-                style="@style/ToastButton" />
-
-    </LinearLayout>
+    <ViewStub android:id="@+id/toast"
+              android:layout="@layout/button_toast"
+              style="@style/Toast"/>
 
 </RelativeLayout>