blob: 5daf17ae1078b59267046467c304320b1cee08e5 [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;
20
John Reck74830e12011-03-14 11:43:05 -070021import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070023import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070024import android.content.res.Configuration;
25import android.content.res.Resources;
26import android.graphics.Bitmap;
27import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
29import android.os.Bundle;
30import android.text.TextUtils;
31import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070032import android.view.Gravity;
33import android.view.LayoutInflater;
34import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080036import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080038import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080040import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.webkit.WebView;
43import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080044import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070045import android.widget.LinearLayout;
46import android.widget.Toast;
47
Michael Kolb1bf23132010-11-19 12:55:12 -080048import java.util.List;
49
Michael Kolb8233fac2010-10-26 16:08:53 -070050/**
51 * UI interface definitions
52 */
Michael Kolb66706532010-12-12 19:50:22 -080053public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070054
55 private static final String LOGTAG = "BaseUi";
56
Michael Kolb66706532010-12-12 19:50:22 -080057 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070058 new FrameLayout.LayoutParams(
59 ViewGroup.LayoutParams.MATCH_PARENT,
60 ViewGroup.LayoutParams.MATCH_PARENT);
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT,
66 Gravity.CENTER);
67
68 Activity mActivity;
69 UiController mUiController;
70 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080071 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080072 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070073
74 private Drawable mSecLockIcon;
75 private Drawable mMixLockIcon;
76
Michael Kolb8233fac2010-10-26 16:08:53 -070077 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080078 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070079 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070080
81 private View mCustomView;
82 private WebChromeClient.CustomViewCallback mCustomViewCallback;
83
84 private CombinedBookmarkHistoryView mComboView;
85
86 private LinearLayout mErrorConsoleContainer = null;
87
88 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070089
90 // the default <video> poster
91 private Bitmap mDefaultVideoPoster;
92 // the video progress view
93 private View mVideoProgressView;
94
Michael Kolb8233fac2010-10-26 16:08:53 -070095 private boolean mActivityPaused;
96
97 public BaseUi(Activity browser, UiController controller) {
98 mActivity = browser;
99 mUiController = controller;
100 mTabControl = controller.getTabControl();
101 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800102 mInputManager = (InputMethodManager)
103 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800104 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700105 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
108 .getDecorView().findViewById(android.R.id.content);
109 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
110 .inflate(R.layout.custom_screen, null);
111 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
112 R.id.main_content);
113 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
114 .findViewById(R.id.error_console);
115 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
116 .findViewById(R.id.fullscreen_custom_content);
117 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700118 }
119
John Reckb9a051b2011-03-18 11:55:48 -0700120 @Override
121 public WebView createWebView(boolean privateBrowsing) {
122 // Create a new WebView
123 BrowserWebView w = new BrowserWebView(mActivity, null,
124 android.R.attr.webViewStyle, privateBrowsing);
125 initWebViewSettings(w);
126 return w;
127 }
128
129 @Override
130 public WebView createSubWebView(boolean privateBrowsing) {
131 return createWebView(privateBrowsing);
132 }
133
Michael Kolb66706532010-12-12 19:50:22 -0800134 /**
135 * common webview initialization
136 * @param w the webview to initialize
137 */
138 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700139 w.setScrollbarFadingEnabled(true);
140 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
141 w.setMapTrackballToArrowKeys(false); // use trackball directly
142 // Enable the built-in zoom
143 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700144 boolean supportsMultiTouch = mActivity.getPackageManager()
145 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
146 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
147 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700148
149 // Add this WebView to the settings observer list and update the
150 // settings
151 final BrowserSettings s = BrowserSettings.getInstance();
152 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700153 }
154
155 private void cancelStopToast() {
156 if (mStopToast != null) {
157 mStopToast.cancel();
158 mStopToast = null;
159 }
160 }
161
162 // lifecycle
163
164 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800165 if (isCustomViewShowing()) {
166 onHideCustomView();
167 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700168 cancelStopToast();
169 mActivityPaused = true;
170 }
171
172 public void onResume() {
173 mActivityPaused = false;
174 }
175
Michael Kolb66706532010-12-12 19:50:22 -0800176 protected boolean isActivityPaused() {
177 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 }
179
180 public void onConfigurationChanged(Configuration config) {
181 }
182
183 // key handling
184
185 @Override
186 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 if (mComboView != null) {
188 if (!mComboView.onBackPressed()) {
189 mUiController.removeComboView();
190 }
191 return true;
192 }
193 if (mCustomView != null) {
194 mUiController.hideCustomView();
195 return true;
196 }
197 return false;
198 }
199
John Reck30c714c2010-12-16 17:30:34 -0800200 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700201 @Override
John Reck30c714c2010-12-16 17:30:34 -0800202 public void onTabDataChanged(Tab tab) {
203 setUrlTitle(tab);
204 setFavicon(tab);
205 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800206 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 }
208
209 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500210 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800211 if (tab.inForeground()) {
212 boolean isBookmark = tab.isBookmarkedSite();
213 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
214 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500215 }
216
217 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 public void onPageStopped(Tab tab) {
219 cancelStopToast();
220 if (tab.inForeground()) {
221 mStopToast = Toast
222 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
223 mStopToast.show();
224 }
225 }
226
227 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800228 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800229 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800230 }
231
232 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 }
235
236 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800237 public void setActiveTab(final Tab tab) {
238 setActiveTab(tab, true);
239 }
240
241 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800242 if ((tab != mActiveTab) && (mActiveTab != null)) {
243 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 }
Michael Kolb77df4562010-11-19 14:49:34 -0800245 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800246 if (needsAttaching) {
247 attachTabToContentView(tab);
248 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800250 onTabDataChanged(tab);
251 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800252 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800253 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500254 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 }
256
Michael Kolbcfa3af52010-12-14 10:36:11 -0800257 Tab getActiveTab() {
258 return mActiveTab;
259 }
260
Michael Kolb8233fac2010-10-26 16:08:53 -0700261 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800262 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800263 }
264
265 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700266 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800267 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700268 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800269 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700270 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 }
272
273 @Override
274 public void detachTab(Tab tab) {
275 removeTabFromContentView(tab);
276 }
277
278 @Override
279 public void attachTab(Tab tab) {
280 attachTabToContentView(tab);
281 }
282
Michael Kolb377ea312011-02-17 14:36:56 -0800283 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800284 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700285 return;
286 }
287 View container = tab.getViewContainer();
288 WebView mainView = tab.getWebView();
289 // Attach the WebView to the container and then attach the
290 // container to the content view.
291 FrameLayout wrapper =
292 (FrameLayout) container.findViewById(R.id.webview_wrapper);
293 ViewGroup parent = (ViewGroup) mainView.getParent();
294 if (parent != wrapper) {
295 if (parent != null) {
296 Log.w(LOGTAG, "mMainView already has a parent in"
297 + " attachTabToContentView!");
298 parent.removeView(mainView);
299 }
300 wrapper.addView(mainView);
301 } else {
302 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
303 + " attachTabToContentView!");
304 }
305 parent = (ViewGroup) container.getParent();
306 if (parent != mContentView) {
307 if (parent != null) {
308 Log.w(LOGTAG, "mContainer already has a parent in"
309 + " attachTabToContentView!");
310 parent.removeView(container);
311 }
312 mContentView.addView(container, COVER_SCREEN_PARAMS);
313 } else {
314 Log.w(LOGTAG, "mContainer is already attached to content in"
315 + " attachTabToContentView!");
316 }
317 mUiController.attachSubWindow(tab);
318 }
319
320 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800321 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700322 // Remove the container that contains the main WebView.
323 WebView mainView = tab.getWebView();
324 View container = tab.getViewContainer();
325 if (mainView == null) {
326 return;
327 }
328 // Remove the container from the content and then remove the
329 // WebView from the container. This will trigger a focus change
330 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800331 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 FrameLayout wrapper =
333 (FrameLayout) container.findViewById(R.id.webview_wrapper);
334 wrapper.removeView(mainView);
335 mContentView.removeView(container);
336 mUiController.endActionMode();
337 mUiController.removeSubWindow(tab);
338 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
339 if (errorConsole != null) {
340 mErrorConsoleContainer.removeView(errorConsole);
341 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700342 }
343
Michael Kolba713ec82010-11-29 17:27:06 -0800344 @Override
345 public void onSetWebView(Tab tab, WebView webView) {
346 View container = tab.getViewContainer();
347 if (container == null) {
348 // The tab consists of a container view, which contains the main
349 // WebView, as well as any other UI elements associated with the tab.
350 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
351 null);
352 tab.setViewContainer(container);
353 }
354 if (tab.getWebView() != webView) {
355 // Just remove the old one.
356 FrameLayout wrapper =
357 (FrameLayout) container.findViewById(R.id.webview_wrapper);
358 wrapper.removeView(tab.getWebView());
359 }
360 }
361
Michael Kolb8233fac2010-10-26 16:08:53 -0700362 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800363 * create a sub window container and webview for the tab
364 * Note: this methods operates through side-effects for now
365 * it sets both the subView and subViewContainer for the given tab
366 * @param tab tab to create the sub window for
367 * @param subView webview to be set as a subwindow for the tab
368 */
369 @Override
370 public void createSubWindow(Tab tab, WebView subView) {
371 View subViewContainer = mActivity.getLayoutInflater().inflate(
372 R.layout.browser_subwindow, null);
373 ViewGroup inner = (ViewGroup) subViewContainer
374 .findViewById(R.id.inner_container);
375 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
376 LayoutParams.MATCH_PARENT));
377 final ImageButton cancel = (ImageButton) subViewContainer
378 .findViewById(R.id.subwindow_close);
379 final WebView cancelSubView = subView;
380 cancel.setOnClickListener(new OnClickListener() {
381 public void onClick(View v) {
382 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
383 }
384 });
385 tab.setSubWebView(subView);
386 tab.setSubViewContainer(subViewContainer);
387 }
388
389 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700390 * Remove the sub window from the content view.
391 */
392 @Override
393 public void removeSubWindow(View subviewContainer) {
394 mContentView.removeView(subviewContainer);
395 mUiController.endActionMode();
396 }
397
398 /**
399 * Attach the sub window to the content view.
400 */
401 @Override
402 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800403 if (container.getParent() != null) {
404 // already attached, remove first
405 ((ViewGroup) container.getParent()).removeView(container);
406 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700407 mContentView.addView(container, COVER_SCREEN_PARAMS);
408 }
409
Michael Kolb11d19782011-03-20 10:17:40 -0700410 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700411 WebView web = getWebView();
412 if (web != null) {
413 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700414 }
415 }
416
Michael Kolb46f987e2011-04-05 10:39:10 -0700417 public void editUrl(boolean clearInput) {
418 if (mUiController.isInCustomActionMode()) {
419 mUiController.endActionMode();
420 }
421 showTitleBar();
422 getTitleBar().startEditingUrl(clearInput);
423 }
424
Michael Kolb7cdc4902011-02-03 17:54:40 -0800425 boolean canShowTitleBar() {
426 return !isTitleBarShowing()
427 && !isActivityPaused()
428 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700429 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800430 && !mUiController.isInCustomActionMode();
431 }
432
433 void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700434 if (canShowTitleBar()) {
435 getTitleBar().show();
436 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800437 }
438
439 protected void hideTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700440 if (getTitleBar().isShowing()) {
441 getTitleBar().hide();
442 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800443 }
444
445 protected boolean isTitleBarShowing() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700446 return getTitleBar().isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800447 }
448
449 protected abstract TitleBarBase getTitleBar();
450
451 protected void setTitleGravity(int gravity) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700452 WebView web = getWebView();
453 if (web != null) {
454 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700455 }
456 }
457
Michael Kolb66706532010-12-12 19:50:22 -0800458 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700459 public void showVoiceTitleBar(String title, List<String> results) {
460 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800461 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700462 }
463
Michael Kolb66706532010-12-12 19:50:22 -0800464 @Override
465 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700466 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800467 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800468 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700469 }
470
471 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700472 public void registerDropdownChangeListener(DropdownChangeListener d) {
473 getTitleBar().registerDropdownChangeListener(d);
474 }
475
476 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700477 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800478 if (mComboView != null) {
479 return;
480 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700481 mComboView = new CombinedBookmarkHistoryView(mActivity,
482 mUiController,
483 startWithHistory ?
484 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
485 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
486 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800487 FrameLayout wrapper =
488 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
489 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700490 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800491 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700492 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800493 if (mActiveTab != null) {
494 WebView web = mActiveTab.getWebView();
495 mActiveTab.putInBackground();
496 }
John Reck74830e12011-03-14 11:43:05 -0700497 mComboView.setAlpha(0f);
498 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
499 Resources res = mActivity.getResources();
500 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
501 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700502 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
503 }
504
Michael Kolbba238702011-03-08 10:40:50 -0800505 public boolean isComboViewShowing() {
506 return (mComboView != null);
507 }
508
Michael Kolb8233fac2010-10-26 16:08:53 -0700509 /**
510 * dismiss the ComboPage
511 */
512 @Override
513 public void hideComboView() {
514 if (mComboView != null) {
515 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800516 FrameLayout wrapper =
517 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
518 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700519 mComboView = null;
520 }
Michael Kolb3a696282010-12-05 13:23:24 -0800521 if (mActiveTab != null) {
522 mActiveTab.putInForeground();
523 }
John Reckb3417f02011-01-14 11:01:05 -0800524 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700525 }
526
527 @Override
528 public void showCustomView(View view,
529 WebChromeClient.CustomViewCallback callback) {
530 // if a view already exists then immediately terminate the new one
531 if (mCustomView != null) {
532 callback.onCustomViewHidden();
533 return;
534 }
535
536 // Add the custom view to its container.
537 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
538 mCustomView = view;
539 mCustomViewCallback = callback;
540 // Hide the content view.
541 mContentView.setVisibility(View.GONE);
542 // Finally show the custom view container.
543 setStatusBarVisibility(false);
544 mCustomViewContainer.setVisibility(View.VISIBLE);
545 mCustomViewContainer.bringToFront();
546 }
547
548 @Override
549 public void onHideCustomView() {
550 if (mCustomView == null)
551 return;
552
553 // Hide the custom view.
554 mCustomView.setVisibility(View.GONE);
555 // Remove the custom view from its container.
556 mCustomViewContainer.removeView(mCustomView);
557 mCustomView = null;
558 mCustomViewContainer.setVisibility(View.GONE);
559 mCustomViewCallback.onCustomViewHidden();
560 // Show the content view.
561 setStatusBarVisibility(true);
562 mContentView.setVisibility(View.VISIBLE);
563 }
564
565 @Override
566 public boolean isCustomViewShowing() {
567 return mCustomView != null;
568 }
569
Michael Kolb66706532010-12-12 19:50:22 -0800570 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800571 if (mInputManager.isActive()) {
572 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
573 0);
574 }
575 }
576
Michael Kolb66706532010-12-12 19:50:22 -0800577 @Override
578 public boolean showsWeb() {
579 return mCustomView == null
580 && mComboView == null;
581 }
582
Patrick Scott92066772011-03-10 08:46:27 -0500583 @Override
584 public void showAutoLogin(Tab tab) {
585 updateAutoLogin(tab, true);
586 }
587
588 @Override
589 public void hideAutoLogin(Tab tab) {
590 updateAutoLogin(tab, true);
591 }
592
Michael Kolb8233fac2010-10-26 16:08:53 -0700593 // -------------------------------------------------------------------------
594
Michael Kolb5a72f182011-01-13 20:35:06 -0800595 protected void updateNavigationState(Tab tab) {
596 }
597
Michael Kolb11d19782011-03-20 10:17:40 -0700598 protected void updateAutoLogin(Tab tab, boolean animate) {
599 getTitleBar().updateAutoLogin(tab, animate);
600 }
Patrick Scott92066772011-03-10 08:46:27 -0500601
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 /**
603 * Update the lock icon to correspond to our latest state.
604 */
Michael Kolb66706532010-12-12 19:50:22 -0800605 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800606 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 updateLockIconImage(t.getLockIconType());
608 }
609 }
610
611 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 * Updates the lock-icon image in the title-bar.
613 */
John Reck30c714c2010-12-16 17:30:34 -0800614 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800616 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800618 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700619 d = mMixLockIcon;
620 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800621 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 }
623
John Reck30c714c2010-12-16 17:30:34 -0800624 protected void setUrlTitle(Tab tab) {
625 String url = tab.getUrl();
626 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800627 if (TextUtils.isEmpty(title)) {
628 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800629 }
Michael Kolb66706532010-12-12 19:50:22 -0800630 if (tab.isInVoiceSearchMode()) return;
631 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800632 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800633 }
634 }
635
636 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800637 protected void setFavicon(Tab tab) {
638 if (tab.inForeground()) {
639 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800640 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800641 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 }
643
644 @Override
645 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700646 }
647
Michael Kolb66706532010-12-12 19:50:22 -0800648 // active tabs page
649
650 public void showActiveTabsPage() {
651 }
652
653 /**
654 * Remove the active tabs page.
655 */
656 public void removeActiveTabsPage() {
657 }
658
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 // menu handling callbacks
660
661 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800662 public boolean onPrepareOptionsMenu(Menu menu) {
663 return true;
664 }
665
666 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700667 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 }
669
670 @Override
671 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 }
673
674 @Override
675 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 }
677
678 @Override
679 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700680 }
681
682 @Override
683 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700684 }
685
686 @Override
687 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700688 }
689
690 // error console
691
692 @Override
693 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800694 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700695 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
696 if (flag) {
697 // Setting the show state of the console will cause it's the layout
698 // to be inflated.
699 if (errorConsole.numberOfErrors() > 0) {
700 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
701 } else {
702 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
703 }
704 if (errorConsole.getParent() != null) {
705 mErrorConsoleContainer.removeView(errorConsole);
706 }
707 // Now we can add it to the main view.
708 mErrorConsoleContainer.addView(errorConsole,
709 new LinearLayout.LayoutParams(
710 ViewGroup.LayoutParams.MATCH_PARENT,
711 ViewGroup.LayoutParams.WRAP_CONTENT));
712 } else {
713 mErrorConsoleContainer.removeView(errorConsole);
714 }
715 }
716
717 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800718 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
719 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
720 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700721 }
722
Michael Kolb8233fac2010-10-26 16:08:53 -0700723 // -------------------------------------------------------------------------
724 // Helper function for WebChromeClient
725 // -------------------------------------------------------------------------
726
727 @Override
728 public Bitmap getDefaultVideoPoster() {
729 if (mDefaultVideoPoster == null) {
730 mDefaultVideoPoster = BitmapFactory.decodeResource(
731 mActivity.getResources(), R.drawable.default_video_poster);
732 }
733 return mDefaultVideoPoster;
734 }
735
736 @Override
737 public View getVideoLoadingProgressView() {
738 if (mVideoProgressView == null) {
739 LayoutInflater inflater = LayoutInflater.from(mActivity);
740 mVideoProgressView = inflater.inflate(
741 R.layout.video_loading_progress, null);
742 }
743 return mVideoProgressView;
744 }
745
Michael Kolb843510f2010-12-09 10:51:49 -0800746 @Override
747 public void showMaxTabsWarning() {
748 Toast warning = Toast.makeText(mActivity,
749 mActivity.getString(R.string.max_tabs_warning),
750 Toast.LENGTH_SHORT);
751 warning.show();
752 }
753
Michael Kolbfdb70242011-03-24 09:41:11 -0700754 protected void captureTab(final Tab tab) {
755 captureTab(tab,
756 (int) mActivity.getResources()
757 .getDimension(R.dimen.qc_thumb_width),
758 (int) mActivity.getResources()
759 .getDimension(R.dimen.qc_thumb_height));
760 }
761
762 protected void captureTab(final Tab tab, int width, int height) {
763 if ((tab == null) || (tab.getWebView() == null)) return;
764 Bitmap sshot = Controller.createScreenshot(tab, width, height);
765 tab.setScreenshot(sshot);
766 }
767
Michael Kolb46f987e2011-04-05 10:39:10 -0700768 protected WebView getWebView() {
769 if (mActiveTab != null) {
770 return mActiveTab.getWebView();
771 } else {
772 return null;
773 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700774 }
775
Michael Kolb8233fac2010-10-26 16:08:53 -0700776}