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