blob: 354e901f2118f4e10de26c77b30fe4576233d4ab [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 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);
Steve Block2466eff2011-10-03 15:33:09 +0100124 mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark);
125 mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700126 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
127 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700128 LayoutInflater.from(mActivity)
129 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700130 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
131 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700132 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700133 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700134 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
135 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700136 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700137 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700138 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700139 mGenericFavicon = res.getDrawable(
140 R.drawable.app_web_browser_sm);
John Reck0f602f32011-07-07 15:38:43 -0700141 mTitleBar = new TitleBar(mActivity, mUiController, this,
142 mContentView);
143 mTitleBar.setProgress(100);
144 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700145 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700146 }
147
Michael Kolb8233fac2010-10-26 16:08:53 -0700148 private void cancelStopToast() {
149 if (mStopToast != null) {
150 mStopToast.cancel();
151 mStopToast = null;
152 }
153 }
154
155 // lifecycle
156
157 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800158 if (isCustomViewShowing()) {
159 onHideCustomView();
160 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700161 cancelStopToast();
162 mActivityPaused = true;
163 }
164
165 public void onResume() {
166 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700167 // check if we exited without setting active tab
168 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700169 final Tab ct = mTabControl.getCurrentTab();
170 if (ct != null) {
171 setActiveTab(ct);
172 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700173 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700174 }
175
Michael Kolb66706532010-12-12 19:50:22 -0800176 protected boolean isActivityPaused() {
177 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 }
179
180 public void onConfigurationChanged(Configuration config) {
181 }
182
John Reck0f602f32011-07-07 15:38:43 -0700183 public Activity getActivity() {
184 return mActivity;
185 }
186
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 // key handling
188
189 @Override
190 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700191 if (mCustomView != null) {
192 mUiController.hideCustomView();
193 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700194 } else if ((mTabControl.getCurrentTab() != null) &&
195 (mTabControl.getCurrentTab().isTabFullScreen())) {
196 mTabControl.getCurrentTab().setTabFullscreen(false);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700197 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 }
199 return false;
200 }
201
Michael Kolb2814a362011-05-19 15:49:41 -0700202 @Override
203 public boolean onMenuKey() {
204 return false;
205 }
206
John Reck30c714c2010-12-16 17:30:34 -0800207 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700208 @Override
John Reck30c714c2010-12-16 17:30:34 -0800209 public void onTabDataChanged(Tab tab) {
210 setUrlTitle(tab);
211 setFavicon(tab);
212 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800213 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700214 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700215 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700216 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 }
218
219 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700220 public void onProgressChanged(Tab tab) {
221 int progress = tab.getLoadProgress();
222 if (tab.inForeground()) {
223 mTitleBar.setProgress(progress);
224 }
225 }
226
227 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500228 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800229 if (tab.inForeground()) {
230 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700231 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800232 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500233 }
234
235 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 public void onPageStopped(Tab tab) {
237 cancelStopToast();
238 if (tab.inForeground()) {
239 mStopToast = Toast
240 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
241 mStopToast.show();
242 }
243 }
244
245 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800246 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700247 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800248 }
249
250 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700251 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 }
253
254 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800255 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800256 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400257 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700258 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400259
Michael Kolbbae0cb22012-05-29 11:15:27 -0700260 // block unnecessary focus change animations during tab switch
261 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700262 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800263 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400264 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700265 WebView web = mActiveTab.getWebView();
266 if (web != null) {
267 web.setOnTouchListener(null);
268 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 }
Michael Kolb77df4562010-11-19 14:49:34 -0800270 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700271 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700272 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700273 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700274 if (web != null) {
275 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700276 web.setTitleBar(mTitleBar);
277 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700278 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700279 }
Michael Kolb4923c222012-04-02 16:18:36 -0700280 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700281 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700282 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800283 onTabDataChanged(tab);
284 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700285 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700286 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400287
Vivek Sekhar943f0672014-05-01 18:35:22 -0700288 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400289 }
290
291 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700292 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400293 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700294 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400295
Vivek Sekhar943f0672014-05-01 18:35:22 -0700296 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400297 //remove previously scehduled tab
298 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700299 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700300 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400301 removeTabFromContentView(mTabToRemove);
302 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700303 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400304 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700305 mTabToRemove = tabToRemove;
306 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400307 mNumRemoveTries = 0;
308
309 if (mTabToRemove != null) {
310 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312 }
313 }
314
315 protected void tryRemoveTab() {
316 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700317 // Ensure the webview is still valid
318 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
319 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700320 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700321 mRunnable = new Runnable() {
322 public void run() {
323 tryRemoveTab();
324 }
325 };
326 }
327 /*if the new tab is still not ready, wait another 2 frames
328 before trying again. 1 frame for the tab to render the first
329 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700330 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400331 return;
332 }
333 }
334 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700335 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700336 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400337 removeTabFromContentView(mTabToRemove);
338 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700339 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400340 }
341 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700342 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700343 }
344
John Reck718a24d2011-08-12 11:08:30 -0700345 protected void updateUrlBarAutoShowManagerTarget() {
346 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700347 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700348 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700349 }
350 }
351
Michael Kolbcfa3af52010-12-14 10:36:11 -0800352 Tab getActiveTab() {
353 return mActiveTab;
354 }
355
Michael Kolb8233fac2010-10-26 16:08:53 -0700356 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800357 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800358 }
359
360 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700361 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800362 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700363 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800364 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700365 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700366 }
367
368 @Override
369 public void detachTab(Tab tab) {
370 removeTabFromContentView(tab);
371 }
372
373 @Override
374 public void attachTab(Tab tab) {
375 attachTabToContentView(tab);
376 }
377
Michael Kolb377ea312011-02-17 14:36:56 -0800378 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800379 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 return;
381 }
382 View container = tab.getViewContainer();
383 WebView mainView = tab.getWebView();
384 // Attach the WebView to the container and then attach the
385 // container to the content view.
386 FrameLayout wrapper =
387 (FrameLayout) container.findViewById(R.id.webview_wrapper);
388 ViewGroup parent = (ViewGroup) mainView.getParent();
389 if (parent != wrapper) {
390 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700391 parent.removeView(mainView);
392 }
393 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700394 }
395 parent = (ViewGroup) container.getParent();
396 if (parent != mContentView) {
397 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700398 parent.removeView(container);
399 }
400 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700401 }
402 mUiController.attachSubWindow(tab);
403 }
404
405 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800406 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700407 // Remove the container that contains the main WebView.
408 WebView mainView = tab.getWebView();
409 View container = tab.getViewContainer();
410 if (mainView == null) {
411 return;
412 }
413 // Remove the container from the content and then remove the
414 // WebView from the container. This will trigger a focus change
415 // needed by WebView.
416 FrameLayout wrapper =
417 (FrameLayout) container.findViewById(R.id.webview_wrapper);
418 wrapper.removeView(mainView);
419 mContentView.removeView(container);
420 mUiController.endActionMode();
421 mUiController.removeSubWindow(tab);
422 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
423 if (errorConsole != null) {
424 mErrorConsoleContainer.removeView(errorConsole);
425 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427
Michael Kolba713ec82010-11-29 17:27:06 -0800428 @Override
429 public void onSetWebView(Tab tab, WebView webView) {
430 View container = tab.getViewContainer();
431 if (container == null) {
432 // The tab consists of a container view, which contains the main
433 // WebView, as well as any other UI elements associated with the tab.
434 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700435 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800436 tab.setViewContainer(container);
437 }
438 if (tab.getWebView() != webView) {
439 // Just remove the old one.
440 FrameLayout wrapper =
441 (FrameLayout) container.findViewById(R.id.webview_wrapper);
442 wrapper.removeView(tab.getWebView());
443 }
444 }
445
Michael Kolb8233fac2010-10-26 16:08:53 -0700446 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800447 * create a sub window container and webview for the tab
448 * Note: this methods operates through side-effects for now
449 * it sets both the subView and subViewContainer for the given tab
450 * @param tab tab to create the sub window for
451 * @param subView webview to be set as a subwindow for the tab
452 */
453 @Override
454 public void createSubWindow(Tab tab, WebView subView) {
455 View subViewContainer = mActivity.getLayoutInflater().inflate(
456 R.layout.browser_subwindow, null);
457 ViewGroup inner = (ViewGroup) subViewContainer
458 .findViewById(R.id.inner_container);
459 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
460 LayoutParams.MATCH_PARENT));
461 final ImageButton cancel = (ImageButton) subViewContainer
462 .findViewById(R.id.subwindow_close);
463 final WebView cancelSubView = subView;
464 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800465 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800466 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800467 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800468 }
469 });
470 tab.setSubWebView(subView);
471 tab.setSubViewContainer(subViewContainer);
472 }
473
474 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700475 * Remove the sub window from the content view.
476 */
477 @Override
478 public void removeSubWindow(View subviewContainer) {
479 mContentView.removeView(subviewContainer);
480 mUiController.endActionMode();
481 }
482
483 /**
484 * Attach the sub window to the content view.
485 */
486 @Override
487 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800488 if (container.getParent() != null) {
489 // already attached, remove first
490 ((ViewGroup) container.getParent()).removeView(container);
491 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700492 mContentView.addView(container, COVER_SCREEN_PARAMS);
493 }
494
Michael Kolb11d19782011-03-20 10:17:40 -0700495 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700496 WebView web = getWebView();
497 if (web != null) {
498 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700499 }
500 }
501
Michael Kolb1f9b3562012-04-24 14:38:34 -0700502 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700503 if (mUiController.isInCustomActionMode()) {
504 mUiController.endActionMode();
505 }
506 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700507 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700508 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700509 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700510 }
511
Michael Kolb7cdc4902011-02-03 17:54:40 -0800512 boolean canShowTitleBar() {
513 return !isTitleBarShowing()
514 && !isActivityPaused()
515 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700516 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800517 && !mUiController.isInCustomActionMode();
518 }
519
John Reck0f602f32011-07-07 15:38:43 -0700520 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700521 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700522 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700523 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700524 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800525 }
526
527 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700528 if (mTitleBar.isShowing()) {
529 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700530 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800531 }
532
533 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700534 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800535 }
536
John Reck5d43ce82011-06-21 17:16:51 -0700537 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700538 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700539 }
540
Michael Kolb80f75082012-04-10 10:50:06 -0700541 public void stopEditingUrl() {
542 mTitleBar.getNavigationBar().stopEditingUrl();
543 }
544
John Reck0f602f32011-07-07 15:38:43 -0700545 public TitleBar getTitleBar() {
546 return mTitleBar;
547 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800548
Michael Kolb66706532010-12-12 19:50:22 -0800549 @Override
John Reck2bc80422011-06-30 15:11:49 -0700550 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700551 Intent intent = new Intent(mActivity, ComboViewActivity.class);
552 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
553 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
554 Tab t = getActiveTab();
555 if (t != null) {
556 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800557 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700558 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700559 }
560
561 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400562 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800563 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700564 // if a view already exists then immediately terminate the new one
565 if (mCustomView != null) {
566 callback.onCustomViewHidden();
567 return;
568 }
569
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400570 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700571 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
572 mFullscreenContainer = new FullscreenHolder(mActivity);
573 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
574 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
575 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700576 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700577 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700578 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400579 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 }
581
582 @Override
583 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700584 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700585 if (mCustomView == null)
586 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700587 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700588 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
589 decor.removeView(mFullscreenContainer);
590 mFullscreenContainer = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700591 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700592 mCustomViewCallback.onCustomViewHidden();
593 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400594 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700595 }
596
597 @Override
598 public boolean isCustomViewShowing() {
599 return mCustomView != null;
600 }
601
Michael Kolb66706532010-12-12 19:50:22 -0800602 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800603 if (mInputManager.isActive()) {
604 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
605 0);
606 }
607 }
608
Michael Kolb66706532010-12-12 19:50:22 -0800609 @Override
John Reck3ba45532011-08-11 16:26:53 -0700610 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700611 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800612 }
613
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 // -------------------------------------------------------------------------
615
Michael Kolb5a72f182011-01-13 20:35:06 -0800616 protected void updateNavigationState(Tab tab) {
617 }
618
Michael Kolb8233fac2010-10-26 16:08:53 -0700619 /**
620 * Update the lock icon to correspond to our latest state.
621 */
Michael Kolb66706532010-12-12 19:50:22 -0800622 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800623 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100624 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 }
626 }
627
628 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700629 * Updates the lock-icon image in the title-bar.
630 */
Steve Block2466eff2011-10-03 15:33:09 +0100631 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700632 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100633 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
634 d = mLockIconSecure;
Steve Block4895b012011-10-03 16:26:46 +0100635 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
636 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
637 // TODO: It would be good to have different icons for insecure vs mixed content.
638 // See http://b/5403800
Steve Block2466eff2011-10-03 15:33:09 +0100639 d = mLockIconMixed;
Michael Kolb8233fac2010-10-26 16:08:53 -0700640 }
John Reck0f602f32011-07-07 15:38:43 -0700641 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 }
643
John Reck30c714c2010-12-16 17:30:34 -0800644 protected void setUrlTitle(Tab tab) {
645 String url = tab.getUrl();
646 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800647 if (TextUtils.isEmpty(title)) {
648 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800649 }
Michael Kolb66706532010-12-12 19:50:22 -0800650 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700651 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800652 }
653 }
654
655 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800656 protected void setFavicon(Tab tab) {
657 if (tab.inForeground()) {
658 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700659 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800660 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 }
662
Michael Kolb66706532010-12-12 19:50:22 -0800663 // active tabs page
664
665 public void showActiveTabsPage() {
666 }
667
668 /**
669 * Remove the active tabs page.
670 */
671 public void removeActiveTabsPage() {
672 }
673
Michael Kolb8233fac2010-10-26 16:08:53 -0700674 // menu handling callbacks
675
676 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800677 public boolean onPrepareOptionsMenu(Menu menu) {
678 return true;
679 }
680
681 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700682 public void updateMenuState(Tab tab, Menu menu) {
683 }
684
685 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700687 }
688
689 @Override
690 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700691 }
692
693 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700694 public boolean onOptionsItemSelected(MenuItem item) {
695 return false;
696 }
697
698 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 }
701
702 @Override
703 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 }
705
706 @Override
707 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700708 }
709
710 @Override
711 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 }
713
714 // error console
715
716 @Override
717 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800718 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700719 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
720 if (flag) {
721 // Setting the show state of the console will cause it's the layout
722 // to be inflated.
723 if (errorConsole.numberOfErrors() > 0) {
724 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
725 } else {
726 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
727 }
728 if (errorConsole.getParent() != null) {
729 mErrorConsoleContainer.removeView(errorConsole);
730 }
731 // Now we can add it to the main view.
732 mErrorConsoleContainer.addView(errorConsole,
733 new LinearLayout.LayoutParams(
734 ViewGroup.LayoutParams.MATCH_PARENT,
735 ViewGroup.LayoutParams.WRAP_CONTENT));
736 } else {
737 mErrorConsoleContainer.removeView(errorConsole);
738 }
739 }
740
Michael Kolb8233fac2010-10-26 16:08:53 -0700741 // -------------------------------------------------------------------------
742 // Helper function for WebChromeClient
743 // -------------------------------------------------------------------------
744
745 @Override
746 public Bitmap getDefaultVideoPoster() {
747 if (mDefaultVideoPoster == null) {
748 mDefaultVideoPoster = BitmapFactory.decodeResource(
749 mActivity.getResources(), R.drawable.default_video_poster);
750 }
751 return mDefaultVideoPoster;
752 }
753
754 @Override
755 public View getVideoLoadingProgressView() {
756 if (mVideoProgressView == null) {
757 LayoutInflater inflater = LayoutInflater.from(mActivity);
758 mVideoProgressView = inflater.inflate(
759 R.layout.video_loading_progress, null);
760 }
761 return mVideoProgressView;
762 }
763
Michael Kolb843510f2010-12-09 10:51:49 -0800764 @Override
765 public void showMaxTabsWarning() {
766 Toast warning = Toast.makeText(mActivity,
767 mActivity.getString(R.string.max_tabs_warning),
768 Toast.LENGTH_SHORT);
769 warning.show();
770 }
771
Michael Kolb46f987e2011-04-05 10:39:10 -0700772 protected WebView getWebView() {
773 if (mActiveTab != null) {
774 return mActiveTab.getWebView();
775 } else {
776 return null;
777 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700778 }
779
Michael Kolbc38c6042011-04-27 10:46:06 -0700780 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700781 Window win = mActivity.getWindow();
782 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800783 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700784 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700785 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700786 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700787 winParams.flags &= ~bits;
788 if (mCustomView != null) {
789 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
790 } else {
791 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
792 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700793 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700794 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700795 }
796
Tarun Nainani8eb00912014-07-17 12:28:32 -0700797 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700798 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700799 mTitleBar.bringToFront();
800 if (topControlsOffsetYPix != 0.0) {
801 mTitleBar.setEnabled(false);
802 } else {
803 mTitleBar.setEnabled(true);
804 }
Tarun Nainani8eb00912014-07-17 12:28:32 -0700805
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700806 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700807 }
808 }
809
John Reck0f602f32011-07-07 15:38:43 -0700810 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700811 Drawable[] array = new Drawable[3];
812 array[0] = new PaintDrawable(Color.BLACK);
813 PaintDrawable p = new PaintDrawable(Color.WHITE);
814 array[1] = p;
815 if (icon == null) {
816 array[2] = mGenericFavicon;
817 } else {
818 array[2] = new BitmapDrawable(icon);
819 }
820 LayerDrawable d = new LayerDrawable(array);
821 d.setLayerInset(1, 1, 1, 1, 1);
822 d.setLayerInset(2, 2, 2, 2, 2);
823 return d;
824 }
825
John Reck5d43ce82011-06-21 17:16:51 -0700826 public boolean isLoading() {
827 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
828 }
829
830 /**
831 * Suggest to the UI that the title bar can be hidden. The UI will then
832 * decide whether or not to hide based off a number of factors, such
833 * as if the user is editing the URL bar or if the page is loading
834 */
835 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700836 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
837 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700838 hideTitleBar();
839 }
840 }
841
John Reckbc6adb42011-09-01 18:03:20 -0700842 protected final void showTitleBarForDuration() {
843 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
844 }
845
846 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700847 showTitleBar();
848 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700849 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700850 }
851
John Reck9c5004e2011-10-07 16:00:12 -0700852 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700853
854 @Override
855 public void handleMessage(Message msg) {
856 if (msg.what == MSG_HIDE_TITLEBAR) {
857 suggestHideTitleBar();
858 }
John Reck9c5004e2011-10-07 16:00:12 -0700859 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700860 }
861 };
John Reck3ba45532011-08-11 16:26:53 -0700862
John Reck9c5004e2011-10-07 16:00:12 -0700863 protected void handleMessage(Message msg) {}
864
John Reck3ba45532011-08-11 16:26:53 -0700865 @Override
866 public void showWeb(boolean animate) {
867 mUiController.hideCustomView();
868 }
869
Michael Kolb31065b12011-10-06 13:51:32 -0700870 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700871
Michael Kolb31065b12011-10-06 13:51:32 -0700872 public FullscreenHolder(Context ctx) {
873 super(ctx);
874 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700875 }
876
Michael Kolb31065b12011-10-06 13:51:32 -0700877 @Override
878 public boolean onTouchEvent(MotionEvent evt) {
879 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700880 }
Michael Kolb31065b12011-10-06 13:51:32 -0700881
Michael Kolb53ed62c2011-10-04 16:18:44 -0700882 }
John Reck2711fab2012-05-18 21:38:59 -0700883
884 public void addFixedTitleBar(View view) {
885 mFixedTitlebarContainer.addView(view);
886 }
887
888 public void setContentViewMarginTop(int margin) {
889 LinearLayout.LayoutParams params =
890 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
891 if (params.topMargin != margin) {
892 params.topMargin = margin;
893 mContentView.setLayoutParams(params);
894 }
895 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700896
897 @Override
898 public boolean blockFocusAnimations() {
899 return mBlockFocusAnimations;
900 }
901
Michael Kolb0b129122012-06-04 16:31:58 -0700902 @Override
903 public void onVoiceResult(String result) {
904 mNavigationBar.onVoiceResult(result);
905 }
906
kaiyizbb2db872013-08-01 22:24:07 -0400907 protected UiController getUiController() {
908 return mUiController;
909 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700910
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700911 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700912 private float getActionModeHeight() {
913 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
914 new int[] { android.R.attr.actionBarSize });
915 float size = actionBarSizeTypedArray.getDimension(0, 0f);
916 actionBarSizeTypedArray.recycle();
917 return size;
918 }
919
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700920
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700921 @Override
922 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700923 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700924
925 if (mTitleBar.isFixed()) {
926 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700927 mFixedTitlebarContainer.setY(fixedTbarHeight);
928 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700929 } else {
930 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700931 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700932 }
933
934 @Override
935 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700936 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700937 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700938 mFixedTitlebarContainer.setY(0);
939 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700940 } else {
941 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700942 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700943 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700944}