Fix for BlackScreen Bug

Cancel request to go to the NavScreen
and discard callback if tab state changes.

Change-Id: I3b29023c10c2a3821f36a43e465df27d663c0825
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index 5a656a2..7edaa7f 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -53,6 +53,7 @@
     private AnimScreen mAnimScreen;
     private NavigationBarPhone mNavigationBar;
     private Activity mBrowser;
+    private boolean mNavScreenRequested = false;
 
     boolean mAnimating;
     boolean mShowNav = false;
@@ -232,26 +233,50 @@
         hideNavScreen(mUiController.getTabControl().getCurrentPosition(), animate);
     }
 
+    //Unblock touch events
+    private void unblockEvents() {
+        mUiController.setBlockEvents(false);
+    }
+    //Block touch events
+    private void blockEvents() {
+        mUiController.setBlockEvents(true);
+    }
+
+    @Override
+    public void cancelNavScreenRequest() {
+        mNavScreenRequested = false;
+    }
+
     void showNavScreen() {
         WebView webView = getWebView();
         if (webView != null) {
-            mShowNav = true;
-            dismissIME();
-            mUiController.setBlockEvents(true);
-
+            blockEvents();
+            mNavScreenRequested = true;
             webView.getContentBitmapAsync(1.0f,
                             new Rect(),
                             new ValueCallback<Bitmap>() {
                                 @Override
                                 public void onReceiveValue(Bitmap bitmap) {
-                                    onShowNavScreenContinue(bitmap);
+
+                                    // If something interrupted the NavScreen request, discard
+                                    // the callback
+                                    if (mNavScreenRequested) {
+                                        onShowNavScreenContinue(bitmap);
+                                    } else {
+                                        unblockEvents();
+                                    }
+
                                 }
                             });
         }
     }
 
-    void onShowNavScreenContinue(Bitmap viewportBitmap) {
 
+
+    void onShowNavScreenContinue(Bitmap viewportBitmap) {
+        dismissIME();
+        mShowNav = true;
+        mNavScreenRequested = false;
         if (mNavScreen == null) {
             mNavScreen = new NavScreen(mActivity, mUiController, this);
             mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
@@ -315,12 +340,12 @@
             public void onAnimationEnd(Animator anim) {
                 mCustomViewContainer.removeView(mAnimScreen.mMain);
                 finishAnimationIn();
-                mUiController.setBlockEvents(false);
+                unblockEvents();
             }
         });
         set1.playSequentially(inanim, disappear);
         set1.start();
-        mUiController.setBlockEvents(false);
+        unblockEvents();
     }
 
     private void finishAnimationIn() {
@@ -332,6 +357,7 @@
     }
 
     void hideNavScreen(int position, boolean animate) {
+
         mShowNav = false;
         if (!showingNavScreen()) return;
         final Tab tab = mUiController.getTabControl().getTab(position);
@@ -356,7 +382,7 @@
             finishAnimateOut();
             return;
         }
-        mUiController.setBlockEvents(true);
+        blockEvents();
         mUiController.setActiveTab(tab);
         mContentView.setVisibility(View.VISIBLE);
         if (mAnimScreen == null) {
@@ -466,7 +492,7 @@
             public void onAnimationEnd(Animator anim) {
                 mCustomViewContainer.removeView(mAnimScreen.mMain);
                 finishAnimateOut();
-                mUiController.setBlockEvents(false);
+                unblockEvents();
             }
         });
         otheralpha.setInterpolator(new DecelerateInterpolator());