blob: 45bd65662b1bec788e8bd3cf96917fb52e92ea22 [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;
271 BrowserWebView webViewToWaitFor = null;
272
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 }
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400297 webViewToWaitFor = web;
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
307 scheduleRemoveTab(tabToRemove, webViewToWaitFor);
308 }
309
310 Tab mTabToRemove = null;
311 BrowserWebView mWebViewToWaitFor = null;
312 int mNumRemoveTries = 0;
313
314 protected void scheduleRemoveTab(Tab tab, BrowserWebView webview) {
315 //remove previously scehduled tab
316 if (mTabToRemove != null) {
317 removeTabFromContentView(mTabToRemove);
318 mTabToRemove.performPostponedDestroy();
319 }
320 mTabToRemove = tab;
321 mWebViewToWaitFor = webview;
322 mNumRemoveTries = 0;
323
324 if (mTabToRemove != null) {
325 mTabToRemove.postponeDestroy();
326 android.os.Handler handler = mTitleBar.getHandler();
327 handler.postDelayed(new Runnable() {
328 public void run() {
329 tryRemoveTab();
330 }
331 }, 33); /*we know at this point for sure that the new tab is not ready
332 since it's just getting created. It'll be at least 1 frame's
333 time that the new tab will painting something, and another 1
334 frame's time that we're sure the swap is done. It is possible
335 that the swap is finish right the way, but unless use use EGL
336 fence we can never be sure. So wait for 2 frames before trying
337 to remove the tab. It is possible that the tab is still not
338 ready after 2 frames, but this is good enough.*/
339 }
340 }
341
342 protected void tryRemoveTab() {
343 mNumRemoveTries++;
344 if (mNumRemoveTries < 20 && mWebViewToWaitFor != null) {
345 if (!mWebViewToWaitFor.isReady()) {
346 android.os.Handler handler = mTitleBar.getHandler();
347 handler.postDelayed(new Runnable() {
348 public void run() {
349 tryRemoveTab();
350 }
351 }, 33); /*if the new tab is still not ready, wait another 2 frames
352 before trying again. 1 frame for the tab to render the first
353 frame, another 1 frame to make sure the swap is done*/
354 return;
355 }
356 }
357 if (mTabToRemove != null) {
358 removeTabFromContentView(mTabToRemove);
359 mTabToRemove.performPostponedDestroy();
360 }
361 mTabToRemove = null;
362 mWebViewToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700363 }
364
John Reck718a24d2011-08-12 11:08:30 -0700365 protected void updateUrlBarAutoShowManagerTarget() {
366 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
367 if (!mUseQuickControls && web instanceof BrowserWebView) {
368 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
369 } else {
370 mUrlBarAutoShowManager.setTarget(null);
371 }
372 }
373
Michael Kolbcfa3af52010-12-14 10:36:11 -0800374 Tab getActiveTab() {
375 return mActiveTab;
376 }
377
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800379 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800380 }
381
382 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700383 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800384 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700385 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800386 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700387 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700388 }
389
390 @Override
391 public void detachTab(Tab tab) {
392 removeTabFromContentView(tab);
393 }
394
395 @Override
396 public void attachTab(Tab tab) {
397 attachTabToContentView(tab);
398 }
399
Michael Kolb377ea312011-02-17 14:36:56 -0800400 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800401 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 return;
403 }
404 View container = tab.getViewContainer();
405 WebView mainView = tab.getWebView();
406 // Attach the WebView to the container and then attach the
407 // container to the content view.
408 FrameLayout wrapper =
409 (FrameLayout) container.findViewById(R.id.webview_wrapper);
410 ViewGroup parent = (ViewGroup) mainView.getParent();
411 if (parent != wrapper) {
412 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700413 parent.removeView(mainView);
414 }
415 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 }
417 parent = (ViewGroup) container.getParent();
418 if (parent != mContentView) {
419 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700420 parent.removeView(container);
421 }
422 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700423 }
424 mUiController.attachSubWindow(tab);
425 }
426
427 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800428 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700429 // Remove the container that contains the main WebView.
430 WebView mainView = tab.getWebView();
431 View container = tab.getViewContainer();
432 if (mainView == null) {
433 return;
434 }
435 // Remove the container from the content and then remove the
436 // WebView from the container. This will trigger a focus change
437 // needed by WebView.
438 FrameLayout wrapper =
439 (FrameLayout) container.findViewById(R.id.webview_wrapper);
440 wrapper.removeView(mainView);
441 mContentView.removeView(container);
442 mUiController.endActionMode();
443 mUiController.removeSubWindow(tab);
444 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
445 if (errorConsole != null) {
446 mErrorConsoleContainer.removeView(errorConsole);
447 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700448 }
449
Michael Kolba713ec82010-11-29 17:27:06 -0800450 @Override
451 public void onSetWebView(Tab tab, WebView webView) {
452 View container = tab.getViewContainer();
453 if (container == null) {
454 // The tab consists of a container view, which contains the main
455 // WebView, as well as any other UI elements associated with the tab.
456 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700457 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800458 tab.setViewContainer(container);
459 }
460 if (tab.getWebView() != webView) {
461 // Just remove the old one.
462 FrameLayout wrapper =
463 (FrameLayout) container.findViewById(R.id.webview_wrapper);
464 wrapper.removeView(tab.getWebView());
465 }
466 }
467
Michael Kolb8233fac2010-10-26 16:08:53 -0700468 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800469 * create a sub window container and webview for the tab
470 * Note: this methods operates through side-effects for now
471 * it sets both the subView and subViewContainer for the given tab
472 * @param tab tab to create the sub window for
473 * @param subView webview to be set as a subwindow for the tab
474 */
475 @Override
476 public void createSubWindow(Tab tab, WebView subView) {
477 View subViewContainer = mActivity.getLayoutInflater().inflate(
478 R.layout.browser_subwindow, null);
479 ViewGroup inner = (ViewGroup) subViewContainer
480 .findViewById(R.id.inner_container);
481 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
482 LayoutParams.MATCH_PARENT));
483 final ImageButton cancel = (ImageButton) subViewContainer
484 .findViewById(R.id.subwindow_close);
485 final WebView cancelSubView = subView;
486 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800487 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800488 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800489 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800490 }
491 });
492 tab.setSubWebView(subView);
493 tab.setSubViewContainer(subViewContainer);
494 }
495
496 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700497 * Remove the sub window from the content view.
498 */
499 @Override
500 public void removeSubWindow(View subviewContainer) {
501 mContentView.removeView(subviewContainer);
502 mUiController.endActionMode();
503 }
504
505 /**
506 * Attach the sub window to the content view.
507 */
508 @Override
509 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800510 if (container.getParent() != null) {
511 // already attached, remove first
512 ((ViewGroup) container.getParent()).removeView(container);
513 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700514 mContentView.addView(container, COVER_SCREEN_PARAMS);
515 }
516
Michael Kolb11d19782011-03-20 10:17:40 -0700517 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700518 WebView web = getWebView();
519 if (web != null) {
520 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700521 }
522 }
523
Michael Kolb1f9b3562012-04-24 14:38:34 -0700524 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700525 if (mUiController.isInCustomActionMode()) {
526 mUiController.endActionMode();
527 }
528 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700529 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700530 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700531 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700532 }
533
Michael Kolb7cdc4902011-02-03 17:54:40 -0800534 boolean canShowTitleBar() {
535 return !isTitleBarShowing()
536 && !isActivityPaused()
537 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700538 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800539 && !mUiController.isInCustomActionMode();
540 }
541
John Reck0f602f32011-07-07 15:38:43 -0700542 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700543 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700544 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700545 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700546 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800547 }
548
549 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700550 if (mTitleBar.isShowing()) {
551 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700552 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800553 }
554
555 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700556 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800557 }
558
John Reck5d43ce82011-06-21 17:16:51 -0700559 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700560 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700561 }
562
Michael Kolb80f75082012-04-10 10:50:06 -0700563 public void stopEditingUrl() {
564 mTitleBar.getNavigationBar().stopEditingUrl();
565 }
566
John Reck0f602f32011-07-07 15:38:43 -0700567 public TitleBar getTitleBar() {
568 return mTitleBar;
569 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800570
Michael Kolb66706532010-12-12 19:50:22 -0800571 @Override
John Reck2bc80422011-06-30 15:11:49 -0700572 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700573 Intent intent = new Intent(mActivity, ComboViewActivity.class);
574 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
575 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
576 Tab t = getActiveTab();
577 if (t != null) {
578 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800579 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700580 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700581 }
582
583 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400584 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800585 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700586 // if a view already exists then immediately terminate the new one
587 if (mCustomView != null) {
588 callback.onCustomViewHidden();
589 return;
590 }
591
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400592 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700593 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
594 mFullscreenContainer = new FullscreenHolder(mActivity);
595 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
596 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
597 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700598 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700599 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700600 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400601 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 }
603
604 @Override
605 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700606 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 if (mCustomView == null)
608 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700609 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700610 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
611 decor.removeView(mFullscreenContainer);
612 mFullscreenContainer = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700613 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 mCustomViewCallback.onCustomViewHidden();
615 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400616 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 }
618
619 @Override
620 public boolean isCustomViewShowing() {
621 return mCustomView != null;
622 }
623
Michael Kolb66706532010-12-12 19:50:22 -0800624 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800625 if (mInputManager.isActive()) {
626 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
627 0);
628 }
629 }
630
Michael Kolb66706532010-12-12 19:50:22 -0800631 @Override
John Reck3ba45532011-08-11 16:26:53 -0700632 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700633 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800634 }
635
Michael Kolb8233fac2010-10-26 16:08:53 -0700636 // -------------------------------------------------------------------------
637
Michael Kolb5a72f182011-01-13 20:35:06 -0800638 protected void updateNavigationState(Tab tab) {
639 }
640
Michael Kolb8233fac2010-10-26 16:08:53 -0700641 /**
642 * Update the lock icon to correspond to our latest state.
643 */
Michael Kolb66706532010-12-12 19:50:22 -0800644 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800645 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100646 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700647 }
648 }
649
650 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 * Updates the lock-icon image in the title-bar.
652 */
Steve Block2466eff2011-10-03 15:33:09 +0100653 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700654 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100655 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
656 d = mLockIconSecure;
Steve Block4895b012011-10-03 16:26:46 +0100657 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
658 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
659 // TODO: It would be good to have different icons for insecure vs mixed content.
660 // See http://b/5403800
Steve Block2466eff2011-10-03 15:33:09 +0100661 d = mLockIconMixed;
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 }
John Reck0f602f32011-07-07 15:38:43 -0700663 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700664 }
665
John Reck30c714c2010-12-16 17:30:34 -0800666 protected void setUrlTitle(Tab tab) {
667 String url = tab.getUrl();
668 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800669 if (TextUtils.isEmpty(title)) {
670 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800671 }
Michael Kolb66706532010-12-12 19:50:22 -0800672 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700673 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800674 }
675 }
676
677 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800678 protected void setFavicon(Tab tab) {
679 if (tab.inForeground()) {
680 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700681 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800682 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700683 }
684
Michael Kolb66706532010-12-12 19:50:22 -0800685 // active tabs page
686
687 public void showActiveTabsPage() {
688 }
689
690 /**
691 * Remove the active tabs page.
692 */
693 public void removeActiveTabsPage() {
694 }
695
Michael Kolb8233fac2010-10-26 16:08:53 -0700696 // menu handling callbacks
697
698 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800699 public boolean onPrepareOptionsMenu(Menu menu) {
700 return true;
701 }
702
703 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700704 public void updateMenuState(Tab tab, Menu menu) {
705 }
706
707 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700708 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700709 }
710
711 @Override
712 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700713 }
714
715 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700716 public boolean onOptionsItemSelected(MenuItem item) {
717 return false;
718 }
719
720 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700721 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700722 }
723
724 @Override
725 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700726 }
727
728 @Override
729 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700730 }
731
732 @Override
733 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 }
735
736 // error console
737
738 @Override
739 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800740 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700741 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
742 if (flag) {
743 // Setting the show state of the console will cause it's the layout
744 // to be inflated.
745 if (errorConsole.numberOfErrors() > 0) {
746 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
747 } else {
748 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
749 }
750 if (errorConsole.getParent() != null) {
751 mErrorConsoleContainer.removeView(errorConsole);
752 }
753 // Now we can add it to the main view.
754 mErrorConsoleContainer.addView(errorConsole,
755 new LinearLayout.LayoutParams(
756 ViewGroup.LayoutParams.MATCH_PARENT,
757 ViewGroup.LayoutParams.WRAP_CONTENT));
758 } else {
759 mErrorConsoleContainer.removeView(errorConsole);
760 }
761 }
762
Michael Kolb8233fac2010-10-26 16:08:53 -0700763 // -------------------------------------------------------------------------
764 // Helper function for WebChromeClient
765 // -------------------------------------------------------------------------
766
767 @Override
768 public Bitmap getDefaultVideoPoster() {
769 if (mDefaultVideoPoster == null) {
770 mDefaultVideoPoster = BitmapFactory.decodeResource(
771 mActivity.getResources(), R.drawable.default_video_poster);
772 }
773 return mDefaultVideoPoster;
774 }
775
776 @Override
777 public View getVideoLoadingProgressView() {
778 if (mVideoProgressView == null) {
779 LayoutInflater inflater = LayoutInflater.from(mActivity);
780 mVideoProgressView = inflater.inflate(
781 R.layout.video_loading_progress, null);
782 }
783 return mVideoProgressView;
784 }
785
Michael Kolb843510f2010-12-09 10:51:49 -0800786 @Override
787 public void showMaxTabsWarning() {
788 Toast warning = Toast.makeText(mActivity,
789 mActivity.getString(R.string.max_tabs_warning),
790 Toast.LENGTH_SHORT);
791 warning.show();
792 }
793
Michael Kolb46f987e2011-04-05 10:39:10 -0700794 protected WebView getWebView() {
795 if (mActiveTab != null) {
796 return mActiveTab.getWebView();
797 } else {
798 return null;
799 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700800 }
801
Michael Kolbc38c6042011-04-27 10:46:06 -0700802 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700803 Window win = mActivity.getWindow();
804 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800805 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700806 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700807 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700808 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700809 winParams.flags &= ~bits;
810 if (mCustomView != null) {
811 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
812 } else {
813 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
814 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700815 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700816 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700817 }
818
John Reck0f602f32011-07-07 15:38:43 -0700819 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700820 Drawable[] array = new Drawable[3];
821 array[0] = new PaintDrawable(Color.BLACK);
822 PaintDrawable p = new PaintDrawable(Color.WHITE);
823 array[1] = p;
824 if (icon == null) {
825 array[2] = mGenericFavicon;
826 } else {
827 array[2] = new BitmapDrawable(icon);
828 }
829 LayerDrawable d = new LayerDrawable(array);
830 d.setLayerInset(1, 1, 1, 1, 1);
831 d.setLayerInset(2, 2, 2, 2, 2);
832 return d;
833 }
834
John Reck5d43ce82011-06-21 17:16:51 -0700835 public boolean isLoading() {
836 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
837 }
838
839 /**
840 * Suggest to the UI that the title bar can be hidden. The UI will then
841 * decide whether or not to hide based off a number of factors, such
842 * as if the user is editing the URL bar or if the page is loading
843 */
844 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700845 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
846 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700847 hideTitleBar();
848 }
849 }
850
John Reckbc6adb42011-09-01 18:03:20 -0700851 protected final void showTitleBarForDuration() {
852 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
853 }
854
855 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700856 showTitleBar();
857 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700858 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700859 }
860
John Reck9c5004e2011-10-07 16:00:12 -0700861 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700862
863 @Override
864 public void handleMessage(Message msg) {
865 if (msg.what == MSG_HIDE_TITLEBAR) {
866 suggestHideTitleBar();
867 }
John Reck9c5004e2011-10-07 16:00:12 -0700868 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700869 }
870 };
John Reck3ba45532011-08-11 16:26:53 -0700871
John Reck9c5004e2011-10-07 16:00:12 -0700872 protected void handleMessage(Message msg) {}
873
John Reck3ba45532011-08-11 16:26:53 -0700874 @Override
875 public void showWeb(boolean animate) {
876 mUiController.hideCustomView();
877 }
878
Michael Kolb31065b12011-10-06 13:51:32 -0700879 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700880
Michael Kolb31065b12011-10-06 13:51:32 -0700881 public FullscreenHolder(Context ctx) {
882 super(ctx);
883 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700884 }
885
Michael Kolb31065b12011-10-06 13:51:32 -0700886 @Override
887 public boolean onTouchEvent(MotionEvent evt) {
888 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700889 }
Michael Kolb31065b12011-10-06 13:51:32 -0700890
Michael Kolb53ed62c2011-10-04 16:18:44 -0700891 }
John Reck2711fab2012-05-18 21:38:59 -0700892
893 public void addFixedTitleBar(View view) {
894 mFixedTitlebarContainer.addView(view);
895 }
896
897 public void setContentViewMarginTop(int margin) {
898 LinearLayout.LayoutParams params =
899 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
900 if (params.topMargin != margin) {
901 params.topMargin = margin;
902 mContentView.setLayoutParams(params);
903 }
904 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700905
906 @Override
907 public boolean blockFocusAnimations() {
908 return mBlockFocusAnimations;
909 }
910
Michael Kolb0b129122012-06-04 16:31:58 -0700911 @Override
912 public void onVoiceResult(String result) {
913 mNavigationBar.onVoiceResult(result);
914 }
915
kaiyizbb2db872013-08-01 22:24:07 -0400916 protected UiController getUiController() {
917 return mUiController;
918 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700919
920 @Override
921 public void onActionModeStarted(ActionMode mode) {
922 int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0;
923 mFixedTitlebarContainer.setY(fixedTbarHeight);
924 setContentViewMarginTop(fixedTbarHeight);
925 }
926
927 @Override
928 public void onActionModeFinished(boolean inLoad) {
929 mFixedTitlebarContainer.setY(0);
930 setContentViewMarginTop(0);
931 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700932}