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