blob: e2e313e50c9f5fae2005126ea2eca053df3e5dbb [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
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
Michael Kolbfedb4922011-04-20 16:45:33 -070020import com.android.internal.view.menu.MenuBuilder;
John Reck30c714c2010-12-16 17:30:34 -080021
John Reck74830e12011-03-14 11:43:05 -070022import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070024import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.res.Configuration;
26import android.content.res.Resources;
27import android.graphics.Bitmap;
28import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070029import android.graphics.drawable.Drawable;
30import android.os.Bundle;
31import android.text.TextUtils;
32import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.view.Gravity;
34import android.view.LayoutInflater;
35import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080037import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080039import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080041import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.webkit.WebView;
44import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080045import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.widget.LinearLayout;
47import android.widget.Toast;
48
Michael Kolb1bf23132010-11-19 12:55:12 -080049import java.util.List;
50
Michael Kolb8233fac2010-10-26 16:08:53 -070051/**
52 * UI interface definitions
53 */
Michael Kolb66706532010-12-12 19:50:22 -080054public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070055
56 private static final String LOGTAG = "BaseUi";
57
Michael Kolb66706532010-12-12 19:50:22 -080058 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070059 new FrameLayout.LayoutParams(
60 ViewGroup.LayoutParams.MATCH_PARENT,
61 ViewGroup.LayoutParams.MATCH_PARENT);
62
Michael Kolb66706532010-12-12 19:50:22 -080063 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070064 new FrameLayout.LayoutParams(
65 ViewGroup.LayoutParams.MATCH_PARENT,
66 ViewGroup.LayoutParams.MATCH_PARENT,
67 Gravity.CENTER);
68
69 Activity mActivity;
70 UiController mUiController;
71 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080072 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080073 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070074
75 private Drawable mSecLockIcon;
76 private Drawable mMixLockIcon;
77
Michael Kolb8233fac2010-10-26 16:08:53 -070078 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080079 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070080 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070081
82 private View mCustomView;
83 private WebChromeClient.CustomViewCallback mCustomViewCallback;
84
85 private CombinedBookmarkHistoryView mComboView;
86
87 private LinearLayout mErrorConsoleContainer = null;
88
89 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070090
91 // the default <video> poster
92 private Bitmap mDefaultVideoPoster;
93 // the video progress view
94 private View mVideoProgressView;
95
Michael Kolb8233fac2010-10-26 16:08:53 -070096 private boolean mActivityPaused;
97
98 public BaseUi(Activity browser, UiController controller) {
99 mActivity = browser;
100 mUiController = controller;
101 mTabControl = controller.getTabControl();
102 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800103 mInputManager = (InputMethodManager)
104 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800105 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
107
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
109 .getDecorView().findViewById(android.R.id.content);
110 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
111 .inflate(R.layout.custom_screen, null);
112 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
113 R.id.main_content);
114 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
115 .findViewById(R.id.error_console);
116 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
117 .findViewById(R.id.fullscreen_custom_content);
118 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolbc38c6042011-04-27 10:46:06 -0700119 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb8233fac2010-10-26 16:08:53 -0700120 }
121
John Reckb9a051b2011-03-18 11:55:48 -0700122 @Override
123 public WebView createWebView(boolean privateBrowsing) {
124 // Create a new WebView
125 BrowserWebView w = new BrowserWebView(mActivity, null,
126 android.R.attr.webViewStyle, privateBrowsing);
127 initWebViewSettings(w);
128 return w;
129 }
130
131 @Override
132 public WebView createSubWebView(boolean privateBrowsing) {
133 return createWebView(privateBrowsing);
134 }
135
Michael Kolb66706532010-12-12 19:50:22 -0800136 /**
137 * common webview initialization
138 * @param w the webview to initialize
139 */
140 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700141 w.setScrollbarFadingEnabled(true);
142 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
143 w.setMapTrackballToArrowKeys(false); // use trackball directly
144 // Enable the built-in zoom
145 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700146 boolean supportsMultiTouch = mActivity.getPackageManager()
147 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
148 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
149 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700150
151 // Add this WebView to the settings observer list and update the
152 // settings
153 final BrowserSettings s = BrowserSettings.getInstance();
John Reck35e9dd62011-04-25 09:01:54 -0700154 s.startManagingSettings(w.getSettings());
Michael Kolb8233fac2010-10-26 16:08:53 -0700155 }
156
157 private void cancelStopToast() {
158 if (mStopToast != null) {
159 mStopToast.cancel();
160 mStopToast = null;
161 }
162 }
163
164 // lifecycle
165
166 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800167 if (isCustomViewShowing()) {
168 onHideCustomView();
169 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700170 cancelStopToast();
171 mActivityPaused = true;
172 }
173
174 public void onResume() {
175 mActivityPaused = false;
176 }
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
185 // key handling
186
187 @Override
188 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 if (mComboView != null) {
190 if (!mComboView.onBackPressed()) {
191 mUiController.removeComboView();
192 }
193 return true;
194 }
195 if (mCustomView != null) {
196 mUiController.hideCustomView();
197 return true;
198 }
199 return false;
200 }
201
John Reck30c714c2010-12-16 17:30:34 -0800202 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700203 @Override
John Reck30c714c2010-12-16 17:30:34 -0800204 public void onTabDataChanged(Tab tab) {
205 setUrlTitle(tab);
206 setFavicon(tab);
207 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800208 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700209 }
210
211 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500212 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800213 if (tab.inForeground()) {
214 boolean isBookmark = tab.isBookmarkedSite();
215 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
216 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500217 }
218
219 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 public void onPageStopped(Tab tab) {
221 cancelStopToast();
222 if (tab.inForeground()) {
223 mStopToast = Toast
224 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
225 mStopToast.show();
226 }
227 }
228
229 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800230 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700231 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800232 }
233
234 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 }
237
238 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800239 public void setActiveTab(final Tab tab) {
240 setActiveTab(tab, true);
241 }
242
243 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800244 if ((tab != mActiveTab) && (mActiveTab != null)) {
245 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700246 }
Michael Kolb77df4562010-11-19 14:49:34 -0800247 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800248 if (needsAttaching) {
249 attachTabToContentView(tab);
250 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700251 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800252 onTabDataChanged(tab);
253 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800254 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800255 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500256 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 }
258
Michael Kolbcfa3af52010-12-14 10:36:11 -0800259 Tab getActiveTab() {
260 return mActiveTab;
261 }
262
Michael Kolb8233fac2010-10-26 16:08:53 -0700263 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800264 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800265 }
266
267 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700268 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800269 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700270 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800271 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700273 }
274
275 @Override
276 public void detachTab(Tab tab) {
277 removeTabFromContentView(tab);
278 }
279
280 @Override
281 public void attachTab(Tab tab) {
282 attachTabToContentView(tab);
283 }
284
Michael Kolb377ea312011-02-17 14:36:56 -0800285 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800286 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700287 return;
288 }
289 View container = tab.getViewContainer();
290 WebView mainView = tab.getWebView();
291 // Attach the WebView to the container and then attach the
292 // container to the content view.
293 FrameLayout wrapper =
294 (FrameLayout) container.findViewById(R.id.webview_wrapper);
295 ViewGroup parent = (ViewGroup) mainView.getParent();
296 if (parent != wrapper) {
297 if (parent != null) {
298 Log.w(LOGTAG, "mMainView already has a parent in"
299 + " attachTabToContentView!");
300 parent.removeView(mainView);
301 }
302 wrapper.addView(mainView);
303 } else {
304 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
305 + " attachTabToContentView!");
306 }
307 parent = (ViewGroup) container.getParent();
308 if (parent != mContentView) {
309 if (parent != null) {
310 Log.w(LOGTAG, "mContainer already has a parent in"
311 + " attachTabToContentView!");
312 parent.removeView(container);
313 }
314 mContentView.addView(container, COVER_SCREEN_PARAMS);
315 } else {
316 Log.w(LOGTAG, "mContainer is already attached to content in"
317 + " attachTabToContentView!");
318 }
319 mUiController.attachSubWindow(tab);
320 }
321
322 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800323 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700324 // Remove the container that contains the main WebView.
325 WebView mainView = tab.getWebView();
326 View container = tab.getViewContainer();
327 if (mainView == null) {
328 return;
329 }
330 // Remove the container from the content and then remove the
331 // WebView from the container. This will trigger a focus change
332 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800333 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700334 FrameLayout wrapper =
335 (FrameLayout) container.findViewById(R.id.webview_wrapper);
336 wrapper.removeView(mainView);
337 mContentView.removeView(container);
338 mUiController.endActionMode();
339 mUiController.removeSubWindow(tab);
340 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
341 if (errorConsole != null) {
342 mErrorConsoleContainer.removeView(errorConsole);
343 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700344 }
345
Michael Kolba713ec82010-11-29 17:27:06 -0800346 @Override
347 public void onSetWebView(Tab tab, WebView webView) {
348 View container = tab.getViewContainer();
349 if (container == null) {
350 // The tab consists of a container view, which contains the main
351 // WebView, as well as any other UI elements associated with the tab.
352 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
353 null);
354 tab.setViewContainer(container);
355 }
356 if (tab.getWebView() != webView) {
357 // Just remove the old one.
358 FrameLayout wrapper =
359 (FrameLayout) container.findViewById(R.id.webview_wrapper);
360 wrapper.removeView(tab.getWebView());
361 }
362 }
363
Michael Kolb8233fac2010-10-26 16:08:53 -0700364 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800365 * create a sub window container and webview for the tab
366 * Note: this methods operates through side-effects for now
367 * it sets both the subView and subViewContainer for the given tab
368 * @param tab tab to create the sub window for
369 * @param subView webview to be set as a subwindow for the tab
370 */
371 @Override
372 public void createSubWindow(Tab tab, WebView subView) {
373 View subViewContainer = mActivity.getLayoutInflater().inflate(
374 R.layout.browser_subwindow, null);
375 ViewGroup inner = (ViewGroup) subViewContainer
376 .findViewById(R.id.inner_container);
377 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
378 LayoutParams.MATCH_PARENT));
379 final ImageButton cancel = (ImageButton) subViewContainer
380 .findViewById(R.id.subwindow_close);
381 final WebView cancelSubView = subView;
382 cancel.setOnClickListener(new OnClickListener() {
383 public void onClick(View v) {
384 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
385 }
386 });
387 tab.setSubWebView(subView);
388 tab.setSubViewContainer(subViewContainer);
389 }
390
391 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700392 * Remove the sub window from the content view.
393 */
394 @Override
395 public void removeSubWindow(View subviewContainer) {
396 mContentView.removeView(subviewContainer);
397 mUiController.endActionMode();
398 }
399
400 /**
401 * Attach the sub window to the content view.
402 */
403 @Override
404 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800405 if (container.getParent() != null) {
406 // already attached, remove first
407 ((ViewGroup) container.getParent()).removeView(container);
408 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700409 mContentView.addView(container, COVER_SCREEN_PARAMS);
410 }
411
Michael Kolb11d19782011-03-20 10:17:40 -0700412 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700413 WebView web = getWebView();
414 if (web != null) {
415 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700416 }
417 }
418
Michael Kolb46f987e2011-04-05 10:39:10 -0700419 public void editUrl(boolean clearInput) {
420 if (mUiController.isInCustomActionMode()) {
421 mUiController.endActionMode();
422 }
423 showTitleBar();
424 getTitleBar().startEditingUrl(clearInput);
425 }
426
Michael Kolb7cdc4902011-02-03 17:54:40 -0800427 boolean canShowTitleBar() {
428 return !isTitleBarShowing()
429 && !isActivityPaused()
430 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700431 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800432 && !mUiController.isInCustomActionMode();
433 }
434
435 void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700436 if (canShowTitleBar()) {
437 getTitleBar().show();
438 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800439 }
440
441 protected void hideTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700442 if (getTitleBar().isShowing()) {
443 getTitleBar().hide();
444 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800445 }
446
447 protected boolean isTitleBarShowing() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700448 return getTitleBar().isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800449 }
450
451 protected abstract TitleBarBase getTitleBar();
452
453 protected void setTitleGravity(int gravity) {
Michael Kolbd463a722011-04-08 10:17:49 -0700454 // update the titlebar layout params
455 // required to avoid scroll to top when focused
456 getTitleBar().setTitleGravity(gravity);
Michael Kolb46f987e2011-04-05 10:39:10 -0700457 WebView web = getWebView();
458 if (web != null) {
459 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 }
461 }
462
Michael Kolb66706532010-12-12 19:50:22 -0800463 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700464 public void showVoiceTitleBar(String title, List<String> results) {
465 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800466 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 }
468
Michael Kolb66706532010-12-12 19:50:22 -0800469 @Override
470 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700471 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800472 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800473 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700474 }
475
476 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700477 public void registerDropdownChangeListener(DropdownChangeListener d) {
478 getTitleBar().registerDropdownChangeListener(d);
479 }
480
481 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700482 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800483 if (mComboView != null) {
484 return;
485 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700486 mComboView = new CombinedBookmarkHistoryView(mActivity,
487 mUiController,
488 startWithHistory ?
489 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
490 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
491 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800492 FrameLayout wrapper =
493 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
494 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700495 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800496 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700497 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800498 if (mActiveTab != null) {
499 WebView web = mActiveTab.getWebView();
500 mActiveTab.putInBackground();
501 }
John Reck74830e12011-03-14 11:43:05 -0700502 mComboView.setAlpha(0f);
503 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
504 Resources res = mActivity.getResources();
505 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
506 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700507 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
508 }
509
Michael Kolbba238702011-03-08 10:40:50 -0800510 public boolean isComboViewShowing() {
511 return (mComboView != null);
512 }
513
Michael Kolb8233fac2010-10-26 16:08:53 -0700514 /**
515 * dismiss the ComboPage
516 */
517 @Override
518 public void hideComboView() {
519 if (mComboView != null) {
520 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800521 FrameLayout wrapper =
522 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
523 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700524 mComboView = null;
525 }
Michael Kolb3a696282010-12-05 13:23:24 -0800526 if (mActiveTab != null) {
527 mActiveTab.putInForeground();
528 }
John Reckb3417f02011-01-14 11:01:05 -0800529 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700530 }
531
532 @Override
533 public void showCustomView(View view,
534 WebChromeClient.CustomViewCallback callback) {
535 // if a view already exists then immediately terminate the new one
536 if (mCustomView != null) {
537 callback.onCustomViewHidden();
538 return;
539 }
540
541 // Add the custom view to its container.
542 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
543 mCustomView = view;
544 mCustomViewCallback = callback;
545 // Hide the content view.
546 mContentView.setVisibility(View.GONE);
547 // Finally show the custom view container.
548 setStatusBarVisibility(false);
549 mCustomViewContainer.setVisibility(View.VISIBLE);
550 mCustomViewContainer.bringToFront();
551 }
552
553 @Override
554 public void onHideCustomView() {
555 if (mCustomView == null)
556 return;
557
558 // Hide the custom view.
559 mCustomView.setVisibility(View.GONE);
560 // Remove the custom view from its container.
561 mCustomViewContainer.removeView(mCustomView);
562 mCustomView = null;
563 mCustomViewContainer.setVisibility(View.GONE);
564 mCustomViewCallback.onCustomViewHidden();
565 // Show the content view.
566 setStatusBarVisibility(true);
567 mContentView.setVisibility(View.VISIBLE);
568 }
569
570 @Override
571 public boolean isCustomViewShowing() {
572 return mCustomView != null;
573 }
574
Michael Kolb66706532010-12-12 19:50:22 -0800575 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800576 if (mInputManager.isActive()) {
577 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
578 0);
579 }
580 }
581
Michael Kolb66706532010-12-12 19:50:22 -0800582 @Override
583 public boolean showsWeb() {
584 return mCustomView == null
585 && mComboView == null;
586 }
587
Patrick Scott92066772011-03-10 08:46:27 -0500588 @Override
589 public void showAutoLogin(Tab tab) {
590 updateAutoLogin(tab, true);
591 }
592
593 @Override
594 public void hideAutoLogin(Tab tab) {
595 updateAutoLogin(tab, true);
596 }
597
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 // -------------------------------------------------------------------------
599
Michael Kolb5a72f182011-01-13 20:35:06 -0800600 protected void updateNavigationState(Tab tab) {
601 }
602
Michael Kolb11d19782011-03-20 10:17:40 -0700603 protected void updateAutoLogin(Tab tab, boolean animate) {
604 getTitleBar().updateAutoLogin(tab, animate);
605 }
Patrick Scott92066772011-03-10 08:46:27 -0500606
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 /**
608 * Update the lock icon to correspond to our latest state.
609 */
Michael Kolb66706532010-12-12 19:50:22 -0800610 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800611 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 updateLockIconImage(t.getLockIconType());
613 }
614 }
615
616 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 * Updates the lock-icon image in the title-bar.
618 */
John Reck30c714c2010-12-16 17:30:34 -0800619 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800621 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800623 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700624 d = mMixLockIcon;
625 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800626 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700627 }
628
John Reck30c714c2010-12-16 17:30:34 -0800629 protected void setUrlTitle(Tab tab) {
630 String url = tab.getUrl();
631 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800632 if (TextUtils.isEmpty(title)) {
633 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800634 }
Michael Kolb66706532010-12-12 19:50:22 -0800635 if (tab.isInVoiceSearchMode()) return;
636 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800637 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800638 }
639 }
640
641 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800642 protected void setFavicon(Tab tab) {
643 if (tab.inForeground()) {
644 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800645 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800646 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700647 }
648
649 @Override
650 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 }
652
Michael Kolb66706532010-12-12 19:50:22 -0800653 // active tabs page
654
655 public void showActiveTabsPage() {
656 }
657
658 /**
659 * Remove the active tabs page.
660 */
661 public void removeActiveTabsPage() {
662 }
663
Michael Kolb8233fac2010-10-26 16:08:53 -0700664 // menu handling callbacks
665
666 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800667 public boolean onPrepareOptionsMenu(Menu menu) {
668 return true;
669 }
670
671 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700673 }
674
675 @Override
676 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 }
678
679 @Override
680 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700681 }
682
683 @Override
684 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700685 }
686
687 @Override
688 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700689 }
690
691 @Override
692 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700693 }
694
695 // error console
696
697 @Override
698 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800699 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
701 if (flag) {
702 // Setting the show state of the console will cause it's the layout
703 // to be inflated.
704 if (errorConsole.numberOfErrors() > 0) {
705 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
706 } else {
707 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
708 }
709 if (errorConsole.getParent() != null) {
710 mErrorConsoleContainer.removeView(errorConsole);
711 }
712 // Now we can add it to the main view.
713 mErrorConsoleContainer.addView(errorConsole,
714 new LinearLayout.LayoutParams(
715 ViewGroup.LayoutParams.MATCH_PARENT,
716 ViewGroup.LayoutParams.WRAP_CONTENT));
717 } else {
718 mErrorConsoleContainer.removeView(errorConsole);
719 }
720 }
721
722 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800723 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
724 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
725 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700726 }
727
Michael Kolb8233fac2010-10-26 16:08:53 -0700728 // -------------------------------------------------------------------------
729 // Helper function for WebChromeClient
730 // -------------------------------------------------------------------------
731
732 @Override
733 public Bitmap getDefaultVideoPoster() {
734 if (mDefaultVideoPoster == null) {
735 mDefaultVideoPoster = BitmapFactory.decodeResource(
736 mActivity.getResources(), R.drawable.default_video_poster);
737 }
738 return mDefaultVideoPoster;
739 }
740
741 @Override
742 public View getVideoLoadingProgressView() {
743 if (mVideoProgressView == null) {
744 LayoutInflater inflater = LayoutInflater.from(mActivity);
745 mVideoProgressView = inflater.inflate(
746 R.layout.video_loading_progress, null);
747 }
748 return mVideoProgressView;
749 }
750
Michael Kolb843510f2010-12-09 10:51:49 -0800751 @Override
752 public void showMaxTabsWarning() {
753 Toast warning = Toast.makeText(mActivity,
754 mActivity.getString(R.string.max_tabs_warning),
755 Toast.LENGTH_SHORT);
756 warning.show();
757 }
758
Michael Kolbfdb70242011-03-24 09:41:11 -0700759 protected void captureTab(final Tab tab) {
760 captureTab(tab,
761 (int) mActivity.getResources()
762 .getDimension(R.dimen.qc_thumb_width),
763 (int) mActivity.getResources()
764 .getDimension(R.dimen.qc_thumb_height));
765 }
766
767 protected void captureTab(final Tab tab, int width, int height) {
768 if ((tab == null) || (tab.getWebView() == null)) return;
769 Bitmap sshot = Controller.createScreenshot(tab, width, height);
770 tab.setScreenshot(sshot);
771 }
772
Michael Kolb46f987e2011-04-05 10:39:10 -0700773 protected WebView getWebView() {
774 if (mActiveTab != null) {
775 return mActiveTab.getWebView();
776 } else {
777 return null;
778 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700779 }
780
Michael Kolbfedb4922011-04-20 16:45:33 -0700781 protected Menu getMenu() {
782 MenuBuilder menu = new MenuBuilder(mActivity);
783 mActivity.getMenuInflater().inflate(R.menu.browser, menu);
784 return menu;
785 }
786
Michael Kolbc38c6042011-04-27 10:46:06 -0700787 public void setFullscreen(boolean enabled) {
788 if (enabled) {
789 mActivity.getWindow().setFlags(
790 WindowManager.LayoutParams.FLAG_FULLSCREEN,
791 WindowManager.LayoutParams.FLAG_FULLSCREEN);
792 } else {
793 mActivity.getWindow().clearFlags(
794 WindowManager.LayoutParams.FLAG_FULLSCREEN);
795 }
796 }
797
Michael Kolb8233fac2010-10-26 16:08:53 -0700798}