blob: 27b2b829610cf12954892549974b7b5310f2ef9e [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;
53
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;
196 }
197 return false;
198 }
199
Michael Kolb2814a362011-05-19 15:49:41 -0700200 @Override
201 public boolean onMenuKey() {
202 return false;
203 }
204
Michael Kolbda580632012-04-16 13:30:28 -0700205 @Override
206 public void setUseQuickControls(boolean useQuickControls) {
207 mUseQuickControls = useQuickControls;
208 mTitleBar.setUseQuickControls(mUseQuickControls);
209 if (useQuickControls) {
210 mPieControl = new PieControl(mActivity, mUiController, this);
211 mPieControl.attachToContainer(mContentView);
212 } else {
213 if (mPieControl != null) {
214 mPieControl.removeFromContainer(mContentView);
215 }
216 }
217 updateUrlBarAutoShowManagerTarget();
218 }
219
John Reck30c714c2010-12-16 17:30:34 -0800220 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 @Override
John Reck30c714c2010-12-16 17:30:34 -0800222 public void onTabDataChanged(Tab tab) {
223 setUrlTitle(tab);
224 setFavicon(tab);
225 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800226 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700227 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700228 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700229 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700230 }
231
232 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700233 public void onProgressChanged(Tab tab) {
234 int progress = tab.getLoadProgress();
235 if (tab.inForeground()) {
236 mTitleBar.setProgress(progress);
237 }
238 }
239
240 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500241 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800242 if (tab.inForeground()) {
243 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700244 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800245 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500246 }
247
248 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 public void onPageStopped(Tab tab) {
250 cancelStopToast();
251 if (tab.inForeground()) {
252 mStopToast = Toast
253 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
254 mStopToast.show();
255 }
256 }
257
258 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800259 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700260 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800261 }
262
263 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700264 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 }
266
267 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800268 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800269 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400270 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700271 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400272
Michael Kolbbae0cb22012-05-29 11:15:27 -0700273 // block unnecessary focus change animations during tab switch
274 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700275 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800276 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400277 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700278 WebView web = mActiveTab.getWebView();
279 if (web != null) {
280 web.setOnTouchListener(null);
281 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700282 }
Michael Kolb77df4562010-11-19 14:49:34 -0800283 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700284 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700285 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700286 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700287 if (web != null) {
288 // Request focus on the top window.
289 if (mUseQuickControls) {
290 mPieControl.forceToTop(mContentView);
291 web.setTitleBar(null);
Michael Kolbe8a82332012-04-25 14:14:26 -0700292 mTitleBar.hide();
Michael Kolbda580632012-04-16 13:30:28 -0700293 } else {
294 web.setTitleBar(mTitleBar);
295 mTitleBar.onScrollChanged();
296 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700297 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700298 }
Michael Kolb4923c222012-04-02 16:18:36 -0700299 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700300 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700301 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800302 onTabDataChanged(tab);
303 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700304 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700305 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400306
Vivek Sekhar943f0672014-05-01 18:35:22 -0700307 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400308 }
309
310 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700313 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400314
Vivek Sekhar943f0672014-05-01 18:35:22 -0700315 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400316 //remove previously scehduled tab
317 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700318 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700319 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400320 removeTabFromContentView(mTabToRemove);
321 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700322 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400323 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700324 mTabToRemove = tabToRemove;
325 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400326 mNumRemoveTries = 0;
327
328 if (mTabToRemove != null) {
329 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700330 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400331 }
332 }
333
334 protected void tryRemoveTab() {
335 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 // Ensure the webview is still valid
337 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
338 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700339 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700340 mRunnable = new Runnable() {
341 public void run() {
342 tryRemoveTab();
343 }
344 };
345 }
346 /*if the new tab is still not ready, wait another 2 frames
347 before trying again. 1 frame for the tab to render the first
348 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700349 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400350 return;
351 }
352 }
353 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700355 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400356 removeTabFromContentView(mTabToRemove);
357 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700358 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400359 }
360 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700361 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700362 }
363
John Reck718a24d2011-08-12 11:08:30 -0700364 protected void updateUrlBarAutoShowManagerTarget() {
365 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
366 if (!mUseQuickControls && web instanceof BrowserWebView) {
367 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
368 } else {
369 mUrlBarAutoShowManager.setTarget(null);
370 }
371 }
372
Michael Kolbcfa3af52010-12-14 10:36:11 -0800373 Tab getActiveTab() {
374 return mActiveTab;
375 }
376
Michael Kolb8233fac2010-10-26 16:08:53 -0700377 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800378 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800379 }
380
381 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800383 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700384 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800385 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700386 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700387 }
388
389 @Override
390 public void detachTab(Tab tab) {
391 removeTabFromContentView(tab);
392 }
393
394 @Override
395 public void attachTab(Tab tab) {
396 attachTabToContentView(tab);
397 }
398
Michael Kolb377ea312011-02-17 14:36:56 -0800399 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800400 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700401 return;
402 }
403 View container = tab.getViewContainer();
404 WebView mainView = tab.getWebView();
405 // Attach the WebView to the container and then attach the
406 // container to the content view.
407 FrameLayout wrapper =
408 (FrameLayout) container.findViewById(R.id.webview_wrapper);
409 ViewGroup parent = (ViewGroup) mainView.getParent();
410 if (parent != wrapper) {
411 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700412 parent.removeView(mainView);
413 }
414 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700415 }
416 parent = (ViewGroup) container.getParent();
417 if (parent != mContentView) {
418 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700419 parent.removeView(container);
420 }
421 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700422 }
423 mUiController.attachSubWindow(tab);
424 }
425
426 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800427 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 // Remove the container that contains the main WebView.
429 WebView mainView = tab.getWebView();
430 View container = tab.getViewContainer();
431 if (mainView == null) {
432 return;
433 }
434 // Remove the container from the content and then remove the
435 // WebView from the container. This will trigger a focus change
436 // needed by WebView.
437 FrameLayout wrapper =
438 (FrameLayout) container.findViewById(R.id.webview_wrapper);
439 wrapper.removeView(mainView);
440 mContentView.removeView(container);
441 mUiController.endActionMode();
442 mUiController.removeSubWindow(tab);
443 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
444 if (errorConsole != null) {
445 mErrorConsoleContainer.removeView(errorConsole);
446 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700447 }
448
Michael Kolba713ec82010-11-29 17:27:06 -0800449 @Override
450 public void onSetWebView(Tab tab, WebView webView) {
451 View container = tab.getViewContainer();
452 if (container == null) {
453 // The tab consists of a container view, which contains the main
454 // WebView, as well as any other UI elements associated with the tab.
455 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700456 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800457 tab.setViewContainer(container);
458 }
459 if (tab.getWebView() != webView) {
460 // Just remove the old one.
461 FrameLayout wrapper =
462 (FrameLayout) container.findViewById(R.id.webview_wrapper);
463 wrapper.removeView(tab.getWebView());
464 }
465 }
466
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800468 * create a sub window container and webview for the tab
469 * Note: this methods operates through side-effects for now
470 * it sets both the subView and subViewContainer for the given tab
471 * @param tab tab to create the sub window for
472 * @param subView webview to be set as a subwindow for the tab
473 */
474 @Override
475 public void createSubWindow(Tab tab, WebView subView) {
476 View subViewContainer = mActivity.getLayoutInflater().inflate(
477 R.layout.browser_subwindow, null);
478 ViewGroup inner = (ViewGroup) subViewContainer
479 .findViewById(R.id.inner_container);
480 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
481 LayoutParams.MATCH_PARENT));
482 final ImageButton cancel = (ImageButton) subViewContainer
483 .findViewById(R.id.subwindow_close);
484 final WebView cancelSubView = subView;
485 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800486 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800487 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800488 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800489 }
490 });
491 tab.setSubWebView(subView);
492 tab.setSubViewContainer(subViewContainer);
493 }
494
495 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700496 * Remove the sub window from the content view.
497 */
498 @Override
499 public void removeSubWindow(View subviewContainer) {
500 mContentView.removeView(subviewContainer);
501 mUiController.endActionMode();
502 }
503
504 /**
505 * Attach the sub window to the content view.
506 */
507 @Override
508 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800509 if (container.getParent() != null) {
510 // already attached, remove first
511 ((ViewGroup) container.getParent()).removeView(container);
512 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700513 mContentView.addView(container, COVER_SCREEN_PARAMS);
514 }
515
Michael Kolb11d19782011-03-20 10:17:40 -0700516 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700517 WebView web = getWebView();
518 if (web != null) {
519 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700520 }
521 }
522
Michael Kolb1f9b3562012-04-24 14:38:34 -0700523 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700524 if (mUiController.isInCustomActionMode()) {
525 mUiController.endActionMode();
526 }
527 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700528 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700529 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700530 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700531 }
532
Michael Kolb7cdc4902011-02-03 17:54:40 -0800533 boolean canShowTitleBar() {
534 return !isTitleBarShowing()
535 && !isActivityPaused()
536 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700537 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800538 && !mUiController.isInCustomActionMode();
539 }
540
John Reck0f602f32011-07-07 15:38:43 -0700541 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700542 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700543 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700544 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700545 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800546 }
547
548 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700549 if (mTitleBar.isShowing()) {
550 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700551 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800552 }
553
554 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700555 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800556 }
557
John Reck5d43ce82011-06-21 17:16:51 -0700558 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700559 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700560 }
561
Michael Kolb80f75082012-04-10 10:50:06 -0700562 public void stopEditingUrl() {
563 mTitleBar.getNavigationBar().stopEditingUrl();
564 }
565
John Reck0f602f32011-07-07 15:38:43 -0700566 public TitleBar getTitleBar() {
567 return mTitleBar;
568 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800569
Michael Kolb66706532010-12-12 19:50:22 -0800570 @Override
John Reck2bc80422011-06-30 15:11:49 -0700571 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700572 Intent intent = new Intent(mActivity, ComboViewActivity.class);
573 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
574 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
575 Tab t = getActiveTab();
576 if (t != null) {
577 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800578 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700579 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 }
581
582 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400583 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800584 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700585 // if a view already exists then immediately terminate the new one
586 if (mCustomView != null) {
587 callback.onCustomViewHidden();
588 return;
589 }
590
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400591 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700592 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
593 mFullscreenContainer = new FullscreenHolder(mActivity);
594 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
595 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
596 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700597 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700598 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700599 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400600 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 }
602
603 @Override
604 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700605 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 if (mCustomView == null)
607 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700608 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700609 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
610 decor.removeView(mFullscreenContainer);
611 mFullscreenContainer = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700613 mCustomViewCallback.onCustomViewHidden();
614 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400615 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 }
617
618 @Override
619 public boolean isCustomViewShowing() {
620 return mCustomView != null;
621 }
622
Michael Kolb66706532010-12-12 19:50:22 -0800623 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800624 if (mInputManager.isActive()) {
625 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
626 0);
627 }
628 }
629
Michael Kolb66706532010-12-12 19:50:22 -0800630 @Override
John Reck3ba45532011-08-11 16:26:53 -0700631 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700632 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800633 }
634
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 // -------------------------------------------------------------------------
636
Michael Kolb5a72f182011-01-13 20:35:06 -0800637 protected void updateNavigationState(Tab tab) {
638 }
639
Michael Kolb8233fac2010-10-26 16:08:53 -0700640 /**
641 * Update the lock icon to correspond to our latest state.
642 */
Michael Kolb66706532010-12-12 19:50:22 -0800643 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800644 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100645 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700646 }
647 }
648
649 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700650 * Updates the lock-icon image in the title-bar.
651 */
Steve Block2466eff2011-10-03 15:33:09 +0100652 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700653 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100654 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
655 d = mLockIconSecure;
Steve Block4895b012011-10-03 16:26:46 +0100656 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
657 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
658 // TODO: It would be good to have different icons for insecure vs mixed content.
659 // See http://b/5403800
Steve Block2466eff2011-10-03 15:33:09 +0100660 d = mLockIconMixed;
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 }
John Reck0f602f32011-07-07 15:38:43 -0700662 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 }
664
John Reck30c714c2010-12-16 17:30:34 -0800665 protected void setUrlTitle(Tab tab) {
666 String url = tab.getUrl();
667 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800668 if (TextUtils.isEmpty(title)) {
669 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800670 }
Michael Kolb66706532010-12-12 19:50:22 -0800671 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700672 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800673 }
674 }
675
676 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800677 protected void setFavicon(Tab tab) {
678 if (tab.inForeground()) {
679 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700680 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800681 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700682 }
683
Michael Kolb66706532010-12-12 19:50:22 -0800684 // active tabs page
685
686 public void showActiveTabsPage() {
687 }
688
689 /**
690 * Remove the active tabs page.
691 */
692 public void removeActiveTabsPage() {
693 }
694
Michael Kolb8233fac2010-10-26 16:08:53 -0700695 // menu handling callbacks
696
697 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800698 public boolean onPrepareOptionsMenu(Menu menu) {
699 return true;
700 }
701
702 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700703 public void updateMenuState(Tab tab, Menu menu) {
704 }
705
706 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700707 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700708 }
709
710 @Override
711 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 }
713
714 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700715 public boolean onOptionsItemSelected(MenuItem item) {
716 return false;
717 }
718
719 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700720 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700721 }
722
723 @Override
724 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 }
726
727 @Override
728 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700729 }
730
731 @Override
732 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700733 }
734
735 // error console
736
737 @Override
738 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800739 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700740 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
741 if (flag) {
742 // Setting the show state of the console will cause it's the layout
743 // to be inflated.
744 if (errorConsole.numberOfErrors() > 0) {
745 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
746 } else {
747 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
748 }
749 if (errorConsole.getParent() != null) {
750 mErrorConsoleContainer.removeView(errorConsole);
751 }
752 // Now we can add it to the main view.
753 mErrorConsoleContainer.addView(errorConsole,
754 new LinearLayout.LayoutParams(
755 ViewGroup.LayoutParams.MATCH_PARENT,
756 ViewGroup.LayoutParams.WRAP_CONTENT));
757 } else {
758 mErrorConsoleContainer.removeView(errorConsole);
759 }
760 }
761
Michael Kolb8233fac2010-10-26 16:08:53 -0700762 // -------------------------------------------------------------------------
763 // Helper function for WebChromeClient
764 // -------------------------------------------------------------------------
765
766 @Override
767 public Bitmap getDefaultVideoPoster() {
768 if (mDefaultVideoPoster == null) {
769 mDefaultVideoPoster = BitmapFactory.decodeResource(
770 mActivity.getResources(), R.drawable.default_video_poster);
771 }
772 return mDefaultVideoPoster;
773 }
774
775 @Override
776 public View getVideoLoadingProgressView() {
777 if (mVideoProgressView == null) {
778 LayoutInflater inflater = LayoutInflater.from(mActivity);
779 mVideoProgressView = inflater.inflate(
780 R.layout.video_loading_progress, null);
781 }
782 return mVideoProgressView;
783 }
784
Michael Kolb843510f2010-12-09 10:51:49 -0800785 @Override
786 public void showMaxTabsWarning() {
787 Toast warning = Toast.makeText(mActivity,
788 mActivity.getString(R.string.max_tabs_warning),
789 Toast.LENGTH_SHORT);
790 warning.show();
791 }
792
Michael Kolb46f987e2011-04-05 10:39:10 -0700793 protected WebView getWebView() {
794 if (mActiveTab != null) {
795 return mActiveTab.getWebView();
796 } else {
797 return null;
798 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700799 }
800
Michael Kolbc38c6042011-04-27 10:46:06 -0700801 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700802 Window win = mActivity.getWindow();
803 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800804 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700805 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700806 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700807 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700808 winParams.flags &= ~bits;
809 if (mCustomView != null) {
810 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
811 } else {
812 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
813 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700814 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700815 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700816 }
817
John Reck0f602f32011-07-07 15:38:43 -0700818 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700819 Drawable[] array = new Drawable[3];
820 array[0] = new PaintDrawable(Color.BLACK);
821 PaintDrawable p = new PaintDrawable(Color.WHITE);
822 array[1] = p;
823 if (icon == null) {
824 array[2] = mGenericFavicon;
825 } else {
826 array[2] = new BitmapDrawable(icon);
827 }
828 LayerDrawable d = new LayerDrawable(array);
829 d.setLayerInset(1, 1, 1, 1, 1);
830 d.setLayerInset(2, 2, 2, 2, 2);
831 return d;
832 }
833
John Reck5d43ce82011-06-21 17:16:51 -0700834 public boolean isLoading() {
835 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
836 }
837
838 /**
839 * Suggest to the UI that the title bar can be hidden. The UI will then
840 * decide whether or not to hide based off a number of factors, such
841 * as if the user is editing the URL bar or if the page is loading
842 */
843 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700844 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
845 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700846 hideTitleBar();
847 }
848 }
849
John Reckbc6adb42011-09-01 18:03:20 -0700850 protected final void showTitleBarForDuration() {
851 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
852 }
853
854 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700855 showTitleBar();
856 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700857 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700858 }
859
John Reck9c5004e2011-10-07 16:00:12 -0700860 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700861
862 @Override
863 public void handleMessage(Message msg) {
864 if (msg.what == MSG_HIDE_TITLEBAR) {
865 suggestHideTitleBar();
866 }
John Reck9c5004e2011-10-07 16:00:12 -0700867 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700868 }
869 };
John Reck3ba45532011-08-11 16:26:53 -0700870
John Reck9c5004e2011-10-07 16:00:12 -0700871 protected void handleMessage(Message msg) {}
872
John Reck3ba45532011-08-11 16:26:53 -0700873 @Override
874 public void showWeb(boolean animate) {
875 mUiController.hideCustomView();
876 }
877
Michael Kolb31065b12011-10-06 13:51:32 -0700878 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700879
Michael Kolb31065b12011-10-06 13:51:32 -0700880 public FullscreenHolder(Context ctx) {
881 super(ctx);
882 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700883 }
884
Michael Kolb31065b12011-10-06 13:51:32 -0700885 @Override
886 public boolean onTouchEvent(MotionEvent evt) {
887 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700888 }
Michael Kolb31065b12011-10-06 13:51:32 -0700889
Michael Kolb53ed62c2011-10-04 16:18:44 -0700890 }
John Reck2711fab2012-05-18 21:38:59 -0700891
892 public void addFixedTitleBar(View view) {
893 mFixedTitlebarContainer.addView(view);
894 }
895
896 public void setContentViewMarginTop(int margin) {
897 LinearLayout.LayoutParams params =
898 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
899 if (params.topMargin != margin) {
900 params.topMargin = margin;
901 mContentView.setLayoutParams(params);
902 }
903 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700904
905 @Override
906 public boolean blockFocusAnimations() {
907 return mBlockFocusAnimations;
908 }
909
Michael Kolb0b129122012-06-04 16:31:58 -0700910 @Override
911 public void onVoiceResult(String result) {
912 mNavigationBar.onVoiceResult(result);
913 }
914
kaiyizbb2db872013-08-01 22:24:07 -0400915 protected UiController getUiController() {
916 return mUiController;
917 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700918
919 @Override
920 public void onActionModeStarted(ActionMode mode) {
921 int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0;
922 mFixedTitlebarContainer.setY(fixedTbarHeight);
923 setContentViewMarginTop(fixedTbarHeight);
924 }
925
926 @Override
927 public void onActionModeFinished(boolean inLoad) {
928 mFixedTitlebarContainer.setY(0);
929 setContentViewMarginTop(0);
930 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700931}