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