blob: 666b997cb34be7c167fd45cd054a3ceb8d61fa9d [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;
Michael Kolb5a4372f2011-04-29 13:53:10 -070090 protected 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;
Michael Kolb31065b12011-10-06 13:51:32 -070094 protected FrameLayout mFullscreenContainer;
John Reck2711fab2012-05-18 21:38:59 -070095 private FrameLayout mFixedTitlebarContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070096
Michael Kolb31065b12011-10-06 13:51:32 -070097 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080098 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040099 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -0700100
Michael Kolb8233fac2010-10-26 16:08:53 -0700101 private LinearLayout mErrorConsoleContainer = null;
102
John Reck718a24d2011-08-12 11:08:30 -0700103 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -0700104
John Reck718a24d2011-08-12 11:08:30 -0700105 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 // the default <video> poster
108 private Bitmap mDefaultVideoPoster;
109 // the video progress view
110 private View mVideoProgressView;
111
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 private boolean mActivityPaused;
John Reckbf2ec202011-06-29 17:47:38 -0700113 protected boolean mUseQuickControls;
John Reck0f602f32011-07-07 15:38:43 -0700114 protected TitleBar mTitleBar;
115 private NavigationBarBase mNavigationBar;
Michael Kolbda580632012-04-16 13:30:28 -0700116 protected PieControl mPieControl;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700117 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700118
119 public BaseUi(Activity browser, UiController controller) {
120 mActivity = browser;
121 mUiController = controller;
122 mTabControl = controller.getTabControl();
123 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800124 mInputManager = (InputMethodManager)
125 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Steve Block2466eff2011-10-03 15:33:09 +0100126 mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark);
127 mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
129 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700130 LayoutInflater.from(mActivity)
131 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700132 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
133 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700134 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700135 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700136 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
137 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700138 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700139 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700140 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700141 mGenericFavicon = res.getDrawable(
142 R.drawable.app_web_browser_sm);
John Reck0f602f32011-07-07 15:38:43 -0700143 mTitleBar = new TitleBar(mActivity, mUiController, this,
144 mContentView);
145 mTitleBar.setProgress(100);
146 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700147 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700148 }
149
Michael Kolb8233fac2010-10-26 16:08:53 -0700150 private void cancelStopToast() {
151 if (mStopToast != null) {
152 mStopToast.cancel();
153 mStopToast = null;
154 }
155 }
156
157 // lifecycle
158
159 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800160 if (isCustomViewShowing()) {
161 onHideCustomView();
162 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 cancelStopToast();
164 mActivityPaused = true;
165 }
166
167 public void onResume() {
168 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700169 // check if we exited without setting active tab
170 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700171 final Tab ct = mTabControl.getCurrentTab();
172 if (ct != null) {
173 setActiveTab(ct);
174 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700175 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700176 }
177
Michael Kolb66706532010-12-12 19:50:22 -0800178 protected boolean isActivityPaused() {
179 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700180 }
181
182 public void onConfigurationChanged(Configuration config) {
183 }
184
John Reck0f602f32011-07-07 15:38:43 -0700185 public Activity getActivity() {
186 return mActivity;
187 }
188
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 // key handling
190
191 @Override
192 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 if (mCustomView != null) {
194 mUiController.hideCustomView();
195 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700196 } else if ((mTabControl.getCurrentTab() != null) &&
197 (mTabControl.getCurrentTab().isTabFullScreen())) {
198 mTabControl.getCurrentTab().setTabFullscreen(false);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700199 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700200 }
201 return false;
202 }
203
Michael Kolb2814a362011-05-19 15:49:41 -0700204 @Override
205 public boolean onMenuKey() {
206 return false;
207 }
208
Michael Kolbda580632012-04-16 13:30:28 -0700209 @Override
210 public void setUseQuickControls(boolean useQuickControls) {
211 mUseQuickControls = useQuickControls;
212 mTitleBar.setUseQuickControls(mUseQuickControls);
213 if (useQuickControls) {
214 mPieControl = new PieControl(mActivity, mUiController, this);
215 mPieControl.attachToContainer(mContentView);
216 } else {
217 if (mPieControl != null) {
218 mPieControl.removeFromContainer(mContentView);
219 }
220 }
221 updateUrlBarAutoShowManagerTarget();
222 }
223
John Reck30c714c2010-12-16 17:30:34 -0800224 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700225 @Override
John Reck30c714c2010-12-16 17:30:34 -0800226 public void onTabDataChanged(Tab tab) {
227 setUrlTitle(tab);
228 setFavicon(tab);
229 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800230 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700231 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700232 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700233 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 }
235
236 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700237 public void onProgressChanged(Tab tab) {
238 int progress = tab.getLoadProgress();
239 if (tab.inForeground()) {
240 mTitleBar.setProgress(progress);
241 }
242 }
243
244 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500245 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800246 if (tab.inForeground()) {
247 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700248 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800249 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500250 }
251
252 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700253 public void onPageStopped(Tab tab) {
254 cancelStopToast();
255 if (tab.inForeground()) {
256 mStopToast = Toast
257 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
258 mStopToast.show();
259 }
260 }
261
262 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800263 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700264 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800265 }
266
267 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700268 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 }
270
271 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800272 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800273 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400274 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700275 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400276
Michael Kolbbae0cb22012-05-29 11:15:27 -0700277 // block unnecessary focus change animations during tab switch
278 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700279 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800280 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400281 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700282 WebView web = mActiveTab.getWebView();
283 if (web != null) {
284 web.setOnTouchListener(null);
285 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700286 }
Michael Kolb77df4562010-11-19 14:49:34 -0800287 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700288 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700289 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700290 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700291 if (web != null) {
292 // Request focus on the top window.
293 if (mUseQuickControls) {
294 mPieControl.forceToTop(mContentView);
295 web.setTitleBar(null);
Michael Kolbe8a82332012-04-25 14:14:26 -0700296 mTitleBar.hide();
Michael Kolbda580632012-04-16 13:30:28 -0700297 } else {
298 web.setTitleBar(mTitleBar);
299 mTitleBar.onScrollChanged();
300 }
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();
Michael Kolb8233fac2010-10-26 16:08:53 -0700305 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800306 onTabDataChanged(tab);
307 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700308 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700309 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400310
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312 }
313
314 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700315 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400316 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700317 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400318
Vivek Sekhar943f0672014-05-01 18:35:22 -0700319 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400320 //remove previously scehduled tab
321 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700322 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700323 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400324 removeTabFromContentView(mTabToRemove);
325 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700326 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400327 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700328 mTabToRemove = tabToRemove;
329 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400330 mNumRemoveTries = 0;
331
332 if (mTabToRemove != null) {
333 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700334 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400335 }
336 }
337
338 protected void tryRemoveTab() {
339 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700340 // Ensure the webview is still valid
341 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
342 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700343 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700344 mRunnable = new Runnable() {
345 public void run() {
346 tryRemoveTab();
347 }
348 };
349 }
350 /*if the new tab is still not ready, wait another 2 frames
351 before trying again. 1 frame for the tab to render the first
352 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700353 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400354 return;
355 }
356 }
357 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700358 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700359 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400360 removeTabFromContentView(mTabToRemove);
361 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700362 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400363 }
364 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700365 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700366 }
367
John Reck718a24d2011-08-12 11:08:30 -0700368 protected void updateUrlBarAutoShowManagerTarget() {
369 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
370 if (!mUseQuickControls && web instanceof BrowserWebView) {
371 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
372 } else {
373 mUrlBarAutoShowManager.setTarget(null);
374 }
375 }
376
Michael Kolbcfa3af52010-12-14 10:36:11 -0800377 Tab getActiveTab() {
378 return mActiveTab;
379 }
380
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800382 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800383 }
384
385 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700386 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800387 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700388 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800389 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700390 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700391 }
392
393 @Override
394 public void detachTab(Tab tab) {
395 removeTabFromContentView(tab);
396 }
397
398 @Override
399 public void attachTab(Tab tab) {
400 attachTabToContentView(tab);
401 }
402
Michael Kolb377ea312011-02-17 14:36:56 -0800403 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800404 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700405 return;
406 }
407 View container = tab.getViewContainer();
408 WebView mainView = tab.getWebView();
409 // Attach the WebView to the container and then attach the
410 // container to the content view.
411 FrameLayout wrapper =
412 (FrameLayout) container.findViewById(R.id.webview_wrapper);
413 ViewGroup parent = (ViewGroup) mainView.getParent();
414 if (parent != wrapper) {
415 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 parent.removeView(mainView);
417 }
418 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700419 }
420 parent = (ViewGroup) container.getParent();
421 if (parent != mContentView) {
422 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700423 parent.removeView(container);
424 }
425 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427 mUiController.attachSubWindow(tab);
428 }
429
430 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800431 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700432 // Remove the container that contains the main WebView.
433 WebView mainView = tab.getWebView();
434 View container = tab.getViewContainer();
435 if (mainView == null) {
436 return;
437 }
438 // Remove the container from the content and then remove the
439 // WebView from the container. This will trigger a focus change
440 // needed by WebView.
441 FrameLayout wrapper =
442 (FrameLayout) container.findViewById(R.id.webview_wrapper);
443 wrapper.removeView(mainView);
444 mContentView.removeView(container);
445 mUiController.endActionMode();
446 mUiController.removeSubWindow(tab);
447 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
448 if (errorConsole != null) {
449 mErrorConsoleContainer.removeView(errorConsole);
450 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700451 }
452
Michael Kolba713ec82010-11-29 17:27:06 -0800453 @Override
454 public void onSetWebView(Tab tab, WebView webView) {
455 View container = tab.getViewContainer();
456 if (container == null) {
457 // The tab consists of a container view, which contains the main
458 // WebView, as well as any other UI elements associated with the tab.
459 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700460 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800461 tab.setViewContainer(container);
462 }
463 if (tab.getWebView() != webView) {
464 // Just remove the old one.
465 FrameLayout wrapper =
466 (FrameLayout) container.findViewById(R.id.webview_wrapper);
467 wrapper.removeView(tab.getWebView());
468 }
469 }
470
Michael Kolb8233fac2010-10-26 16:08:53 -0700471 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800472 * create a sub window container and webview for the tab
473 * Note: this methods operates through side-effects for now
474 * it sets both the subView and subViewContainer for the given tab
475 * @param tab tab to create the sub window for
476 * @param subView webview to be set as a subwindow for the tab
477 */
478 @Override
479 public void createSubWindow(Tab tab, WebView subView) {
480 View subViewContainer = mActivity.getLayoutInflater().inflate(
481 R.layout.browser_subwindow, null);
482 ViewGroup inner = (ViewGroup) subViewContainer
483 .findViewById(R.id.inner_container);
484 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
485 LayoutParams.MATCH_PARENT));
486 final ImageButton cancel = (ImageButton) subViewContainer
487 .findViewById(R.id.subwindow_close);
488 final WebView cancelSubView = subView;
489 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800490 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800491 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800492 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800493 }
494 });
495 tab.setSubWebView(subView);
496 tab.setSubViewContainer(subViewContainer);
497 }
498
499 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700500 * Remove the sub window from the content view.
501 */
502 @Override
503 public void removeSubWindow(View subviewContainer) {
504 mContentView.removeView(subviewContainer);
505 mUiController.endActionMode();
506 }
507
508 /**
509 * Attach the sub window to the content view.
510 */
511 @Override
512 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800513 if (container.getParent() != null) {
514 // already attached, remove first
515 ((ViewGroup) container.getParent()).removeView(container);
516 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700517 mContentView.addView(container, COVER_SCREEN_PARAMS);
518 }
519
Michael Kolb11d19782011-03-20 10:17:40 -0700520 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700521 WebView web = getWebView();
522 if (web != null) {
523 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700524 }
525 }
526
Michael Kolb1f9b3562012-04-24 14:38:34 -0700527 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700528 if (mUiController.isInCustomActionMode()) {
529 mUiController.endActionMode();
530 }
531 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700532 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700533 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700534 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700535 }
536
Michael Kolb7cdc4902011-02-03 17:54:40 -0800537 boolean canShowTitleBar() {
538 return !isTitleBarShowing()
539 && !isActivityPaused()
540 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700541 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800542 && !mUiController.isInCustomActionMode();
543 }
544
John Reck0f602f32011-07-07 15:38:43 -0700545 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700546 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700547 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700548 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700549 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800550 }
551
552 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700553 if (mTitleBar.isShowing()) {
554 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700555 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800556 }
557
558 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700559 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800560 }
561
John Reck5d43ce82011-06-21 17:16:51 -0700562 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700563 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700564 }
565
Michael Kolb80f75082012-04-10 10:50:06 -0700566 public void stopEditingUrl() {
567 mTitleBar.getNavigationBar().stopEditingUrl();
568 }
569
John Reck0f602f32011-07-07 15:38:43 -0700570 public TitleBar getTitleBar() {
571 return mTitleBar;
572 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800573
Michael Kolb66706532010-12-12 19:50:22 -0800574 @Override
John Reck2bc80422011-06-30 15:11:49 -0700575 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700576 Intent intent = new Intent(mActivity, ComboViewActivity.class);
577 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
578 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
579 Tab t = getActiveTab();
580 if (t != null) {
581 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800582 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700583 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700584 }
585
586 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400587 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800588 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700589 // if a view already exists then immediately terminate the new one
590 if (mCustomView != null) {
591 callback.onCustomViewHidden();
592 return;
593 }
594
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400595 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700596 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
597 mFullscreenContainer = new FullscreenHolder(mActivity);
598 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
599 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
600 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700601 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700602 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400604 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700605 }
606
607 @Override
608 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700609 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700610 if (mCustomView == null)
611 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700612 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700613 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
614 decor.removeView(mFullscreenContainer);
615 mFullscreenContainer = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 mCustomViewCallback.onCustomViewHidden();
618 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400619 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 }
621
622 @Override
623 public boolean isCustomViewShowing() {
624 return mCustomView != null;
625 }
626
Michael Kolb66706532010-12-12 19:50:22 -0800627 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800628 if (mInputManager.isActive()) {
629 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
630 0);
631 }
632 }
633
Michael Kolb66706532010-12-12 19:50:22 -0800634 @Override
John Reck3ba45532011-08-11 16:26:53 -0700635 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700636 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800637 }
638
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 // -------------------------------------------------------------------------
640
Michael Kolb5a72f182011-01-13 20:35:06 -0800641 protected void updateNavigationState(Tab tab) {
642 }
643
Michael Kolb8233fac2010-10-26 16:08:53 -0700644 /**
645 * Update the lock icon to correspond to our latest state.
646 */
Michael Kolb66706532010-12-12 19:50:22 -0800647 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800648 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100649 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700650 }
651 }
652
653 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700654 * Updates the lock-icon image in the title-bar.
655 */
Steve Block2466eff2011-10-03 15:33:09 +0100656 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700657 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100658 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
659 d = mLockIconSecure;
Steve Block4895b012011-10-03 16:26:46 +0100660 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
661 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
662 // TODO: It would be good to have different icons for insecure vs mixed content.
663 // See http://b/5403800
Steve Block2466eff2011-10-03 15:33:09 +0100664 d = mLockIconMixed;
Michael Kolb8233fac2010-10-26 16:08:53 -0700665 }
John Reck0f602f32011-07-07 15:38:43 -0700666 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700667 }
668
John Reck30c714c2010-12-16 17:30:34 -0800669 protected void setUrlTitle(Tab tab) {
670 String url = tab.getUrl();
671 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800672 if (TextUtils.isEmpty(title)) {
673 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800674 }
Michael Kolb66706532010-12-12 19:50:22 -0800675 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700676 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800677 }
678 }
679
680 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800681 protected void setFavicon(Tab tab) {
682 if (tab.inForeground()) {
683 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700684 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800685 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 }
687
Michael Kolb66706532010-12-12 19:50:22 -0800688 // active tabs page
689
690 public void showActiveTabsPage() {
691 }
692
693 /**
694 * Remove the active tabs page.
695 */
696 public void removeActiveTabsPage() {
697 }
698
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 // menu handling callbacks
700
701 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800702 public boolean onPrepareOptionsMenu(Menu menu) {
703 return true;
704 }
705
706 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700707 public void updateMenuState(Tab tab, Menu menu) {
708 }
709
710 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700711 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 }
713
714 @Override
715 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700716 }
717
718 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700719 public boolean onOptionsItemSelected(MenuItem item) {
720 return false;
721 }
722
723 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700724 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 }
726
727 @Override
728 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700729 }
730
731 @Override
732 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700733 }
734
735 @Override
736 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700737 }
738
739 // error console
740
741 @Override
742 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800743 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700744 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
745 if (flag) {
746 // Setting the show state of the console will cause it's the layout
747 // to be inflated.
748 if (errorConsole.numberOfErrors() > 0) {
749 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
750 } else {
751 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
752 }
753 if (errorConsole.getParent() != null) {
754 mErrorConsoleContainer.removeView(errorConsole);
755 }
756 // Now we can add it to the main view.
757 mErrorConsoleContainer.addView(errorConsole,
758 new LinearLayout.LayoutParams(
759 ViewGroup.LayoutParams.MATCH_PARENT,
760 ViewGroup.LayoutParams.WRAP_CONTENT));
761 } else {
762 mErrorConsoleContainer.removeView(errorConsole);
763 }
764 }
765
Michael Kolb8233fac2010-10-26 16:08:53 -0700766 // -------------------------------------------------------------------------
767 // Helper function for WebChromeClient
768 // -------------------------------------------------------------------------
769
770 @Override
771 public Bitmap getDefaultVideoPoster() {
772 if (mDefaultVideoPoster == null) {
773 mDefaultVideoPoster = BitmapFactory.decodeResource(
774 mActivity.getResources(), R.drawable.default_video_poster);
775 }
776 return mDefaultVideoPoster;
777 }
778
779 @Override
780 public View getVideoLoadingProgressView() {
781 if (mVideoProgressView == null) {
782 LayoutInflater inflater = LayoutInflater.from(mActivity);
783 mVideoProgressView = inflater.inflate(
784 R.layout.video_loading_progress, null);
785 }
786 return mVideoProgressView;
787 }
788
Michael Kolb843510f2010-12-09 10:51:49 -0800789 @Override
790 public void showMaxTabsWarning() {
791 Toast warning = Toast.makeText(mActivity,
792 mActivity.getString(R.string.max_tabs_warning),
793 Toast.LENGTH_SHORT);
794 warning.show();
795 }
796
Michael Kolb46f987e2011-04-05 10:39:10 -0700797 protected WebView getWebView() {
798 if (mActiveTab != null) {
799 return mActiveTab.getWebView();
800 } else {
801 return null;
802 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700803 }
804
Michael Kolbc38c6042011-04-27 10:46:06 -0700805 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700806 Window win = mActivity.getWindow();
807 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800808 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700809 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700810 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700811 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700812 winParams.flags &= ~bits;
813 if (mCustomView != null) {
814 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
815 } else {
816 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
817 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700818 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700819 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700820 }
821
Tarun Nainani8eb00912014-07-17 12:28:32 -0700822 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700823 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700824 mTitleBar.bringToFront();
825 if (topControlsOffsetYPix != 0.0) {
826 mTitleBar.setEnabled(false);
827 } else {
828 mTitleBar.setEnabled(true);
829 }
Tarun Nainani8eb00912014-07-17 12:28:32 -0700830
831 if (!mUseQuickControls)
832 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700833 }
834 }
835
John Reck0f602f32011-07-07 15:38:43 -0700836 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700837 Drawable[] array = new Drawable[3];
838 array[0] = new PaintDrawable(Color.BLACK);
839 PaintDrawable p = new PaintDrawable(Color.WHITE);
840 array[1] = p;
841 if (icon == null) {
842 array[2] = mGenericFavicon;
843 } else {
844 array[2] = new BitmapDrawable(icon);
845 }
846 LayerDrawable d = new LayerDrawable(array);
847 d.setLayerInset(1, 1, 1, 1, 1);
848 d.setLayerInset(2, 2, 2, 2, 2);
849 return d;
850 }
851
John Reck5d43ce82011-06-21 17:16:51 -0700852 public boolean isLoading() {
853 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
854 }
855
856 /**
857 * Suggest to the UI that the title bar can be hidden. The UI will then
858 * decide whether or not to hide based off a number of factors, such
859 * as if the user is editing the URL bar or if the page is loading
860 */
861 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700862 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
863 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700864 hideTitleBar();
865 }
866 }
867
John Reckbc6adb42011-09-01 18:03:20 -0700868 protected final void showTitleBarForDuration() {
869 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
870 }
871
872 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700873 showTitleBar();
874 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700875 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700876 }
877
John Reck9c5004e2011-10-07 16:00:12 -0700878 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700879
880 @Override
881 public void handleMessage(Message msg) {
882 if (msg.what == MSG_HIDE_TITLEBAR) {
883 suggestHideTitleBar();
884 }
John Reck9c5004e2011-10-07 16:00:12 -0700885 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700886 }
887 };
John Reck3ba45532011-08-11 16:26:53 -0700888
John Reck9c5004e2011-10-07 16:00:12 -0700889 protected void handleMessage(Message msg) {}
890
John Reck3ba45532011-08-11 16:26:53 -0700891 @Override
892 public void showWeb(boolean animate) {
893 mUiController.hideCustomView();
894 }
895
Michael Kolb31065b12011-10-06 13:51:32 -0700896 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700897
Michael Kolb31065b12011-10-06 13:51:32 -0700898 public FullscreenHolder(Context ctx) {
899 super(ctx);
900 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700901 }
902
Michael Kolb31065b12011-10-06 13:51:32 -0700903 @Override
904 public boolean onTouchEvent(MotionEvent evt) {
905 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700906 }
Michael Kolb31065b12011-10-06 13:51:32 -0700907
Michael Kolb53ed62c2011-10-04 16:18:44 -0700908 }
John Reck2711fab2012-05-18 21:38:59 -0700909
910 public void addFixedTitleBar(View view) {
911 mFixedTitlebarContainer.addView(view);
912 }
913
914 public void setContentViewMarginTop(int margin) {
915 LinearLayout.LayoutParams params =
916 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
917 if (params.topMargin != margin) {
918 params.topMargin = margin;
919 mContentView.setLayoutParams(params);
920 }
921 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700922
923 @Override
924 public boolean blockFocusAnimations() {
925 return mBlockFocusAnimations;
926 }
927
Michael Kolb0b129122012-06-04 16:31:58 -0700928 @Override
929 public void onVoiceResult(String result) {
930 mNavigationBar.onVoiceResult(result);
931 }
932
kaiyizbb2db872013-08-01 22:24:07 -0400933 protected UiController getUiController() {
934 return mUiController;
935 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700936
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700937 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700938 private float getActionModeHeight() {
939 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
940 new int[] { android.R.attr.actionBarSize });
941 float size = actionBarSizeTypedArray.getDimension(0, 0f);
942 actionBarSizeTypedArray.recycle();
943 return size;
944 }
945
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700946
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700947 @Override
948 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700949 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700950
951 if (mTitleBar.isFixed()) {
952 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700953 mFixedTitlebarContainer.setY(fixedTbarHeight);
954 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700955 } else {
956 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700957 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700958 }
959
960 @Override
961 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700962 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700963 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700964 mFixedTitlebarContainer.setY(0);
965 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700966 } else {
967 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700968 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700969 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700970}