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