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