blob: cfd3f8ed4da36a05dc278e79f4aea7f23314c227 [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;
Michael Kolb53ed62c2011-10-04 16:18:44 -070020import android.content.Context;
John Reckd3e4d5b2011-07-13 15:48:43 -070021import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070026import android.graphics.Color;
27import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.drawable.LayerDrawable;
30import android.graphics.drawable.PaintDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070032import android.os.Handler;
33import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070035import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.Gravity;
37import android.view.LayoutInflater;
38import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070039import android.view.MenuItem;
Michael Kolb31065b12011-10-06 13:51:32 -070040import android.view.MotionEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080044import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070045import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080047import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080048import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080050import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070051import android.widget.LinearLayout;
52import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070053import android.content.res.TypedArray;
Bijan Amirzada41242f22014-03-21 12:12:18 -070054import com.android.browser.R;
55import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080056
57import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070058
Michael Kolb1bf23132010-11-19 12:55:12 -080059import java.util.List;
60
Michael Kolb8233fac2010-10-26 16:08:53 -070061/**
62 * UI interface definitions
63 */
John Reck718a24d2011-08-12 11:08:30 -070064public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070065
66 private static final String LOGTAG = "BaseUi";
67
Michael Kolb66706532010-12-12 19:50:22 -080068 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070069 new FrameLayout.LayoutParams(
70 ViewGroup.LayoutParams.MATCH_PARENT,
71 ViewGroup.LayoutParams.MATCH_PARENT);
72
Michael Kolb66706532010-12-12 19:50:22 -080073 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070074 new FrameLayout.LayoutParams(
75 ViewGroup.LayoutParams.MATCH_PARENT,
76 ViewGroup.LayoutParams.MATCH_PARENT,
77 Gravity.CENTER);
78
John Reck5d43ce82011-06-21 17:16:51 -070079 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070080 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070081
Michael Kolb8233fac2010-10-26 16:08:53 -070082 Activity mActivity;
83 UiController mUiController;
84 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080085 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080086 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070087
Steve Block2466eff2011-10-03 15:33:09 +010088 private Drawable mLockIconSecure;
89 private Drawable mLockIconMixed;
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070090 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb66706532010-12-12 19:50:22 -080092 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070093 protected FrameLayout mCustomViewContainer;
John Reck2711fab2012-05-18 21:38:59 -070094 private FrameLayout mFixedTitlebarContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
Michael Kolb31065b12011-10-06 13:51:32 -070096 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080097 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040098 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070099
Michael Kolb8233fac2010-10-26 16:08:53 -0700100 private LinearLayout mErrorConsoleContainer = null;
101
John Reck718a24d2011-08-12 11:08:30 -0700102 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -0700103
John Reck718a24d2011-08-12 11:08:30 -0700104 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700105
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 // the default <video> poster
107 private Bitmap mDefaultVideoPoster;
108 // the video progress view
109 private View mVideoProgressView;
110
Michael Kolb8233fac2010-10-26 16:08:53 -0700111 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700112 protected TitleBar mTitleBar;
113 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700114 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700115
116 public BaseUi(Activity browser, UiController controller) {
117 mActivity = browser;
118 mUiController = controller;
119 mTabControl = controller.getTabControl();
120 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800121 mInputManager = (InputMethodManager)
122 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700123 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
124 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700125 LayoutInflater.from(mActivity)
126 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700127 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
128 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700129 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700130 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700131 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
132 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700133 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700134 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700135 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700136 mTitleBar = new TitleBar(mActivity, mUiController, this,
137 mContentView);
138 mTitleBar.setProgress(100);
139 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700140 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700141 }
142
Michael Kolb8233fac2010-10-26 16:08:53 -0700143 private void cancelStopToast() {
144 if (mStopToast != null) {
145 mStopToast.cancel();
146 mStopToast = null;
147 }
148 }
149
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700150 private Drawable getLockIconSecure() {
151 if (mLockIconSecure == null) {
152 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_secure_holo_dark);
153 }
154 return mLockIconSecure;
155 }
156
157 private Drawable getLockIconMixed() {
158 if (mLockIconMixed == null) {
159 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_secure_partial_holo_dark);
160 }
161 return mLockIconMixed;
162 }
163
164 protected Drawable getGenericFavicon() {
165 if (mGenericFavicon == null) {
166 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.app_web_browser_sm);
167 }
168 return mGenericFavicon;
169 }
170
Michael Kolb8233fac2010-10-26 16:08:53 -0700171 // lifecycle
172
173 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800174 if (isCustomViewShowing()) {
175 onHideCustomView();
176 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500177 if (mTabControl.getCurrentTab() != null) {
178 mTabControl.getCurrentTab().exitFullscreen();
179 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700180 cancelStopToast();
181 mActivityPaused = true;
182 }
183
184 public void onResume() {
185 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700186 // check if we exited without setting active tab
187 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700188 final Tab ct = mTabControl.getCurrentTab();
189 if (ct != null) {
190 setActiveTab(ct);
191 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700192 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 }
194
Michael Kolb66706532010-12-12 19:50:22 -0800195 protected boolean isActivityPaused() {
196 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700197 }
198
199 public void onConfigurationChanged(Configuration config) {
200 }
201
John Reck0f602f32011-07-07 15:38:43 -0700202 public Activity getActivity() {
203 return mActivity;
204 }
205
Michael Kolb8233fac2010-10-26 16:08:53 -0700206 // key handling
207
208 @Override
209 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700210 if (mCustomView != null) {
211 mUiController.hideCustomView();
212 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700213 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700214 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700215 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 }
217 return false;
218 }
219
Michael Kolb2814a362011-05-19 15:49:41 -0700220 @Override
221 public boolean onMenuKey() {
222 return false;
223 }
224
John Reck30c714c2010-12-16 17:30:34 -0800225 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 @Override
John Reck30c714c2010-12-16 17:30:34 -0800227 public void onTabDataChanged(Tab tab) {
228 setUrlTitle(tab);
229 setFavicon(tab);
230 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800231 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700232 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700233 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700234 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 }
236
237 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700238 public void onProgressChanged(Tab tab) {
239 int progress = tab.getLoadProgress();
240 if (tab.inForeground()) {
241 mTitleBar.setProgress(progress);
242 }
243 }
244
245 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500246 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800247 if (tab.inForeground()) {
248 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700249 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800250 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500251 }
252
253 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 public void onPageStopped(Tab tab) {
255 cancelStopToast();
256 if (tab.inForeground()) {
257 mStopToast = Toast
258 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
259 mStopToast.show();
260 }
261 }
262
263 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800264 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700265 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800266 }
267
268 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700270 }
271
272 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800273 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800274 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400275 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700276 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400277
Michael Kolbbae0cb22012-05-29 11:15:27 -0700278 // block unnecessary focus change animations during tab switch
279 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700280 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800281 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400282 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700283 WebView web = mActiveTab.getWebView();
284 if (web != null) {
285 web.setOnTouchListener(null);
286 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700287 }
Michael Kolb77df4562010-11-19 14:49:34 -0800288 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700289 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700290 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700291 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700292 if (web != null) {
293 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700294 web.setTitleBar(mTitleBar);
295 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700296 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700297 }
Michael Kolb4923c222012-04-02 16:18:36 -0700298 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700299 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700300 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800301 onTabDataChanged(tab);
302 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700303 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700304 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400305
Vivek Sekhar943f0672014-05-01 18:35:22 -0700306 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400307 }
308
309 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700310 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400311 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700312 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400313
Vivek Sekhar943f0672014-05-01 18:35:22 -0700314 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400315 //remove previously scehduled tab
316 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700317 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700318 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400319 removeTabFromContentView(mTabToRemove);
320 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700321 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400322 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700323 mTabToRemove = tabToRemove;
324 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400325 mNumRemoveTries = 0;
326
327 if (mTabToRemove != null) {
328 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700329 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400330 }
331 }
332
333 protected void tryRemoveTab() {
334 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700335 // Ensure the webview is still valid
336 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
337 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700338 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700339 mRunnable = new Runnable() {
340 public void run() {
341 tryRemoveTab();
342 }
343 };
344 }
345 /*if the new tab is still not ready, wait another 2 frames
346 before trying again. 1 frame for the tab to render the first
347 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700348 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400349 return;
350 }
351 }
352 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700353 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700354 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400355 removeTabFromContentView(mTabToRemove);
356 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700357 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400358 }
359 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700360 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700361 }
362
John Reck718a24d2011-08-12 11:08:30 -0700363 protected void updateUrlBarAutoShowManagerTarget() {
364 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700365 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700366 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700367 }
368 }
369
Michael Kolbcfa3af52010-12-14 10:36:11 -0800370 Tab getActiveTab() {
371 return mActiveTab;
372 }
373
Michael Kolb8233fac2010-10-26 16:08:53 -0700374 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800375 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800376 }
377
378 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800380 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800382 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700383 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700384 }
385
386 @Override
387 public void detachTab(Tab tab) {
388 removeTabFromContentView(tab);
389 }
390
391 @Override
392 public void attachTab(Tab tab) {
393 attachTabToContentView(tab);
394 }
395
Michael Kolb377ea312011-02-17 14:36:56 -0800396 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800397 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700398 return;
399 }
400 View container = tab.getViewContainer();
401 WebView mainView = tab.getWebView();
402 // Attach the WebView to the container and then attach the
403 // container to the content view.
404 FrameLayout wrapper =
405 (FrameLayout) container.findViewById(R.id.webview_wrapper);
406 ViewGroup parent = (ViewGroup) mainView.getParent();
407 if (parent != wrapper) {
408 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700409 parent.removeView(mainView);
410 }
411 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700412 }
413 parent = (ViewGroup) container.getParent();
414 if (parent != mContentView) {
415 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 parent.removeView(container);
417 }
418 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700419 }
420 mUiController.attachSubWindow(tab);
421 }
422
423 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800424 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700425 // Remove the container that contains the main WebView.
426 WebView mainView = tab.getWebView();
427 View container = tab.getViewContainer();
428 if (mainView == null) {
429 return;
430 }
431 // Remove the container from the content and then remove the
432 // WebView from the container. This will trigger a focus change
433 // needed by WebView.
434 FrameLayout wrapper =
435 (FrameLayout) container.findViewById(R.id.webview_wrapper);
436 wrapper.removeView(mainView);
437 mContentView.removeView(container);
438 mUiController.endActionMode();
439 mUiController.removeSubWindow(tab);
440 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
441 if (errorConsole != null) {
442 mErrorConsoleContainer.removeView(errorConsole);
443 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700444 }
445
Michael Kolba713ec82010-11-29 17:27:06 -0800446 @Override
447 public void onSetWebView(Tab tab, WebView webView) {
448 View container = tab.getViewContainer();
449 if (container == null) {
450 // The tab consists of a container view, which contains the main
451 // WebView, as well as any other UI elements associated with the tab.
452 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700453 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800454 tab.setViewContainer(container);
455 }
456 if (tab.getWebView() != webView) {
457 // Just remove the old one.
458 FrameLayout wrapper =
459 (FrameLayout) container.findViewById(R.id.webview_wrapper);
460 wrapper.removeView(tab.getWebView());
461 }
462 }
463
Michael Kolb8233fac2010-10-26 16:08:53 -0700464 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800465 * create a sub window container and webview for the tab
466 * Note: this methods operates through side-effects for now
467 * it sets both the subView and subViewContainer for the given tab
468 * @param tab tab to create the sub window for
469 * @param subView webview to be set as a subwindow for the tab
470 */
471 @Override
472 public void createSubWindow(Tab tab, WebView subView) {
473 View subViewContainer = mActivity.getLayoutInflater().inflate(
474 R.layout.browser_subwindow, null);
475 ViewGroup inner = (ViewGroup) subViewContainer
476 .findViewById(R.id.inner_container);
477 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
478 LayoutParams.MATCH_PARENT));
479 final ImageButton cancel = (ImageButton) subViewContainer
480 .findViewById(R.id.subwindow_close);
481 final WebView cancelSubView = subView;
482 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800483 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800484 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800485 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800486 }
487 });
488 tab.setSubWebView(subView);
489 tab.setSubViewContainer(subViewContainer);
490 }
491
492 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700493 * Remove the sub window from the content view.
494 */
495 @Override
496 public void removeSubWindow(View subviewContainer) {
497 mContentView.removeView(subviewContainer);
498 mUiController.endActionMode();
499 }
500
501 /**
502 * Attach the sub window to the content view.
503 */
504 @Override
505 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800506 if (container.getParent() != null) {
507 // already attached, remove first
508 ((ViewGroup) container.getParent()).removeView(container);
509 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700510 mContentView.addView(container, COVER_SCREEN_PARAMS);
511 }
512
Michael Kolb11d19782011-03-20 10:17:40 -0700513 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700514 WebView web = getWebView();
515 if (web != null) {
516 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700517 }
518 }
519
Michael Kolb1f9b3562012-04-24 14:38:34 -0700520 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700521 if (mUiController.isInCustomActionMode()) {
522 mUiController.endActionMode();
523 }
524 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700525 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700526 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700527 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700528 }
529
Michael Kolb7cdc4902011-02-03 17:54:40 -0800530 boolean canShowTitleBar() {
531 return !isTitleBarShowing()
532 && !isActivityPaused()
533 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700534 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800535 && !mUiController.isInCustomActionMode();
536 }
537
John Reck0f602f32011-07-07 15:38:43 -0700538 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700539 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700540 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700541 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700542 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800543 }
544
545 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700546 if (mTitleBar.isShowing()) {
547 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700548 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800549 }
550
551 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700552 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800553 }
554
John Reck5d43ce82011-06-21 17:16:51 -0700555 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700556 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700557 }
558
Michael Kolb80f75082012-04-10 10:50:06 -0700559 public void stopEditingUrl() {
560 mTitleBar.getNavigationBar().stopEditingUrl();
561 }
562
John Reck0f602f32011-07-07 15:38:43 -0700563 public TitleBar getTitleBar() {
564 return mTitleBar;
565 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800566
Michael Kolb66706532010-12-12 19:50:22 -0800567 @Override
John Reck2bc80422011-06-30 15:11:49 -0700568 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700569 Intent intent = new Intent(mActivity, ComboViewActivity.class);
570 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
571 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
572 Tab t = getActiveTab();
573 if (t != null) {
574 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800575 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700576 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700577 }
578
579 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400580 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800581 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700582 // if a view already exists then immediately terminate the new one
583 if (mCustomView != null) {
584 callback.onCustomViewHidden();
585 return;
586 }
587
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400588 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700589 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400590 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700591 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400592 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700593 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700594 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400595 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 }
597
598 @Override
599 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700600 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 if (mCustomView == null)
602 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400603 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700604 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400605 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 mCustomViewCallback.onCustomViewHidden();
608 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400609 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700610 }
611
612 @Override
613 public boolean isCustomViewShowing() {
614 return mCustomView != null;
615 }
616
Michael Kolb66706532010-12-12 19:50:22 -0800617 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800618 if (mInputManager.isActive()) {
619 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
620 0);
621 }
622 }
623
Michael Kolb66706532010-12-12 19:50:22 -0800624 @Override
John Reck3ba45532011-08-11 16:26:53 -0700625 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700626 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800627 }
628
Michael Kolb8233fac2010-10-26 16:08:53 -0700629 // -------------------------------------------------------------------------
630
Michael Kolb5a72f182011-01-13 20:35:06 -0800631 protected void updateNavigationState(Tab tab) {
632 }
633
Michael Kolb8233fac2010-10-26 16:08:53 -0700634 /**
635 * Update the lock icon to correspond to our latest state.
636 */
Michael Kolb66706532010-12-12 19:50:22 -0800637 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800638 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100639 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700640 }
641 }
642
643 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700644 * Updates the lock-icon image in the title-bar.
645 */
Steve Block2466eff2011-10-03 15:33:09 +0100646 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700647 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100648 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700649 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100650 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
651 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
652 // TODO: It would be good to have different icons for insecure vs mixed content.
653 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700654 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 }
John Reck0f602f32011-07-07 15:38:43 -0700656 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700657 }
658
John Reck30c714c2010-12-16 17:30:34 -0800659 protected void setUrlTitle(Tab tab) {
660 String url = tab.getUrl();
661 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800662 if (TextUtils.isEmpty(title)) {
663 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800664 }
Michael Kolb66706532010-12-12 19:50:22 -0800665 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700666 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800667 }
668 }
669
670 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800671 protected void setFavicon(Tab tab) {
672 if (tab.inForeground()) {
673 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700674 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800675 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 }
677
Michael Kolb66706532010-12-12 19:50:22 -0800678 // active tabs page
679
680 public void showActiveTabsPage() {
681 }
682
683 /**
684 * Remove the active tabs page.
685 */
686 public void removeActiveTabsPage() {
687 }
688
Michael Kolb8233fac2010-10-26 16:08:53 -0700689 // menu handling callbacks
690
691 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800692 public boolean onPrepareOptionsMenu(Menu menu) {
693 return true;
694 }
695
696 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700697 public void updateMenuState(Tab tab, Menu menu) {
698 }
699
700 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700701 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700702 }
703
704 @Override
705 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700706 }
707
708 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700709 public boolean onOptionsItemSelected(MenuItem item) {
710 return false;
711 }
712
713 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700714 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700715 }
716
717 @Override
718 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700719 }
720
721 @Override
722 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700723 }
724
725 @Override
726 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700727 }
728
729 // error console
730
731 @Override
732 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800733 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
735 if (flag) {
736 // Setting the show state of the console will cause it's the layout
737 // to be inflated.
738 if (errorConsole.numberOfErrors() > 0) {
739 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
740 } else {
741 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
742 }
743 if (errorConsole.getParent() != null) {
744 mErrorConsoleContainer.removeView(errorConsole);
745 }
746 // Now we can add it to the main view.
747 mErrorConsoleContainer.addView(errorConsole,
748 new LinearLayout.LayoutParams(
749 ViewGroup.LayoutParams.MATCH_PARENT,
750 ViewGroup.LayoutParams.WRAP_CONTENT));
751 } else {
752 mErrorConsoleContainer.removeView(errorConsole);
753 }
754 }
755
Michael Kolb8233fac2010-10-26 16:08:53 -0700756 // -------------------------------------------------------------------------
757 // Helper function for WebChromeClient
758 // -------------------------------------------------------------------------
759
760 @Override
761 public Bitmap getDefaultVideoPoster() {
762 if (mDefaultVideoPoster == null) {
763 mDefaultVideoPoster = BitmapFactory.decodeResource(
764 mActivity.getResources(), R.drawable.default_video_poster);
765 }
766 return mDefaultVideoPoster;
767 }
768
769 @Override
770 public View getVideoLoadingProgressView() {
771 if (mVideoProgressView == null) {
772 LayoutInflater inflater = LayoutInflater.from(mActivity);
773 mVideoProgressView = inflater.inflate(
774 R.layout.video_loading_progress, null);
775 }
776 return mVideoProgressView;
777 }
778
Michael Kolb843510f2010-12-09 10:51:49 -0800779 @Override
780 public void showMaxTabsWarning() {
781 Toast warning = Toast.makeText(mActivity,
782 mActivity.getString(R.string.max_tabs_warning),
783 Toast.LENGTH_SHORT);
784 warning.show();
785 }
786
Michael Kolb46f987e2011-04-05 10:39:10 -0700787 protected WebView getWebView() {
788 if (mActiveTab != null) {
789 return mActiveTab.getWebView();
790 } else {
791 return null;
792 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700793 }
794
Michael Kolbc38c6042011-04-27 10:46:06 -0700795 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700796 Window win = mActivity.getWindow();
797 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800798 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500799 final int fullscreenImmersiveSetting =
800 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
801 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
802 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
803 View.SYSTEM_UI_FLAG_FULLSCREEN |
804 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
805
806 if (mCustomView != null) {
807 mCustomView.setSystemUiVisibility(enabled ?
808 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700809 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500810 mContentView.setSystemUiVisibility(enabled ?
811 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700812 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500813 if (enabled)
814 winParams.flags |= bits;
815 else
816 winParams.flags &= ~bits;
817
Michael Kolbc5675ad2011-10-21 13:34:28 -0700818 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700819 }
820
Denise LaFayetteda31d742014-10-10 18:03:13 -0400821 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700822 public void showFullscreen(boolean fullScreen) {
823 //Hide/show system ui bar as needed
824 if (!BrowserSettings.getInstance().useFullscreen())
825 setFullscreen(fullScreen);
826
827 //Hide/show topbar as needed
828 if (getWebView() != null) {
829 if (fullScreen) {
830 //hide topbar
831 getWebView().updateTopControls(true, false, false);
832 } else {
833 //show the topbar
834 getWebView().updateTopControls(false, true, true);
835 //enable for auto-hide
836 if (!mTitleBar.isFixed())
837 getWebView().updateTopControls(true, true, false);
838 }
839 }
840 }
841
842
843
Tarun Nainani8eb00912014-07-17 12:28:32 -0700844 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700845 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700846 mTitleBar.bringToFront();
847 if (topControlsOffsetYPix != 0.0) {
848 mTitleBar.setEnabled(false);
849 } else {
850 mTitleBar.setEnabled(true);
851 }
Vivek Sekhar8a660782014-10-27 17:00:53 -0700852 if (!mTitleBar.isFixed() && !isLoading())
853 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700854 }
855 }
856
John Reck0f602f32011-07-07 15:38:43 -0700857 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700858 Drawable[] array = new Drawable[3];
859 array[0] = new PaintDrawable(Color.BLACK);
860 PaintDrawable p = new PaintDrawable(Color.WHITE);
861 array[1] = p;
862 if (icon == null) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700863 array[2] = getGenericFavicon();
Michael Kolb5a4372f2011-04-29 13:53:10 -0700864 } else {
865 array[2] = new BitmapDrawable(icon);
866 }
867 LayerDrawable d = new LayerDrawable(array);
868 d.setLayerInset(1, 1, 1, 1, 1);
869 d.setLayerInset(2, 2, 2, 2, 2);
870 return d;
871 }
872
John Reck5d43ce82011-06-21 17:16:51 -0700873 public boolean isLoading() {
874 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
875 }
876
877 /**
878 * Suggest to the UI that the title bar can be hidden. The UI will then
879 * decide whether or not to hide based off a number of factors, such
880 * as if the user is editing the URL bar or if the page is loading
881 */
882 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700883 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
884 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700885 hideTitleBar();
886 }
887 }
888
John Reckbc6adb42011-09-01 18:03:20 -0700889 protected final void showTitleBarForDuration() {
890 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
891 }
892
893 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700894 showTitleBar();
895 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700896 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700897 }
898
John Reck9c5004e2011-10-07 16:00:12 -0700899 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700900
901 @Override
902 public void handleMessage(Message msg) {
903 if (msg.what == MSG_HIDE_TITLEBAR) {
904 suggestHideTitleBar();
905 }
John Reck9c5004e2011-10-07 16:00:12 -0700906 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700907 }
908 };
John Reck3ba45532011-08-11 16:26:53 -0700909
John Reck9c5004e2011-10-07 16:00:12 -0700910 protected void handleMessage(Message msg) {}
911
John Reck3ba45532011-08-11 16:26:53 -0700912 @Override
913 public void showWeb(boolean animate) {
914 mUiController.hideCustomView();
915 }
916
John Reck2711fab2012-05-18 21:38:59 -0700917 public void setContentViewMarginTop(int margin) {
918 LinearLayout.LayoutParams params =
919 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
920 if (params.topMargin != margin) {
921 params.topMargin = margin;
922 mContentView.setLayoutParams(params);
923 }
924 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700925
926 @Override
927 public boolean blockFocusAnimations() {
928 return mBlockFocusAnimations;
929 }
930
Michael Kolb0b129122012-06-04 16:31:58 -0700931 @Override
932 public void onVoiceResult(String result) {
933 mNavigationBar.onVoiceResult(result);
934 }
935
kaiyizbb2db872013-08-01 22:24:07 -0400936 protected UiController getUiController() {
937 return mUiController;
938 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700939
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700940 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700941 private float getActionModeHeight() {
942 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
943 new int[] { android.R.attr.actionBarSize });
944 float size = actionBarSizeTypedArray.getDimension(0, 0f);
945 actionBarSizeTypedArray.recycle();
946 return size;
947 }
948
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700949
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700950 @Override
951 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700952 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700953
954 if (mTitleBar.isFixed()) {
955 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700956 mFixedTitlebarContainer.setY(fixedTbarHeight);
957 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700958 } else {
959 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700960 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700961 }
962
963 @Override
964 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700965 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700966 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700967 mFixedTitlebarContainer.setY(0);
968 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700969 } else {
970 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700971 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700972 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700973}