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