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