Bug 725389 - Set number of columns in top site's grid view onMeasure (r=mfinkle a=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Tue, 08 May 2012 11:44:48 +0100
changeset 95713 6c1aface06732ac46f4b26db90c8ef0a754748a3
parent 95712 a8a1d8dfba1d723ac3fe13336989d0af9c09a89f
child 95714 9d04b27de4c383c47d51f7eff35b5933f42892ca
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, mfinkle
bugs725389
milestone14.0a2
Bug 725389 - Set number of columns in top site's grid view onMeasure (r=mfinkle a=mfinkle)
mobile/android/base/AboutHomeContent.java
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -319,24 +319,16 @@ public class AboutHomeContent extends Sc
     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;
     }
 
-    private int getNumberOfColumns() {
-        Configuration config = getContext().getResources().getConfiguration();
-        if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
-            return NUMBER_OF_COLS_LANDSCAPE;
-        else
-            return NUMBER_OF_COLS_PORTRAIT;
-    }
-
     private void loadTopSites(final Activity activity) {
         // Ensure we initialize GeckoApp's startup mode in
         // background thread before we use it when updating
         // the top sites section layout in main thread.
         final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode();
 
         // The isSyncSetup method should not be called on
         // UI thread as it touches disk to access a sqlite DB.
@@ -356,18 +348,16 @@ public class AboutHomeContent extends Sc
                                                                  new int[] { R.id.title, R.id.thumbnail });
 
                     mTopSitesAdapter.setViewBinder(new TopSitesViewBinder());
                     mTopSitesGrid.setAdapter(mTopSitesAdapter);
                 } else {
                     mTopSitesAdapter.changeCursor(mCursor);
                 }
 
-                mTopSitesGrid.setNumColumns(getNumberOfColumns());
-
                 updateLayout(startupMode, syncIsSetup);
             }
         });
     }
 
     void update(final Activity activity, final EnumSet<UpdateFlags> flags) {
         GeckoAppShell.getHandler().post(new Runnable() {
             public void run() {
@@ -391,18 +381,16 @@ public class AboutHomeContent extends Sc
     }
 
     public void onActivityContentChanged(Activity activity) {
         update(activity, EnumSet.of(UpdateFlags.TOP_SITES));
     }
 
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
-        if (mTopSitesGrid != null) 
-            mTopSitesGrid.setNumColumns(getNumberOfColumns());
         if (mTopSitesAdapter != null)
             mTopSitesAdapter.notifyDataSetChanged();
 
         super.onConfigurationChanged(newConfig);
     }
 
     private String readFromZipFile(Activity activity, String filename) {
         ZipFile zip = null;
@@ -704,23 +692,26 @@ public class AboutHomeContent extends Sc
                 if (c != null)
                     nSites = c.getCount();
             }
 
             Configuration config = getContext().getResources().getConfiguration();
             if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                 nSites = Math.min(nSites, NUMBER_OF_TOP_SITES_LANDSCAPE);
                 numRows = (int) Math.round((double) nSites / NUMBER_OF_COLS_LANDSCAPE);
+                setNumColumns(NUMBER_OF_COLS_LANDSCAPE);
             } else {
                 nSites = Math.min(nSites, NUMBER_OF_TOP_SITES_PORTRAIT);
                 numRows = (int) Math.round((double) nSites / NUMBER_OF_COLS_PORTRAIT);
+                setNumColumns(NUMBER_OF_COLS_PORTRAIT);
             }
             int expandedHeightSpec = 
                 MeasureSpec.makeMeasureSpec((int)(mDisplayDensity * numRows * kTopSiteItemHeight),
                                             MeasureSpec.EXACTLY);
+
             super.onMeasure(widthMeasureSpec, expandedHeightSpec);
         }
     }
 
     public class TopSitesCursorAdapter extends SimpleCursorAdapter {
         public TopSitesCursorAdapter(Context context, int layout, Cursor c,
                                      String[] from, int[] to) {
             super(context, layout, c, from, to);