Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 20 | import android.content.Intent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 21 | import android.content.res.Configuration; |
| 22 | import android.content.res.Resources; |
| 23 | import android.graphics.Bitmap; |
| 24 | import android.graphics.BitmapFactory; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 25 | import android.graphics.Color; |
| 26 | import android.graphics.drawable.BitmapDrawable; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.LayerDrawable; |
| 29 | import android.graphics.drawable.PaintDrawable; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 30 | import android.os.Bundle; |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
| 32 | import android.os.Message; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 33 | import android.text.TextUtils; |
| 34 | import android.util.Log; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 35 | import android.view.Gravity; |
| 36 | import android.view.LayoutInflater; |
| 37 | import android.view.Menu; |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 38 | import android.view.MenuItem; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 39 | import android.view.View; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 40 | import android.view.View.OnClickListener; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 41 | import android.view.ViewGroup; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 42 | import android.view.ViewGroup.LayoutParams; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 43 | import android.view.WindowManager; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 44 | import android.view.inputmethod.InputMethodManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 45 | import android.webkit.WebChromeClient; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 46 | import android.webkit.WebView; |
| 47 | import android.widget.FrameLayout; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 48 | import android.widget.ImageButton; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 49 | import android.widget.LinearLayout; |
| 50 | import android.widget.Toast; |
| 51 | |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 52 | import com.android.browser.Tab.LockIcon; |
| 53 | import com.android.internal.view.menu.MenuBuilder; |
| 54 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 55 | import java.util.List; |
| 56 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 57 | /** |
| 58 | * UI interface definitions |
| 59 | */ |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 60 | public abstract class BaseUi implements UI { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 61 | |
| 62 | private static final String LOGTAG = "BaseUi"; |
| 63 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 64 | protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 65 | new FrameLayout.LayoutParams( |
| 66 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 67 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 68 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 69 | protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 70 | new FrameLayout.LayoutParams( |
| 71 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 72 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 73 | Gravity.CENTER); |
| 74 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 75 | private static final int MSG_HIDE_TITLEBAR = 1; |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 76 | public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 77 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 78 | Activity mActivity; |
| 79 | UiController mUiController; |
| 80 | TabControl mTabControl; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 81 | protected Tab mActiveTab; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 82 | private InputMethodManager mInputManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 83 | |
| 84 | private Drawable mSecLockIcon; |
| 85 | private Drawable mMixLockIcon; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 86 | protected Drawable mGenericFavicon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 87 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 88 | protected FrameLayout mContentView; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 89 | protected FrameLayout mCustomViewContainer; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 90 | |
| 91 | private View mCustomView; |
| 92 | private WebChromeClient.CustomViewCallback mCustomViewCallback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 93 | private int mOriginalOrientation; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 94 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 95 | private LinearLayout mErrorConsoleContainer = null; |
| 96 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 97 | private UrlBarAutoShowManager mUrlBarAutoShowManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 98 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 99 | private Toast mStopToast; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 100 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 101 | // the default <video> poster |
| 102 | private Bitmap mDefaultVideoPoster; |
| 103 | // the video progress view |
| 104 | private View mVideoProgressView; |
| 105 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 106 | private boolean mActivityPaused; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 107 | protected boolean mUseQuickControls; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 108 | protected TitleBar mTitleBar; |
| 109 | private NavigationBarBase mNavigationBar; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 110 | |
| 111 | public BaseUi(Activity browser, UiController controller) { |
| 112 | mActivity = browser; |
| 113 | mUiController = controller; |
| 114 | mTabControl = controller.getTabControl(); |
| 115 | Resources res = mActivity.getResources(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 116 | mInputManager = (InputMethodManager) |
| 117 | browser.getSystemService(Activity.INPUT_METHOD_SERVICE); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 118 | mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark); |
Michael Kolb | 6ced844 | 2011-08-22 13:04:30 -0700 | [diff] [blame] | 119 | mMixLockIcon = res.getDrawable(R.drawable.ic_secure_partial_holo_dark); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 120 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 121 | FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() |
| 122 | .getDecorView().findViewById(android.R.id.content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 123 | LayoutInflater.from(mActivity) |
| 124 | .inflate(R.layout.custom_screen, frameLayout); |
| 125 | mContentView = (FrameLayout) frameLayout.findViewById( |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 126 | R.id.main_content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 127 | mErrorConsoleContainer = (LinearLayout) frameLayout |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 128 | .findViewById(R.id.error_console); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 129 | mCustomViewContainer = (FrameLayout) frameLayout |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 130 | .findViewById(R.id.fullscreen_custom_content); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 131 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 132 | mGenericFavicon = res.getDrawable( |
| 133 | R.drawable.app_web_browser_sm); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 134 | mTitleBar = new TitleBar(mActivity, mUiController, this, |
| 135 | mContentView); |
| 136 | mTitleBar.setProgress(100); |
| 137 | mNavigationBar = mTitleBar.getNavigationBar(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 138 | mUrlBarAutoShowManager = new UrlBarAutoShowManager(this); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 141 | private void cancelStopToast() { |
| 142 | if (mStopToast != null) { |
| 143 | mStopToast.cancel(); |
| 144 | mStopToast = null; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // lifecycle |
| 149 | |
| 150 | public void onPause() { |
Michael Kolb | 7a5cf47 | 2010-11-30 13:23:53 -0800 | [diff] [blame] | 151 | if (isCustomViewShowing()) { |
| 152 | onHideCustomView(); |
| 153 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 154 | cancelStopToast(); |
| 155 | mActivityPaused = true; |
| 156 | } |
| 157 | |
| 158 | public void onResume() { |
| 159 | mActivityPaused = false; |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 160 | // check if we exited without setting active tab |
| 161 | // b: 5188145 |
Michael Kolb | 1a4625a | 2011-08-24 13:40:44 -0700 | [diff] [blame] | 162 | final Tab ct = mTabControl.getCurrentTab(); |
| 163 | if (ct != null) { |
| 164 | setActiveTab(ct); |
| 165 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 168 | protected boolean isActivityPaused() { |
| 169 | return mActivityPaused; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | public void onConfigurationChanged(Configuration config) { |
| 173 | } |
| 174 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 175 | public Activity getActivity() { |
| 176 | return mActivity; |
| 177 | } |
| 178 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 179 | // key handling |
| 180 | |
| 181 | @Override |
| 182 | public boolean onBackKey() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 183 | if (mCustomView != null) { |
| 184 | mUiController.hideCustomView(); |
| 185 | return true; |
| 186 | } |
| 187 | return false; |
| 188 | } |
| 189 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 190 | @Override |
| 191 | public boolean onMenuKey() { |
| 192 | return false; |
| 193 | } |
| 194 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 195 | // Tab callbacks |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 196 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 197 | public void onTabDataChanged(Tab tab) { |
| 198 | setUrlTitle(tab); |
| 199 | setFavicon(tab); |
| 200 | updateLockIconToLatest(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 201 | updateNavigationState(tab); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 202 | mTitleBar.onTabDataChanged(tab); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 203 | mNavigationBar.onTabDataChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 207 | public void bookmarkedStatusHasChanged(Tab tab) { |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 208 | if (tab.inForeground()) { |
| 209 | boolean isBookmark = tab.isBookmarkedSite(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 210 | mNavigationBar.setCurrentUrlIsBookmark(isBookmark); |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 211 | } |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 215 | public void onPageStopped(Tab tab) { |
| 216 | cancelStopToast(); |
| 217 | if (tab.inForeground()) { |
| 218 | mStopToast = Toast |
| 219 | .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); |
| 220 | mStopToast.show(); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 225 | public boolean needsRestoreAllTabs() { |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 226 | return true; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 230 | public void addTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 234 | public void setActiveTab(final Tab tab) { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 235 | mHandler.removeMessages(MSG_HIDE_TITLEBAR); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 236 | if ((tab != mActiveTab) && (mActiveTab != null)) { |
| 237 | removeTabFromContentView(mActiveTab); |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 238 | WebView web = mActiveTab.getWebView(); |
| 239 | if (web != null) { |
| 240 | web.setOnTouchListener(null); |
| 241 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 242 | } |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 243 | mActiveTab = tab; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 244 | WebView web = mActiveTab.getWebView(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 245 | updateUrlBarAutoShowManagerTarget(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 246 | attachTabToContentView(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 247 | setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 248 | onTabDataChanged(tab); |
| 249 | onProgressChanged(tab); |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 250 | boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 251 | mNavigationBar.setIncognitoMode(incognito); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 252 | updateAutoLogin(tab, false); |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 253 | if (web != null && web.getVisibleTitleHeight() |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 254 | != mTitleBar.getEmbeddedHeight() |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 255 | && !mUseQuickControls) { |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 256 | showTitleBarForDuration(); |
| 257 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 258 | } |
| 259 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 260 | protected void updateUrlBarAutoShowManagerTarget() { |
| 261 | WebView web = mActiveTab != null ? mActiveTab.getWebView() : null; |
| 262 | if (!mUseQuickControls && web instanceof BrowserWebView) { |
| 263 | mUrlBarAutoShowManager.setTarget((BrowserWebView) web); |
| 264 | } else { |
| 265 | mUrlBarAutoShowManager.setTarget(null); |
| 266 | } |
| 267 | } |
| 268 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 269 | Tab getActiveTab() { |
| 270 | return mActiveTab; |
| 271 | } |
| 272 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 273 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 274 | public void updateTabs(List<Tab> tabs) { |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 278 | public void removeTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 279 | if (mActiveTab == tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 280 | removeTabFromContentView(tab); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 281 | mActiveTab = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 282 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public void detachTab(Tab tab) { |
| 287 | removeTabFromContentView(tab); |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void attachTab(Tab tab) { |
| 292 | attachTabToContentView(tab); |
| 293 | } |
| 294 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 295 | protected void attachTabToContentView(Tab tab) { |
Michael Kolb | d1e2ccc | 2011-01-24 11:38:31 -0800 | [diff] [blame] | 296 | if ((tab == null) || (tab.getWebView() == null)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 297 | return; |
| 298 | } |
| 299 | View container = tab.getViewContainer(); |
| 300 | WebView mainView = tab.getWebView(); |
| 301 | // Attach the WebView to the container and then attach the |
| 302 | // container to the content view. |
| 303 | FrameLayout wrapper = |
| 304 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 305 | ViewGroup parent = (ViewGroup) mainView.getParent(); |
| 306 | if (parent != wrapper) { |
| 307 | if (parent != null) { |
| 308 | Log.w(LOGTAG, "mMainView already has a parent in" |
| 309 | + " attachTabToContentView!"); |
| 310 | parent.removeView(mainView); |
| 311 | } |
| 312 | wrapper.addView(mainView); |
| 313 | } else { |
| 314 | Log.w(LOGTAG, "mMainView is already attached to wrapper in" |
| 315 | + " attachTabToContentView!"); |
| 316 | } |
| 317 | parent = (ViewGroup) container.getParent(); |
| 318 | if (parent != mContentView) { |
| 319 | if (parent != null) { |
| 320 | Log.w(LOGTAG, "mContainer already has a parent in" |
| 321 | + " attachTabToContentView!"); |
| 322 | parent.removeView(container); |
| 323 | } |
| 324 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 325 | } else { |
| 326 | Log.w(LOGTAG, "mContainer is already attached to content in" |
| 327 | + " attachTabToContentView!"); |
| 328 | } |
| 329 | mUiController.attachSubWindow(tab); |
| 330 | } |
| 331 | |
| 332 | private void removeTabFromContentView(Tab tab) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 333 | hideTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 334 | // Remove the container that contains the main WebView. |
| 335 | WebView mainView = tab.getWebView(); |
| 336 | View container = tab.getViewContainer(); |
| 337 | if (mainView == null) { |
| 338 | return; |
| 339 | } |
| 340 | // Remove the container from the content and then remove the |
| 341 | // WebView from the container. This will trigger a focus change |
| 342 | // needed by WebView. |
Michael Kolb | 20776cc | 2011-01-31 10:19:05 -0800 | [diff] [blame] | 343 | mainView.setEmbeddedTitleBar(null); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 344 | FrameLayout wrapper = |
| 345 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 346 | wrapper.removeView(mainView); |
| 347 | mContentView.removeView(container); |
| 348 | mUiController.endActionMode(); |
| 349 | mUiController.removeSubWindow(tab); |
| 350 | ErrorConsoleView errorConsole = tab.getErrorConsole(false); |
| 351 | if (errorConsole != null) { |
| 352 | mErrorConsoleContainer.removeView(errorConsole); |
| 353 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 356 | @Override |
| 357 | public void onSetWebView(Tab tab, WebView webView) { |
| 358 | View container = tab.getViewContainer(); |
| 359 | if (container == null) { |
| 360 | // The tab consists of a container view, which contains the main |
| 361 | // WebView, as well as any other UI elements associated with the tab. |
| 362 | container = mActivity.getLayoutInflater().inflate(R.layout.tab, |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 363 | mContentView, false); |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 364 | tab.setViewContainer(container); |
| 365 | } |
| 366 | if (tab.getWebView() != webView) { |
| 367 | // Just remove the old one. |
| 368 | FrameLayout wrapper = |
| 369 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 370 | wrapper.removeView(tab.getWebView()); |
| 371 | } |
| 372 | } |
| 373 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 374 | /** |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 375 | * create a sub window container and webview for the tab |
| 376 | * Note: this methods operates through side-effects for now |
| 377 | * it sets both the subView and subViewContainer for the given tab |
| 378 | * @param tab tab to create the sub window for |
| 379 | * @param subView webview to be set as a subwindow for the tab |
| 380 | */ |
| 381 | @Override |
| 382 | public void createSubWindow(Tab tab, WebView subView) { |
| 383 | View subViewContainer = mActivity.getLayoutInflater().inflate( |
| 384 | R.layout.browser_subwindow, null); |
| 385 | ViewGroup inner = (ViewGroup) subViewContainer |
| 386 | .findViewById(R.id.inner_container); |
| 387 | inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, |
| 388 | LayoutParams.MATCH_PARENT)); |
| 389 | final ImageButton cancel = (ImageButton) subViewContainer |
| 390 | .findViewById(R.id.subwindow_close); |
| 391 | final WebView cancelSubView = subView; |
| 392 | cancel.setOnClickListener(new OnClickListener() { |
| 393 | public void onClick(View v) { |
| 394 | cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView); |
| 395 | } |
| 396 | }); |
| 397 | tab.setSubWebView(subView); |
| 398 | tab.setSubViewContainer(subViewContainer); |
| 399 | } |
| 400 | |
| 401 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 402 | * Remove the sub window from the content view. |
| 403 | */ |
| 404 | @Override |
| 405 | public void removeSubWindow(View subviewContainer) { |
| 406 | mContentView.removeView(subviewContainer); |
| 407 | mUiController.endActionMode(); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Attach the sub window to the content view. |
| 412 | */ |
| 413 | @Override |
| 414 | public void attachSubWindow(View container) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 415 | if (container.getParent() != null) { |
| 416 | // already attached, remove first |
| 417 | ((ViewGroup) container.getParent()).removeView(container); |
| 418 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 419 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 420 | } |
| 421 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 422 | protected void refreshWebView() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 423 | WebView web = getWebView(); |
| 424 | if (web != null) { |
| 425 | web.invalidate(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 429 | public void editUrl(boolean clearInput) { |
| 430 | if (mUiController.isInCustomActionMode()) { |
| 431 | mUiController.endActionMode(); |
| 432 | } |
| 433 | showTitleBar(); |
Michael Kolb | ace2ff8 | 2011-08-12 13:36:07 -0700 | [diff] [blame] | 434 | if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 435 | mNavigationBar.startEditingUrl(clearInput); |
| 436 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 439 | boolean canShowTitleBar() { |
| 440 | return !isTitleBarShowing() |
| 441 | && !isActivityPaused() |
| 442 | && (getActiveTab() != null) |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 443 | && (getWebView() != null) |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 444 | && !mUiController.isInCustomActionMode(); |
| 445 | } |
| 446 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 447 | protected void showTitleBar() { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 448 | mHandler.removeMessages(MSG_HIDE_TITLEBAR); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 449 | if (canShowTitleBar()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 450 | mTitleBar.show(); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 451 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | protected void hideTitleBar() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 455 | if (mTitleBar.isShowing()) { |
| 456 | mTitleBar.hide(); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 457 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | protected boolean isTitleBarShowing() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 461 | return mTitleBar.isShowing(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 462 | } |
| 463 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 464 | public boolean isEditingUrl() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 465 | return mTitleBar.isEditingUrl(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 466 | } |
| 467 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 468 | public TitleBar getTitleBar() { |
| 469 | return mTitleBar; |
| 470 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 471 | |
| 472 | protected void setTitleGravity(int gravity) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 473 | WebView web = getWebView(); |
| 474 | if (web != null) { |
| 475 | web.setTitleBarGravity(gravity); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 479 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 480 | public void showVoiceTitleBar(String title, List<String> results) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 481 | mNavigationBar.setInVoiceMode(true, results); |
| 482 | mNavigationBar.setDisplayTitle(title); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 485 | @Override |
| 486 | public void revertVoiceTitleBar(Tab tab) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 487 | mNavigationBar.setInVoiceMode(false, null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 488 | String url = tab.getUrl(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 489 | mNavigationBar.setDisplayTitle(url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 493 | public void registerDropdownChangeListener(DropdownChangeListener d) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 494 | mNavigationBar.registerDropdownChangeListener(d); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | @Override |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 498 | public void showComboView(ComboViews startingView, Bundle extras) { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 499 | Intent intent = new Intent(mActivity, ComboViewActivity.class); |
| 500 | intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name()); |
| 501 | intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras); |
| 502 | Tab t = getActiveTab(); |
| 503 | if (t != null) { |
| 504 | intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl()); |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 505 | } |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 506 | intent.putExtra(ComboViewActivity.EXTRA_BOOKMARK_PAGE, |
| 507 | mUiController.createBookmarkCurrentPageIntent(false)); |
| 508 | mActivity.startActivityForResult(intent, Controller.COMBO_VIEW); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | @Override |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 512 | public void showCustomView(View view, int requestedOrientation, |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 513 | WebChromeClient.CustomViewCallback callback) { |
| 514 | // if a view already exists then immediately terminate the new one |
| 515 | if (mCustomView != null) { |
| 516 | callback.onCustomViewHidden(); |
| 517 | return; |
| 518 | } |
| 519 | |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 520 | mOriginalOrientation = mActivity.getRequestedOrientation(); |
| 521 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 522 | // Add the custom view to its container. |
| 523 | mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); |
| 524 | mCustomView = view; |
| 525 | mCustomViewCallback = callback; |
| 526 | // Hide the content view. |
| 527 | mContentView.setVisibility(View.GONE); |
| 528 | // Finally show the custom view container. |
| 529 | setStatusBarVisibility(false); |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 530 | mActivity.setRequestedOrientation(requestedOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 531 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 532 | mCustomViewContainer.bringToFront(); |
| 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public void onHideCustomView() { |
| 537 | if (mCustomView == null) |
| 538 | return; |
| 539 | |
| 540 | // Hide the custom view. |
| 541 | mCustomView.setVisibility(View.GONE); |
| 542 | // Remove the custom view from its container. |
| 543 | mCustomViewContainer.removeView(mCustomView); |
| 544 | mCustomView = null; |
| 545 | mCustomViewContainer.setVisibility(View.GONE); |
| 546 | mCustomViewCallback.onCustomViewHidden(); |
| 547 | // Show the content view. |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 548 | mActivity.setRequestedOrientation(mOriginalOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 549 | setStatusBarVisibility(true); |
| 550 | mContentView.setVisibility(View.VISIBLE); |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public boolean isCustomViewShowing() { |
| 555 | return mCustomView != null; |
| 556 | } |
| 557 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 558 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 559 | if (mInputManager.isActive()) { |
| 560 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 561 | 0); |
| 562 | } |
| 563 | } |
| 564 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 565 | @Override |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 566 | public boolean isWebShowing() { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 567 | return mCustomView == null; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 568 | } |
| 569 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 570 | @Override |
| 571 | public void showAutoLogin(Tab tab) { |
| 572 | updateAutoLogin(tab, true); |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public void hideAutoLogin(Tab tab) { |
| 577 | updateAutoLogin(tab, true); |
| 578 | } |
| 579 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 580 | // ------------------------------------------------------------------------- |
| 581 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 582 | protected void updateNavigationState(Tab tab) { |
| 583 | } |
| 584 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 585 | protected void updateAutoLogin(Tab tab, boolean animate) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 586 | mTitleBar.updateAutoLogin(tab, animate); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 587 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 588 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 589 | /** |
| 590 | * Update the lock icon to correspond to our latest state. |
| 591 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 592 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 593 | if (t != null && t.inForeground()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 594 | updateLockIconImage(t.getLockIconType()); |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 599 | * Updates the lock-icon image in the title-bar. |
| 600 | */ |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 601 | private void updateLockIconImage(LockIcon lockIconType) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 602 | Drawable d = null; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 603 | if (lockIconType == LockIcon.LOCK_ICON_SECURE) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 604 | d = mSecLockIcon; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 605 | } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 606 | d = mMixLockIcon; |
| 607 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 608 | mNavigationBar.setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 609 | } |
| 610 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 611 | protected void setUrlTitle(Tab tab) { |
| 612 | String url = tab.getUrl(); |
| 613 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 614 | if (TextUtils.isEmpty(title)) { |
| 615 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 616 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 617 | if (tab.isInVoiceSearchMode()) return; |
| 618 | if (tab.inForeground()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 619 | mNavigationBar.setDisplayTitle(url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 624 | protected void setFavicon(Tab tab) { |
| 625 | if (tab.inForeground()) { |
| 626 | Bitmap icon = tab.getFavicon(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 627 | mNavigationBar.setFavicon(icon); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 628 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | @Override |
| 632 | public void onActionModeFinished(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 635 | // active tabs page |
| 636 | |
| 637 | public void showActiveTabsPage() { |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Remove the active tabs page. |
| 642 | */ |
| 643 | public void removeActiveTabsPage() { |
| 644 | } |
| 645 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 646 | // menu handling callbacks |
| 647 | |
| 648 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 649 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 650 | return true; |
| 651 | } |
| 652 | |
| 653 | @Override |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 654 | public void updateMenuState(Tab tab, Menu menu) { |
| 655 | } |
| 656 | |
| 657 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 658 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | @Override |
| 662 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 666 | public boolean onOptionsItemSelected(MenuItem item) { |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 671 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | @Override |
| 675 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | @Override |
| 679 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | @Override |
| 683 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | // error console |
| 687 | |
| 688 | @Override |
| 689 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
Michael Kolb | 9fcefd1 | 2011-02-17 10:55:59 -0800 | [diff] [blame] | 690 | if (tab == null) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 691 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 692 | if (flag) { |
| 693 | // Setting the show state of the console will cause it's the layout |
| 694 | // to be inflated. |
| 695 | if (errorConsole.numberOfErrors() > 0) { |
| 696 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 697 | } else { |
| 698 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 699 | } |
| 700 | if (errorConsole.getParent() != null) { |
| 701 | mErrorConsoleContainer.removeView(errorConsole); |
| 702 | } |
| 703 | // Now we can add it to the main view. |
| 704 | mErrorConsoleContainer.addView(errorConsole, |
| 705 | new LinearLayout.LayoutParams( |
| 706 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 707 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 708 | } else { |
| 709 | mErrorConsoleContainer.removeView(errorConsole); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | private void setStatusBarVisibility(boolean visible) { |
Joe Onorato | d3bf86f | 2011-01-25 20:07:10 -0800 | [diff] [blame] | 714 | WindowManager.LayoutParams params = mActivity.getWindow().getAttributes(); |
| 715 | params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN; |
| 716 | mActivity.getWindow().setAttributes(params); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 719 | // ------------------------------------------------------------------------- |
| 720 | // Helper function for WebChromeClient |
| 721 | // ------------------------------------------------------------------------- |
| 722 | |
| 723 | @Override |
| 724 | public Bitmap getDefaultVideoPoster() { |
| 725 | if (mDefaultVideoPoster == null) { |
| 726 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 727 | mActivity.getResources(), R.drawable.default_video_poster); |
| 728 | } |
| 729 | return mDefaultVideoPoster; |
| 730 | } |
| 731 | |
| 732 | @Override |
| 733 | public View getVideoLoadingProgressView() { |
| 734 | if (mVideoProgressView == null) { |
| 735 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 736 | mVideoProgressView = inflater.inflate( |
| 737 | R.layout.video_loading_progress, null); |
| 738 | } |
| 739 | return mVideoProgressView; |
| 740 | } |
| 741 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 742 | @Override |
| 743 | public void showMaxTabsWarning() { |
| 744 | Toast warning = Toast.makeText(mActivity, |
| 745 | mActivity.getString(R.string.max_tabs_warning), |
| 746 | Toast.LENGTH_SHORT); |
| 747 | warning.show(); |
| 748 | } |
| 749 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 750 | protected WebView getWebView() { |
| 751 | if (mActiveTab != null) { |
| 752 | return mActiveTab.getWebView(); |
| 753 | } else { |
| 754 | return null; |
| 755 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Michael Kolb | fedb492 | 2011-04-20 16:45:33 -0700 | [diff] [blame] | 758 | protected Menu getMenu() { |
| 759 | MenuBuilder menu = new MenuBuilder(mActivity); |
| 760 | mActivity.getMenuInflater().inflate(R.menu.browser, menu); |
| 761 | return menu; |
| 762 | } |
| 763 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 764 | public void setFullscreen(boolean enabled) { |
| 765 | if (enabled) { |
| 766 | mActivity.getWindow().setFlags( |
| 767 | WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| 768 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 769 | } else { |
| 770 | mActivity.getWindow().clearFlags( |
| 771 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 772 | } |
| 773 | } |
| 774 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 775 | public Drawable getFaviconDrawable(Bitmap icon) { |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 776 | Drawable[] array = new Drawable[3]; |
| 777 | array[0] = new PaintDrawable(Color.BLACK); |
| 778 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 779 | array[1] = p; |
| 780 | if (icon == null) { |
| 781 | array[2] = mGenericFavicon; |
| 782 | } else { |
| 783 | array[2] = new BitmapDrawable(icon); |
| 784 | } |
| 785 | LayerDrawable d = new LayerDrawable(array); |
| 786 | d.setLayerInset(1, 1, 1, 1, 1); |
| 787 | d.setLayerInset(2, 2, 2, 2, 2); |
| 788 | return d; |
| 789 | } |
| 790 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 791 | public boolean isLoading() { |
| 792 | return mActiveTab != null ? mActiveTab.inPageLoad() : false; |
| 793 | } |
| 794 | |
| 795 | /** |
| 796 | * Suggest to the UI that the title bar can be hidden. The UI will then |
| 797 | * decide whether or not to hide based off a number of factors, such |
| 798 | * as if the user is editing the URL bar or if the page is loading |
| 799 | */ |
| 800 | public void suggestHideTitleBar() { |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 801 | if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible() |
| 802 | && !mNavigationBar.isMenuShowing()) { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 803 | hideTitleBar(); |
| 804 | } |
| 805 | } |
| 806 | |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame^] | 807 | protected final void showTitleBarForDuration() { |
| 808 | showTitleBarForDuration(HIDE_TITLEBAR_DELAY); |
| 809 | } |
| 810 | |
| 811 | protected final void showTitleBarForDuration(long duration) { |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 812 | showTitleBar(); |
| 813 | Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR); |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame^] | 814 | mHandler.sendMessageDelayed(msg, duration); |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 815 | } |
| 816 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 817 | private Handler mHandler = new Handler() { |
| 818 | |
| 819 | @Override |
| 820 | public void handleMessage(Message msg) { |
| 821 | if (msg.what == MSG_HIDE_TITLEBAR) { |
| 822 | suggestHideTitleBar(); |
| 823 | } |
| 824 | } |
| 825 | }; |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 826 | |
| 827 | @Override |
| 828 | public void showWeb(boolean animate) { |
| 829 | mUiController.hideCustomView(); |
| 830 | } |
| 831 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 832 | } |