Controller Refactor

    Bug: 3170671
    First step towards a model/view/control design in Browser
    introduced Controller object
    started separating UI code
    represent state of the app in one place only

Change-Id: Ica387d6bde2dcf1a4993c3db0cce498cf34ff60f
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index f39c769..7e54710 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -18,6 +18,7 @@
 
 import com.android.browser.UrlInputView.UrlInputListener;
 
+import android.app.Activity;
 import android.app.SearchManager;
 import android.content.Context;
 import android.content.Intent;
@@ -42,11 +43,12 @@
 
     private static final int PROGRESS_MAX = 100;
 
-    private BrowserActivity mBrowserActivity;
+    private Activity mActivity;
+    private UiController mUiController;
+
     private Drawable mStopDrawable;
     private Drawable mReloadDrawable;
 
-
     private View mContainer;
     private View mBackButton;
     private View mForwardButton;
@@ -63,13 +65,14 @@
     private TextView mUrlUnfocused;
     private boolean mInLoad;
 
-    public TitleBarXLarge(BrowserActivity context) {
-        super(context);
-        mBrowserActivity = context;
-        Resources resources = context.getResources();
+    public TitleBarXLarge(Activity activity, UiController controller) {
+        super(activity);
+        mActivity = activity;
+        mUiController = controller;
+        Resources resources = activity.getResources();
         mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal);
         mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal);
-        rebuildLayout(context, true);
+        rebuildLayout(activity, true);
     }
 
     private void rebuildLayout(Context context, boolean rebuildData) {
@@ -123,14 +126,14 @@
         if (mUnfocusContainer == v) {
             mUrlUnfocused.requestFocus();
         } else if (mBackButton == v) {
-            mBrowserActivity.getTopWindow().goBack();
+            mUiController.getCurrentTopWebView().goBack();
         } else if (mForwardButton == v) {
-            mBrowserActivity.getTopWindow().goForward();
+            mUiController.getCurrentTopWebView().goForward();
         } else if (mStar == v) {
-            mBrowserActivity.bookmarkCurrentPage(
+            mUiController.bookmarkCurrentPage(
                     AddBookmarkPage.DEFAULT_FOLDER_ID);
         } else if (mAllButton == v) {
-            mBrowserActivity.bookmarksOrHistoryPicker(false);
+            mUiController.bookmarksOrHistoryPicker(false);
         } else if (mSearchButton == v) {
             search();
         } else if (mStopButton == v) {
@@ -155,25 +158,25 @@
 
     @Override
     public void onAction(String text, String extra) {
-        mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
-        mBrowserActivity.hideFakeTitleBar();
+        mUiController.getCurrentTopWebView().requestFocus();
+        ((BaseUi) mUiController.getUi()).hideFakeTitleBar();
         Intent i = new Intent();
         i.setAction(Intent.ACTION_SEARCH);
         i.putExtra(SearchManager.QUERY, text);
         if (extra != null) {
             i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
         }
-        mBrowserActivity.onNewIntent(i);
+        mUiController.handleNewIntent(i);
         setUrlMode(false);
         setDisplayTitle(text);
     }
 
     @Override
     public void onDismiss() {
-        mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
-        mBrowserActivity.hideFakeTitleBar();
+        mUiController.getCurrentTopWebView().requestFocus();
+        ((BaseUi) mUiController.getUi()).hideFakeTitleBar();
         setUrlMode(false);
-        setDisplayTitle(mBrowserActivity.getTabControl().getCurrentWebView().getUrl());
+        setDisplayTitle(mUiController.getCurrentWebView().getUrl());
     }
 
     @Override
@@ -202,9 +205,9 @@
 
     @Override
     public void createContextMenu(ContextMenu menu) {
-        MenuInflater inflater = mBrowserActivity.getMenuInflater();
+        MenuInflater inflater = mActivity.getMenuInflater();
         inflater.inflate(R.menu.title_context, menu);
-        mBrowserActivity.onCreateContextMenu(menu, this, null);
+        mActivity.onCreateContextMenu(menu, this, null);
     }
 
     private void search() {
@@ -214,9 +217,9 @@
 
     private void stopOrRefresh() {
         if (mInLoad) {
-            mBrowserActivity.stopLoading();
+            mUiController.stopLoading();
         } else {
-            mBrowserActivity.getTopWindow().reload();
+            mUiController.getCurrentTopWebView().reload();
         }
     }