blob: 3a05724b9840b4a84bbdfd7681dddc82356e85a8 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
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 Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb8233fac2010-10-26 16:08:53 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
John Reckd3e4d5b2011-07-13 15:48:43 -070020import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.content.res.Configuration;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.graphics.Bitmap;
23import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070024import android.graphics.Color;
25import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070027import android.graphics.drawable.LayerDrawable;
28import android.graphics.drawable.PaintDrawable;
Sagar Dhawan1e040c72014-12-11 20:24:12 -080029import android.os.Build;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070031import android.os.Handler;
32import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070034import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.Gravity;
36import android.view.LayoutInflater;
37import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070038import android.view.MenuItem;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080040import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070043import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080046import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080048import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070050import android.content.res.TypedArray;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070051
Pankaj Garg18aa0a12015-06-22 11:06:12 -070052import org.codeaurora.swe.BrowserCommandLine;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080053import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070054
Michael Kolb1bf23132010-11-19 12:55:12 -080055import java.util.List;
56
Michael Kolb8233fac2010-10-26 16:08:53 -070057/**
58 * UI interface definitions
59 */
John Reck718a24d2011-08-12 11:08:30 -070060public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070061
Enrico Ros1f5a0952014-11-18 20:15:48 -080062 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070063
Michael Kolb66706532010-12-12 19:50:22 -080064 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070065 new FrameLayout.LayoutParams(
66 ViewGroup.LayoutParams.MATCH_PARENT,
67 ViewGroup.LayoutParams.MATCH_PARENT);
68
Michael Kolb66706532010-12-12 19:50:22 -080069 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070070 new FrameLayout.LayoutParams(
71 ViewGroup.LayoutParams.MATCH_PARENT,
72 ViewGroup.LayoutParams.MATCH_PARENT,
73 Gravity.CENTER);
74
John Reck5d43ce82011-06-21 17:16:51 -070075 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070076 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070077
Michael Kolb8233fac2010-10-26 16:08:53 -070078 Activity mActivity;
79 UiController mUiController;
80 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080081 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080082 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070083
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070084 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070085
Michael Kolb66706532010-12-12 19:50:22 -080086 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070087 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Michael Kolb31065b12011-10-06 13:51:32 -070089 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080090 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040091 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070092
John Reck718a24d2011-08-12 11:08:30 -070093 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070094
John Reck718a24d2011-08-12 11:08:30 -070095 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070096
Michael Kolb8233fac2010-10-26 16:08:53 -070097 // the default <video> poster
98 private Bitmap mDefaultVideoPoster;
99 // the video progress view
100 private View mVideoProgressView;
101
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800102 private final View mDecorView;
103
Michael Kolb8233fac2010-10-26 16:08:53 -0700104 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700105 protected TitleBar mTitleBar;
106 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700107 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700108 private boolean mFullscreenModeLocked;
Michael Kolb8233fac2010-10-26 16:08:53 -0700109
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700110 private EdgeSwipeController mEdgeSwipeController;
111 private EdgeSwipeSettings mEdgeSwipeSettings;
112
Michael Kolb8233fac2010-10-26 16:08:53 -0700113 public BaseUi(Activity browser, UiController controller) {
114 mActivity = browser;
115 mUiController = controller;
116 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800117 mInputManager = (InputMethodManager)
118 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800119 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
120 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700121 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
122 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700123 LayoutInflater.from(mActivity)
124 .inflate(R.layout.custom_screen, frameLayout);
125 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700126 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700127 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
128 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700129 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700130 mTitleBar = new TitleBar(mActivity, mUiController, this,
131 mContentView);
132 mTitleBar.setProgress(100);
133 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700134 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800135
136 // install system ui visibility listeners
137 mDecorView = mActivity.getWindow().getDecorView();
138 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700139 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700140 }
141
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800142 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
143 new View.OnSystemUiVisibilityChangeListener() {
144 @Override
145 public void onSystemUiVisibilityChange(int visFlags) {
146 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
147 if (lostFullscreen)
148 setFullscreen(BrowserSettings.getInstance().useFullscreen());
149 }
150 };
151
Michael Kolb8233fac2010-10-26 16:08:53 -0700152 private void cancelStopToast() {
153 if (mStopToast != null) {
154 mStopToast.cancel();
155 mStopToast = null;
156 }
157 }
158
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700159 protected Drawable getGenericFavicon() {
160 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800161 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700162 }
163 return mGenericFavicon;
164 }
165
Michael Kolb8233fac2010-10-26 16:08:53 -0700166 // lifecycle
167
168 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800169 if (isCustomViewShowing()) {
170 onHideCustomView();
171 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500172 if (mTabControl.getCurrentTab() != null) {
173 mTabControl.getCurrentTab().exitFullscreen();
174 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700175 cancelStopToast();
176 mActivityPaused = true;
177 }
178
179 public void onResume() {
180 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700181 // check if we exited without setting active tab
182 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800183 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700184 final Tab ct = mTabControl.getCurrentTab();
185 if (ct != null) {
186 setActiveTab(ct);
187 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700188 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 }
190
Michael Kolb66706532010-12-12 19:50:22 -0800191 protected boolean isActivityPaused() {
192 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 }
194
195 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700196 if (mEdgeSwipeController != null) {
197 mEdgeSwipeController.onConfigurationChanged();
198 }
199 if (mEdgeSwipeSettings != null) {
200 mEdgeSwipeSettings.onConfigurationChanged();
201 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 }
203
John Reck0f602f32011-07-07 15:38:43 -0700204 public Activity getActivity() {
205 return mActivity;
206 }
207
Michael Kolb8233fac2010-10-26 16:08:53 -0700208 // key handling
209
210 @Override
211 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 if (mCustomView != null) {
213 mUiController.hideCustomView();
214 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700215 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700216 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700217 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 }
219 return false;
220 }
221
Michael Kolb2814a362011-05-19 15:49:41 -0700222 @Override
223 public boolean onMenuKey() {
224 return false;
225 }
226
John Reck30c714c2010-12-16 17:30:34 -0800227 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 @Override
John Reck30c714c2010-12-16 17:30:34 -0800229 public void onTabDataChanged(Tab tab) {
230 setUrlTitle(tab);
231 setFavicon(tab);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700232 updateTabSecurityState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800233 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700234 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700235 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700236 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700237 }
238
239 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700240 public void onProgressChanged(Tab tab) {
241 int progress = tab.getLoadProgress();
242 if (tab.inForeground()) {
243 mTitleBar.setProgress(progress);
244 }
245 }
246
247 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500248 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800249 if (tab.inForeground()) {
250 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700251 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800252 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500253 }
254
255 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 public void onPageStopped(Tab tab) {
257 cancelStopToast();
258 if (tab.inForeground()) {
259 mStopToast = Toast
260 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
261 mStopToast.show();
262 }
263 }
264
265 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800266 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700267 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800268 }
269
270 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 }
273
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800274 public void cancelNavScreenRequest(){
275 }
276
Michael Kolb377ea312011-02-17 14:36:56 -0800277 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800278 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400279 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700280 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400281
Michael Kolbbae0cb22012-05-29 11:15:27 -0700282 // block unnecessary focus change animations during tab switch
283 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700284 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800285 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400286 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700287 WebView web = mActiveTab.getWebView();
288 if (web != null) {
289 web.setOnTouchListener(null);
290 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700291 }
Michael Kolb77df4562010-11-19 14:49:34 -0800292 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800293
Michael Kolbda580632012-04-16 13:30:28 -0700294 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700295 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700296 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700297 if (web != null) {
298 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700299 web.setTitleBar(mTitleBar);
300 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700301 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700302 }
Michael Kolb4923c222012-04-02 16:18:36 -0700303 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700304 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800305 onTabDataChanged(tab);
306 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700307 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700308 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400309
Vivek Sekhar943f0672014-05-01 18:35:22 -0700310 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700311
312 updateTabSecurityState(tab);
313 mTitleBar.setSkipTitleBarAnimations(false);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400314 }
315
316 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700317 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400318 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700319 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400320
Vivek Sekhar943f0672014-05-01 18:35:22 -0700321 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800322
323 if(tabToWaitFor == mTabToRemove) {
324 if (mRunnable != null) {
325 mTitleBar.removeCallbacks(mRunnable);
326 }
327 mTabToRemove = null;
328 mTabToWaitFor = null;
329 mRunnable = null;
330 return;
331 }
332
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400333 //remove previously scehduled tab
334 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700335 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700336 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400337 removeTabFromContentView(mTabToRemove);
338 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700339 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400340 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700341 mTabToRemove = tabToRemove;
342 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400343 mNumRemoveTries = 0;
344
345 if (mTabToRemove != null) {
346 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700347 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400348 }
349 }
350
351 protected void tryRemoveTab() {
352 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700353 // Ensure the webview is still valid
354 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
355 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700356 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700357 mRunnable = new Runnable() {
358 public void run() {
359 tryRemoveTab();
360 }
361 };
362 }
363 /*if the new tab is still not ready, wait another 2 frames
364 before trying again. 1 frame for the tab to render the first
365 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700366 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400367 return;
368 }
369 }
370 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700371 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700372 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400373 removeTabFromContentView(mTabToRemove);
374 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700375 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400376 }
377 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700378 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 }
380
John Reck718a24d2011-08-12 11:08:30 -0700381 protected void updateUrlBarAutoShowManagerTarget() {
382 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700383 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700384 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700385 }
386 }
387
Michael Kolbcfa3af52010-12-14 10:36:11 -0800388 Tab getActiveTab() {
389 return mActiveTab;
390 }
391
Michael Kolb8233fac2010-10-26 16:08:53 -0700392 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800393 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800394 }
395
396 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700397 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800398 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700399 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800400 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700401 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 }
403
404 @Override
405 public void detachTab(Tab tab) {
406 removeTabFromContentView(tab);
407 }
408
409 @Override
410 public void attachTab(Tab tab) {
411 attachTabToContentView(tab);
412 }
413
Michael Kolb377ea312011-02-17 14:36:56 -0800414 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800415 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 return;
417 }
418 View container = tab.getViewContainer();
419 WebView mainView = tab.getWebView();
420 // Attach the WebView to the container and then attach the
421 // container to the content view.
422 FrameLayout wrapper =
423 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700424 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
425
426 if (wrapper != parentView) {
427 // clean up old view before attaching new view
428 // this helping in fixing issues such touch event
429 // getting triggered on old view instead of new one
430 if (parentView != null) {
431 parentView.removeView(mainView.getView());
432 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800433 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700434 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800435 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700436 if (parent != mContentView) {
437 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700438 parent.removeView(container);
439 }
440 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700441 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700442
443 refreshEdgeSwipeController(container);
444
Michael Kolb8233fac2010-10-26 16:08:53 -0700445 mUiController.attachSubWindow(tab);
446 }
447
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700448 public void refreshEdgeSwipeController(View container) {
Site Mao61b68212015-07-16 10:56:31 -0700449 if (isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700450 return;
451 }
452
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700453 if (mEdgeSwipeController != null) {
454 mEdgeSwipeController.cleanup();
455 }
456
457 mEdgeSwipeSettings = null;
458
459 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
460
461 if (action.equalsIgnoreCase(
462 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
463 mEdgeSwipeController = new EdgeSwipeController(
464 container,
465 R.id.stationary_navview,
466 R.id.sliding_navview,
467 R.id.sliding_navview_shadow,
468 R.id.navview_opacity,
469 R.id.webview_wrapper,
470 R.id.draggable_mainframe,
471 this);
472 } else if (action.equalsIgnoreCase(
473 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
474 mEdgeSwipeSettings = new EdgeSwipeSettings(
475 container,
476 R.id.stationary_navview,
477 R.id.edge_sliding_settings,
478 R.id.sliding_navview_shadow,
479 R.id.webview_wrapper,
480 R.id.draggable_mainframe,
481 this);
482 } else {
483 DraggableFrameLayout draggableView = (DraggableFrameLayout)
484 container.findViewById(R.id.draggable_mainframe);
485 draggableView.setDragHelper(null);
486 }
487 }
488
Michael Kolb8233fac2010-10-26 16:08:53 -0700489 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800490 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700491 // Remove the container that contains the main WebView.
492 WebView mainView = tab.getWebView();
493 View container = tab.getViewContainer();
494 if (mainView == null) {
495 return;
496 }
497 // Remove the container from the content and then remove the
498 // WebView from the container. This will trigger a focus change
499 // needed by WebView.
500 FrameLayout wrapper =
501 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800502 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700503 mContentView.removeView(container);
504 mUiController.endActionMode();
505 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700506 }
507
Michael Kolba713ec82010-11-29 17:27:06 -0800508 @Override
509 public void onSetWebView(Tab tab, WebView webView) {
510 View container = tab.getViewContainer();
511 if (container == null) {
512 // The tab consists of a container view, which contains the main
513 // WebView, as well as any other UI elements associated with the tab.
514 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700515 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800516 tab.setViewContainer(container);
517 }
518 if (tab.getWebView() != webView) {
519 // Just remove the old one.
520 FrameLayout wrapper =
521 (FrameLayout) container.findViewById(R.id.webview_wrapper);
522 wrapper.removeView(tab.getWebView());
523 }
524 }
525
Michael Kolb8233fac2010-10-26 16:08:53 -0700526 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800527 * create a sub window container and webview for the tab
528 * Note: this methods operates through side-effects for now
529 * it sets both the subView and subViewContainer for the given tab
530 * @param tab tab to create the sub window for
531 * @param subView webview to be set as a subwindow for the tab
532 */
533 @Override
534 public void createSubWindow(Tab tab, WebView subView) {
535 View subViewContainer = mActivity.getLayoutInflater().inflate(
536 R.layout.browser_subwindow, null);
537 ViewGroup inner = (ViewGroup) subViewContainer
538 .findViewById(R.id.inner_container);
539 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
540 LayoutParams.MATCH_PARENT));
541 final ImageButton cancel = (ImageButton) subViewContainer
542 .findViewById(R.id.subwindow_close);
543 final WebView cancelSubView = subView;
544 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800545 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800546 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800547 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800548 }
549 });
550 tab.setSubWebView(subView);
551 tab.setSubViewContainer(subViewContainer);
552 }
553
554 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700555 * Remove the sub window from the content view.
556 */
557 @Override
558 public void removeSubWindow(View subviewContainer) {
559 mContentView.removeView(subviewContainer);
560 mUiController.endActionMode();
561 }
562
563 /**
564 * Attach the sub window to the content view.
565 */
566 @Override
567 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800568 if (container.getParent() != null) {
569 // already attached, remove first
570 ((ViewGroup) container.getParent()).removeView(container);
571 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700572 mContentView.addView(container, COVER_SCREEN_PARAMS);
573 }
574
Michael Kolb11d19782011-03-20 10:17:40 -0700575 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700576 WebView web = getWebView();
577 if (web != null) {
578 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700579 }
580 }
581
Michael Kolb1f9b3562012-04-24 14:38:34 -0700582 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700583 if (mUiController.isInCustomActionMode()) {
584 mUiController.endActionMode();
585 }
586 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700587 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700588 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700589 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700590 }
591
Michael Kolb7cdc4902011-02-03 17:54:40 -0800592 boolean canShowTitleBar() {
593 return !isTitleBarShowing()
594 && !isActivityPaused()
595 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700596 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800597 && !mUiController.isInCustomActionMode();
598 }
599
John Reck0f602f32011-07-07 15:38:43 -0700600 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700601 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700602 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700603 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700604 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800605 }
606
607 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700608 if (mTitleBar.isShowing()) {
609 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700610 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800611 }
612
613 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700614 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800615 }
616
John Reck5d43ce82011-06-21 17:16:51 -0700617 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700618 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700619 }
620
Michael Kolb80f75082012-04-10 10:50:06 -0700621 public void stopEditingUrl() {
622 mTitleBar.getNavigationBar().stopEditingUrl();
623 }
624
John Reck0f602f32011-07-07 15:38:43 -0700625 public TitleBar getTitleBar() {
626 return mTitleBar;
627 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800628
Michael Kolb66706532010-12-12 19:50:22 -0800629 @Override
John Reck2bc80422011-06-30 15:11:49 -0700630 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700631 Intent intent = new Intent(mActivity, ComboViewActivity.class);
632 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
633 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
634 Tab t = getActiveTab();
635 if (t != null) {
636 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800637 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700638 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 }
640
641 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800642 public void hideComboView() {
643 }
644
645 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400646 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800647 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 // if a view already exists then immediately terminate the new one
649 if (mCustomView != null) {
650 callback.onCustomViewHidden();
651 return;
652 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400653 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700654 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400655 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700656 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400657 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700658 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400660 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 }
662
663 @Override
664 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700665 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700666 if (mCustomView == null)
667 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400668 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700669 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400670 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 mCustomViewCallback.onCustomViewHidden();
673 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400674 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700675 }
676
677 @Override
678 public boolean isCustomViewShowing() {
679 return mCustomView != null;
680 }
681
Michael Kolb66706532010-12-12 19:50:22 -0800682 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800683 if (mInputManager.isActive()) {
684 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
685 0);
686 }
687 }
688
Michael Kolb66706532010-12-12 19:50:22 -0800689 @Override
John Reck3ba45532011-08-11 16:26:53 -0700690 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700691 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800692 }
693
Tarun Nainani87a86682015-02-05 11:47:35 -0800694 @Override
695 public boolean isComboViewShowing() {
696 return false;
697 }
698
Site Mao61b68212015-07-16 10:56:31 -0700699 public static boolean isUiLowPowerMode() {
700 return BrowserCommandLine.hasSwitch("ui-low-power-mode") ||
701 BrowserSettings.getInstance().isPowerSaveModeEnabled();
702 }
703
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 // -------------------------------------------------------------------------
705
Michael Kolb5a72f182011-01-13 20:35:06 -0800706 protected void updateNavigationState(Tab tab) {
707 }
708
Michael Kolb8233fac2010-10-26 16:08:53 -0700709 /**
710 * Update the lock icon to correspond to our latest state.
711 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700712 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800713 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700714 mNavigationBar.setSecurityState(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700715 }
716 }
717
John Reck30c714c2010-12-16 17:30:34 -0800718 protected void setUrlTitle(Tab tab) {
719 String url = tab.getUrl();
720 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800721 if (TextUtils.isEmpty(title)) {
722 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800723 }
Michael Kolb66706532010-12-12 19:50:22 -0800724 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700725 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800726 }
727 }
728
729 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800730 protected void setFavicon(Tab tab) {
731 if (tab.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700732 mNavigationBar.setFavicon(tab.getWebView().getFavicon());
John Reck30c714c2010-12-16 17:30:34 -0800733 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 }
735
Michael Kolb66706532010-12-12 19:50:22 -0800736 // active tabs page
737
738 public void showActiveTabsPage() {
739 }
740
741 /**
742 * Remove the active tabs page.
743 */
744 public void removeActiveTabsPage() {
745 }
746
Michael Kolb8233fac2010-10-26 16:08:53 -0700747 // menu handling callbacks
748
749 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800750 public boolean onPrepareOptionsMenu(Menu menu) {
751 return true;
752 }
753
754 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700755 public void updateMenuState(Tab tab, Menu menu) {
756 }
757
758 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700759 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700760 }
761
762 @Override
763 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700764 }
765
766 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700767 public boolean onOptionsItemSelected(MenuItem item) {
768 return false;
769 }
770
771 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700772 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700773 }
774
775 @Override
776 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700777 }
778
779 @Override
780 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700781 }
782
783 @Override
784 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700785 }
786
Michael Kolb8233fac2010-10-26 16:08:53 -0700787 // -------------------------------------------------------------------------
788 // Helper function for WebChromeClient
789 // -------------------------------------------------------------------------
790
791 @Override
792 public Bitmap getDefaultVideoPoster() {
793 if (mDefaultVideoPoster == null) {
794 mDefaultVideoPoster = BitmapFactory.decodeResource(
795 mActivity.getResources(), R.drawable.default_video_poster);
796 }
797 return mDefaultVideoPoster;
798 }
799
800 @Override
801 public View getVideoLoadingProgressView() {
802 if (mVideoProgressView == null) {
803 LayoutInflater inflater = LayoutInflater.from(mActivity);
804 mVideoProgressView = inflater.inflate(
805 R.layout.video_loading_progress, null);
806 }
807 return mVideoProgressView;
808 }
809
Michael Kolb843510f2010-12-09 10:51:49 -0800810 @Override
811 public void showMaxTabsWarning() {
812 Toast warning = Toast.makeText(mActivity,
813 mActivity.getString(R.string.max_tabs_warning),
814 Toast.LENGTH_SHORT);
815 warning.show();
816 }
817
Michael Kolb46f987e2011-04-05 10:39:10 -0700818 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800819
Michael Kolb46f987e2011-04-05 10:39:10 -0700820 if (mActiveTab != null) {
821 return mActiveTab.getWebView();
822 } else {
823 return null;
824 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700825 }
826
Pankaj Garg62bc7912015-04-14 16:08:59 -0700827 public void forceDisableFullscreenMode(boolean disabled) {
828 mFullscreenModeLocked = false;
829 setFullscreen(!disabled);
830 mFullscreenModeLocked = disabled;
831 }
832
Michael Kolbc38c6042011-04-27 10:46:06 -0700833 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700834 if (mFullscreenModeLocked)
835 return;
836
Michael Kolbc5675ad2011-10-21 13:34:28 -0700837 Window win = mActivity.getWindow();
838 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800839 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500840 final int fullscreenImmersiveSetting =
841 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
842 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
843 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
844 View.SYSTEM_UI_FLAG_FULLSCREEN |
845 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
846
847 if (mCustomView != null) {
848 mCustomView.setSystemUiVisibility(enabled ?
849 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800850 } else if (Build.VERSION.SDK_INT >= 19) {
851 mContentView.setSystemUiVisibility(enabled ?
852 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700853 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500854 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800855 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700856 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500857 if (enabled)
858 winParams.flags |= bits;
859 else
860 winParams.flags &= ~bits;
861
Michael Kolbc5675ad2011-10-21 13:34:28 -0700862 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700863 }
864
Denise LaFayetteda31d742014-10-10 18:03:13 -0400865 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700866 public void showFullscreen(boolean fullScreen) {
867 //Hide/show system ui bar as needed
868 if (!BrowserSettings.getInstance().useFullscreen())
869 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700870 //Hide/show topbar as needed
871 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700872 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700873 if (fullScreen) {
874 //hide topbar
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700875 bwv.enableTopControls(false);
Vivek Sekhare337acf2015-04-02 21:00:48 -0700876 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700877 } else {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700878 bwv.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700879 //show the topbar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700880 mTitleBar.showTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700881 //enable for auto-hide
882 if (!mTitleBar.isFixed())
Vivek Sekhare337acf2015-04-02 21:00:48 -0700883 mTitleBar.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700884 }
885 }
886 }
887
Tarun Nainani8eb00912014-07-17 12:28:32 -0700888 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700889 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700890 if (topControlsOffsetYPix != 0.0) {
891 mTitleBar.setEnabled(false);
892 } else {
893 mTitleBar.setEnabled(true);
894 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800895 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800896 float currentY = mTitleBar.getTranslationY();
Devdeep Choudhury904c7062015-03-17 19:47:29 -0700897 float height = mNavigationBar.getHeight();
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800898 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
899 mTitleBar.requestLayout();
900 } else if ((height + topControlsOffsetYPix) <= 0) {
901 topControlsOffsetYPix -= 1;
902 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
903 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800904 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800905 // This was done to get HTML5 fullscreen API to work with fixed mode since
906 // topcontrols are used to implement HTML5 fullscreen
907 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700908 }
909 }
910
John Reck0f602f32011-07-07 15:38:43 -0700911 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800912 if (ENABLE_BORDER_AROUND_FAVICON) {
913 Drawable[] array = new Drawable[3];
914 array[0] = new PaintDrawable(Color.BLACK);
915 PaintDrawable p = new PaintDrawable(Color.WHITE);
916 array[1] = p;
917 if (icon == null) {
918 array[2] = getGenericFavicon();
919 } else {
920 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
921 }
922 LayerDrawable d = new LayerDrawable(array);
923 d.setLayerInset(1, 1, 1, 1, 1);
924 d.setLayerInset(2, 2, 2, 2, 2);
925 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700926 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800927 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700928 }
929
John Reck5d43ce82011-06-21 17:16:51 -0700930 public boolean isLoading() {
931 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
932 }
933
934 /**
935 * Suggest to the UI that the title bar can be hidden. The UI will then
936 * decide whether or not to hide based off a number of factors, such
937 * as if the user is editing the URL bar or if the page is loading
938 */
939 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700940 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
941 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700942 hideTitleBar();
943 }
944 }
945
John Reckbc6adb42011-09-01 18:03:20 -0700946 protected final void showTitleBarForDuration() {
947 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
948 }
949
950 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700951 showTitleBar();
952 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700953 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700954 }
955
Enrico Ros1f5a0952014-11-18 20:15:48 -0800956 protected void setMenuItemVisibility(Menu menu, int id,
957 boolean visibility) {
958 MenuItem item = menu.findItem(id);
959 if (item != null) {
960 item.setVisible(visibility);
961 }
962 }
963
John Reck9c5004e2011-10-07 16:00:12 -0700964 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700965
966 @Override
967 public void handleMessage(Message msg) {
968 if (msg.what == MSG_HIDE_TITLEBAR) {
969 suggestHideTitleBar();
970 }
John Reck9c5004e2011-10-07 16:00:12 -0700971 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700972 }
973 };
John Reck3ba45532011-08-11 16:26:53 -0700974
John Reck9c5004e2011-10-07 16:00:12 -0700975 protected void handleMessage(Message msg) {}
976
John Reck3ba45532011-08-11 16:26:53 -0700977 @Override
978 public void showWeb(boolean animate) {
979 mUiController.hideCustomView();
980 }
981
John Reck2711fab2012-05-18 21:38:59 -0700982 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800983 FrameLayout.LayoutParams params =
984 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700985 if (params.topMargin != margin) {
986 params.topMargin = margin;
987 mContentView.setLayoutParams(params);
988 }
989 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700990
991 @Override
992 public boolean blockFocusAnimations() {
993 return mBlockFocusAnimations;
994 }
995
Michael Kolb0b129122012-06-04 16:31:58 -0700996 @Override
997 public void onVoiceResult(String result) {
998 mNavigationBar.onVoiceResult(result);
999 }
1000
kaiyizbb2db872013-08-01 22:24:07 -04001001 protected UiController getUiController() {
1002 return mUiController;
1003 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001004
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001005 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001006 private float getActionModeHeight() {
1007 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1008 new int[] { android.R.attr.actionBarSize });
1009 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1010 actionBarSizeTypedArray.recycle();
1011 return size;
1012 }
1013
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001014
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001015 @Override
1016 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001017 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001018
1019 if (mTitleBar.isFixed()) {
1020 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001021 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001022 } else {
1023 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001024 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001025 }
1026
1027 @Override
1028 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001029 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001030 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001031 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001032 } else {
1033 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001034 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001035 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001036
1037 @Override
1038 public boolean shouldCaptureThumbnails() {
1039 return true;
1040 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001041}