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