blob: 7530732179bdfed9810173d7e05075436d317e93 [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 Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.Color;
30import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070032import android.graphics.drawable.LayerDrawable;
33import android.graphics.drawable.PaintDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.os.Bundle;
35import android.text.TextUtils;
36import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.Gravity;
38import android.view.LayoutInflater;
39import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080041import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.webkit.WebView;
48import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080049import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.LinearLayout;
51import android.widget.Toast;
52
Michael Kolb1bf23132010-11-19 12:55:12 -080053import java.util.List;
54
Michael Kolb8233fac2010-10-26 16:08:53 -070055/**
56 * UI interface definitions
57 */
Michael Kolb66706532010-12-12 19:50:22 -080058public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070059
60 private static final String LOGTAG = "BaseUi";
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT);
66
Michael Kolb66706532010-12-12 19:50:22 -080067 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070068 new FrameLayout.LayoutParams(
69 ViewGroup.LayoutParams.MATCH_PARENT,
70 ViewGroup.LayoutParams.MATCH_PARENT,
71 Gravity.CENTER);
72
73 Activity mActivity;
74 UiController mUiController;
75 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080076 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080077 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070078
79 private Drawable mSecLockIcon;
80 private Drawable mMixLockIcon;
Michael Kolb5a4372f2011-04-29 13:53:10 -070081 protected Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080084 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070085 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070086
87 private View mCustomView;
88 private WebChromeClient.CustomViewCallback mCustomViewCallback;
89
90 private CombinedBookmarkHistoryView mComboView;
91
92 private LinearLayout mErrorConsoleContainer = null;
93
94 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
Michael Kolb5a4372f2011-04-29 13:53:10 -070096
Michael Kolb8233fac2010-10-26 16:08:53 -070097 // the default <video> poster
98 private Bitmap mDefaultVideoPoster;
99 // the video progress view
100 private View mVideoProgressView;
101
Michael Kolb8233fac2010-10-26 16:08:53 -0700102 private boolean mActivityPaused;
103
104 public BaseUi(Activity browser, UiController controller) {
105 mActivity = browser;
106 mUiController = controller;
107 mTabControl = controller.getTabControl();
108 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800109 mInputManager = (InputMethodManager)
110 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800111 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
113
Michael Kolb8233fac2010-10-26 16:08:53 -0700114 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
115 .getDecorView().findViewById(android.R.id.content);
116 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
117 .inflate(R.layout.custom_screen, null);
118 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
119 R.id.main_content);
120 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
121 .findViewById(R.id.error_console);
122 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
123 .findViewById(R.id.fullscreen_custom_content);
124 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolbc38c6042011-04-27 10:46:06 -0700125 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700126 mGenericFavicon = res.getDrawable(
127 R.drawable.app_web_browser_sm);
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 }
129
John Reckb9a051b2011-03-18 11:55:48 -0700130 @Override
131 public WebView createWebView(boolean privateBrowsing) {
132 // Create a new WebView
133 BrowserWebView w = new BrowserWebView(mActivity, null,
134 android.R.attr.webViewStyle, privateBrowsing);
135 initWebViewSettings(w);
136 return w;
137 }
138
139 @Override
140 public WebView createSubWebView(boolean privateBrowsing) {
141 return createWebView(privateBrowsing);
142 }
143
Michael Kolb66706532010-12-12 19:50:22 -0800144 /**
145 * common webview initialization
146 * @param w the webview to initialize
147 */
148 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700149 w.setScrollbarFadingEnabled(true);
150 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
151 w.setMapTrackballToArrowKeys(false); // use trackball directly
152 // Enable the built-in zoom
153 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700154 boolean supportsMultiTouch = mActivity.getPackageManager()
155 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
156 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
157 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700158
159 // Add this WebView to the settings observer list and update the
160 // settings
161 final BrowserSettings s = BrowserSettings.getInstance();
John Reck35e9dd62011-04-25 09:01:54 -0700162 s.startManagingSettings(w.getSettings());
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 }
164
165 private void cancelStopToast() {
166 if (mStopToast != null) {
167 mStopToast.cancel();
168 mStopToast = null;
169 }
170 }
171
172 // lifecycle
173
174 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800175 if (isCustomViewShowing()) {
176 onHideCustomView();
177 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 cancelStopToast();
179 mActivityPaused = true;
180 }
181
182 public void onResume() {
183 mActivityPaused = false;
184 }
185
Michael Kolb66706532010-12-12 19:50:22 -0800186 protected boolean isActivityPaused() {
187 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 }
189
190 public void onConfigurationChanged(Configuration config) {
191 }
192
193 // key handling
194
195 @Override
196 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700197 if (mComboView != null) {
198 if (!mComboView.onBackPressed()) {
199 mUiController.removeComboView();
200 }
201 return true;
202 }
203 if (mCustomView != null) {
204 mUiController.hideCustomView();
205 return true;
206 }
207 return false;
208 }
209
John Reck30c714c2010-12-16 17:30:34 -0800210 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 @Override
John Reck30c714c2010-12-16 17:30:34 -0800212 public void onTabDataChanged(Tab tab) {
213 setUrlTitle(tab);
214 setFavicon(tab);
215 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800216 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 }
218
219 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500220 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800221 if (tab.inForeground()) {
222 boolean isBookmark = tab.isBookmarkedSite();
223 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
224 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500225 }
226
227 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 public void onPageStopped(Tab tab) {
229 cancelStopToast();
230 if (tab.inForeground()) {
231 mStopToast = Toast
232 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
233 mStopToast.show();
234 }
235 }
236
237 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800238 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700239 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800240 }
241
242 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 }
245
246 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800247 public void setActiveTab(final Tab tab) {
248 setActiveTab(tab, true);
249 }
250
251 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800252 if ((tab != mActiveTab) && (mActiveTab != null)) {
253 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 }
Michael Kolb77df4562010-11-19 14:49:34 -0800255 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800256 if (needsAttaching) {
257 attachTabToContentView(tab);
258 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800260 onTabDataChanged(tab);
261 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800262 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800263 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500264 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 }
266
Michael Kolbcfa3af52010-12-14 10:36:11 -0800267 Tab getActiveTab() {
268 return mActiveTab;
269 }
270
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800272 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800273 }
274
275 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700276 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800277 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700278 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800279 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700280 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700281 }
282
283 @Override
284 public void detachTab(Tab tab) {
285 removeTabFromContentView(tab);
286 }
287
288 @Override
289 public void attachTab(Tab tab) {
290 attachTabToContentView(tab);
291 }
292
Michael Kolb377ea312011-02-17 14:36:56 -0800293 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800294 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700295 return;
296 }
297 View container = tab.getViewContainer();
298 WebView mainView = tab.getWebView();
299 // Attach the WebView to the container and then attach the
300 // container to the content view.
301 FrameLayout wrapper =
302 (FrameLayout) container.findViewById(R.id.webview_wrapper);
303 ViewGroup parent = (ViewGroup) mainView.getParent();
304 if (parent != wrapper) {
305 if (parent != null) {
306 Log.w(LOGTAG, "mMainView already has a parent in"
307 + " attachTabToContentView!");
308 parent.removeView(mainView);
309 }
310 wrapper.addView(mainView);
311 } else {
312 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
313 + " attachTabToContentView!");
314 }
315 parent = (ViewGroup) container.getParent();
316 if (parent != mContentView) {
317 if (parent != null) {
318 Log.w(LOGTAG, "mContainer already has a parent in"
319 + " attachTabToContentView!");
320 parent.removeView(container);
321 }
322 mContentView.addView(container, COVER_SCREEN_PARAMS);
323 } else {
324 Log.w(LOGTAG, "mContainer is already attached to content in"
325 + " attachTabToContentView!");
326 }
327 mUiController.attachSubWindow(tab);
328 }
329
330 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800331 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 // Remove the container that contains the main WebView.
333 WebView mainView = tab.getWebView();
334 View container = tab.getViewContainer();
335 if (mainView == null) {
336 return;
337 }
338 // Remove the container from the content and then remove the
339 // WebView from the container. This will trigger a focus change
340 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800341 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700342 FrameLayout wrapper =
343 (FrameLayout) container.findViewById(R.id.webview_wrapper);
344 wrapper.removeView(mainView);
345 mContentView.removeView(container);
346 mUiController.endActionMode();
347 mUiController.removeSubWindow(tab);
348 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
349 if (errorConsole != null) {
350 mErrorConsoleContainer.removeView(errorConsole);
351 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700352 }
353
Michael Kolba713ec82010-11-29 17:27:06 -0800354 @Override
355 public void onSetWebView(Tab tab, WebView webView) {
356 View container = tab.getViewContainer();
357 if (container == null) {
358 // The tab consists of a container view, which contains the main
359 // WebView, as well as any other UI elements associated with the tab.
360 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
361 null);
362 tab.setViewContainer(container);
363 }
364 if (tab.getWebView() != webView) {
365 // Just remove the old one.
366 FrameLayout wrapper =
367 (FrameLayout) container.findViewById(R.id.webview_wrapper);
368 wrapper.removeView(tab.getWebView());
369 }
370 }
371
Michael Kolb8233fac2010-10-26 16:08:53 -0700372 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800373 * create a sub window container and webview for the tab
374 * Note: this methods operates through side-effects for now
375 * it sets both the subView and subViewContainer for the given tab
376 * @param tab tab to create the sub window for
377 * @param subView webview to be set as a subwindow for the tab
378 */
379 @Override
380 public void createSubWindow(Tab tab, WebView subView) {
381 View subViewContainer = mActivity.getLayoutInflater().inflate(
382 R.layout.browser_subwindow, null);
383 ViewGroup inner = (ViewGroup) subViewContainer
384 .findViewById(R.id.inner_container);
385 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
386 LayoutParams.MATCH_PARENT));
387 final ImageButton cancel = (ImageButton) subViewContainer
388 .findViewById(R.id.subwindow_close);
389 final WebView cancelSubView = subView;
390 cancel.setOnClickListener(new OnClickListener() {
391 public void onClick(View v) {
392 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
393 }
394 });
395 tab.setSubWebView(subView);
396 tab.setSubViewContainer(subViewContainer);
397 }
398
399 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700400 * Remove the sub window from the content view.
401 */
402 @Override
403 public void removeSubWindow(View subviewContainer) {
404 mContentView.removeView(subviewContainer);
405 mUiController.endActionMode();
406 }
407
408 /**
409 * Attach the sub window to the content view.
410 */
411 @Override
412 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800413 if (container.getParent() != null) {
414 // already attached, remove first
415 ((ViewGroup) container.getParent()).removeView(container);
416 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 mContentView.addView(container, COVER_SCREEN_PARAMS);
418 }
419
Michael Kolb11d19782011-03-20 10:17:40 -0700420 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700421 WebView web = getWebView();
422 if (web != null) {
423 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700424 }
425 }
426
Michael Kolb46f987e2011-04-05 10:39:10 -0700427 public void editUrl(boolean clearInput) {
428 if (mUiController.isInCustomActionMode()) {
429 mUiController.endActionMode();
430 }
431 showTitleBar();
432 getTitleBar().startEditingUrl(clearInput);
433 }
434
Michael Kolb7cdc4902011-02-03 17:54:40 -0800435 boolean canShowTitleBar() {
436 return !isTitleBarShowing()
437 && !isActivityPaused()
438 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700439 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800440 && !mUiController.isInCustomActionMode();
441 }
442
443 void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700444 if (canShowTitleBar()) {
445 getTitleBar().show();
446 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800447 }
448
449 protected void hideTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700450 if (getTitleBar().isShowing()) {
451 getTitleBar().hide();
452 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800453 }
454
455 protected boolean isTitleBarShowing() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700456 return getTitleBar().isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800457 }
458
459 protected abstract TitleBarBase getTitleBar();
460
461 protected void setTitleGravity(int gravity) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700462 WebView web = getWebView();
463 if (web != null) {
464 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700465 }
466 }
467
Michael Kolb66706532010-12-12 19:50:22 -0800468 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700469 public void showVoiceTitleBar(String title, List<String> results) {
470 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800471 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 }
473
Michael Kolb66706532010-12-12 19:50:22 -0800474 @Override
475 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700476 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800477 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800478 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700479 }
480
481 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700482 public void registerDropdownChangeListener(DropdownChangeListener d) {
483 getTitleBar().registerDropdownChangeListener(d);
484 }
485
486 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700487 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800488 if (mComboView != null) {
489 return;
490 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700491 mComboView = new CombinedBookmarkHistoryView(mActivity,
492 mUiController,
493 startWithHistory ?
494 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
495 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
496 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800497 FrameLayout wrapper =
498 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
499 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700500 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800501 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700502 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800503 if (mActiveTab != null) {
504 WebView web = mActiveTab.getWebView();
505 mActiveTab.putInBackground();
506 }
John Reck74830e12011-03-14 11:43:05 -0700507 mComboView.setAlpha(0f);
508 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
509 Resources res = mActivity.getResources();
510 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
511 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700512 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
513 }
514
Michael Kolbba238702011-03-08 10:40:50 -0800515 public boolean isComboViewShowing() {
516 return (mComboView != null);
517 }
518
Michael Kolb8233fac2010-10-26 16:08:53 -0700519 /**
520 * dismiss the ComboPage
521 */
522 @Override
523 public void hideComboView() {
524 if (mComboView != null) {
525 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800526 FrameLayout wrapper =
527 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
528 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700529 mComboView = null;
530 }
Michael Kolb3a696282010-12-05 13:23:24 -0800531 if (mActiveTab != null) {
532 mActiveTab.putInForeground();
533 }
John Reckb3417f02011-01-14 11:01:05 -0800534 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700535 }
536
537 @Override
538 public void showCustomView(View view,
539 WebChromeClient.CustomViewCallback callback) {
540 // if a view already exists then immediately terminate the new one
541 if (mCustomView != null) {
542 callback.onCustomViewHidden();
543 return;
544 }
545
546 // Add the custom view to its container.
547 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
548 mCustomView = view;
549 mCustomViewCallback = callback;
550 // Hide the content view.
551 mContentView.setVisibility(View.GONE);
552 // Finally show the custom view container.
553 setStatusBarVisibility(false);
554 mCustomViewContainer.setVisibility(View.VISIBLE);
555 mCustomViewContainer.bringToFront();
556 }
557
558 @Override
559 public void onHideCustomView() {
560 if (mCustomView == null)
561 return;
562
563 // Hide the custom view.
564 mCustomView.setVisibility(View.GONE);
565 // Remove the custom view from its container.
566 mCustomViewContainer.removeView(mCustomView);
567 mCustomView = null;
568 mCustomViewContainer.setVisibility(View.GONE);
569 mCustomViewCallback.onCustomViewHidden();
570 // Show the content view.
571 setStatusBarVisibility(true);
572 mContentView.setVisibility(View.VISIBLE);
573 }
574
575 @Override
576 public boolean isCustomViewShowing() {
577 return mCustomView != null;
578 }
579
Michael Kolb66706532010-12-12 19:50:22 -0800580 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800581 if (mInputManager.isActive()) {
582 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
583 0);
584 }
585 }
586
Michael Kolb66706532010-12-12 19:50:22 -0800587 @Override
588 public boolean showsWeb() {
589 return mCustomView == null
590 && mComboView == null;
591 }
592
Patrick Scott92066772011-03-10 08:46:27 -0500593 @Override
594 public void showAutoLogin(Tab tab) {
595 updateAutoLogin(tab, true);
596 }
597
598 @Override
599 public void hideAutoLogin(Tab tab) {
600 updateAutoLogin(tab, true);
601 }
602
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 // -------------------------------------------------------------------------
604
Michael Kolb5a72f182011-01-13 20:35:06 -0800605 protected void updateNavigationState(Tab tab) {
606 }
607
Michael Kolb11d19782011-03-20 10:17:40 -0700608 protected void updateAutoLogin(Tab tab, boolean animate) {
609 getTitleBar().updateAutoLogin(tab, animate);
610 }
Patrick Scott92066772011-03-10 08:46:27 -0500611
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 /**
613 * Update the lock icon to correspond to our latest state.
614 */
Michael Kolb66706532010-12-12 19:50:22 -0800615 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800616 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 updateLockIconImage(t.getLockIconType());
618 }
619 }
620
621 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 * Updates the lock-icon image in the title-bar.
623 */
John Reck30c714c2010-12-16 17:30:34 -0800624 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800626 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700627 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800628 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700629 d = mMixLockIcon;
630 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800631 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700632 }
633
John Reck30c714c2010-12-16 17:30:34 -0800634 protected void setUrlTitle(Tab tab) {
635 String url = tab.getUrl();
636 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800637 if (TextUtils.isEmpty(title)) {
638 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800639 }
Michael Kolb66706532010-12-12 19:50:22 -0800640 if (tab.isInVoiceSearchMode()) return;
641 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800642 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800643 }
644 }
645
646 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800647 protected void setFavicon(Tab tab) {
648 if (tab.inForeground()) {
649 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800650 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800651 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700652 }
653
654 @Override
655 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 }
657
Michael Kolb66706532010-12-12 19:50:22 -0800658 // active tabs page
659
660 public void showActiveTabsPage() {
661 }
662
663 /**
664 * Remove the active tabs page.
665 */
666 public void removeActiveTabsPage() {
667 }
668
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 // menu handling callbacks
670
671 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800672 public boolean onPrepareOptionsMenu(Menu menu) {
673 return true;
674 }
675
676 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700678 }
679
680 @Override
681 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700682 }
683
684 @Override
685 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 }
687
688 @Override
689 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700690 }
691
692 @Override
693 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700694 }
695
696 @Override
697 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700698 }
699
700 // error console
701
702 @Override
703 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800704 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700705 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
706 if (flag) {
707 // Setting the show state of the console will cause it's the layout
708 // to be inflated.
709 if (errorConsole.numberOfErrors() > 0) {
710 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
711 } else {
712 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
713 }
714 if (errorConsole.getParent() != null) {
715 mErrorConsoleContainer.removeView(errorConsole);
716 }
717 // Now we can add it to the main view.
718 mErrorConsoleContainer.addView(errorConsole,
719 new LinearLayout.LayoutParams(
720 ViewGroup.LayoutParams.MATCH_PARENT,
721 ViewGroup.LayoutParams.WRAP_CONTENT));
722 } else {
723 mErrorConsoleContainer.removeView(errorConsole);
724 }
725 }
726
727 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800728 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
729 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
730 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700731 }
732
Michael Kolb8233fac2010-10-26 16:08:53 -0700733 // -------------------------------------------------------------------------
734 // Helper function for WebChromeClient
735 // -------------------------------------------------------------------------
736
737 @Override
738 public Bitmap getDefaultVideoPoster() {
739 if (mDefaultVideoPoster == null) {
740 mDefaultVideoPoster = BitmapFactory.decodeResource(
741 mActivity.getResources(), R.drawable.default_video_poster);
742 }
743 return mDefaultVideoPoster;
744 }
745
746 @Override
747 public View getVideoLoadingProgressView() {
748 if (mVideoProgressView == null) {
749 LayoutInflater inflater = LayoutInflater.from(mActivity);
750 mVideoProgressView = inflater.inflate(
751 R.layout.video_loading_progress, null);
752 }
753 return mVideoProgressView;
754 }
755
Michael Kolb843510f2010-12-09 10:51:49 -0800756 @Override
757 public void showMaxTabsWarning() {
758 Toast warning = Toast.makeText(mActivity,
759 mActivity.getString(R.string.max_tabs_warning),
760 Toast.LENGTH_SHORT);
761 warning.show();
762 }
763
Michael Kolbfdb70242011-03-24 09:41:11 -0700764 protected void captureTab(final Tab tab) {
765 captureTab(tab,
766 (int) mActivity.getResources()
767 .getDimension(R.dimen.qc_thumb_width),
768 (int) mActivity.getResources()
769 .getDimension(R.dimen.qc_thumb_height));
770 }
771
772 protected void captureTab(final Tab tab, int width, int height) {
773 if ((tab == null) || (tab.getWebView() == null)) return;
774 Bitmap sshot = Controller.createScreenshot(tab, width, height);
775 tab.setScreenshot(sshot);
776 }
777
Michael Kolb46f987e2011-04-05 10:39:10 -0700778 protected WebView getWebView() {
779 if (mActiveTab != null) {
780 return mActiveTab.getWebView();
781 } else {
782 return null;
783 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700784 }
785
Michael Kolbfedb4922011-04-20 16:45:33 -0700786 protected Menu getMenu() {
787 MenuBuilder menu = new MenuBuilder(mActivity);
788 mActivity.getMenuInflater().inflate(R.menu.browser, menu);
789 return menu;
790 }
791
Michael Kolbc38c6042011-04-27 10:46:06 -0700792 public void setFullscreen(boolean enabled) {
793 if (enabled) {
794 mActivity.getWindow().setFlags(
795 WindowManager.LayoutParams.FLAG_FULLSCREEN,
796 WindowManager.LayoutParams.FLAG_FULLSCREEN);
797 } else {
798 mActivity.getWindow().clearFlags(
799 WindowManager.LayoutParams.FLAG_FULLSCREEN);
800 }
801 }
802
Michael Kolb5a4372f2011-04-29 13:53:10 -0700803 protected Drawable getFaviconDrawable(Bitmap icon) {
804 Drawable[] array = new Drawable[3];
805 array[0] = new PaintDrawable(Color.BLACK);
806 PaintDrawable p = new PaintDrawable(Color.WHITE);
807 array[1] = p;
808 if (icon == null) {
809 array[2] = mGenericFavicon;
810 } else {
811 array[2] = new BitmapDrawable(icon);
812 }
813 LayerDrawable d = new LayerDrawable(array);
814 d.setLayerInset(1, 1, 1, 1, 1);
815 d.setLayerInset(2, 2, 2, 2, 2);
816 return d;
817 }
818
Michael Kolb8233fac2010-10-26 16:08:53 -0700819}