From 8233facddcc51865d612a919d450db6954aa48e3 Mon Sep 17 00:00:00 2001 From: Michael Kolb Date: Tue, 26 Oct 2010 16:08:53 -0700 Subject: 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 --- src/com/android/browser/ActiveTabsPage.java | 33 +- src/com/android/browser/AddBookmarkPage.java | 2 +- src/com/android/browser/BaseUi.java | 829 ++++ src/com/android/browser/BrowserActivity.java | 4054 +------------------- src/com/android/browser/BrowserBookmarksPage.java | 4 +- .../android/browser/BrowserHomepagePreference.java | 14 +- src/com/android/browser/BrowserSettings.java | 20 +- src/com/android/browser/CircularProgressView.java | 140 - .../browser/CombinedBookmarkHistoryView.java | 30 +- src/com/android/browser/Controller.java | 2340 +++++++++++ src/com/android/browser/Dots.java | 83 - src/com/android/browser/DownloadHandler.java | 218 ++ src/com/android/browser/FetchUrlMimeType.java | 24 +- src/com/android/browser/IntentHandler.java | 371 ++ src/com/android/browser/NetworkStateHandler.java | 140 + src/com/android/browser/PageDialogsHandler.java | 465 +++ src/com/android/browser/Performance.java | 133 + src/com/android/browser/Tab.java | 493 +-- src/com/android/browser/TabBar.java | 119 +- src/com/android/browser/TabControl.java | 106 +- src/com/android/browser/TabScrollView.java | 6 +- src/com/android/browser/TitleBar.java | 106 +- src/com/android/browser/TitleBarXLarge.java | 45 +- src/com/android/browser/UI.java | 122 + src/com/android/browser/UiController.java | 74 + src/com/android/browser/UploadHandler.java | 214 ++ src/com/android/browser/UrlHandler.java | 238 ++ src/com/android/browser/UrlUtils.java | 99 + src/com/android/browser/WallpaperHandler.java | 127 + src/com/android/browser/WebViewController.java | 101 + src/com/android/browser/WebViewFactory.java | 28 + 31 files changed, 5913 insertions(+), 4865 deletions(-) create mode 100644 src/com/android/browser/BaseUi.java delete mode 100644 src/com/android/browser/CircularProgressView.java create mode 100644 src/com/android/browser/Controller.java delete mode 100644 src/com/android/browser/Dots.java create mode 100644 src/com/android/browser/DownloadHandler.java create mode 100644 src/com/android/browser/IntentHandler.java create mode 100644 src/com/android/browser/NetworkStateHandler.java create mode 100644 src/com/android/browser/PageDialogsHandler.java create mode 100644 src/com/android/browser/Performance.java create mode 100644 src/com/android/browser/UI.java create mode 100644 src/com/android/browser/UiController.java create mode 100644 src/com/android/browser/UploadHandler.java create mode 100644 src/com/android/browser/UrlHandler.java create mode 100644 src/com/android/browser/WallpaperHandler.java create mode 100644 src/com/android/browser/WebViewController.java create mode 100644 src/com/android/browser/WebViewFactory.java (limited to 'src/com') diff --git a/src/com/android/browser/ActiveTabsPage.java b/src/com/android/browser/ActiveTabsPage.java index e450a99..fb5ed3b 100644 --- a/src/com/android/browser/ActiveTabsPage.java +++ b/src/com/android/browser/ActiveTabsPage.java @@ -21,7 +21,6 @@ import android.graphics.Bitmap; import android.os.Handler; import android.util.AttributeSet; import android.util.Log; -import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -33,17 +32,19 @@ import android.widget.ListView; import android.widget.TextView; public class ActiveTabsPage extends LinearLayout { + private static final String LOGTAG = "TabPicker"; - private final BrowserActivity mBrowserActivity; - private final LayoutInflater mFactory; - private final TabControl mControl; - private final TabsListAdapter mAdapter; - private final ListView mListView; - public ActiveTabsPage(BrowserActivity context, TabControl control) { + private final LayoutInflater mFactory; + private final UiController mUiController; + private final TabControl mControl; + private final TabsListAdapter mAdapter; + private final ListView mListView; + + public ActiveTabsPage(Context context, UiController control) { super(context); - mBrowserActivity = context; - mControl = control; + mUiController = control; + mControl = control.getTabControl(); mFactory = LayoutInflater.from(context); mFactory.inflate(R.layout.active_tabs, this); mListView = (ListView) findViewById(R.id.list); @@ -58,19 +59,19 @@ public class ActiveTabsPage extends LinearLayout { boolean needToAttach = false; if (position == -2) { // Create a new tab - mBrowserActivity.openTabToHomePage(); + mUiController.openTabToHomePage(); } else if (position == -1) { // Create a new incognito tab - mBrowserActivity.openIncognitoTab(); + mUiController.openIncognitoTab(); } else { // Open the corresponding tab // If the tab is the current one, switchToTab will // do nothing and return, so we need to make sure // it gets attached back to its mContentView in // removeActiveTabPage - needToAttach = !mBrowserActivity.switchToTab(position); + needToAttach = !mUiController.switchToTab(position); } - mBrowserActivity.removeActiveTabPage(needToAttach); + mUiController.removeActiveTabsPage(needToAttach); } }); } @@ -186,11 +187,11 @@ public class ActiveTabsPage extends LinearLayout { final int closePosition = position; close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - mBrowserActivity.closeTab( + mUiController.closeTab( mControl.getTab(closePosition)); if (tabCount == 1) { - mBrowserActivity.openTabToHomePage(); - mBrowserActivity.removeActiveTabPage(false); + mUiController.openTabToHomePage(); + mUiController.removeActiveTabsPage(false); } else { mNotified = true; notifyDataSetChanged(); diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java index 2b745b1..5670881 100644 --- a/src/com/android/browser/AddBookmarkPage.java +++ b/src/com/android/browser/AddBookmarkPage.java @@ -671,7 +671,7 @@ public class AddBookmarkPage extends Activity String title = mTitle.getText().toString().trim(); String unfilteredUrl; - unfilteredUrl = BrowserActivity.fixUrl(mAddress.getText().toString()); + unfilteredUrl = UrlUtils.fixUrl(mAddress.getText().toString()); boolean emptyTitle = title.length() == 0; boolean emptyUrl = unfilteredUrl.trim().length() == 0; diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java new file mode 100644 index 0000000..052c9c5 --- /dev/null +++ b/src/com/android/browser/BaseUi.java @@ -0,0 +1,829 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser; + +import android.app.ActionBar; +import android.app.Activity; +import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.PixelFormat; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.ActionMode; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.webkit.WebChromeClient; +import android.webkit.WebHistoryItem; +import android.webkit.WebView; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.Toast; + +/** + * UI interface definitions + */ +public class BaseUi implements UI, WebViewFactory { + + private static final String LOGTAG = "BaseUi"; + + private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = + new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT); + + private static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = + new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT, + Gravity.CENTER); + + Activity mActivity; + UiController mUiController; + TabControl mTabControl; + + private Drawable mSecLockIcon; + private Drawable mMixLockIcon; + + private boolean mXLargeScreenSize; + private FrameLayout mBrowserFrameLayout; + private FrameLayout mContentView; + private FrameLayout mCustomViewContainer; + private TitleBarBase mTitleBar; + private TitleBarBase mFakeTitleBar; + private TabBar mTabBar; + + private View mCustomView; + private WebChromeClient.CustomViewCallback mCustomViewCallback; + + private CombinedBookmarkHistoryView mComboView; + + private LinearLayout mErrorConsoleContainer = null; + + private Toast mStopToast; + private ActiveTabsPage mActiveTabsPage; + + // the default