blob: 1ea14601d9973f6130ec445ce767e28ed25c7d12 [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;
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 Reck0f602f32011-07-07 15:38:43 -0700113 protected TitleBar mTitleBar;
114 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700115 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700116
117 public BaseUi(Activity browser, UiController controller) {
118 mActivity = browser;
119 mUiController = controller;
120 mTabControl = controller.getTabControl();
121 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800122 mInputManager = (InputMethodManager)
123 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700124 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
125 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700126 LayoutInflater.from(mActivity)
127 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700128 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
129 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700130 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700131 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700132 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
133 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700134 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700135 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700136 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700137 mTitleBar = new TitleBar(mActivity, mUiController, this,
138 mContentView);
139 mTitleBar.setProgress(100);
140 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700141 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700142 }
143
Michael Kolb8233fac2010-10-26 16:08:53 -0700144 private void cancelStopToast() {
145 if (mStopToast != null) {
146 mStopToast.cancel();
147 mStopToast = null;
148 }
149 }
150
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700151 private Drawable getLockIconSecure() {
152 if (mLockIconSecure == null) {
153 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_secure_holo_dark);
154 }
155 return mLockIconSecure;
156 }
157
158 private Drawable getLockIconMixed() {
159 if (mLockIconMixed == null) {
160 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_secure_partial_holo_dark);
161 }
162 return mLockIconMixed;
163 }
164
165 protected Drawable getGenericFavicon() {
166 if (mGenericFavicon == null) {
167 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.app_web_browser_sm);
168 }
169 return mGenericFavicon;
170 }
171
Michael Kolb8233fac2010-10-26 16:08:53 -0700172 // lifecycle
173
174 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800175 if (isCustomViewShowing()) {
176 onHideCustomView();
177 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 cancelStopToast();
179 mActivityPaused = true;
180 }
181
182 public void onResume() {
183 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700184 // check if we exited without setting active tab
185 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700186 final Tab ct = mTabControl.getCurrentTab();
187 if (ct != null) {
188 setActiveTab(ct);
189 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700190 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700191 }
192
Michael Kolb66706532010-12-12 19:50:22 -0800193 protected boolean isActivityPaused() {
194 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700195 }
196
197 public void onConfigurationChanged(Configuration config) {
198 }
199
John Reck0f602f32011-07-07 15:38:43 -0700200 public Activity getActivity() {
201 return mActivity;
202 }
203
Michael Kolb8233fac2010-10-26 16:08:53 -0700204 // key handling
205
206 @Override
207 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700208 if (mCustomView != null) {
209 mUiController.hideCustomView();
210 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700211 } else if ((mTabControl.getCurrentTab() != null) &&
212 (mTabControl.getCurrentTab().isTabFullScreen())) {
213 mTabControl.getCurrentTab().setTabFullscreen(false);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700214 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700215 }
216 return false;
217 }
218
Michael Kolb2814a362011-05-19 15:49:41 -0700219 @Override
220 public boolean onMenuKey() {
221 return false;
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.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700293 web.setTitleBar(mTitleBar);
294 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700295 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700296 }
Michael Kolb4923c222012-04-02 16:18:36 -0700297 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700298 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700299 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800300 onTabDataChanged(tab);
301 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700302 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700303 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400304
Vivek Sekhar943f0672014-05-01 18:35:22 -0700305 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400306 }
307
308 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700309 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400310 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312
Vivek Sekhar943f0672014-05-01 18:35:22 -0700313 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400314 //remove previously scehduled tab
315 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700316 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700317 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400318 removeTabFromContentView(mTabToRemove);
319 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700320 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400321 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700322 mTabToRemove = tabToRemove;
323 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400324 mNumRemoveTries = 0;
325
326 if (mTabToRemove != null) {
327 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700328 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400329 }
330 }
331
332 protected void tryRemoveTab() {
333 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700334 // Ensure the webview is still valid
335 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
336 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700337 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700338 mRunnable = new Runnable() {
339 public void run() {
340 tryRemoveTab();
341 }
342 };
343 }
344 /*if the new tab is still not ready, wait another 2 frames
345 before trying again. 1 frame for the tab to render the first
346 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700347 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400348 return;
349 }
350 }
351 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700352 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700353 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400354 removeTabFromContentView(mTabToRemove);
355 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700356 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400357 }
358 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700359 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700360 }
361
John Reck718a24d2011-08-12 11:08:30 -0700362 protected void updateUrlBarAutoShowManagerTarget() {
363 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700364 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700365 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700366 }
367 }
368
Michael Kolbcfa3af52010-12-14 10:36:11 -0800369 Tab getActiveTab() {
370 return mActiveTab;
371 }
372
Michael Kolb8233fac2010-10-26 16:08:53 -0700373 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800374 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800375 }
376
377 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800379 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800381 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700383 }
384
385 @Override
386 public void detachTab(Tab tab) {
387 removeTabFromContentView(tab);
388 }
389
390 @Override
391 public void attachTab(Tab tab) {
392 attachTabToContentView(tab);
393 }
394
Michael Kolb377ea312011-02-17 14:36:56 -0800395 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800396 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700397 return;
398 }
399 View container = tab.getViewContainer();
400 WebView mainView = tab.getWebView();
401 // Attach the WebView to the container and then attach the
402 // container to the content view.
403 FrameLayout wrapper =
404 (FrameLayout) container.findViewById(R.id.webview_wrapper);
405 ViewGroup parent = (ViewGroup) mainView.getParent();
406 if (parent != wrapper) {
407 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700408 parent.removeView(mainView);
409 }
410 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700411 }
412 parent = (ViewGroup) container.getParent();
413 if (parent != mContentView) {
414 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700415 parent.removeView(container);
416 }
417 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700418 }
419 mUiController.attachSubWindow(tab);
420 }
421
422 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800423 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700424 // Remove the container that contains the main WebView.
425 WebView mainView = tab.getWebView();
426 View container = tab.getViewContainer();
427 if (mainView == null) {
428 return;
429 }
430 // Remove the container from the content and then remove the
431 // WebView from the container. This will trigger a focus change
432 // needed by WebView.
433 FrameLayout wrapper =
434 (FrameLayout) container.findViewById(R.id.webview_wrapper);
435 wrapper.removeView(mainView);
436 mContentView.removeView(container);
437 mUiController.endActionMode();
438 mUiController.removeSubWindow(tab);
439 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
440 if (errorConsole != null) {
441 mErrorConsoleContainer.removeView(errorConsole);
442 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700443 }
444
Michael Kolba713ec82010-11-29 17:27:06 -0800445 @Override
446 public void onSetWebView(Tab tab, WebView webView) {
447 View container = tab.getViewContainer();
448 if (container == null) {
449 // The tab consists of a container view, which contains the main
450 // WebView, as well as any other UI elements associated with the tab.
451 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700452 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800453 tab.setViewContainer(container);
454 }
455 if (tab.getWebView() != webView) {
456 // Just remove the old one.
457 FrameLayout wrapper =
458 (FrameLayout) container.findViewById(R.id.webview_wrapper);
459 wrapper.removeView(tab.getWebView());
460 }
461 }
462
Michael Kolb8233fac2010-10-26 16:08:53 -0700463 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800464 * create a sub window container and webview for the tab
465 * Note: this methods operates through side-effects for now
466 * it sets both the subView and subViewContainer for the given tab
467 * @param tab tab to create the sub window for
468 * @param subView webview to be set as a subwindow for the tab
469 */
470 @Override
471 public void createSubWindow(Tab tab, WebView subView) {
472 View subViewContainer = mActivity.getLayoutInflater().inflate(
473 R.layout.browser_subwindow, null);
474 ViewGroup inner = (ViewGroup) subViewContainer
475 .findViewById(R.id.inner_container);
476 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
477 LayoutParams.MATCH_PARENT));
478 final ImageButton cancel = (ImageButton) subViewContainer
479 .findViewById(R.id.subwindow_close);
480 final WebView cancelSubView = subView;
481 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800482 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800483 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800484 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800485 }
486 });
487 tab.setSubWebView(subView);
488 tab.setSubViewContainer(subViewContainer);
489 }
490
491 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700492 * Remove the sub window from the content view.
493 */
494 @Override
495 public void removeSubWindow(View subviewContainer) {
496 mContentView.removeView(subviewContainer);
497 mUiController.endActionMode();
498 }
499
500 /**
501 * Attach the sub window to the content view.
502 */
503 @Override
504 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800505 if (container.getParent() != null) {
506 // already attached, remove first
507 ((ViewGroup) container.getParent()).removeView(container);
508 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700509 mContentView.addView(container, COVER_SCREEN_PARAMS);
510 }
511
Michael Kolb11d19782011-03-20 10:17:40 -0700512 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700513 WebView web = getWebView();
514 if (web != null) {
515 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700516 }
517 }
518
Michael Kolb1f9b3562012-04-24 14:38:34 -0700519 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700520 if (mUiController.isInCustomActionMode()) {
521 mUiController.endActionMode();
522 }
523 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700524 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700525 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700526 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700527 }
528
Michael Kolb7cdc4902011-02-03 17:54:40 -0800529 boolean canShowTitleBar() {
530 return !isTitleBarShowing()
531 && !isActivityPaused()
532 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700533 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800534 && !mUiController.isInCustomActionMode();
535 }
536
John Reck0f602f32011-07-07 15:38:43 -0700537 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700538 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700539 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700540 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700541 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800542 }
543
544 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700545 if (mTitleBar.isShowing()) {
546 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700547 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800548 }
549
550 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700551 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800552 }
553
John Reck5d43ce82011-06-21 17:16:51 -0700554 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700555 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700556 }
557
Michael Kolb80f75082012-04-10 10:50:06 -0700558 public void stopEditingUrl() {
559 mTitleBar.getNavigationBar().stopEditingUrl();
560 }
561
John Reck0f602f32011-07-07 15:38:43 -0700562 public TitleBar getTitleBar() {
563 return mTitleBar;
564 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800565
Michael Kolb66706532010-12-12 19:50:22 -0800566 @Override
John Reck2bc80422011-06-30 15:11:49 -0700567 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700568 Intent intent = new Intent(mActivity, ComboViewActivity.class);
569 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
570 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
571 Tab t = getActiveTab();
572 if (t != null) {
573 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800574 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700575 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700576 }
577
578 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400579 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800580 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700581 // if a view already exists then immediately terminate the new one
582 if (mCustomView != null) {
583 callback.onCustomViewHidden();
584 return;
585 }
586
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400587 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700588 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
589 mFullscreenContainer = new FullscreenHolder(mActivity);
590 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
591 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
592 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700593 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700594 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700595 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400596 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700597 }
598
599 @Override
600 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700601 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 if (mCustomView == null)
603 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700604 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700605 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
606 decor.removeView(mFullscreenContainer);
607 mFullscreenContainer = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 mCustomViewCallback.onCustomViewHidden();
610 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400611 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 }
613
614 @Override
615 public boolean isCustomViewShowing() {
616 return mCustomView != null;
617 }
618
Michael Kolb66706532010-12-12 19:50:22 -0800619 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800620 if (mInputManager.isActive()) {
621 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
622 0);
623 }
624 }
625
Michael Kolb66706532010-12-12 19:50:22 -0800626 @Override
John Reck3ba45532011-08-11 16:26:53 -0700627 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700628 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800629 }
630
Michael Kolb8233fac2010-10-26 16:08:53 -0700631 // -------------------------------------------------------------------------
632
Michael Kolb5a72f182011-01-13 20:35:06 -0800633 protected void updateNavigationState(Tab tab) {
634 }
635
Michael Kolb8233fac2010-10-26 16:08:53 -0700636 /**
637 * Update the lock icon to correspond to our latest state.
638 */
Michael Kolb66706532010-12-12 19:50:22 -0800639 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800640 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100641 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 }
643 }
644
645 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700646 * Updates the lock-icon image in the title-bar.
647 */
Steve Block2466eff2011-10-03 15:33:09 +0100648 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700649 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100650 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700651 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100652 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
653 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
654 // TODO: It would be good to have different icons for insecure vs mixed content.
655 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700656 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700657 }
John Reck0f602f32011-07-07 15:38:43 -0700658 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 }
660
John Reck30c714c2010-12-16 17:30:34 -0800661 protected void setUrlTitle(Tab tab) {
662 String url = tab.getUrl();
663 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800664 if (TextUtils.isEmpty(title)) {
665 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800666 }
Michael Kolb66706532010-12-12 19:50:22 -0800667 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700668 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800669 }
670 }
671
672 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800673 protected void setFavicon(Tab tab) {
674 if (tab.inForeground()) {
675 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700676 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800677 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700678 }
679
Michael Kolb66706532010-12-12 19:50:22 -0800680 // active tabs page
681
682 public void showActiveTabsPage() {
683 }
684
685 /**
686 * Remove the active tabs page.
687 */
688 public void removeActiveTabsPage() {
689 }
690
Michael Kolb8233fac2010-10-26 16:08:53 -0700691 // menu handling callbacks
692
693 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800694 public boolean onPrepareOptionsMenu(Menu menu) {
695 return true;
696 }
697
698 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700699 public void updateMenuState(Tab tab, Menu menu) {
700 }
701
702 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700703 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 }
705
706 @Override
707 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700708 }
709
710 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700711 public boolean onOptionsItemSelected(MenuItem item) {
712 return false;
713 }
714
715 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700716 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700717 }
718
719 @Override
720 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700721 }
722
723 @Override
724 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 }
726
727 @Override
728 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700729 }
730
731 // error console
732
733 @Override
734 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800735 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700736 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
737 if (flag) {
738 // Setting the show state of the console will cause it's the layout
739 // to be inflated.
740 if (errorConsole.numberOfErrors() > 0) {
741 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
742 } else {
743 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
744 }
745 if (errorConsole.getParent() != null) {
746 mErrorConsoleContainer.removeView(errorConsole);
747 }
748 // Now we can add it to the main view.
749 mErrorConsoleContainer.addView(errorConsole,
750 new LinearLayout.LayoutParams(
751 ViewGroup.LayoutParams.MATCH_PARENT,
752 ViewGroup.LayoutParams.WRAP_CONTENT));
753 } else {
754 mErrorConsoleContainer.removeView(errorConsole);
755 }
756 }
757
Michael Kolb8233fac2010-10-26 16:08:53 -0700758 // -------------------------------------------------------------------------
759 // Helper function for WebChromeClient
760 // -------------------------------------------------------------------------
761
762 @Override
763 public Bitmap getDefaultVideoPoster() {
764 if (mDefaultVideoPoster == null) {
765 mDefaultVideoPoster = BitmapFactory.decodeResource(
766 mActivity.getResources(), R.drawable.default_video_poster);
767 }
768 return mDefaultVideoPoster;
769 }
770
771 @Override
772 public View getVideoLoadingProgressView() {
773 if (mVideoProgressView == null) {
774 LayoutInflater inflater = LayoutInflater.from(mActivity);
775 mVideoProgressView = inflater.inflate(
776 R.layout.video_loading_progress, null);
777 }
778 return mVideoProgressView;
779 }
780
Michael Kolb843510f2010-12-09 10:51:49 -0800781 @Override
782 public void showMaxTabsWarning() {
783 Toast warning = Toast.makeText(mActivity,
784 mActivity.getString(R.string.max_tabs_warning),
785 Toast.LENGTH_SHORT);
786 warning.show();
787 }
788
Michael Kolb46f987e2011-04-05 10:39:10 -0700789 protected WebView getWebView() {
790 if (mActiveTab != null) {
791 return mActiveTab.getWebView();
792 } else {
793 return null;
794 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700795 }
796
Michael Kolbc38c6042011-04-27 10:46:06 -0700797 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700798 Window win = mActivity.getWindow();
799 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800800 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700801 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700802 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700803 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700804 winParams.flags &= ~bits;
805 if (mCustomView != null) {
806 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
807 } else {
808 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
809 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700810 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700811 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700812 }
813
Tarun Nainani8eb00912014-07-17 12:28:32 -0700814 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700815 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700816 mTitleBar.bringToFront();
817 if (topControlsOffsetYPix != 0.0) {
818 mTitleBar.setEnabled(false);
819 } else {
820 mTitleBar.setEnabled(true);
821 }
Vivek Sekhar8a660782014-10-27 17:00:53 -0700822 if (!mTitleBar.isFixed() && !isLoading())
823 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700824 }
825 }
826
John Reck0f602f32011-07-07 15:38:43 -0700827 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700828 Drawable[] array = new Drawable[3];
829 array[0] = new PaintDrawable(Color.BLACK);
830 PaintDrawable p = new PaintDrawable(Color.WHITE);
831 array[1] = p;
832 if (icon == null) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700833 array[2] = getGenericFavicon();
Michael Kolb5a4372f2011-04-29 13:53:10 -0700834 } else {
835 array[2] = new BitmapDrawable(icon);
836 }
837 LayerDrawable d = new LayerDrawable(array);
838 d.setLayerInset(1, 1, 1, 1, 1);
839 d.setLayerInset(2, 2, 2, 2, 2);
840 return d;
841 }
842
John Reck5d43ce82011-06-21 17:16:51 -0700843 public boolean isLoading() {
844 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
845 }
846
847 /**
848 * Suggest to the UI that the title bar can be hidden. The UI will then
849 * decide whether or not to hide based off a number of factors, such
850 * as if the user is editing the URL bar or if the page is loading
851 */
852 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700853 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
854 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700855 hideTitleBar();
856 }
857 }
858
John Reckbc6adb42011-09-01 18:03:20 -0700859 protected final void showTitleBarForDuration() {
860 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
861 }
862
863 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700864 showTitleBar();
865 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700866 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700867 }
868
John Reck9c5004e2011-10-07 16:00:12 -0700869 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700870
871 @Override
872 public void handleMessage(Message msg) {
873 if (msg.what == MSG_HIDE_TITLEBAR) {
874 suggestHideTitleBar();
875 }
John Reck9c5004e2011-10-07 16:00:12 -0700876 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700877 }
878 };
John Reck3ba45532011-08-11 16:26:53 -0700879
John Reck9c5004e2011-10-07 16:00:12 -0700880 protected void handleMessage(Message msg) {}
881
John Reck3ba45532011-08-11 16:26:53 -0700882 @Override
883 public void showWeb(boolean animate) {
884 mUiController.hideCustomView();
885 }
886
Michael Kolb31065b12011-10-06 13:51:32 -0700887 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700888
Michael Kolb31065b12011-10-06 13:51:32 -0700889 public FullscreenHolder(Context ctx) {
890 super(ctx);
891 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700892 }
893
Michael Kolb31065b12011-10-06 13:51:32 -0700894 @Override
895 public boolean onTouchEvent(MotionEvent evt) {
896 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700897 }
Michael Kolb31065b12011-10-06 13:51:32 -0700898
Michael Kolb53ed62c2011-10-04 16:18:44 -0700899 }
John Reck2711fab2012-05-18 21:38:59 -0700900
John Reck2711fab2012-05-18 21:38:59 -0700901 public void setContentViewMarginTop(int margin) {
902 LinearLayout.LayoutParams params =
903 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
904 if (params.topMargin != margin) {
905 params.topMargin = margin;
906 mContentView.setLayoutParams(params);
907 }
908 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700909
910 @Override
911 public boolean blockFocusAnimations() {
912 return mBlockFocusAnimations;
913 }
914
Michael Kolb0b129122012-06-04 16:31:58 -0700915 @Override
916 public void onVoiceResult(String result) {
917 mNavigationBar.onVoiceResult(result);
918 }
919
kaiyizbb2db872013-08-01 22:24:07 -0400920 protected UiController getUiController() {
921 return mUiController;
922 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700923
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700924 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700925 private float getActionModeHeight() {
926 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
927 new int[] { android.R.attr.actionBarSize });
928 float size = actionBarSizeTypedArray.getDimension(0, 0f);
929 actionBarSizeTypedArray.recycle();
930 return size;
931 }
932
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700933
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700934 @Override
935 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700936 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700937
938 if (mTitleBar.isFixed()) {
939 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700940 mFixedTitlebarContainer.setY(fixedTbarHeight);
941 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700942 } else {
943 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700944 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700945 }
946
947 @Override
948 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700949 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700950 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700951 mFixedTitlebarContainer.setY(0);
952 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700953 } else {
954 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700955 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700956 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700957}