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