Bug 686528 - (5 of 5) about:home recreates itself onConfigurationChange. r=sriram
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 01 Aug 2012 22:23:51 -0400
changeset 101191 88e900fd365e2086ce4933e686891e429b30e585
parent 101190 ac4872c6b21a21b58ca05b10f3928f8269c9a12d
child 101192 71531b2ece95f1f3058758d4fba9135d904ecebd
push id12890
push userryanvm@gmail.com
push dateThu, 02 Aug 2012 02:23:58 +0000
treeherdermozilla-inbound@71531b2ece95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs686528
milestone17.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 686528 - (5 of 5) about:home recreates itself onConfigurationChange. r=sriram
mobile/android/base/AboutHomeContent.java
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -103,28 +103,50 @@ public class AboutHomeContent extends Sc
 
     public AboutHomeContent(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;
         mActivity = (BrowserApp) context;
     }
 
     public void init() {
-        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-        mInflater.inflate(R.layout.abouthome_content, this);
+        inflate();
 
         mAccountManager = AccountManager.get(mContext);
 
         // The listener will run on the background thread (see 2nd argument)
         mAccountManager.addOnAccountsUpdatedListener(mAccountListener = new OnAccountsUpdateListener() {
             public void onAccountsUpdated(Account[] accounts) {
                 updateLayoutForSync();
             }
         }, GeckoAppShell.getHandler(), false);
 
+        mRemoteTabClickListener = new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                String url = ((String) v.getTag());
+                JSONObject args = new JSONObject();
+                try {
+                    args.put("url", url);
+                    args.put("engine", null);
+                    args.put("userEntered", false);
+                } catch (Exception e) {
+                    Log.e(LOGTAG, "error building JSON arguments");
+                }
+    
+                Log.d(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add");
+                GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString()));
+            }
+        };
+    }
+
+    private void inflate() {
+        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        mInflater.inflate(R.layout.abouthome_content, this);
+
         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);
 
@@ -174,34 +196,16 @@ public class AboutHomeContent extends Sc
         syncBox.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 Context context = v.getContext();
                 Intent intent = new Intent(context, SetupSyncActivity.class);
                 context.startActivity(intent);
             }
         });
 
-        mRemoteTabClickListener = new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                String url = ((String) v.getTag());
-                JSONObject args = new JSONObject();
-                try {
-                    args.put("url", url);
-                    args.put("engine", null);
-                    args.put("userEntered", false);
-                } catch (Exception e) {
-                    Log.e(LOGTAG, "error building JSON arguments");
-                }
-    
-                Log.d(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add");
-                GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString()));
-            }
-        };
-
         setTopSitesConstants();
     }
 
     public void onDestroy() {
         if (mAccountListener != null) {
             mAccountManager.removeOnAccountsUpdatedListener(mAccountListener);
             mAccountListener = null;
         }
@@ -330,17 +334,21 @@ public class AboutHomeContent extends Sc
         mNumberOfTopSites = getResources().getInteger(R.integer.number_of_top_sites);
         mNumberOfCols = getResources().getInteger(R.integer.number_of_top_sites_cols);
     }
 
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
         if (mTopSitesAdapter != null)
             mTopSitesAdapter.notifyDataSetChanged();
-        setTopSitesConstants();
+
+        removeAllViews(); // We must remove the currently inflated view to allow for reinflation.
+        inflate();
+        mTopSitesGrid.setAdapter(mTopSitesAdapter); // mTopSitesGrid is a new instance (from loadTopSites()).
+        update(AboutHomeContent.UpdateFlags.ALL); // Refresh all elements.
 
         super.onConfigurationChanged(newConfig);
     }
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent event) {
         if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onInterceptTouchEvent(this, event))
             return true;