blob: 026e6612f475be801b2b6b0615719b7eb7d56a0e [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
75 Activity mActivity;
76 UiController mUiController;
77 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080078 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080079 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070080
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070081 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
Michael Kolb66706532010-12-12 19:50:22 -080083 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070084 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070085
Michael Kolb31065b12011-10-06 13:51:32 -070086 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080087 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040088 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070089
John Reck718a24d2011-08-12 11:08:30 -070090 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070091
Michael Kolb8233fac2010-10-26 16:08:53 -070092 // the default <video> poster
93 private Bitmap mDefaultVideoPoster;
94 // the video progress view
95 private View mVideoProgressView;
96
Sagar Dhawan1e040c72014-12-11 20:24:12 -080097 private final View mDecorView;
98
Michael Kolb8233fac2010-10-26 16:08:53 -070099 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700100 protected TitleBar mTitleBar;
101 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700102 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700103 private boolean mFullscreenModeLocked;
Michael Kolb8233fac2010-10-26 16:08:53 -0700104
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700105 private EdgeSwipeController mEdgeSwipeController;
106 private EdgeSwipeSettings mEdgeSwipeSettings;
107
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 public BaseUi(Activity browser, UiController controller) {
109 mActivity = browser;
110 mUiController = controller;
111 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800112 mInputManager = (InputMethodManager)
113 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800114 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
115 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700116 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
117 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700118 LayoutInflater.from(mActivity)
119 .inflate(R.layout.custom_screen, frameLayout);
120 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700121 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700122 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
123 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700124 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700125 mTitleBar = new TitleBar(mActivity, mUiController, this,
126 mContentView);
127 mTitleBar.setProgress(100);
128 mNavigationBar = mTitleBar.getNavigationBar();
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800129
130 // install system ui visibility listeners
131 mDecorView = mActivity.getWindow().getDecorView();
132 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700133 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700134 }
135
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800136 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
137 new View.OnSystemUiVisibilityChangeListener() {
138 @Override
139 public void onSystemUiVisibilityChange(int visFlags) {
140 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
141 if (lostFullscreen)
142 setFullscreen(BrowserSettings.getInstance().useFullscreen());
143 }
144 };
145
Michael Kolb8233fac2010-10-26 16:08:53 -0700146 private void cancelStopToast() {
147 if (mStopToast != null) {
148 mStopToast.cancel();
149 mStopToast = null;
150 }
151 }
152
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700153 protected Drawable getGenericFavicon() {
154 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800155 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700156 }
157 return mGenericFavicon;
158 }
159
Michael Kolb8233fac2010-10-26 16:08:53 -0700160 // lifecycle
161
162 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800163 if (isCustomViewShowing()) {
164 onHideCustomView();
165 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500166 if (mTabControl.getCurrentTab() != null) {
167 mTabControl.getCurrentTab().exitFullscreen();
168 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700169 cancelStopToast();
170 mActivityPaused = true;
171 }
172
173 public void onResume() {
174 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700175 // check if we exited without setting active tab
176 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800177 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700178 final Tab ct = mTabControl.getCurrentTab();
179 if (ct != null) {
180 setActiveTab(ct);
181 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700182 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700183 }
184
Michael Kolb66706532010-12-12 19:50:22 -0800185 protected boolean isActivityPaused() {
186 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 }
188
189 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700190 if (mEdgeSwipeController != null) {
191 mEdgeSwipeController.onConfigurationChanged();
192 }
193 if (mEdgeSwipeSettings != null) {
194 mEdgeSwipeSettings.onConfigurationChanged();
195 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 }
197
John Reck0f602f32011-07-07 15:38:43 -0700198 public Activity getActivity() {
199 return mActivity;
200 }
201
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 // key handling
203
204 @Override
205 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700206 if (mCustomView != null) {
207 mUiController.hideCustomView();
208 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700209 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700210 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700211 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 }
213 return false;
214 }
215
Vivek Sekhard4de6162015-07-21 15:01:45 -0700216 public boolean isFullScreen() {
217 if (mTabControl.getCurrentTab() != null)
218 return mTabControl.getCurrentTab().isTabFullScreen();
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;
Michael Kolb77df4562010-11-19 14:49:34 -0800284 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400285 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700286 WebView web = mActiveTab.getWebView();
287 if (web != null) {
288 web.setOnTouchListener(null);
289 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700290 }
Michael Kolb77df4562010-11-19 14:49:34 -0800291 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800292
Michael Kolbda580632012-04-16 13:30:28 -0700293 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck5d43ce82011-06-21 17:16:51 -0700294 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700295 if (web != null) {
296 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700297 web.setTitleBar(mTitleBar);
298 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700299 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700300 }
Michael Kolb4923c222012-04-02 16:18:36 -0700301 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700302 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800303 onTabDataChanged(tab);
304 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700305 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700306 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400307
Vivek Sekhar943f0672014-05-01 18:35:22 -0700308 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700309
310 updateTabSecurityState(tab);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400311 }
312
313 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700314 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400315 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700316 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400317
Vivek Sekhar943f0672014-05-01 18:35:22 -0700318 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800319
320 if(tabToWaitFor == mTabToRemove) {
321 if (mRunnable != null) {
322 mTitleBar.removeCallbacks(mRunnable);
323 }
324 mTabToRemove = null;
325 mTabToWaitFor = null;
326 mRunnable = null;
327 return;
328 }
329
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400330 //remove previously scehduled tab
331 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700332 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700333 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400334 removeTabFromContentView(mTabToRemove);
335 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400337 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700338 mTabToRemove = tabToRemove;
339 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400340 mNumRemoveTries = 0;
341
342 if (mTabToRemove != null) {
343 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700344 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400345 }
346 }
347
348 protected void tryRemoveTab() {
349 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700350 // Ensure the webview is still valid
351 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
352 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700353 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 mRunnable = new Runnable() {
355 public void run() {
356 tryRemoveTab();
357 }
358 };
359 }
360 /*if the new tab is still not ready, wait another 2 frames
361 before trying again. 1 frame for the tab to render the first
362 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700363 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400364 return;
365 }
366 }
367 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700368 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700369 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400370 removeTabFromContentView(mTabToRemove);
371 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700372 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400373 }
374 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700375 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700376 }
377
Michael Kolbcfa3af52010-12-14 10:36:11 -0800378 Tab getActiveTab() {
379 return mActiveTab;
380 }
381
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800383 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800384 }
385
386 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700387 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800388 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700389 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800390 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700391 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700392 }
393
394 @Override
395 public void detachTab(Tab tab) {
396 removeTabFromContentView(tab);
397 }
398
399 @Override
400 public void attachTab(Tab tab) {
401 attachTabToContentView(tab);
402 }
403
Michael Kolb377ea312011-02-17 14:36:56 -0800404 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800405 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700406 return;
407 }
408 View container = tab.getViewContainer();
409 WebView mainView = tab.getWebView();
410 // Attach the WebView to the container and then attach the
411 // container to the content view.
412 FrameLayout wrapper =
413 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700414 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
415
416 if (wrapper != parentView) {
417 // clean up old view before attaching new view
418 // this helping in fixing issues such touch event
419 // getting triggered on old view instead of new one
420 if (parentView != null) {
421 parentView.removeView(mainView.getView());
422 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800423 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700424 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800425 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 if (parent != mContentView) {
427 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 parent.removeView(container);
429 }
430 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700432
433 refreshEdgeSwipeController(container);
434
Michael Kolb8233fac2010-10-26 16:08:53 -0700435 mUiController.attachSubWindow(tab);
436 }
437
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700438 public void refreshEdgeSwipeController(View container) {
Site Mao61b68212015-07-16 10:56:31 -0700439 if (isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700440 return;
441 }
442
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700443 if (mEdgeSwipeController != null) {
444 mEdgeSwipeController.cleanup();
445 }
446
447 mEdgeSwipeSettings = null;
448
449 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
450
451 if (action.equalsIgnoreCase(
452 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
453 mEdgeSwipeController = new EdgeSwipeController(
454 container,
455 R.id.stationary_navview,
456 R.id.sliding_navview,
457 R.id.sliding_navview_shadow,
458 R.id.navview_opacity,
459 R.id.webview_wrapper,
460 R.id.draggable_mainframe,
461 this);
462 } else if (action.equalsIgnoreCase(
463 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
464 mEdgeSwipeSettings = new EdgeSwipeSettings(
465 container,
466 R.id.stationary_navview,
467 R.id.edge_sliding_settings,
468 R.id.sliding_navview_shadow,
469 R.id.webview_wrapper,
470 R.id.draggable_mainframe,
471 this);
472 } else {
473 DraggableFrameLayout draggableView = (DraggableFrameLayout)
474 container.findViewById(R.id.draggable_mainframe);
475 draggableView.setDragHelper(null);
476 }
477 }
478
Michael Kolb8233fac2010-10-26 16:08:53 -0700479 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800480 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700481 // Remove the container that contains the main WebView.
482 WebView mainView = tab.getWebView();
483 View container = tab.getViewContainer();
484 if (mainView == null) {
485 return;
486 }
487 // Remove the container from the content and then remove the
488 // WebView from the container. This will trigger a focus change
489 // needed by WebView.
490 FrameLayout wrapper =
491 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800492 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700493 mContentView.removeView(container);
494 mUiController.endActionMode();
495 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700496 }
497
Michael Kolba713ec82010-11-29 17:27:06 -0800498 @Override
499 public void onSetWebView(Tab tab, WebView webView) {
500 View container = tab.getViewContainer();
501 if (container == null) {
502 // The tab consists of a container view, which contains the main
503 // WebView, as well as any other UI elements associated with the tab.
504 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700505 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800506 tab.setViewContainer(container);
507 }
508 if (tab.getWebView() != webView) {
509 // Just remove the old one.
510 FrameLayout wrapper =
511 (FrameLayout) container.findViewById(R.id.webview_wrapper);
512 wrapper.removeView(tab.getWebView());
513 }
514 }
515
Michael Kolb8233fac2010-10-26 16:08:53 -0700516 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800517 * create a sub window container and webview for the tab
518 * Note: this methods operates through side-effects for now
519 * it sets both the subView and subViewContainer for the given tab
520 * @param tab tab to create the sub window for
521 * @param subView webview to be set as a subwindow for the tab
522 */
523 @Override
524 public void createSubWindow(Tab tab, WebView subView) {
525 View subViewContainer = mActivity.getLayoutInflater().inflate(
526 R.layout.browser_subwindow, null);
527 ViewGroup inner = (ViewGroup) subViewContainer
528 .findViewById(R.id.inner_container);
529 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
530 LayoutParams.MATCH_PARENT));
531 final ImageButton cancel = (ImageButton) subViewContainer
532 .findViewById(R.id.subwindow_close);
533 final WebView cancelSubView = subView;
534 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800535 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800536 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800537 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800538 }
539 });
540 tab.setSubWebView(subView);
541 tab.setSubViewContainer(subViewContainer);
542 }
543
544 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 * Remove the sub window from the content view.
546 */
547 @Override
548 public void removeSubWindow(View subviewContainer) {
549 mContentView.removeView(subviewContainer);
550 mUiController.endActionMode();
551 }
552
553 /**
554 * Attach the sub window to the content view.
555 */
556 @Override
557 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800558 if (container.getParent() != null) {
559 // already attached, remove first
560 ((ViewGroup) container.getParent()).removeView(container);
561 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700562 mContentView.addView(container, COVER_SCREEN_PARAMS);
563 }
564
Michael Kolb11d19782011-03-20 10:17:40 -0700565 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700566 WebView web = getWebView();
567 if (web != null) {
568 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700569 }
570 }
571
Michael Kolb1f9b3562012-04-24 14:38:34 -0700572 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700573 if (mUiController.isInCustomActionMode()) {
574 mUiController.endActionMode();
575 }
576 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700577 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700578 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700579 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700580 }
581
Michael Kolb7cdc4902011-02-03 17:54:40 -0800582 boolean canShowTitleBar() {
583 return !isTitleBarShowing()
584 && !isActivityPaused()
585 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700586 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800587 && !mUiController.isInCustomActionMode();
588 }
589
John Reck0f602f32011-07-07 15:38:43 -0700590 protected void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700591 if (canShowTitleBar()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700592 mTitleBar.showTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700593 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800594 }
595
596 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700597 if (mTitleBar.isShowing()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700598 mTitleBar.enableTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700599 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800600 }
601
602 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700603 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800604 }
605
John Reck5d43ce82011-06-21 17:16:51 -0700606 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700607 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700608 }
609
Michael Kolb80f75082012-04-10 10:50:06 -0700610 public void stopEditingUrl() {
611 mTitleBar.getNavigationBar().stopEditingUrl();
612 }
613
John Reck0f602f32011-07-07 15:38:43 -0700614 public TitleBar getTitleBar() {
615 return mTitleBar;
616 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800617
Michael Kolb66706532010-12-12 19:50:22 -0800618 @Override
John Reck2bc80422011-06-30 15:11:49 -0700619 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700620 Intent intent = new Intent(mActivity, ComboViewActivity.class);
621 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
622 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
623 Tab t = getActiveTab();
624 if (t != null) {
625 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800626 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700627 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700628 }
629
630 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800631 public void hideComboView() {
632 }
633
634 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400635 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800636 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700637 // if a view already exists then immediately terminate the new one
638 if (mCustomView != null) {
639 callback.onCustomViewHidden();
640 return;
641 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400642 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700643 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400644 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700645 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400646 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700647 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400649 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700650 }
651
652 @Override
653 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700654 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 if (mCustomView == null)
656 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400657 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700658 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400659 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700660 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 mCustomViewCallback.onCustomViewHidden();
662 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400663 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700664 }
665
666 @Override
667 public boolean isCustomViewShowing() {
668 return mCustomView != null;
669 }
670
Michael Kolb66706532010-12-12 19:50:22 -0800671 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800672 if (mInputManager.isActive()) {
673 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
674 0);
675 }
676 }
677
Michael Kolb66706532010-12-12 19:50:22 -0800678 @Override
John Reck3ba45532011-08-11 16:26:53 -0700679 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700680 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800681 }
682
Tarun Nainani87a86682015-02-05 11:47:35 -0800683 @Override
684 public boolean isComboViewShowing() {
685 return false;
686 }
687
Site Mao61b68212015-07-16 10:56:31 -0700688 public static boolean isUiLowPowerMode() {
Site Mao7521b092015-07-20 18:27:20 -0700689 return BrowserCommandLine.hasSwitch("ui-low-power-mode")
690 || BrowserSettings.getInstance().isPowerSaveModeEnabled()
691 || BrowserSettings.getInstance().isDisablePerfFeatures();
Site Mao61b68212015-07-16 10:56:31 -0700692 }
693
Michael Kolb8233fac2010-10-26 16:08:53 -0700694 // -------------------------------------------------------------------------
695
Michael Kolb5a72f182011-01-13 20:35:06 -0800696 protected void updateNavigationState(Tab tab) {
697 }
698
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 /**
700 * Update the lock icon to correspond to our latest state.
701 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700702 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800703 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700704 mNavigationBar.setSecurityState(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700705 }
706 }
707
John Reck30c714c2010-12-16 17:30:34 -0800708 protected void setUrlTitle(Tab tab) {
709 String url = tab.getUrl();
710 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800711 if (TextUtils.isEmpty(title)) {
712 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800713 }
Michael Kolb66706532010-12-12 19:50:22 -0800714 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700715 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800716 }
717 }
718
719 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800720 protected void setFavicon(Tab tab) {
721 if (tab.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700722 mNavigationBar.setFavicon(tab.getWebView().getFavicon());
John Reck30c714c2010-12-16 17:30:34 -0800723 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700724 }
725
Michael Kolb66706532010-12-12 19:50:22 -0800726 // active tabs page
727
728 public void showActiveTabsPage() {
729 }
730
731 /**
732 * Remove the active tabs page.
733 */
734 public void removeActiveTabsPage() {
735 }
736
Michael Kolb8233fac2010-10-26 16:08:53 -0700737 // menu handling callbacks
738
739 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800740 public boolean onPrepareOptionsMenu(Menu menu) {
741 return true;
742 }
743
744 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700745 public void updateMenuState(Tab tab, Menu menu) {
746 }
747
748 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700749 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700750 }
751
752 @Override
753 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700754 }
755
756 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700757 public boolean onOptionsItemSelected(MenuItem item) {
758 return false;
759 }
760
761 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700762 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700763 }
764
765 @Override
766 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700767 }
768
769 @Override
770 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700771 }
772
773 @Override
774 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700775 }
776
Michael Kolb8233fac2010-10-26 16:08:53 -0700777 // -------------------------------------------------------------------------
778 // Helper function for WebChromeClient
779 // -------------------------------------------------------------------------
780
781 @Override
782 public Bitmap getDefaultVideoPoster() {
783 if (mDefaultVideoPoster == null) {
784 mDefaultVideoPoster = BitmapFactory.decodeResource(
785 mActivity.getResources(), R.drawable.default_video_poster);
786 }
787 return mDefaultVideoPoster;
788 }
789
790 @Override
791 public View getVideoLoadingProgressView() {
792 if (mVideoProgressView == null) {
793 LayoutInflater inflater = LayoutInflater.from(mActivity);
794 mVideoProgressView = inflater.inflate(
795 R.layout.video_loading_progress, null);
796 }
797 return mVideoProgressView;
798 }
799
Michael Kolb843510f2010-12-09 10:51:49 -0800800 @Override
801 public void showMaxTabsWarning() {
802 Toast warning = Toast.makeText(mActivity,
803 mActivity.getString(R.string.max_tabs_warning),
804 Toast.LENGTH_SHORT);
805 warning.show();
806 }
807
Michael Kolb46f987e2011-04-05 10:39:10 -0700808 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800809
Michael Kolb46f987e2011-04-05 10:39:10 -0700810 if (mActiveTab != null) {
811 return mActiveTab.getWebView();
812 } else {
813 return null;
814 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700815 }
816
Pankaj Garg62bc7912015-04-14 16:08:59 -0700817 public void forceDisableFullscreenMode(boolean disabled) {
818 mFullscreenModeLocked = false;
819 setFullscreen(!disabled);
820 mFullscreenModeLocked = disabled;
821 }
822
Michael Kolbc38c6042011-04-27 10:46:06 -0700823 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700824 if (mFullscreenModeLocked)
825 return;
826
Michael Kolbc5675ad2011-10-21 13:34:28 -0700827 Window win = mActivity.getWindow();
828 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800829 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500830 final int fullscreenImmersiveSetting =
831 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
832 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
833 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
834 View.SYSTEM_UI_FLAG_FULLSCREEN |
835 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
836
837 if (mCustomView != null) {
838 mCustomView.setSystemUiVisibility(enabled ?
839 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800840 } else if (Build.VERSION.SDK_INT >= 19) {
841 mContentView.setSystemUiVisibility(enabled ?
842 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700843 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500844 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800845 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700846 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500847 if (enabled)
848 winParams.flags |= bits;
849 else
850 winParams.flags &= ~bits;
851
Michael Kolbc5675ad2011-10-21 13:34:28 -0700852 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700853 }
854
Denise LaFayetteda31d742014-10-10 18:03:13 -0400855 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700856 public void showFullscreen(boolean fullScreen) {
857 //Hide/show system ui bar as needed
858 if (!BrowserSettings.getInstance().useFullscreen())
859 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700860 //Hide/show topbar as needed
861 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700862 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700863 if (fullScreen) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700864 // hide titlebar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700865 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700866 } else {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700867 // show titlebar
868 mTitleBar.showTopControls(false);
869 // enable auto hide titlebar
Sudheer Koganti24766882014-10-02 10:58:09 -0700870 if (!mTitleBar.isFixed())
Vivek Sekhard4de6162015-07-21 15:01:45 -0700871 mTitleBar.enableTopControls(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700872 }
873 }
874 }
875
Tarun Nainani8eb00912014-07-17 12:28:32 -0700876 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700877 if (mTitleBar == null || mTitleBar.isFixed())
878 return;
879 if (!mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700880 if (topControlsOffsetYPix != 0.0) {
881 mTitleBar.setEnabled(false);
882 } else {
883 mTitleBar.setEnabled(true);
884 }
Vivek Sekhard4de6162015-07-21 15:01:45 -0700885 float currentY = mTitleBar.getTranslationY();
886 float height = mNavigationBar.getHeight();
887 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
888 mTitleBar.requestLayout();
889 } else if ((height + topControlsOffsetYPix) <= 0) {
890 topControlsOffsetYPix -= 1;
891 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800892 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800893 // This was done to get HTML5 fullscreen API to work with fixed mode since
894 // topcontrols are used to implement HTML5 fullscreen
895 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700896 }
897 }
898
John Reck0f602f32011-07-07 15:38:43 -0700899 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800900 if (ENABLE_BORDER_AROUND_FAVICON) {
901 Drawable[] array = new Drawable[3];
902 array[0] = new PaintDrawable(Color.BLACK);
903 PaintDrawable p = new PaintDrawable(Color.WHITE);
904 array[1] = p;
905 if (icon == null) {
906 array[2] = getGenericFavicon();
907 } else {
908 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
909 }
910 LayerDrawable d = new LayerDrawable(array);
911 d.setLayerInset(1, 1, 1, 1, 1);
912 d.setLayerInset(2, 2, 2, 2, 2);
913 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700914 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800915 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700916 }
917
John Reck5d43ce82011-06-21 17:16:51 -0700918 public boolean isLoading() {
919 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
920 }
921
Enrico Ros1f5a0952014-11-18 20:15:48 -0800922 protected void setMenuItemVisibility(Menu menu, int id,
923 boolean visibility) {
924 MenuItem item = menu.findItem(id);
925 if (item != null) {
926 item.setVisible(visibility);
927 }
928 }
929
John Reck9c5004e2011-10-07 16:00:12 -0700930 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700931
932 @Override
933 public void handleMessage(Message msg) {
John Reck9c5004e2011-10-07 16:00:12 -0700934 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700935 }
936 };
John Reck3ba45532011-08-11 16:26:53 -0700937
John Reck9c5004e2011-10-07 16:00:12 -0700938 protected void handleMessage(Message msg) {}
939
John Reck3ba45532011-08-11 16:26:53 -0700940 @Override
941 public void showWeb(boolean animate) {
942 mUiController.hideCustomView();
943 }
944
John Reck2711fab2012-05-18 21:38:59 -0700945 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800946 FrameLayout.LayoutParams params =
947 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700948 if (params.topMargin != margin) {
949 params.topMargin = margin;
950 mContentView.setLayoutParams(params);
951 }
952 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700953
954 @Override
955 public boolean blockFocusAnimations() {
956 return mBlockFocusAnimations;
957 }
958
Michael Kolb0b129122012-06-04 16:31:58 -0700959 @Override
960 public void onVoiceResult(String result) {
961 mNavigationBar.onVoiceResult(result);
962 }
963
kaiyizbb2db872013-08-01 22:24:07 -0400964 protected UiController getUiController() {
965 return mUiController;
966 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700967
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700968 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700969 private float getActionModeHeight() {
970 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
971 new int[] { android.R.attr.actionBarSize });
972 float size = actionBarSizeTypedArray.getDimension(0, 0f);
973 actionBarSizeTypedArray.recycle();
974 return size;
975 }
976
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700977
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700978 @Override
979 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700980 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700981
982 if (mTitleBar.isFixed()) {
983 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700984 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700985 } else {
986 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700987 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700988 }
989
990 @Override
991 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700992 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700993 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700994 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700995 } else {
996 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700997 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700998 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700999
1000 @Override
1001 public boolean shouldCaptureThumbnails() {
1002 return true;
1003 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001004}