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