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