bug 711184 - make sure we don't do any work creating about:home if we're not showing about:home r=dougt
authorBrad Lassey <blassey@mozilla.com>
Tue, 20 Dec 2011 02:49:44 -0500
changeset 83104 feaccb6a4c352008d68264ab1ceb1343bbc6cf3d
parent 83103 687289854e5683ab8c8c4bee9bb542de3b9efa51
child 83105 32d762c16927bab0e90e96e40e40d99bb9949fe2
child 83114 e3766ee732ccbec82ad84e76eb60f87a3e8182d3
push id21724
push userbmo@edmorley.co.uk
push dateTue, 20 Dec 2011 11:16:15 +0000
treeherdermozilla-central@32d762c16927 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs711184
milestone11.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 711184 - make sure we don't do any work creating about:home if we're not showing about:home r=dougt
mobile/android/base/AboutHomeContent.java
mobile/android/base/GeckoApp.java
mobile/android/base/resources/layout-v11/gecko_app.xml
mobile/android/base/resources/layout/gecko_app.xml
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -57,16 +57,17 @@ import android.content.Context;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.text.SpannableString;
 import android.text.style.UnderlineSpan;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.GridView;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.ScrollView;
 import android.widget.SimpleCursorAdapter;
@@ -76,77 +77,70 @@ public class AboutHomeContent extends Sc
     private static final String LOGTAG = "GeckoAboutHome";
 
     private static final int NUMBER_OF_TOP_SITES_PORTRAIT = 4;
     private static final int NUMBER_OF_TOP_SITES_LANDSCAPE = 3;
 
     private static final int NUMBER_OF_COLS_PORTRAIT = 2;
     private static final int NUMBER_OF_COLS_LANDSCAPE = 3;
 
-    private boolean mInflated;
-
     private Cursor mCursor;
     UriLoadCallback mUriLoadCallback = null;
 
     protected SimpleCursorAdapter mTopSitesAdapter;
     protected GridView mTopSitesGrid;
 
     protected ArrayAdapter<String> mAddonsAdapter;
     protected ListView mAddonsList;
 
     public interface UriLoadCallback {
         public void callback(String uriSpec);
     }
 
     public AboutHomeContent(Context context, AttributeSet attrs) {
         super(context, attrs);
-        mInflated = false;
     }
 
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
-
-        // HACK: Without this, the onFinishInflate is called twice
-        // This issue is due to a bug when Android inflates a layout with a
-        // parent. Fixed in Honeycomb
-        if (mInflated)
-            return;
+        synchronized (this) {
+            if (mTopSitesGrid != null && mAddonsList != null)
+                return;
 
-        mInflated = true;
+            mTopSitesGrid = (GridView)findViewById(R.id.top_sites_grid);
+            mTopSitesGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+                public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
+                    Cursor c = (Cursor) parent.getItemAtPosition(position);
 
-        mTopSitesGrid = (GridView)findViewById(R.id.top_sites_grid);
-        mTopSitesGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
-                Cursor c = (Cursor) parent.getItemAtPosition(position);
+                    String spec = c.getString(c.getColumnIndex(URLColumns.URL));
+                    Log.i(LOGTAG, "clicked: " + spec);
 
-                String spec = c.getString(c.getColumnIndex(URLColumns.URL));
-                Log.i(LOGTAG, "clicked: " + spec);
+                    if (mUriLoadCallback != null)
+                        mUriLoadCallback.callback(spec);
+                }
+            });
 
-                if (mUriLoadCallback != null)
-                    mUriLoadCallback.callback(spec);
-            }
-        });
+            mAddonsList = (ListView) findViewById(R.id.recommended_addons_list);
 
-        mAddonsList = (ListView) findViewById(R.id.recommended_addons_list);
+            TextView allTopSitesText = (TextView) findViewById(R.id.all_top_sites_text);
+            allTopSitesText.setOnClickListener(new View.OnClickListener() {
+                public void onClick(View v) {
+                    GeckoApp.mAppContext.showAwesomebar(AwesomeBar.Type.EDIT);
+                }
+            });
 
-        TextView allTopSitesText = (TextView) findViewById(R.id.all_top_sites_text);
-        allTopSitesText.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View v) {
-                GeckoApp.mAppContext.showAwesomebar(AwesomeBar.Type.EDIT);
-            }
-        });
-
-        TextView allAddonsText = (TextView) findViewById(R.id.all_addons_text);
-        allAddonsText.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View v) {
-                if (mUriLoadCallback != null)
-                    mUriLoadCallback.callback("about:addons");
-            }
-        });
+            TextView allAddonsText = (TextView) findViewById(R.id.all_addons_text);
+            allAddonsText.setOnClickListener(new View.OnClickListener() {
+                public void onClick(View v) {
+                    if (mUriLoadCallback != null)
+                        mUriLoadCallback.callback("about:addons");
+                }
+            });
+        }
     }
 
     private int getNumberOfTopSites() {
         Configuration config = getContext().getResources().getConfiguration();
         if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
             return NUMBER_OF_TOP_SITES_LANDSCAPE;
         else
             return NUMBER_OF_TOP_SITES_PORTRAIT;
@@ -156,17 +150,21 @@ public class AboutHomeContent extends Sc
         Configuration config = getContext().getResources().getConfiguration();
         if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
             return NUMBER_OF_COLS_LANDSCAPE;
         else
             return NUMBER_OF_COLS_PORTRAIT;
     }
 
     void init(final Activity activity) {
-        GeckoAppShell.getHandler().post(new Runnable() {
+        LayoutInflater inflater =
+            (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+        inflater.inflate(R.layout.abouthome_content, this);
+        final Runnable generateCursorsRunnable = new Runnable() {
             public void run() {
                 if (mCursor != null)
                     activity.stopManagingCursor(mCursor);
 
                 ContentResolver resolver = GeckoApp.mAppContext.getContentResolver();
                 mCursor = BrowserDB.filter(resolver, "", NUMBER_OF_TOP_SITES_PORTRAIT);
                 activity.startManagingCursor(mCursor);
 
@@ -188,17 +186,24 @@ public class AboutHomeContent extends Sc
                         mTopSitesAdapter.setViewBinder(new TopSitesViewBinder());
 
                         mAddonsList.setAdapter(mAddonsAdapter);
                     }
                 });
 
                 readRecommendedAddons(activity);
             }
-        });
+        };
+        Runnable finishInflateRunnable = new Runnable() {
+            public void run() {
+                onFinishInflate();
+                GeckoAppShell.getHandler().post(generateCursorsRunnable);
+            }
+        };
+        GeckoApp.mAppContext.mMainHandler.post(finishInflateRunnable);
     }
 
     public void setUriLoadCallback(UriLoadCallback uriLoadCallback) {
         mUriLoadCallback = uriLoadCallback;
     }
 
     public void onActivityContentChanged(Activity activity) {
         GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
@@ -300,24 +305,24 @@ public class AboutHomeContent extends Sc
             super(context, attrs);
         }
 
         @Override
         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
             // This is to ensure that the GridView always has a size that shows
             // all items with no need for scrolling.
             int expandedHeightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
-                    MeasureSpec.AT_MOST);
+                                                                 MeasureSpec.AT_MOST);
             super.onMeasure(widthMeasureSpec, expandedHeightSpec);
         }
     }
 
     public class TopSitesCursorAdapter extends SimpleCursorAdapter {
         public TopSitesCursorAdapter(Context context, int layout, Cursor c,
-                String[] from, int[] to) {
+                                     String[] from, int[] to) {
             super(context, layout, c, from, to);
         }
 
         @Override
         public int getCount() {
             return Math.min(super.getCount(), getNumberOfTopSites());
         }
     }
@@ -379,17 +384,17 @@ public class AboutHomeContent extends Sc
             super(context, attrs);
         }
 
         @Override
         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
             // This is to ensure that the ListView always has a size that shows
             // all items with no need for scrolling.
             int expandedHeightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
-                    MeasureSpec.AT_MOST);
+                                                                 MeasureSpec.AT_MOST);
             super.onMeasure(widthMeasureSpec, expandedHeightSpec);
         }
     }
 
     public static class LinkTextView extends TextView {
         public LinkTextView(Context context, AttributeSet attrs) {
             super(context, attrs);
         }
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -124,17 +124,17 @@ abstract public class GeckoApp
     public static AutoCompletePopup mAutoCompletePopup;
     public Favicons mFavicons;
 
     private Geocoder mGeocoder;
     private Address  mLastGeoAddress;
     private static LayerController mLayerController;
     private static PlaceholderLayerClient mPlaceholderLayerClient;
     private static GeckoSoftwareLayerClient mSoftwareLayerClient;
-    AboutHomeContent mAboutHomeContent;
+    private AboutHomeContent mAboutHomeContent;
     private static AbsoluteLayout mPluginContainer;
     boolean mUserDefinedProfile = false;
 
     public String mLastUri;
     public String mLastTitle;
     public String mLastViewport;
     public byte[] mLastScreen;
     public int mOwnActivityDepth = 0;
@@ -1006,27 +1006,29 @@ abstract public class GeckoApp
     public class AboutHomeRunnable implements Runnable {
         boolean mShow;
         AboutHomeRunnable(boolean show) {
             mShow = show;
         }
 
         public void run() {
             mAutoCompletePopup.hide();
-            if (mAboutHomeContent == null) {
-                mAboutHomeContent = (AboutHomeContent) findViewById(R.id.abouthome_content);
+            if (mAboutHomeContent == null && mShow) {
+                mAboutHomeContent = new AboutHomeContent(GeckoApp.mAppContext, null);
                 mAboutHomeContent.init(GeckoApp.mAppContext);
                 mAboutHomeContent.setUriLoadCallback(new AboutHomeContent.UriLoadCallback() {
                     public void callback(String url) {
                         mBrowserToolbar.setProgressVisibility(true);
                         loadUrl(url, AwesomeBar.Type.EDIT);
                     }
                 });
+                mGeckoLayout.addView(mAboutHomeContent);
             }
-            mAboutHomeContent.setVisibility(mShow ? View.VISIBLE : View.GONE);
+            if (mAboutHomeContent != null)
+                mAboutHomeContent.setVisibility(mShow ? View.VISIBLE : View.GONE);
         }
     }
 
     void updateAgentModeMenuItem(final Tab tab, final Tab.AgentMode agentMode) {
         if (sMenu == null)
             return;
 
         mMainHandler.post(new Runnable() {
@@ -1782,20 +1784,18 @@ abstract public class GeckoApp
 
         unregisterReceiver(mSmsReceiver);
         unregisterReceiver(mBatteryReceiver);
     }
 
     @Override
     public void onContentChanged() {
         super.onContentChanged();
-        if (mAboutHomeContent == null)
-            return;
-        mAboutHomeContent = (AboutHomeContent) findViewById(R.id.abouthome_content);
-        mAboutHomeContent.onActivityContentChanged(this);
+        if (mAboutHomeContent != null)
+            mAboutHomeContent.onActivityContentChanged(this);
     }
 
 
     @Override
     public void onConfigurationChanged(android.content.res.Configuration newConfig)
     {
         Log.i(LOGTAG, "configuration changed");
 
--- a/mobile/android/base/resources/layout-v11/gecko_app.xml
+++ b/mobile/android/base/resources/layout-v11/gecko_app.xml
@@ -8,27 +8,16 @@
                     android:layout_height="fill_parent"
                     android:layout_weight="1">
 
         <AbsoluteLayout android:id="@+id/plugin_container"
                         android:background="@android:color/transparent"
                         android:layout_width="fill_parent"
                         android:layout_height="fill_parent"/>
 
-        <org.mozilla.gecko.AboutHomeContent android:id="@+id/abouthome_content"
-                                            android:orientation="vertical"
-                                            android:layout_width="fill_parent"
-                                            android:layout_height="fill_parent"
-                                            android:background="#ffffff"
-                                            android:isScrollContainer="true">
-
-            <include layout="@layout/abouthome_content"/>
-
-        </org.mozilla.gecko.AboutHomeContent>
-
         <org.mozilla.gecko.AutoCompletePopup android:id="@+id/autocomplete_popup"
                                              style="@android:style/Widget.ListView.White"
                                              android:layout_width="fill_parent"
                                              android:layout_height="100dip"
                                              android:background="@drawable/autocomplete_list_bg"
                                              android:cacheColorHint="#ffffff"
                                              android:listSelector="@android:drawable/list_selector_background"
                                              android:visibility="gone"/>
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -15,28 +15,16 @@
                     android:layout_height="fill_parent"
                     android:layout_weight="1">
 
         <AbsoluteLayout android:id="@+id/plugin_container"
                         android:background="@android:color/transparent"
                         android:layout_width="fill_parent"
                         android:layout_height="fill_parent"/>
 
-        <org.mozilla.gecko.AboutHomeContent android:id="@+id/abouthome_content"
-                                            android:orientation="vertical"
-                                            android:layout_width="fill_parent"
-                                            android:layout_height="fill_parent"
-                                            android:background="#ffffff"
-                                            android:isScrollContainer="true"
-                                            android:visibility="gone">
-
-            <include layout="@layout/abouthome_content"/>
-
-        </org.mozilla.gecko.AboutHomeContent>
-
         <org.mozilla.gecko.AutoCompletePopup android:id="@+id/autocomplete_popup"
                                              style="@android:style/Widget.ListView.White"
                                              android:layout_width="fill_parent"
                                              android:layout_height="100dip"
                                              android:background="@drawable/autocomplete_list_bg"
                                              android:cacheColorHint="#ffffff"
                                              android:listSelector="@android:drawable/list_selector_background"
                                              android:visibility="gone"/>