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