blob: 43bc7d693e2dd7dcf671c57c6a736e3aa1868171 [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 Kolbf2055602011-04-09 17:20:03 -070079 protected 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() {
John Reck847b5322011-04-14 17:02:18 -0700229 return true;
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 Kolbd463a722011-04-08 10:17:49 -0700452 // update the titlebar layout params
453 // required to avoid scroll to top when focused
454 getTitleBar().setTitleGravity(gravity);
Michael Kolb46f987e2011-04-05 10:39:10 -0700455 WebView web = getWebView();
456 if (web != null) {
457 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700458 }
459 }
460
Michael Kolb66706532010-12-12 19:50:22 -0800461 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700462 public void showVoiceTitleBar(String title, List<String> results) {
463 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800464 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700465 }
466
Michael Kolb66706532010-12-12 19:50:22 -0800467 @Override
468 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700469 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800470 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800471 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 }
473
474 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700475 public void registerDropdownChangeListener(DropdownChangeListener d) {
476 getTitleBar().registerDropdownChangeListener(d);
477 }
478
479 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700480 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800481 if (mComboView != null) {
482 return;
483 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700484 mComboView = new CombinedBookmarkHistoryView(mActivity,
485 mUiController,
486 startWithHistory ?
487 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
488 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
489 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800490 FrameLayout wrapper =
491 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
492 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700493 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800494 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700495 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800496 if (mActiveTab != null) {
497 WebView web = mActiveTab.getWebView();
498 mActiveTab.putInBackground();
499 }
John Reck74830e12011-03-14 11:43:05 -0700500 mComboView.setAlpha(0f);
501 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
502 Resources res = mActivity.getResources();
503 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
504 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700505 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
506 }
507
Michael Kolbba238702011-03-08 10:40:50 -0800508 public boolean isComboViewShowing() {
509 return (mComboView != null);
510 }
511
Michael Kolb8233fac2010-10-26 16:08:53 -0700512 /**
513 * dismiss the ComboPage
514 */
515 @Override
516 public void hideComboView() {
517 if (mComboView != null) {
518 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800519 FrameLayout wrapper =
520 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
521 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700522 mComboView = null;
523 }
Michael Kolb3a696282010-12-05 13:23:24 -0800524 if (mActiveTab != null) {
525 mActiveTab.putInForeground();
526 }
John Reckb3417f02011-01-14 11:01:05 -0800527 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700528 }
529
530 @Override
531 public void showCustomView(View view,
532 WebChromeClient.CustomViewCallback callback) {
533 // if a view already exists then immediately terminate the new one
534 if (mCustomView != null) {
535 callback.onCustomViewHidden();
536 return;
537 }
538
539 // Add the custom view to its container.
540 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
541 mCustomView = view;
542 mCustomViewCallback = callback;
543 // Hide the content view.
544 mContentView.setVisibility(View.GONE);
545 // Finally show the custom view container.
546 setStatusBarVisibility(false);
547 mCustomViewContainer.setVisibility(View.VISIBLE);
548 mCustomViewContainer.bringToFront();
549 }
550
551 @Override
552 public void onHideCustomView() {
553 if (mCustomView == null)
554 return;
555
556 // Hide the custom view.
557 mCustomView.setVisibility(View.GONE);
558 // Remove the custom view from its container.
559 mCustomViewContainer.removeView(mCustomView);
560 mCustomView = null;
561 mCustomViewContainer.setVisibility(View.GONE);
562 mCustomViewCallback.onCustomViewHidden();
563 // Show the content view.
564 setStatusBarVisibility(true);
565 mContentView.setVisibility(View.VISIBLE);
566 }
567
568 @Override
569 public boolean isCustomViewShowing() {
570 return mCustomView != null;
571 }
572
Michael Kolb66706532010-12-12 19:50:22 -0800573 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800574 if (mInputManager.isActive()) {
575 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
576 0);
577 }
578 }
579
Michael Kolb66706532010-12-12 19:50:22 -0800580 @Override
581 public boolean showsWeb() {
582 return mCustomView == null
583 && mComboView == null;
584 }
585
Patrick Scott92066772011-03-10 08:46:27 -0500586 @Override
587 public void showAutoLogin(Tab tab) {
588 updateAutoLogin(tab, true);
589 }
590
591 @Override
592 public void hideAutoLogin(Tab tab) {
593 updateAutoLogin(tab, true);
594 }
595
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 // -------------------------------------------------------------------------
597
Michael Kolb5a72f182011-01-13 20:35:06 -0800598 protected void updateNavigationState(Tab tab) {
599 }
600
Michael Kolb11d19782011-03-20 10:17:40 -0700601 protected void updateAutoLogin(Tab tab, boolean animate) {
602 getTitleBar().updateAutoLogin(tab, animate);
603 }
Patrick Scott92066772011-03-10 08:46:27 -0500604
Michael Kolb8233fac2010-10-26 16:08:53 -0700605 /**
606 * Update the lock icon to correspond to our latest state.
607 */
Michael Kolb66706532010-12-12 19:50:22 -0800608 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800609 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700610 updateLockIconImage(t.getLockIconType());
611 }
612 }
613
614 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 * Updates the lock-icon image in the title-bar.
616 */
John Reck30c714c2010-12-16 17:30:34 -0800617 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700618 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800619 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800621 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 d = mMixLockIcon;
623 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800624 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 }
626
John Reck30c714c2010-12-16 17:30:34 -0800627 protected void setUrlTitle(Tab tab) {
628 String url = tab.getUrl();
629 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800630 if (TextUtils.isEmpty(title)) {
631 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800632 }
Michael Kolb66706532010-12-12 19:50:22 -0800633 if (tab.isInVoiceSearchMode()) return;
634 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800635 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800636 }
637 }
638
639 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800640 protected void setFavicon(Tab tab) {
641 if (tab.inForeground()) {
642 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800643 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800644 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700645 }
646
647 @Override
648 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700649 }
650
Michael Kolb66706532010-12-12 19:50:22 -0800651 // active tabs page
652
653 public void showActiveTabsPage() {
654 }
655
656 /**
657 * Remove the active tabs page.
658 */
659 public void removeActiveTabsPage() {
660 }
661
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 // menu handling callbacks
663
664 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800665 public boolean onPrepareOptionsMenu(Menu menu) {
666 return true;
667 }
668
669 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700670 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 }
672
673 @Override
674 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700675 }
676
677 @Override
678 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700679 }
680
681 @Override
682 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700683 }
684
685 @Override
686 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700687 }
688
689 @Override
690 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700691 }
692
693 // error console
694
695 @Override
696 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800697 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700698 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
699 if (flag) {
700 // Setting the show state of the console will cause it's the layout
701 // to be inflated.
702 if (errorConsole.numberOfErrors() > 0) {
703 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
704 } else {
705 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
706 }
707 if (errorConsole.getParent() != null) {
708 mErrorConsoleContainer.removeView(errorConsole);
709 }
710 // Now we can add it to the main view.
711 mErrorConsoleContainer.addView(errorConsole,
712 new LinearLayout.LayoutParams(
713 ViewGroup.LayoutParams.MATCH_PARENT,
714 ViewGroup.LayoutParams.WRAP_CONTENT));
715 } else {
716 mErrorConsoleContainer.removeView(errorConsole);
717 }
718 }
719
720 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800721 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
722 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
723 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700724 }
725
Michael Kolb8233fac2010-10-26 16:08:53 -0700726 // -------------------------------------------------------------------------
727 // Helper function for WebChromeClient
728 // -------------------------------------------------------------------------
729
730 @Override
731 public Bitmap getDefaultVideoPoster() {
732 if (mDefaultVideoPoster == null) {
733 mDefaultVideoPoster = BitmapFactory.decodeResource(
734 mActivity.getResources(), R.drawable.default_video_poster);
735 }
736 return mDefaultVideoPoster;
737 }
738
739 @Override
740 public View getVideoLoadingProgressView() {
741 if (mVideoProgressView == null) {
742 LayoutInflater inflater = LayoutInflater.from(mActivity);
743 mVideoProgressView = inflater.inflate(
744 R.layout.video_loading_progress, null);
745 }
746 return mVideoProgressView;
747 }
748
Michael Kolb843510f2010-12-09 10:51:49 -0800749 @Override
750 public void showMaxTabsWarning() {
751 Toast warning = Toast.makeText(mActivity,
752 mActivity.getString(R.string.max_tabs_warning),
753 Toast.LENGTH_SHORT);
754 warning.show();
755 }
756
Michael Kolbfdb70242011-03-24 09:41:11 -0700757 protected void captureTab(final Tab tab) {
758 captureTab(tab,
759 (int) mActivity.getResources()
760 .getDimension(R.dimen.qc_thumb_width),
761 (int) mActivity.getResources()
762 .getDimension(R.dimen.qc_thumb_height));
763 }
764
765 protected void captureTab(final Tab tab, int width, int height) {
766 if ((tab == null) || (tab.getWebView() == null)) return;
767 Bitmap sshot = Controller.createScreenshot(tab, width, height);
768 tab.setScreenshot(sshot);
769 }
770
Michael Kolb46f987e2011-04-05 10:39:10 -0700771 protected WebView getWebView() {
772 if (mActiveTab != null) {
773 return mActiveTab.getWebView();
774 } else {
775 return null;
776 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700777 }
778
Michael Kolb8233fac2010-10-26 16:08:53 -0700779}