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