bug 711184 - make sure we don't do any work creating about:home if we're not showing about:home r=dougt
☠☠ backed out by 6d281a8799fb ☠ ☠
authorBrad Lassey <blassey@mozilla.com>
Tue, 20 Dec 2011 00:08:07 -0500
changeset 84737 3f050eb4f8ac9a63faefd706959dbba8e26bfb24
parent 84736 43fd5d2ede79298b3d3cb8796e8ed6a77c76e9b6
child 84738 7e83d0b591612d9eb10912a14cb405b9871fa9fd
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [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/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
@@ -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() {
--- 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"/>