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