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