OSDN Git Service

Check for null before animating the tab/webview.
authorPatrick Scott <phanna@android.com>
Mon, 20 Apr 2009 17:51:49 +0000 (13:51 -0400)
committerPatrick Scott <phanna@android.com>
Mon, 20 Apr 2009 17:51:49 +0000 (13:51 -0400)
The tab will most likely not be null but the top window could easily be null if
the tab has been freed due to low memory. Update getTabIndex to return -1 if the
tab is null.

src/com/android/browser/BrowserActivity.java
src/com/android/browser/TabControl.java

index ad50a92..8681be2 100644 (file)
@@ -4232,13 +4232,19 @@ public class BrowserActivity extends Activity
         AnimatingView(Context ctxt, TabControl.Tab t) {
             super(ctxt);
             mTab = t;
-            // Use the top window in the animation since the tab overview will
-            // display the top window in each cell.
-            final WebView w = t.getTopWindow();
-            mPicture = w.capturePicture();
-            mScale = w.getScale() / w.getWidth();
-            mScrollX = w.getScrollX();
-            mScrollY = w.getScrollY();
+            if (t != null && t.getTopWindow() != null) {
+                // Use the top window in the animation since the tab overview
+                // will display the top window in each cell.
+                final WebView w = t.getTopWindow();
+                mPicture = w.capturePicture();
+                mScale = w.getScale() / w.getWidth();
+                mScrollX = w.getScrollX();
+                mScrollY = w.getScrollY();
+            } else {
+                mPicture = null;
+                mScale = 1.0f;
+                mScrollX = mScrollY = 0;
+            }
         }
 
         @Override
index ee63f2c..0cbef69 100644 (file)
@@ -407,6 +407,9 @@ class TabControl {
      * @return index of Tab or -1 if not found
      */
     int getTabIndex(Tab tab) {
+        if (tab == null) {
+            return -1;
+        }
         return mTabs.indexOf(tab);
     }