blob: 5bb4c1f121901114ceba407c093e05e45713ca11 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
Michael Kolbfedb4922011-04-20 16:45:33 -070020import com.android.internal.view.menu.MenuBuilder;
John Reck30c714c2010-12-16 17:30:34 -080021
John Reck74830e12011-03-14 11:43:05 -070022import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070024import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.res.Configuration;
26import android.content.res.Resources;
27import android.graphics.Bitmap;
28import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070029import android.graphics.drawable.Drawable;
30import android.os.Bundle;
31import android.text.TextUtils;
32import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.view.Gravity;
34import android.view.LayoutInflater;
35import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080037import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080039import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080041import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.webkit.WebView;
44import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080045import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.widget.LinearLayout;
47import android.widget.Toast;
48
Michael Kolb1bf23132010-11-19 12:55:12 -080049import java.util.List;
50
Michael Kolb8233fac2010-10-26 16:08:53 -070051/**
52 * UI interface definitions
53 */
Michael Kolb66706532010-12-12 19:50:22 -080054public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070055
56 private static final String LOGTAG = "BaseUi";
57
Michael Kolb66706532010-12-12 19:50:22 -080058 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070059 new FrameLayout.LayoutParams(
60 ViewGroup.LayoutParams.MATCH_PARENT,
61 ViewGroup.LayoutParams.MATCH_PARENT);
62
Michael Kolb66706532010-12-12 19:50:22 -080063 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070064 new FrameLayout.LayoutParams(
65 ViewGroup.LayoutParams.MATCH_PARENT,
66 ViewGroup.LayoutParams.MATCH_PARENT,
67 Gravity.CENTER);
68
69 Activity mActivity;
70 UiController mUiController;
71 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080072 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080073 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070074
75 private Drawable mSecLockIcon;
76 private Drawable mMixLockIcon;
77
Michael Kolb8233fac2010-10-26 16:08:53 -070078 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080079 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070080 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070081
82 private View mCustomView;
83 private WebChromeClient.CustomViewCallback mCustomViewCallback;
84
85 private CombinedBookmarkHistoryView mComboView;
86
87 private LinearLayout mErrorConsoleContainer = null;
88
89 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070090
91 // the default <video> poster
92 private Bitmap mDefaultVideoPoster;
93 // the video progress view
94 private View mVideoProgressView;
95
Michael Kolb8233fac2010-10-26 16:08:53 -070096 private boolean mActivityPaused;
97
98 public BaseUi(Activity browser, UiController controller) {
99 mActivity = browser;
100 mUiController = controller;
101 mTabControl = controller.getTabControl();
102 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800103 mInputManager = (InputMethodManager)
104 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800105 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
107
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
109 .getDecorView().findViewById(android.R.id.content);
110 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
111 .inflate(R.layout.custom_screen, null);
112 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
113 R.id.main_content);
114 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
115 .findViewById(R.id.error_console);
116 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
117 .findViewById(R.id.fullscreen_custom_content);
118 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700119 }
120
John Reckb9a051b2011-03-18 11:55:48 -0700121 @Override
122 public WebView createWebView(boolean privateBrowsing) {
123 // Create a new WebView
124 BrowserWebView w = new BrowserWebView(mActivity, null,
125 android.R.attr.webViewStyle, privateBrowsing);
126 initWebViewSettings(w);
127 return w;
128 }
129
130 @Override
131 public WebView createSubWebView(boolean privateBrowsing) {
132 return createWebView(privateBrowsing);
133 }
134
Michael Kolb66706532010-12-12 19:50:22 -0800135 /**
136 * common webview initialization
137 * @param w the webview to initialize
138 */
139 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700140 w.setScrollbarFadingEnabled(true);
141 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
142 w.setMapTrackballToArrowKeys(false); // use trackball directly
143 // Enable the built-in zoom
144 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700145 boolean supportsMultiTouch = mActivity.getPackageManager()
146 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
147 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
148 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700149
150 // Add this WebView to the settings observer list and update the
151 // settings
152 final BrowserSettings s = BrowserSettings.getInstance();
John Reck35e9dd62011-04-25 09:01:54 -0700153 s.startManagingSettings(w.getSettings());
Michael Kolb8233fac2010-10-26 16:08:53 -0700154 }
155
156 private void cancelStopToast() {
157 if (mStopToast != null) {
158 mStopToast.cancel();
159 mStopToast = null;
160 }
161 }
162
163 // lifecycle
164
165 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800166 if (isCustomViewShowing()) {
167 onHideCustomView();
168 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700169 cancelStopToast();
170 mActivityPaused = true;
171 }
172
173 public void onResume() {
174 mActivityPaused = false;
175 }
176
Michael Kolb66706532010-12-12 19:50:22 -0800177 protected boolean isActivityPaused() {
178 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700179 }
180
181 public void onConfigurationChanged(Configuration config) {
182 }
183
184 // key handling
185
186 @Override
187 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 if (mComboView != null) {
189 if (!mComboView.onBackPressed()) {
190 mUiController.removeComboView();
191 }
192 return true;
193 }
194 if (mCustomView != null) {
195 mUiController.hideCustomView();
196 return true;
197 }
198 return false;
199 }
200
John Reck30c714c2010-12-16 17:30:34 -0800201 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 @Override
John Reck30c714c2010-12-16 17:30:34 -0800203 public void onTabDataChanged(Tab tab) {
204 setUrlTitle(tab);
205 setFavicon(tab);
206 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800207 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700208 }
209
210 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500211 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800212 if (tab.inForeground()) {
213 boolean isBookmark = tab.isBookmarkedSite();
214 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
215 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500216 }
217
218 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 public void onPageStopped(Tab tab) {
220 cancelStopToast();
221 if (tab.inForeground()) {
222 mStopToast = Toast
223 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
224 mStopToast.show();
225 }
226 }
227
228 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800229 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700230 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800231 }
232
233 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 }
236
237 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800238 public void setActiveTab(final Tab tab) {
239 setActiveTab(tab, true);
240 }
241
242 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800243 if ((tab != mActiveTab) && (mActiveTab != null)) {
244 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700245 }
Michael Kolb77df4562010-11-19 14:49:34 -0800246 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800247 if (needsAttaching) {
248 attachTabToContentView(tab);
249 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800251 onTabDataChanged(tab);
252 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800253 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800254 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500255 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 }
257
Michael Kolbcfa3af52010-12-14 10:36:11 -0800258 Tab getActiveTab() {
259 return mActiveTab;
260 }
261
Michael Kolb8233fac2010-10-26 16:08:53 -0700262 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800263 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800264 }
265
266 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700267 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800268 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800270 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 }
273
274 @Override
275 public void detachTab(Tab tab) {
276 removeTabFromContentView(tab);
277 }
278
279 @Override
280 public void attachTab(Tab tab) {
281 attachTabToContentView(tab);
282 }
283
Michael Kolb377ea312011-02-17 14:36:56 -0800284 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800285 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700286 return;
287 }
288 View container = tab.getViewContainer();
289 WebView mainView = tab.getWebView();
290 // Attach the WebView to the container and then attach the
291 // container to the content view.
292 FrameLayout wrapper =
293 (FrameLayout) container.findViewById(R.id.webview_wrapper);
294 ViewGroup parent = (ViewGroup) mainView.getParent();
295 if (parent != wrapper) {
296 if (parent != null) {
297 Log.w(LOGTAG, "mMainView already has a parent in"
298 + " attachTabToContentView!");
299 parent.removeView(mainView);
300 }
301 wrapper.addView(mainView);
302 } else {
303 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
304 + " attachTabToContentView!");
305 }
306 parent = (ViewGroup) container.getParent();
307 if (parent != mContentView) {
308 if (parent != null) {
309 Log.w(LOGTAG, "mContainer already has a parent in"
310 + " attachTabToContentView!");
311 parent.removeView(container);
312 }
313 mContentView.addView(container, COVER_SCREEN_PARAMS);
314 } else {
315 Log.w(LOGTAG, "mContainer is already attached to content in"
316 + " attachTabToContentView!");
317 }
318 mUiController.attachSubWindow(tab);
319 }
320
321 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800322 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700323 // Remove the container that contains the main WebView.
324 WebView mainView = tab.getWebView();
325 View container = tab.getViewContainer();
326 if (mainView == null) {
327 return;
328 }
329 // Remove the container from the content and then remove the
330 // WebView from the container. This will trigger a focus change
331 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800332 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700333 FrameLayout wrapper =
334 (FrameLayout) container.findViewById(R.id.webview_wrapper);
335 wrapper.removeView(mainView);
336 mContentView.removeView(container);
337 mUiController.endActionMode();
338 mUiController.removeSubWindow(tab);
339 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
340 if (errorConsole != null) {
341 mErrorConsoleContainer.removeView(errorConsole);
342 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700343 }
344
Michael Kolba713ec82010-11-29 17:27:06 -0800345 @Override
346 public void onSetWebView(Tab tab, WebView webView) {
347 View container = tab.getViewContainer();
348 if (container == null) {
349 // The tab consists of a container view, which contains the main
350 // WebView, as well as any other UI elements associated with the tab.
351 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
352 null);
353 tab.setViewContainer(container);
354 }
355 if (tab.getWebView() != webView) {
356 // Just remove the old one.
357 FrameLayout wrapper =
358 (FrameLayout) container.findViewById(R.id.webview_wrapper);
359 wrapper.removeView(tab.getWebView());
360 }
361 }
362
Michael Kolb8233fac2010-10-26 16:08:53 -0700363 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800364 * create a sub window container and webview for the tab
365 * Note: this methods operates through side-effects for now
366 * it sets both the subView and subViewContainer for the given tab
367 * @param tab tab to create the sub window for
368 * @param subView webview to be set as a subwindow for the tab
369 */
370 @Override
371 public void createSubWindow(Tab tab, WebView subView) {
372 View subViewContainer = mActivity.getLayoutInflater().inflate(
373 R.layout.browser_subwindow, null);
374 ViewGroup inner = (ViewGroup) subViewContainer
375 .findViewById(R.id.inner_container);
376 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
377 LayoutParams.MATCH_PARENT));
378 final ImageButton cancel = (ImageButton) subViewContainer
379 .findViewById(R.id.subwindow_close);
380 final WebView cancelSubView = subView;
381 cancel.setOnClickListener(new OnClickListener() {
382 public void onClick(View v) {
383 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
384 }
385 });
386 tab.setSubWebView(subView);
387 tab.setSubViewContainer(subViewContainer);
388 }
389
390 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700391 * Remove the sub window from the content view.
392 */
393 @Override
394 public void removeSubWindow(View subviewContainer) {
395 mContentView.removeView(subviewContainer);
396 mUiController.endActionMode();
397 }
398
399 /**
400 * Attach the sub window to the content view.
401 */
402 @Override
403 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800404 if (container.getParent() != null) {
405 // already attached, remove first
406 ((ViewGroup) container.getParent()).removeView(container);
407 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700408 mContentView.addView(container, COVER_SCREEN_PARAMS);
409 }
410
Michael Kolb11d19782011-03-20 10:17:40 -0700411 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700412 WebView web = getWebView();
413 if (web != null) {
414 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700415 }
416 }
417
Michael Kolb46f987e2011-04-05 10:39:10 -0700418 public void editUrl(boolean clearInput) {
419 if (mUiController.isInCustomActionMode()) {
420 mUiController.endActionMode();
421 }
422 showTitleBar();
423 getTitleBar().startEditingUrl(clearInput);
424 }
425
Michael Kolb7cdc4902011-02-03 17:54:40 -0800426 boolean canShowTitleBar() {
427 return !isTitleBarShowing()
428 && !isActivityPaused()
429 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700430 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800431 && !mUiController.isInCustomActionMode();
432 }
433
434 void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700435 if (canShowTitleBar()) {
436 getTitleBar().show();
437 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800438 }
439
440 protected void hideTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700441 if (getTitleBar().isShowing()) {
442 getTitleBar().hide();
443 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800444 }
445
446 protected boolean isTitleBarShowing() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700447 return getTitleBar().isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800448 }
449
450 protected abstract TitleBarBase getTitleBar();
451
452 protected void setTitleGravity(int gravity) {
Michael Kolbd463a722011-04-08 10:17:49 -0700453 // update the titlebar layout params
454 // required to avoid scroll to top when focused
455 getTitleBar().setTitleGravity(gravity);
Michael Kolb46f987e2011-04-05 10:39:10 -0700456 WebView web = getWebView();
457 if (web != null) {
458 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700459 }
460 }
461
Michael Kolb66706532010-12-12 19:50:22 -0800462 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700463 public void showVoiceTitleBar(String title, List<String> results) {
464 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800465 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700466 }
467
Michael Kolb66706532010-12-12 19:50:22 -0800468 @Override
469 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700470 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800471 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800472 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700473 }
474
475 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700476 public void registerDropdownChangeListener(DropdownChangeListener d) {
477 getTitleBar().registerDropdownChangeListener(d);
478 }
479
480 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700481 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800482 if (mComboView != null) {
483 return;
484 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700485 mComboView = new CombinedBookmarkHistoryView(mActivity,
486 mUiController,
487 startWithHistory ?
488 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
489 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
490 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800491 FrameLayout wrapper =
492 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
493 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700494 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800495 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700496 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800497 if (mActiveTab != null) {
498 WebView web = mActiveTab.getWebView();
499 mActiveTab.putInBackground();
500 }
John Reck74830e12011-03-14 11:43:05 -0700501 mComboView.setAlpha(0f);
502 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
503 Resources res = mActivity.getResources();
504 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
505 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700506 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
507 }
508
Michael Kolbba238702011-03-08 10:40:50 -0800509 public boolean isComboViewShowing() {
510 return (mComboView != null);
511 }
512
Michael Kolb8233fac2010-10-26 16:08:53 -0700513 /**
514 * dismiss the ComboPage
515 */
516 @Override
517 public void hideComboView() {
518 if (mComboView != null) {
519 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800520 FrameLayout wrapper =
521 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
522 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700523 mComboView = null;
524 }
Michael Kolb3a696282010-12-05 13:23:24 -0800525 if (mActiveTab != null) {
526 mActiveTab.putInForeground();
527 }
John Reckb3417f02011-01-14 11:01:05 -0800528 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700529 }
530
531 @Override
532 public void showCustomView(View view,
533 WebChromeClient.CustomViewCallback callback) {
534 // if a view already exists then immediately terminate the new one
535 if (mCustomView != null) {
536 callback.onCustomViewHidden();
537 return;
538 }
539
540 // Add the custom view to its container.
541 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
542 mCustomView = view;
543 mCustomViewCallback = callback;
544 // Hide the content view.
545 mContentView.setVisibility(View.GONE);
546 // Finally show the custom view container.
547 setStatusBarVisibility(false);
548 mCustomViewContainer.setVisibility(View.VISIBLE);
549 mCustomViewContainer.bringToFront();
550 }
551
552 @Override
553 public void onHideCustomView() {
554 if (mCustomView == null)
555 return;
556
557 // Hide the custom view.
558 mCustomView.setVisibility(View.GONE);
559 // Remove the custom view from its container.
560 mCustomViewContainer.removeView(mCustomView);
561 mCustomView = null;
562 mCustomViewContainer.setVisibility(View.GONE);
563 mCustomViewCallback.onCustomViewHidden();
564 // Show the content view.
565 setStatusBarVisibility(true);
566 mContentView.setVisibility(View.VISIBLE);
567 }
568
569 @Override
570 public boolean isCustomViewShowing() {
571 return mCustomView != null;
572 }
573
Michael Kolb66706532010-12-12 19:50:22 -0800574 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800575 if (mInputManager.isActive()) {
576 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
577 0);
578 }
579 }
580
Michael Kolb66706532010-12-12 19:50:22 -0800581 @Override
582 public boolean showsWeb() {
583 return mCustomView == null
584 && mComboView == null;
585 }
586
Patrick Scott92066772011-03-10 08:46:27 -0500587 @Override
588 public void showAutoLogin(Tab tab) {
589 updateAutoLogin(tab, true);
590 }
591
592 @Override
593 public void hideAutoLogin(Tab tab) {
594 updateAutoLogin(tab, true);
595 }
596
Michael Kolb8233fac2010-10-26 16:08:53 -0700597 // -------------------------------------------------------------------------
598
Michael Kolb5a72f182011-01-13 20:35:06 -0800599 protected void updateNavigationState(Tab tab) {
600 }
601
Michael Kolb11d19782011-03-20 10:17:40 -0700602 protected void updateAutoLogin(Tab tab, boolean animate) {
603 getTitleBar().updateAutoLogin(tab, animate);
604 }
Patrick Scott92066772011-03-10 08:46:27 -0500605
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 /**
607 * Update the lock icon to correspond to our latest state.
608 */
Michael Kolb66706532010-12-12 19:50:22 -0800609 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800610 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 updateLockIconImage(t.getLockIconType());
612 }
613 }
614
615 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 * Updates the lock-icon image in the title-bar.
617 */
John Reck30c714c2010-12-16 17:30:34 -0800618 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700619 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800620 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700621 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800622 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700623 d = mMixLockIcon;
624 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800625 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700626 }
627
John Reck30c714c2010-12-16 17:30:34 -0800628 protected void setUrlTitle(Tab tab) {
629 String url = tab.getUrl();
630 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800631 if (TextUtils.isEmpty(title)) {
632 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800633 }
Michael Kolb66706532010-12-12 19:50:22 -0800634 if (tab.isInVoiceSearchMode()) return;
635 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800636 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800637 }
638 }
639
640 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800641 protected void setFavicon(Tab tab) {
642 if (tab.inForeground()) {
643 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800644 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800645 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700646 }
647
648 @Override
649 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700650 }
651
Michael Kolb66706532010-12-12 19:50:22 -0800652 // active tabs page
653
654 public void showActiveTabsPage() {
655 }
656
657 /**
658 * Remove the active tabs page.
659 */
660 public void removeActiveTabsPage() {
661 }
662
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 // menu handling callbacks
664
665 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800666 public boolean onPrepareOptionsMenu(Menu menu) {
667 return true;
668 }
669
670 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 }
673
674 @Override
675 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 }
677
678 @Override
679 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700680 }
681
682 @Override
683 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700684 }
685
686 @Override
687 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700688 }
689
690 @Override
691 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700692 }
693
694 // error console
695
696 @Override
697 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800698 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
700 if (flag) {
701 // Setting the show state of the console will cause it's the layout
702 // to be inflated.
703 if (errorConsole.numberOfErrors() > 0) {
704 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
705 } else {
706 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
707 }
708 if (errorConsole.getParent() != null) {
709 mErrorConsoleContainer.removeView(errorConsole);
710 }
711 // Now we can add it to the main view.
712 mErrorConsoleContainer.addView(errorConsole,
713 new LinearLayout.LayoutParams(
714 ViewGroup.LayoutParams.MATCH_PARENT,
715 ViewGroup.LayoutParams.WRAP_CONTENT));
716 } else {
717 mErrorConsoleContainer.removeView(errorConsole);
718 }
719 }
720
721 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800722 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
723 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
724 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 }
726
Michael Kolb8233fac2010-10-26 16:08:53 -0700727 // -------------------------------------------------------------------------
728 // Helper function for WebChromeClient
729 // -------------------------------------------------------------------------
730
731 @Override
732 public Bitmap getDefaultVideoPoster() {
733 if (mDefaultVideoPoster == null) {
734 mDefaultVideoPoster = BitmapFactory.decodeResource(
735 mActivity.getResources(), R.drawable.default_video_poster);
736 }
737 return mDefaultVideoPoster;
738 }
739
740 @Override
741 public View getVideoLoadingProgressView() {
742 if (mVideoProgressView == null) {
743 LayoutInflater inflater = LayoutInflater.from(mActivity);
744 mVideoProgressView = inflater.inflate(
745 R.layout.video_loading_progress, null);
746 }
747 return mVideoProgressView;
748 }
749
Michael Kolb843510f2010-12-09 10:51:49 -0800750 @Override
751 public void showMaxTabsWarning() {
752 Toast warning = Toast.makeText(mActivity,
753 mActivity.getString(R.string.max_tabs_warning),
754 Toast.LENGTH_SHORT);
755 warning.show();
756 }
757
Michael Kolbfdb70242011-03-24 09:41:11 -0700758 protected void captureTab(final Tab tab) {
759 captureTab(tab,
760 (int) mActivity.getResources()
761 .getDimension(R.dimen.qc_thumb_width),
762 (int) mActivity.getResources()
763 .getDimension(R.dimen.qc_thumb_height));
764 }
765
766 protected void captureTab(final Tab tab, int width, int height) {
767 if ((tab == null) || (tab.getWebView() == null)) return;
768 Bitmap sshot = Controller.createScreenshot(tab, width, height);
769 tab.setScreenshot(sshot);
770 }
771
Michael Kolb46f987e2011-04-05 10:39:10 -0700772 protected WebView getWebView() {
773 if (mActiveTab != null) {
774 return mActiveTab.getWebView();
775 } else {
776 return null;
777 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700778 }
779
Michael Kolbfedb4922011-04-20 16:45:33 -0700780 protected Menu getMenu() {
781 MenuBuilder menu = new MenuBuilder(mActivity);
782 mActivity.getMenuInflater().inflate(R.menu.browser, menu);
783 return menu;
784 }
785
Michael Kolb8233fac2010-10-26 16:08:53 -0700786}