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 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 18 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 20 | import android.content.Context; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 21 | import android.content.Intent; |
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; |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 35 | import android.view.ActionMode; |
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; |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 39 | import android.view.MenuItem; |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 40 | import android.view.MotionEvent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 41 | import android.view.View; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 42 | import android.view.View.OnClickListener; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 43 | import android.view.ViewGroup; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 44 | import android.view.ViewGroup.LayoutParams; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 45 | import android.view.Window; |
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; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 48 | import android.webkit.WebChromeClient.CustomViewCallback; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 49 | import android.widget.FrameLayout; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 50 | import android.widget.ImageButton; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 51 | import android.widget.LinearLayout; |
| 52 | import android.widget.Toast; |
| 53 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 54 | import com.android.browser.R; |
| 55 | import com.android.browser.Tab.SecurityState; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 56 | |
| 57 | import org.codeaurora.swe.WebView; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 58 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 59 | import java.util.List; |
| 60 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 61 | /** |
| 62 | * UI interface definitions |
| 63 | */ |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 64 | public abstract class BaseUi implements UI { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 65 | |
| 66 | private static final String LOGTAG = "BaseUi"; |
| 67 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 68 | protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 69 | new FrameLayout.LayoutParams( |
| 70 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 71 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 72 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 73 | protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 74 | new FrameLayout.LayoutParams( |
| 75 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 76 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 77 | Gravity.CENTER); |
| 78 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 79 | private static final int MSG_HIDE_TITLEBAR = 1; |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 80 | public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 81 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 82 | Activity mActivity; |
| 83 | UiController mUiController; |
| 84 | TabControl mTabControl; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 85 | protected Tab mActiveTab; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 86 | private InputMethodManager mInputManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 87 | |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 88 | private Drawable mLockIconSecure; |
| 89 | private Drawable mLockIconMixed; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 90 | protected Drawable mGenericFavicon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 91 | |
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 | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 94 | protected FrameLayout mFullscreenContainer; |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 95 | private FrameLayout mFixedTitlebarContainer; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 96 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 97 | private View mCustomView; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 98 | private CustomViewCallback mCustomViewCallback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 99 | private int mOriginalOrientation; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 100 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 101 | private LinearLayout mErrorConsoleContainer = null; |
| 102 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 103 | private UrlBarAutoShowManager mUrlBarAutoShowManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 104 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 105 | private Toast mStopToast; |
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; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 114 | protected TitleBar mTitleBar; |
| 115 | private NavigationBarBase mNavigationBar; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 116 | protected PieControl mPieControl; |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 117 | private boolean mBlockFocusAnimations; |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 118 | private boolean mFullScreen; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 119 | |
| 120 | public BaseUi(Activity browser, UiController controller) { |
| 121 | mActivity = browser; |
| 122 | mUiController = controller; |
| 123 | mTabControl = controller.getTabControl(); |
| 124 | Resources res = mActivity.getResources(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 125 | mInputManager = (InputMethodManager) |
| 126 | browser.getSystemService(Activity.INPUT_METHOD_SERVICE); |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 127 | mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark); |
| 128 | mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 129 | FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() |
| 130 | .getDecorView().findViewById(android.R.id.content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 131 | LayoutInflater.from(mActivity) |
| 132 | .inflate(R.layout.custom_screen, frameLayout); |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 133 | mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById( |
| 134 | R.id.fixed_titlebar_container); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 135 | mContentView = (FrameLayout) frameLayout.findViewById( |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 136 | R.id.main_content); |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 137 | mCustomViewContainer = (FrameLayout) frameLayout.findViewById( |
| 138 | R.id.fullscreen_custom_content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 139 | mErrorConsoleContainer = (LinearLayout) frameLayout |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 140 | .findViewById(R.id.error_console); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 141 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 142 | mGenericFavicon = res.getDrawable( |
| 143 | R.drawable.app_web_browser_sm); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 144 | mTitleBar = new TitleBar(mActivity, mUiController, this, |
| 145 | mContentView); |
| 146 | mTitleBar.setProgress(100); |
| 147 | mNavigationBar = mTitleBar.getNavigationBar(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 148 | mUrlBarAutoShowManager = new UrlBarAutoShowManager(this); |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 149 | mFullScreen = false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 152 | private void cancelStopToast() { |
| 153 | if (mStopToast != null) { |
| 154 | mStopToast.cancel(); |
| 155 | mStopToast = null; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // lifecycle |
| 160 | |
| 161 | public void onPause() { |
Michael Kolb | 7a5cf47 | 2010-11-30 13:23:53 -0800 | [diff] [blame] | 162 | if (isCustomViewShowing()) { |
| 163 | onHideCustomView(); |
| 164 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 165 | cancelStopToast(); |
| 166 | mActivityPaused = true; |
| 167 | } |
| 168 | |
| 169 | public void onResume() { |
| 170 | mActivityPaused = false; |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 171 | // check if we exited without setting active tab |
| 172 | // b: 5188145 |
Michael Kolb | 1a4625a | 2011-08-24 13:40:44 -0700 | [diff] [blame] | 173 | final Tab ct = mTabControl.getCurrentTab(); |
| 174 | if (ct != null) { |
| 175 | setActiveTab(ct); |
| 176 | } |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 177 | mTitleBar.onResume(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 180 | protected boolean isActivityPaused() { |
| 181 | return mActivityPaused; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | public void onConfigurationChanged(Configuration config) { |
| 185 | } |
| 186 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 187 | public Activity getActivity() { |
| 188 | return mActivity; |
| 189 | } |
| 190 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 191 | // key handling |
| 192 | |
| 193 | @Override |
| 194 | public boolean onBackKey() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 195 | if (mCustomView != null) { |
| 196 | mUiController.hideCustomView(); |
| 197 | return true; |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 198 | } else if (mFullScreen) { |
| 199 | setTabFullscreen(false); |
| 200 | return true; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 201 | } |
| 202 | return false; |
| 203 | } |
| 204 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 205 | @Override |
| 206 | public boolean onMenuKey() { |
| 207 | return false; |
| 208 | } |
| 209 | |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 210 | @Override |
| 211 | public void setUseQuickControls(boolean useQuickControls) { |
| 212 | mUseQuickControls = useQuickControls; |
| 213 | mTitleBar.setUseQuickControls(mUseQuickControls); |
| 214 | if (useQuickControls) { |
| 215 | mPieControl = new PieControl(mActivity, mUiController, this); |
| 216 | mPieControl.attachToContainer(mContentView); |
| 217 | } else { |
| 218 | if (mPieControl != null) { |
| 219 | mPieControl.removeFromContainer(mContentView); |
| 220 | } |
| 221 | } |
| 222 | updateUrlBarAutoShowManagerTarget(); |
| 223 | } |
| 224 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 225 | // Tab callbacks |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 226 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 227 | public void onTabDataChanged(Tab tab) { |
| 228 | setUrlTitle(tab); |
| 229 | setFavicon(tab); |
| 230 | updateLockIconToLatest(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 231 | updateNavigationState(tab); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 232 | mTitleBar.onTabDataChanged(tab); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 233 | mNavigationBar.onTabDataChanged(tab); |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 234 | onProgressChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 238 | public void onProgressChanged(Tab tab) { |
| 239 | int progress = tab.getLoadProgress(); |
| 240 | if (tab.inForeground()) { |
| 241 | mTitleBar.setProgress(progress); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 246 | public void bookmarkedStatusHasChanged(Tab tab) { |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 247 | if (tab.inForeground()) { |
| 248 | boolean isBookmark = tab.isBookmarkedSite(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 249 | mNavigationBar.setCurrentUrlIsBookmark(isBookmark); |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 250 | } |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 254 | public void onPageStopped(Tab tab) { |
| 255 | cancelStopToast(); |
| 256 | if (tab.inForeground()) { |
| 257 | mStopToast = Toast |
| 258 | .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); |
| 259 | mStopToast.show(); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 264 | public boolean needsRestoreAllTabs() { |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 265 | return true; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 269 | public void addTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 273 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 7ac63b6 | 2011-12-16 09:52:29 -0800 | [diff] [blame] | 274 | if (tab == null) return; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 275 | Tab tabToRemove = null; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 276 | Tab tabToWaitFor = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 277 | |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 278 | // block unnecessary focus change animations during tab switch |
| 279 | mBlockFocusAnimations = true; |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 280 | mHandler.removeMessages(MSG_HIDE_TITLEBAR); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 281 | if ((tab != mActiveTab) && (mActiveTab != null)) { |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 282 | tabToRemove = mActiveTab; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 283 | WebView web = mActiveTab.getWebView(); |
| 284 | if (web != null) { |
| 285 | web.setOnTouchListener(null); |
| 286 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 287 | } |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 288 | mActiveTab = tab; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 289 | BrowserWebView web = (BrowserWebView) mActiveTab.getWebView(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 290 | updateUrlBarAutoShowManagerTarget(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 291 | attachTabToContentView(tab); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 292 | if (web != null) { |
| 293 | // Request focus on the top window. |
| 294 | if (mUseQuickControls) { |
| 295 | mPieControl.forceToTop(mContentView); |
| 296 | web.setTitleBar(null); |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 297 | mTitleBar.hide(); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 298 | } else { |
| 299 | web.setTitleBar(mTitleBar); |
| 300 | mTitleBar.onScrollChanged(); |
| 301 | } |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 302 | tabToWaitFor = mActiveTab; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 303 | } |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 304 | mTitleBar.bringToFront(); |
Michael Kolb | f896352 | 2012-04-10 10:52:34 -0700 | [diff] [blame] | 305 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 306 | setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 307 | onTabDataChanged(tab); |
| 308 | onProgressChanged(tab); |
Michael Kolb | 03b6bc6 | 2011-09-02 16:19:53 -0700 | [diff] [blame] | 309 | mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled()); |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 310 | mBlockFocusAnimations = false; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 311 | |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 312 | scheduleRemoveTab(tabToRemove, tabToWaitFor); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | Tab mTabToRemove = null; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 316 | Tab mTabToWaitFor = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 317 | int mNumRemoveTries = 0; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 318 | Runnable mRunnable = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 319 | |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 320 | protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) { |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 321 | //remove previously scehduled tab |
| 322 | if (mTabToRemove != null) { |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 323 | if (mRunnable != null) |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 324 | mTitleBar.removeCallbacks(mRunnable); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 325 | removeTabFromContentView(mTabToRemove); |
| 326 | mTabToRemove.performPostponedDestroy(); |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 327 | mRunnable = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 328 | } |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 329 | mTabToRemove = tabToRemove; |
| 330 | mTabToWaitFor = tabToWaitFor; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 331 | mNumRemoveTries = 0; |
| 332 | |
| 333 | if (mTabToRemove != null) { |
| 334 | mTabToRemove.postponeDestroy(); |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 335 | tryRemoveTab(); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
| 339 | protected void tryRemoveTab() { |
| 340 | mNumRemoveTries++; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 341 | // Ensure the webview is still valid |
| 342 | if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) { |
| 343 | if (!mTabToWaitFor.getWebView().isReady()) { |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 344 | if (mRunnable == null) { |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 345 | mRunnable = new Runnable() { |
| 346 | public void run() { |
| 347 | tryRemoveTab(); |
| 348 | } |
| 349 | }; |
| 350 | } |
| 351 | /*if the new tab is still not ready, wait another 2 frames |
| 352 | before trying again. 1 frame for the tab to render the first |
| 353 | frame, another 1 frame to make sure the swap is done*/ |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 354 | mTitleBar.postDelayed(mRunnable, 33); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | } |
| 358 | if (mTabToRemove != null) { |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 359 | if (mRunnable != null) |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 360 | mTitleBar.removeCallbacks(mRunnable); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 361 | removeTabFromContentView(mTabToRemove); |
| 362 | mTabToRemove.performPostponedDestroy(); |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 363 | mRunnable = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 364 | } |
| 365 | mTabToRemove = null; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 366 | mTabToWaitFor = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 367 | } |
| 368 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 369 | protected void updateUrlBarAutoShowManagerTarget() { |
| 370 | WebView web = mActiveTab != null ? mActiveTab.getWebView() : null; |
| 371 | if (!mUseQuickControls && web instanceof BrowserWebView) { |
| 372 | mUrlBarAutoShowManager.setTarget((BrowserWebView) web); |
| 373 | } else { |
| 374 | mUrlBarAutoShowManager.setTarget(null); |
| 375 | } |
| 376 | } |
| 377 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 378 | Tab getActiveTab() { |
| 379 | return mActiveTab; |
| 380 | } |
| 381 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 382 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 383 | public void updateTabs(List<Tab> tabs) { |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 387 | public void removeTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 388 | if (mActiveTab == tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 389 | removeTabFromContentView(tab); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 390 | mActiveTab = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 391 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public void detachTab(Tab tab) { |
| 396 | removeTabFromContentView(tab); |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public void attachTab(Tab tab) { |
| 401 | attachTabToContentView(tab); |
| 402 | } |
| 403 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 404 | protected void attachTabToContentView(Tab tab) { |
Michael Kolb | d1e2ccc | 2011-01-24 11:38:31 -0800 | [diff] [blame] | 405 | if ((tab == null) || (tab.getWebView() == null)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 406 | return; |
| 407 | } |
| 408 | View container = tab.getViewContainer(); |
| 409 | WebView mainView = tab.getWebView(); |
| 410 | // Attach the WebView to the container and then attach the |
| 411 | // container to the content view. |
| 412 | FrameLayout wrapper = |
| 413 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 414 | ViewGroup parent = (ViewGroup) mainView.getParent(); |
| 415 | if (parent != wrapper) { |
| 416 | if (parent != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 417 | parent.removeView(mainView); |
| 418 | } |
| 419 | wrapper.addView(mainView); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 420 | } |
| 421 | parent = (ViewGroup) container.getParent(); |
| 422 | if (parent != mContentView) { |
| 423 | if (parent != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 424 | parent.removeView(container); |
| 425 | } |
| 426 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 427 | } |
| 428 | mUiController.attachSubWindow(tab); |
| 429 | } |
| 430 | |
| 431 | private void removeTabFromContentView(Tab tab) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 432 | hideTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 433 | // Remove the container that contains the main WebView. |
| 434 | WebView mainView = tab.getWebView(); |
| 435 | View container = tab.getViewContainer(); |
| 436 | if (mainView == null) { |
| 437 | return; |
| 438 | } |
| 439 | // Remove the container from the content and then remove the |
| 440 | // WebView from the container. This will trigger a focus change |
| 441 | // needed by WebView. |
| 442 | FrameLayout wrapper = |
| 443 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 444 | wrapper.removeView(mainView); |
| 445 | mContentView.removeView(container); |
| 446 | mUiController.endActionMode(); |
| 447 | mUiController.removeSubWindow(tab); |
| 448 | ErrorConsoleView errorConsole = tab.getErrorConsole(false); |
| 449 | if (errorConsole != null) { |
| 450 | mErrorConsoleContainer.removeView(errorConsole); |
| 451 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 454 | @Override |
| 455 | public void onSetWebView(Tab tab, WebView webView) { |
| 456 | View container = tab.getViewContainer(); |
| 457 | if (container == null) { |
| 458 | // The tab consists of a container view, which contains the main |
| 459 | // WebView, as well as any other UI elements associated with the tab. |
| 460 | container = mActivity.getLayoutInflater().inflate(R.layout.tab, |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 461 | mContentView, false); |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 462 | tab.setViewContainer(container); |
| 463 | } |
| 464 | if (tab.getWebView() != webView) { |
| 465 | // Just remove the old one. |
| 466 | FrameLayout wrapper = |
| 467 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 468 | wrapper.removeView(tab.getWebView()); |
| 469 | } |
| 470 | } |
| 471 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 472 | /** |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 473 | * create a sub window container and webview for the tab |
| 474 | * Note: this methods operates through side-effects for now |
| 475 | * it sets both the subView and subViewContainer for the given tab |
| 476 | * @param tab tab to create the sub window for |
| 477 | * @param subView webview to be set as a subwindow for the tab |
| 478 | */ |
| 479 | @Override |
| 480 | public void createSubWindow(Tab tab, WebView subView) { |
| 481 | View subViewContainer = mActivity.getLayoutInflater().inflate( |
| 482 | R.layout.browser_subwindow, null); |
| 483 | ViewGroup inner = (ViewGroup) subViewContainer |
| 484 | .findViewById(R.id.inner_container); |
| 485 | inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, |
| 486 | LayoutParams.MATCH_PARENT)); |
| 487 | final ImageButton cancel = (ImageButton) subViewContainer |
| 488 | .findViewById(R.id.subwindow_close); |
| 489 | final WebView cancelSubView = subView; |
| 490 | cancel.setOnClickListener(new OnClickListener() { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 491 | @Override |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 492 | public void onClick(View v) { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 493 | ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView); |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 494 | } |
| 495 | }); |
| 496 | tab.setSubWebView(subView); |
| 497 | tab.setSubViewContainer(subViewContainer); |
| 498 | } |
| 499 | |
| 500 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 501 | * Remove the sub window from the content view. |
| 502 | */ |
| 503 | @Override |
| 504 | public void removeSubWindow(View subviewContainer) { |
| 505 | mContentView.removeView(subviewContainer); |
| 506 | mUiController.endActionMode(); |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Attach the sub window to the content view. |
| 511 | */ |
| 512 | @Override |
| 513 | public void attachSubWindow(View container) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 514 | if (container.getParent() != null) { |
| 515 | // already attached, remove first |
| 516 | ((ViewGroup) container.getParent()).removeView(container); |
| 517 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 518 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 519 | } |
| 520 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 521 | protected void refreshWebView() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 522 | WebView web = getWebView(); |
| 523 | if (web != null) { |
| 524 | web.invalidate(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 528 | public void editUrl(boolean clearInput, boolean forceIME) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 529 | if (mUiController.isInCustomActionMode()) { |
| 530 | mUiController.endActionMode(); |
| 531 | } |
| 532 | showTitleBar(); |
Michael Kolb | ace2ff8 | 2011-08-12 13:36:07 -0700 | [diff] [blame] | 533 | if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 534 | mNavigationBar.startEditingUrl(clearInput, forceIME); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 535 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 538 | boolean canShowTitleBar() { |
| 539 | return !isTitleBarShowing() |
| 540 | && !isActivityPaused() |
| 541 | && (getActiveTab() != null) |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 542 | && (getWebView() != null) |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 543 | && !mUiController.isInCustomActionMode(); |
| 544 | } |
| 545 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 546 | protected void showTitleBar() { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 547 | mHandler.removeMessages(MSG_HIDE_TITLEBAR); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 548 | if (canShowTitleBar()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 549 | mTitleBar.show(); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 550 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | protected void hideTitleBar() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 554 | if (mTitleBar.isShowing()) { |
| 555 | mTitleBar.hide(); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 556 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | protected boolean isTitleBarShowing() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 560 | return mTitleBar.isShowing(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 561 | } |
| 562 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 563 | public boolean isEditingUrl() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 564 | return mTitleBar.isEditingUrl(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Michael Kolb | 80f7508 | 2012-04-10 10:50:06 -0700 | [diff] [blame] | 567 | public void stopEditingUrl() { |
| 568 | mTitleBar.getNavigationBar().stopEditingUrl(); |
| 569 | } |
| 570 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 571 | public TitleBar getTitleBar() { |
| 572 | return mTitleBar; |
| 573 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 574 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 575 | @Override |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 576 | public void showComboView(ComboViews startingView, Bundle extras) { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 577 | Intent intent = new Intent(mActivity, ComboViewActivity.class); |
| 578 | intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name()); |
| 579 | intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras); |
| 580 | Tab t = getActiveTab(); |
| 581 | if (t != null) { |
| 582 | intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl()); |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 583 | } |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 584 | mActivity.startActivityForResult(intent, Controller.COMBO_VIEW); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | @Override |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 588 | public void showCustomView(View view, int requestedOrientation, |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 589 | CustomViewCallback callback) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 590 | // if a view already exists then immediately terminate the new one |
| 591 | if (mCustomView != null) { |
| 592 | callback.onCustomViewHidden(); |
| 593 | return; |
| 594 | } |
| 595 | |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 596 | mOriginalOrientation = mActivity.getRequestedOrientation(); |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 597 | FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); |
| 598 | mFullscreenContainer = new FullscreenHolder(mActivity); |
| 599 | mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS); |
| 600 | decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS); |
| 601 | mCustomView = view; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 602 | setFullscreen(true); |
Michael Kolb | 54217b3 | 2012-05-15 13:24:24 -0700 | [diff] [blame] | 603 | ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 604 | mCustomViewCallback = callback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 605 | mActivity.setRequestedOrientation(requestedOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public void onHideCustomView() { |
Michael Kolb | 54217b3 | 2012-05-15 13:24:24 -0700 | [diff] [blame] | 610 | ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 611 | if (mCustomView == null) |
| 612 | return; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 613 | setFullscreen(false); |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 614 | FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); |
| 615 | decor.removeView(mFullscreenContainer); |
| 616 | mFullscreenContainer = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 617 | mCustomView = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 618 | mCustomViewCallback.onCustomViewHidden(); |
| 619 | // Show the content view. |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 620 | mActivity.setRequestedOrientation(mOriginalOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public boolean isCustomViewShowing() { |
| 625 | return mCustomView != null; |
| 626 | } |
| 627 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 628 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 629 | if (mInputManager.isActive()) { |
| 630 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 631 | 0); |
| 632 | } |
| 633 | } |
| 634 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 635 | @Override |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 636 | public boolean isWebShowing() { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 637 | return mCustomView == null; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 638 | } |
| 639 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 640 | // ------------------------------------------------------------------------- |
| 641 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 642 | protected void updateNavigationState(Tab tab) { |
| 643 | } |
| 644 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 645 | /** |
| 646 | * Update the lock icon to correspond to our latest state. |
| 647 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 648 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 649 | if (t != null && t.inForeground()) { |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 650 | updateLockIconImage(t.getSecurityState()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 655 | * Updates the lock-icon image in the title-bar. |
| 656 | */ |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 657 | private void updateLockIconImage(SecurityState securityState) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 658 | Drawable d = null; |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 659 | if (securityState == SecurityState.SECURITY_STATE_SECURE) { |
| 660 | d = mLockIconSecure; |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 661 | } else if (securityState == SecurityState.SECURITY_STATE_MIXED |
| 662 | || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) { |
| 663 | // TODO: It would be good to have different icons for insecure vs mixed content. |
| 664 | // See http://b/5403800 |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 665 | d = mLockIconMixed; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 666 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 667 | mNavigationBar.setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 668 | } |
| 669 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 670 | protected void setUrlTitle(Tab tab) { |
| 671 | String url = tab.getUrl(); |
| 672 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 673 | if (TextUtils.isEmpty(title)) { |
| 674 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 675 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 676 | if (tab.inForeground()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 677 | mNavigationBar.setDisplayTitle(url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
| 681 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 682 | protected void setFavicon(Tab tab) { |
| 683 | if (tab.inForeground()) { |
| 684 | Bitmap icon = tab.getFavicon(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 685 | mNavigationBar.setFavicon(icon); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 686 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 689 | // active tabs page |
| 690 | |
| 691 | public void showActiveTabsPage() { |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * Remove the active tabs page. |
| 696 | */ |
| 697 | public void removeActiveTabsPage() { |
| 698 | } |
| 699 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 700 | // menu handling callbacks |
| 701 | |
| 702 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 703 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 704 | return true; |
| 705 | } |
| 706 | |
| 707 | @Override |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 708 | public void updateMenuState(Tab tab, Menu menu) { |
| 709 | } |
| 710 | |
| 711 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 712 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | @Override |
| 716 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 720 | public boolean onOptionsItemSelected(MenuItem item) { |
| 721 | return false; |
| 722 | } |
| 723 | |
| 724 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 725 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | @Override |
| 729 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | @Override |
| 733 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | @Override |
| 737 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | // error console |
| 741 | |
| 742 | @Override |
| 743 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
Michael Kolb | 9fcefd1 | 2011-02-17 10:55:59 -0800 | [diff] [blame] | 744 | if (tab == null) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 745 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 746 | if (flag) { |
| 747 | // Setting the show state of the console will cause it's the layout |
| 748 | // to be inflated. |
| 749 | if (errorConsole.numberOfErrors() > 0) { |
| 750 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 751 | } else { |
| 752 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 753 | } |
| 754 | if (errorConsole.getParent() != null) { |
| 755 | mErrorConsoleContainer.removeView(errorConsole); |
| 756 | } |
| 757 | // Now we can add it to the main view. |
| 758 | mErrorConsoleContainer.addView(errorConsole, |
| 759 | new LinearLayout.LayoutParams( |
| 760 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 761 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 762 | } else { |
| 763 | mErrorConsoleContainer.removeView(errorConsole); |
| 764 | } |
| 765 | } |
| 766 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 767 | // ------------------------------------------------------------------------- |
| 768 | // Helper function for WebChromeClient |
| 769 | // ------------------------------------------------------------------------- |
| 770 | |
| 771 | @Override |
| 772 | public Bitmap getDefaultVideoPoster() { |
| 773 | if (mDefaultVideoPoster == null) { |
| 774 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 775 | mActivity.getResources(), R.drawable.default_video_poster); |
| 776 | } |
| 777 | return mDefaultVideoPoster; |
| 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public View getVideoLoadingProgressView() { |
| 782 | if (mVideoProgressView == null) { |
| 783 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 784 | mVideoProgressView = inflater.inflate( |
| 785 | R.layout.video_loading_progress, null); |
| 786 | } |
| 787 | return mVideoProgressView; |
| 788 | } |
| 789 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 790 | @Override |
| 791 | public void showMaxTabsWarning() { |
| 792 | Toast warning = Toast.makeText(mActivity, |
| 793 | mActivity.getString(R.string.max_tabs_warning), |
| 794 | Toast.LENGTH_SHORT); |
| 795 | warning.show(); |
| 796 | } |
| 797 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 798 | protected WebView getWebView() { |
| 799 | if (mActiveTab != null) { |
| 800 | return mActiveTab.getWebView(); |
| 801 | } else { |
| 802 | return null; |
| 803 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 806 | public void setFullscreen(boolean enabled) { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 807 | Window win = mActivity.getWindow(); |
| 808 | WindowManager.LayoutParams winParams = win.getAttributes(); |
Michael Kolb | 76dff39 | 2011-12-06 09:51:18 -0800 | [diff] [blame] | 809 | final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 810 | if (enabled) { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 811 | winParams.flags |= bits; |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 812 | mFullScreen = true; |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 813 | } else { |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 814 | mFullScreen = false; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 815 | winParams.flags &= ~bits; |
| 816 | if (mCustomView != null) { |
| 817 | mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); |
| 818 | } else { |
| 819 | mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); |
| 820 | } |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 821 | } |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 822 | win.setAttributes(winParams); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 825 | public boolean isTabFullScreen() { |
| 826 | return mFullScreen; |
| 827 | } |
| 828 | |
| 829 | public void setTabFullscreen(boolean enabled) { |
| 830 | setFullscreen(enabled); |
| 831 | FrameLayout main = (FrameLayout) mActivity.getWindow() |
| 832 | .getDecorView().findViewById(android.R.id.content); |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 833 | boolean hide_title_on_scroll = |
| 834 | mActivity.getResources().getBoolean(R.bool.hide_title_on_scroll); |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 835 | LinearLayout titleBarParent = (LinearLayout) main.findViewById(R.id.vertical_layout); |
| 836 | if (titleBarParent != null) { |
| 837 | if (enabled) { |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 838 | if (!hide_title_on_scroll) { |
| 839 | titleBarParent.removeView(mFixedTitlebarContainer); |
| 840 | } |
| 841 | else { |
| 842 | mContentView.removeView(mTitleBar); |
| 843 | } |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 844 | } else { |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 845 | if (!hide_title_on_scroll) { |
| 846 | titleBarParent.addView(mFixedTitlebarContainer, 1); |
| 847 | } |
| 848 | else { |
| 849 | mContentView.addView(mTitleBar, |
| 850 | new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 851 | LayoutParams.WRAP_CONTENT)); |
| 852 | } |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 857 | public void transalateTitleBar(float topControlsOffsetYPix) { |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame^] | 858 | if (mTitleBar != null && !mInActionMode) { |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 859 | mTitleBar.bringToFront(); |
| 860 | if (topControlsOffsetYPix != 0.0) { |
| 861 | mTitleBar.setEnabled(false); |
| 862 | } else { |
| 863 | mTitleBar.setEnabled(true); |
| 864 | } |
| 865 | mTitleBar.setTranslationY(topControlsOffsetYPix); |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 869 | public Drawable getFaviconDrawable(Bitmap icon) { |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 870 | Drawable[] array = new Drawable[3]; |
| 871 | array[0] = new PaintDrawable(Color.BLACK); |
| 872 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 873 | array[1] = p; |
| 874 | if (icon == null) { |
| 875 | array[2] = mGenericFavicon; |
| 876 | } else { |
| 877 | array[2] = new BitmapDrawable(icon); |
| 878 | } |
| 879 | LayerDrawable d = new LayerDrawable(array); |
| 880 | d.setLayerInset(1, 1, 1, 1, 1); |
| 881 | d.setLayerInset(2, 2, 2, 2, 2); |
| 882 | return d; |
| 883 | } |
| 884 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 885 | public boolean isLoading() { |
| 886 | return mActiveTab != null ? mActiveTab.inPageLoad() : false; |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Suggest to the UI that the title bar can be hidden. The UI will then |
| 891 | * decide whether or not to hide based off a number of factors, such |
| 892 | * as if the user is editing the URL bar or if the page is loading |
| 893 | */ |
| 894 | public void suggestHideTitleBar() { |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 895 | if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible() |
| 896 | && !mNavigationBar.isMenuShowing()) { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 897 | hideTitleBar(); |
| 898 | } |
| 899 | } |
| 900 | |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame] | 901 | protected final void showTitleBarForDuration() { |
| 902 | showTitleBarForDuration(HIDE_TITLEBAR_DELAY); |
| 903 | } |
| 904 | |
| 905 | protected final void showTitleBarForDuration(long duration) { |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 906 | showTitleBar(); |
| 907 | Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR); |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame] | 908 | mHandler.sendMessageDelayed(msg, duration); |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 909 | } |
| 910 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 911 | protected Handler mHandler = new Handler() { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 912 | |
| 913 | @Override |
| 914 | public void handleMessage(Message msg) { |
| 915 | if (msg.what == MSG_HIDE_TITLEBAR) { |
| 916 | suggestHideTitleBar(); |
| 917 | } |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 918 | BaseUi.this.handleMessage(msg); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 919 | } |
| 920 | }; |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 921 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 922 | protected void handleMessage(Message msg) {} |
| 923 | |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 924 | @Override |
| 925 | public void showWeb(boolean animate) { |
| 926 | mUiController.hideCustomView(); |
| 927 | } |
| 928 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 929 | static class FullscreenHolder extends FrameLayout { |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 930 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 931 | public FullscreenHolder(Context ctx) { |
| 932 | super(ctx); |
| 933 | setBackgroundColor(ctx.getResources().getColor(R.color.black)); |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 936 | @Override |
| 937 | public boolean onTouchEvent(MotionEvent evt) { |
| 938 | return true; |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 939 | } |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 940 | |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 941 | } |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 942 | |
| 943 | public void addFixedTitleBar(View view) { |
| 944 | mFixedTitlebarContainer.addView(view); |
| 945 | } |
| 946 | |
| 947 | public void setContentViewMarginTop(int margin) { |
| 948 | LinearLayout.LayoutParams params = |
| 949 | (LinearLayout.LayoutParams) mContentView.getLayoutParams(); |
| 950 | if (params.topMargin != margin) { |
| 951 | params.topMargin = margin; |
| 952 | mContentView.setLayoutParams(params); |
| 953 | } |
| 954 | } |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 955 | |
| 956 | @Override |
| 957 | public boolean blockFocusAnimations() { |
| 958 | return mBlockFocusAnimations; |
| 959 | } |
| 960 | |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 961 | @Override |
| 962 | public void onVoiceResult(String result) { |
| 963 | mNavigationBar.onVoiceResult(result); |
| 964 | } |
| 965 | |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 966 | protected UiController getUiController() { |
| 967 | return mUiController; |
| 968 | } |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 969 | |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame^] | 970 | boolean mInActionMode = false; |
| 971 | |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 972 | @Override |
| 973 | public void onActionModeStarted(ActionMode mode) { |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame^] | 974 | mInActionMode = true; |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 975 | boolean hide_title_on_scroll = |
| 976 | mActivity.getResources().getBoolean(R.bool.hide_title_on_scroll); |
| 977 | if (!hide_title_on_scroll) { |
| 978 | int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0; |
| 979 | mFixedTitlebarContainer.setY(fixedTbarHeight); |
| 980 | setContentViewMarginTop(fixedTbarHeight); |
| 981 | } |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | @Override |
| 985 | public void onActionModeFinished(boolean inLoad) { |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame^] | 986 | mInActionMode = false; |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 987 | boolean hide_title_on_scroll = |
| 988 | mActivity.getResources().getBoolean(R.bool.hide_title_on_scroll); |
| 989 | if (!hide_title_on_scroll) { |
| 990 | mFixedTitlebarContainer.setY(0); |
| 991 | setContentViewMarginTop(0); |
| 992 | } |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 993 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 994 | } |