Bug 727454: BrowserToolbar inflation crash in ActionBar. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Tue, 20 Mar 2012 17:23:06 -0700
changeset 90583 f03ef32a3057318c8db4681fcdd0b71fd6ce20c9
parent 90582 68578d82198bb798e1373459d774d97f87f8f730
child 90584 48b51740d3d288db65631618aba7fca33daa87cd
push id1017
push userblassey@mozilla.com
push dateSat, 24 Mar 2012 05:27:08 +0000
treeherdermozilla-aurora@e14e81432a54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs727454
milestone13.0a2
Bug 727454: BrowserToolbar inflation crash in ActionBar. [r=mfinkle]
mobile/android/base/BrowserToolbar.java
mobile/android/base/GeckoApp.java
mobile/android/base/resources/layout-land-v14/browser_toolbar.xml
mobile/android/base/resources/layout/browser_toolbar.xml
mobile/android/base/resources/values-v11/themes.xml
mobile/android/base/resources/values/themes.xml
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -59,18 +59,19 @@ import android.view.View;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.TextSwitcher;
 import android.widget.ViewSwitcher.ViewFactory;
 
-public class BrowserToolbar extends LinearLayout {
-    private static final String LOGTAG = "GeckoToolbar";    
+public class BrowserToolbar {
+    private static final String LOGTAG = "GeckoToolbar";
+    private LinearLayout mLayout;
     private Button mAwesomeBar;
     private ImageButton mTabs;
     public ImageButton mFavicon;
     public ImageButton mStop;
     public ImageButton mSiteSecurity;
     private AnimationDrawable mProgressSpinner;
     private TextSwitcher mTabsCount;
     private ImageView mShadow;
@@ -85,72 +86,72 @@ public class BrowserToolbar extends Line
     private int mDuration;
     private TranslateAnimation mSlideUpIn;
     private TranslateAnimation mSlideUpOut;
     private TranslateAnimation mSlideDownIn;
     private TranslateAnimation mSlideDownOut;
 
     private int mCount;
 
-    public BrowserToolbar(Context context, AttributeSet attrs) {
-        super(context, attrs);
+    public BrowserToolbar(Context context) {
         mContext = context;
+    }
+
+    public void from(LinearLayout layout) {
+        mLayout = layout;
         mTitleCanExpand = true;
 
         // Get the device's highlight color
         TypedArray typedArray;
 
         if (Build.VERSION.SDK_INT >= 11) {            
-            typedArray = context.obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight });
+            typedArray = mContext.obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight });
         } else {
             ContextThemeWrapper wrapper  = new ContextThemeWrapper(mContext, android.R.style.TextAppearance);
             typedArray = wrapper.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight });
         }
 
         mColor = typedArray.getColor(typedArray.getIndex(0), 0);
         typedArray.recycle();
-    }
-
-    public void init() {
-        mAwesomeBar = (Button) findViewById(R.id.awesome_bar);
+        mAwesomeBar = (Button) mLayout.findViewById(R.id.awesome_bar);
         mAwesomeBar.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 onAwesomeBarSearch();
             }
         });
 
-        Resources resources = getResources();
+        Resources resources = mContext.getResources();
         
         mPadding = new int[] { mAwesomeBar.getPaddingLeft(),
                                mAwesomeBar.getPaddingTop(),
                                mAwesomeBar.getPaddingRight(),
                                mAwesomeBar.getPaddingBottom() };
 
         GeckoStateListDrawable states = new GeckoStateListDrawable();
         states.initializeFilter(mColor);
         states.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.address_bar_url_pressed));
         states.addState(new int[] { }, resources.getDrawable(R.drawable.address_bar_url_default));
         mAwesomeBar.setBackgroundDrawable(states);
 
         mAwesomeBar.setPadding(mPadding[0], mPadding[1], mPadding[2], mPadding[3]);
 
-        mTabs = (ImageButton) findViewById(R.id.tabs);
+        mTabs = (ImageButton) mLayout.findViewById(R.id.tabs);
         mTabs.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 if (Tabs.getInstance().getCount() > 1)
                     showTabs();
                 else
                     addTab();
             }
         });
         mTabs.setImageLevel(0);
 
         mCounterColor = 0xFFC7D1DB;
 
-        mTabsCount = (TextSwitcher) findViewById(R.id.tabs_count);
+        mTabsCount = (TextSwitcher) mLayout.findViewById(R.id.tabs_count);
         mTabsCount.removeAllViews();
         mTabsCount.setFactory(new ViewFactory() {
             public View makeView() {
                 TextView text = new TextView(mContext);
                 text.setGravity(Gravity.CENTER);
 
                 if (Build.VERSION.SDK_INT >= 11) {
                     if (GeckoApp.mOrientation == Configuration.ORIENTATION_PORTRAIT)
@@ -164,28 +165,28 @@ public class BrowserToolbar extends Line
                 text.setTextColor(mCounterColor);
                 text.setShadowLayer(1.0f, 0f, 1.0f, Color.BLACK);
                 return text;
             }
         }); 
         mTabsCount.setText("0");
         mCount = 0;
 
-        mFavicon = (ImageButton) findViewById(R.id.favicon);
-        mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
+        mFavicon = (ImageButton) mLayout.findViewById(R.id.favicon);
+        mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security);
         mProgressSpinner = (AnimationDrawable) resources.getDrawable(R.drawable.progress_spinner);
         
-        mStop = (ImageButton) findViewById(R.id.stop);
+        mStop = (ImageButton) mLayout.findViewById(R.id.stop);
         mStop.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 doStop();
             }
         });
 
-        mShadow = (ImageView) findViewById(R.id.shadow);
+        mShadow = (ImageView) mLayout.findViewById(R.id.shadow);
 
         mHandler = new Handler();
         mSlideUpIn = new TranslateAnimation(0, 0, 40, 0);
         mSlideUpOut = new TranslateAnimation(0, 0, 0, -40);
         mSlideDownIn = new TranslateAnimation(0, 0, -40, 0);
         mSlideDownOut = new TranslateAnimation(0, 0, 0, 40);
 
         mDuration = 750;
@@ -324,28 +325,36 @@ public class BrowserToolbar extends Line
         } else if (mode.equals("verified")) {
             mSiteSecurity.setImageLevel(2);
         } else {
             mSiteSecurity.setImageLevel(0);
             mTitleCanExpand = true;
         }
     }
 
+    public void setVisibility(int visibility) {
+        mLayout.setVisibility(visibility);
+    }
+
+    public void requestFocusFromTouch() {
+        mLayout.requestFocusFromTouch();
+    }
+
     public void show() {
         if (Build.VERSION.SDK_INT >= 11)
             GeckoActionBar.show(GeckoApp.mAppContext);
         else
-            setVisibility(View.VISIBLE);
+            mLayout.setVisibility(View.VISIBLE);
     }
 
     public void hide() {
         if (Build.VERSION.SDK_INT >= 11)
             GeckoActionBar.hide(GeckoApp.mAppContext);
         else
-            setVisibility(View.GONE);
+            mLayout.setVisibility(View.GONE);
     }
 
     public void refresh() {
         Tab tab = Tabs.getInstance().getSelectedTab();
         if (tab != null) {
             String url = tab.getURL();
             setTitle(tab.getDisplayTitle());
             setFavicon(tab.getFavicon());
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1586,25 +1586,21 @@ abstract public class GeckoApp
                     window.getDecorView().setSystemUiVisibility(fullscreen ? 1 : 0);
             }
         });
     }
 
     // The ActionBar needs to be refreshed on rotation as different orientation uses different resources
     public void refreshActionBar() {
         if (Build.VERSION.SDK_INT >= 11) {
-            mBrowserToolbar = (BrowserToolbar) getLayoutInflater().inflate(R.layout.browser_toolbar, null);
-            mBrowserToolbar.init();
+            LinearLayout actionBar = (LinearLayout) getLayoutInflater().inflate(R.layout.browser_toolbar, null);
+            mBrowserToolbar.from(actionBar);
             mBrowserToolbar.refresh();
             GeckoActionBar.setBackgroundDrawable(this, getResources().getDrawable(R.drawable.gecko_actionbar_bg));
-            GeckoActionBar.setDisplayOptions(this, ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM |
-                                                                                  ActionBar.DISPLAY_SHOW_HOME |
-                                                                                  ActionBar.DISPLAY_SHOW_TITLE |
-                                                                                  ActionBar.DISPLAY_USE_LOGO);
-            GeckoActionBar.setCustomView(this, mBrowserToolbar);
+            GeckoActionBar.setCustomView(this, actionBar);
         }
     }
 
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         GeckoAppShell.registerGlobalExceptionHandler();
@@ -1627,22 +1623,26 @@ abstract public class GeckoApp
         }
 
         super.onCreate(savedInstanceState);
 
         mOrientation = getResources().getConfiguration().orientation;
 
         setContentView(R.layout.gecko_app);
 
+        LinearLayout actionBar;
         if (Build.VERSION.SDK_INT >= 11) {
-            mBrowserToolbar = (BrowserToolbar) GeckoActionBar.getCustomView(this);
+            actionBar = (LinearLayout) GeckoActionBar.getCustomView(this);
         } else {
-            mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
+            actionBar = (LinearLayout) findViewById(R.id.browser_toolbar);
         }
 
+        mBrowserToolbar = new BrowserToolbar(mAppContext);
+        mBrowserToolbar.from(actionBar);
+
         // setup gecko layout
         mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
         mMainLayout = (LinearLayout) findViewById(R.id.main_layout);
 
         mConnectivityFilter = new IntentFilter();
         mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
         mConnectivityReceiver = new GeckoConnectivityReceiver();
     }
@@ -1664,17 +1664,16 @@ abstract public class GeckoApp
             }
         }
 
         if (ACTION_UPDATE.equals(action) || args != null && args.contains("-alert update-app")) {
             Log.i(LOGTAG,"onCreate: Update request");
             checkAndLaunchUpdate();
         }
 
-        mBrowserToolbar.init();
         mBrowserToolbar.setTitle(mLastTitle);
 
         String passedUri = null;
         String uri = getURIFromIntent(intent);
         if (uri != null && uri.length() > 0)
             passedUri = mLastTitle = uri;
 
         mRestoreSession |= getProfile().shouldRestoreSession();
--- a/mobile/android/base/resources/layout-land-v14/browser_toolbar.xml
+++ b/mobile/android/base/resources/layout-land-v14/browser_toolbar.xml
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
-<org.mozilla.gecko.BrowserToolbar xmlns:android="http://schemas.android.com/apk/res/android"
-                                  android:id="@+id/browser_toolbar"
-                                  style="@style/BrowserToolbar">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/browser_toolbar"
+              style="@style/BrowserToolbar">
 
     <RelativeLayout android:id="@+id/address_bar"
                     style="@style/AddressBar"
                     android:background="@drawable/address_bar_bg">
         
         <Button android:id="@+id/awesome_bar"
                 style="@style/AddressBar.Button"
                 android:layout_width="fill_parent"
@@ -76,9 +76,9 @@
                     android:layout_width="fill_parent"
                     android:layout_height="2dp"
                     android:layout_alignParentBottom="true"
                     android:src="@drawable/address_bar_bg_shadow"
                     android:visibility="gone"/>
 
     </RelativeLayout>
 
-</org.mozilla.gecko.BrowserToolbar>
+</LinearLayout>
--- a/mobile/android/base/resources/layout/browser_toolbar.xml
+++ b/mobile/android/base/resources/layout/browser_toolbar.xml
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
-<org.mozilla.gecko.BrowserToolbar xmlns:android="http://schemas.android.com/apk/res/android"
-                                  android:id="@+id/browser_toolbar"
-                                  style="@style/BrowserToolbar">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/browser_toolbar"
+              style="@style/BrowserToolbar">
 
     <RelativeLayout android:id="@+id/address_bar"
                     style="@style/AddressBar"
                     android:background="@drawable/address_bar_bg">
         
         <Button android:id="@+id/awesome_bar"
                 style="@style/AddressBar.Button"
                 android:layout_width="fill_parent"
@@ -77,9 +77,9 @@
                     android:layout_width="fill_parent"
                     android:layout_height="2dp"
                     android:layout_alignParentBottom="true"
                     android:src="@drawable/address_bar_bg_shadow"
                     android:visibility="gone"/>
 
     </RelativeLayout>
 
-</org.mozilla.gecko.BrowserToolbar>
+</LinearLayout>
--- a/mobile/android/base/resources/values-v11/themes.xml
+++ b/mobile/android/base/resources/values-v11/themes.xml
@@ -24,16 +24,17 @@
     </style>
     
     <style name="Gecko.Translucent" parent="@android:style/Theme.Translucent">
         <item name="android:windowActionBar">true</item>
         <item name="android:windowNoTitle">false</item>
     </style>
 
     <style name="Gecko.App">
+        <item name="android:windowBackground">@drawable/abouthome_bg_repeat</item>
         <item name="android:actionBarStyle">@style/ActionBar.GeckoApp</item>
     </style>
 
     <style name="Gecko.Light.AwesomeBar">
         <item name="android:actionBarStyle">@style/ActionBar.AwesomeBar</item>
     </style>
 
     <style name="Gecko.TitleBar.Preferences">
--- a/mobile/android/base/resources/values/themes.xml
+++ b/mobile/android/base/resources/values/themes.xml
@@ -22,17 +22,19 @@
     </style>
 
     <style name="Gecko.Light.NoActionBar" parent="Gecko.Light"/>
     
     <style name="Gecko.Translucent" parent="@android:style/Theme.Translucent">
         <item name="android:windowNoTitle">true</item>
     </style>
 
-    <style name="Gecko.App"/>
+    <style name="Gecko.App">
+        <item name="android:windowBackground">@drawable/abouthome_bg_repeat</item>
+    </style>
     
     <style name="Gecko.Light.AwesomeBar"/>
     
     <style name="Gecko.TitleBar.Preferences"/>
     
     <style name="Gecko.Translucent.TabsTray"/>
 
 </resources>