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