blob: e2fea168e742345ae08e5692a2f7b8dc449c47d9 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
Michael Kolbfedb4922011-04-20 16:45:33 -070020import com.android.internal.view.menu.MenuBuilder;
John Reck30c714c2010-12-16 17:30:34 -080021
John Reck74830e12011-03-14 11:43:05 -070022import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070024import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.res.Configuration;
26import android.content.res.Resources;
27import android.graphics.Bitmap;
28import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.Color;
30import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070032import android.graphics.drawable.LayerDrawable;
33import android.graphics.drawable.PaintDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.os.Bundle;
35import android.text.TextUtils;
36import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.Gravity;
38import android.view.LayoutInflater;
39import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080041import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.webkit.WebView;
48import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080049import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.LinearLayout;
51import android.widget.Toast;
52
Michael Kolb1bf23132010-11-19 12:55:12 -080053import java.util.List;
54
Michael Kolb8233fac2010-10-26 16:08:53 -070055/**
56 * UI interface definitions
57 */
Michael Kolb66706532010-12-12 19:50:22 -080058public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070059
60 private static final String LOGTAG = "BaseUi";
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT);
66
Michael Kolb66706532010-12-12 19:50:22 -080067 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070068 new FrameLayout.LayoutParams(
69 ViewGroup.LayoutParams.MATCH_PARENT,
70 ViewGroup.LayoutParams.MATCH_PARENT,
71 Gravity.CENTER);
72
73 Activity mActivity;
74 UiController mUiController;
75 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080076 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080077 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070078
79 private Drawable mSecLockIcon;
80 private Drawable mMixLockIcon;
Michael Kolb5a4372f2011-04-29 13:53:10 -070081 protected Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080084 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070085 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070086
87 private View mCustomView;
88 private WebChromeClient.CustomViewCallback mCustomViewCallback;
89
90 private CombinedBookmarkHistoryView mComboView;
91
92 private LinearLayout mErrorConsoleContainer = null;
93
94 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
Michael Kolb5a4372f2011-04-29 13:53:10 -070096
Michael Kolb8233fac2010-10-26 16:08:53 -070097 // the default <video> poster
98 private Bitmap mDefaultVideoPoster;
99 // the video progress view
100 private View mVideoProgressView;
101
Michael Kolb8233fac2010-10-26 16:08:53 -0700102 private boolean mActivityPaused;
103
104 public BaseUi(Activity browser, UiController controller) {
105 mActivity = browser;
106 mUiController = controller;
107 mTabControl = controller.getTabControl();
108 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800109 mInputManager = (InputMethodManager)
110 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800111 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
113
Michael Kolb8233fac2010-10-26 16:08:53 -0700114 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
115 .getDecorView().findViewById(android.R.id.content);
116 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
117 .inflate(R.layout.custom_screen, null);
118 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
119 R.id.main_content);
120 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
121 .findViewById(R.id.error_console);
122 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
123 .findViewById(R.id.fullscreen_custom_content);
124 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolbc38c6042011-04-27 10:46:06 -0700125 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700126 mGenericFavicon = res.getDrawable(
127 R.drawable.app_web_browser_sm);
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 }
129
John Reckb9a051b2011-03-18 11:55:48 -0700130 @Override
131 public WebView createWebView(boolean privateBrowsing) {
132 // Create a new WebView
133 BrowserWebView w = new BrowserWebView(mActivity, null,
134 android.R.attr.webViewStyle, privateBrowsing);
135 initWebViewSettings(w);
136 return w;
137 }
138
139 @Override
140 public WebView createSubWebView(boolean privateBrowsing) {
141 return createWebView(privateBrowsing);
142 }
143
Michael Kolb66706532010-12-12 19:50:22 -0800144 /**
145 * common webview initialization
146 * @param w the webview to initialize
147 */
148 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700149 w.setScrollbarFadingEnabled(true);
150 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
151 w.setMapTrackballToArrowKeys(false); // use trackball directly
152 // Enable the built-in zoom
153 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700154 boolean supportsMultiTouch = mActivity.getPackageManager()
155 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
156 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
157 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700158
159 // Add this WebView to the settings observer list and update the
160 // settings
161 final BrowserSettings s = BrowserSettings.getInstance();
John Reck35e9dd62011-04-25 09:01:54 -0700162 s.startManagingSettings(w.getSettings());
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 }
164
165 private void cancelStopToast() {
166 if (mStopToast != null) {
167 mStopToast.cancel();
168 mStopToast = null;
169 }
170 }
171
172 // lifecycle
173
174 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800175 if (isCustomViewShowing()) {
176 onHideCustomView();
177 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 cancelStopToast();
179 mActivityPaused = true;
180 }
181
182 public void onResume() {
183 mActivityPaused = false;
184 }
185
Michael Kolb66706532010-12-12 19:50:22 -0800186 protected boolean isActivityPaused() {
187 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 }
189
190 public void onConfigurationChanged(Configuration config) {
191 }
192
193 // key handling
194
195 @Override
196 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700197 if (mComboView != null) {
198 if (!mComboView.onBackPressed()) {
199 mUiController.removeComboView();
200 }
201 return true;
202 }
203 if (mCustomView != null) {
204 mUiController.hideCustomView();
205 return true;
206 }
207 return false;
208 }
209
Michael Kolb2814a362011-05-19 15:49:41 -0700210 @Override
211 public boolean onMenuKey() {
212 return false;
213 }
214
John Reck30c714c2010-12-16 17:30:34 -0800215 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 @Override
John Reck30c714c2010-12-16 17:30:34 -0800217 public void onTabDataChanged(Tab tab) {
218 setUrlTitle(tab);
219 setFavicon(tab);
220 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800221 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 }
223
224 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500225 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800226 if (tab.inForeground()) {
227 boolean isBookmark = tab.isBookmarkedSite();
228 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
229 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500230 }
231
232 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 public void onPageStopped(Tab tab) {
234 cancelStopToast();
235 if (tab.inForeground()) {
236 mStopToast = Toast
237 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
238 mStopToast.show();
239 }
240 }
241
242 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800243 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700244 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800245 }
246
247 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 }
250
251 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800252 public void setActiveTab(final Tab tab) {
253 setActiveTab(tab, true);
254 }
255
256 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800257 if ((tab != mActiveTab) && (mActiveTab != null)) {
258 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 }
Michael Kolb77df4562010-11-19 14:49:34 -0800260 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800261 if (needsAttaching) {
262 attachTabToContentView(tab);
263 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700264 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800265 onTabDataChanged(tab);
266 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800267 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800268 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500269 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700270 }
271
Michael Kolbcfa3af52010-12-14 10:36:11 -0800272 Tab getActiveTab() {
273 return mActiveTab;
274 }
275
Michael Kolb8233fac2010-10-26 16:08:53 -0700276 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800277 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800278 }
279
280 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700281 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800282 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700283 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800284 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700285 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700286 }
287
288 @Override
289 public void detachTab(Tab tab) {
290 removeTabFromContentView(tab);
291 }
292
293 @Override
294 public void attachTab(Tab tab) {
295 attachTabToContentView(tab);
296 }
297
Michael Kolb377ea312011-02-17 14:36:56 -0800298 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800299 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700300 return;
301 }
302 View container = tab.getViewContainer();
303 WebView mainView = tab.getWebView();
304 // Attach the WebView to the container and then attach the
305 // container to the content view.
306 FrameLayout wrapper =
307 (FrameLayout) container.findViewById(R.id.webview_wrapper);
308 ViewGroup parent = (ViewGroup) mainView.getParent();
309 if (parent != wrapper) {
310 if (parent != null) {
311 Log.w(LOGTAG, "mMainView already has a parent in"
312 + " attachTabToContentView!");
313 parent.removeView(mainView);
314 }
315 wrapper.addView(mainView);
316 } else {
317 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
318 + " attachTabToContentView!");
319 }
320 parent = (ViewGroup) container.getParent();
321 if (parent != mContentView) {
322 if (parent != null) {
323 Log.w(LOGTAG, "mContainer already has a parent in"
324 + " attachTabToContentView!");
325 parent.removeView(container);
326 }
327 mContentView.addView(container, COVER_SCREEN_PARAMS);
328 } else {
329 Log.w(LOGTAG, "mContainer is already attached to content in"
330 + " attachTabToContentView!");
331 }
332 mUiController.attachSubWindow(tab);
333 }
334
335 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800336 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700337 // Remove the container that contains the main WebView.
338 WebView mainView = tab.getWebView();
339 View container = tab.getViewContainer();
340 if (mainView == null) {
341 return;
342 }
343 // Remove the container from the content and then remove the
344 // WebView from the container. This will trigger a focus change
345 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800346 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700347 FrameLayout wrapper =
348 (FrameLayout) container.findViewById(R.id.webview_wrapper);
349 wrapper.removeView(mainView);
350 mContentView.removeView(container);
351 mUiController.endActionMode();
352 mUiController.removeSubWindow(tab);
353 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
354 if (errorConsole != null) {
355 mErrorConsoleContainer.removeView(errorConsole);
356 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700357 }
358
Michael Kolba713ec82010-11-29 17:27:06 -0800359 @Override
360 public void onSetWebView(Tab tab, WebView webView) {
361 View container = tab.getViewContainer();
362 if (container == null) {
363 // The tab consists of a container view, which contains the main
364 // WebView, as well as any other UI elements associated with the tab.
365 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
366 null);
367 tab.setViewContainer(container);
368 }
369 if (tab.getWebView() != webView) {
370 // Just remove the old one.
371 FrameLayout wrapper =
372 (FrameLayout) container.findViewById(R.id.webview_wrapper);
373 wrapper.removeView(tab.getWebView());
374 }
375 }
376
Michael Kolb8233fac2010-10-26 16:08:53 -0700377 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800378 * create a sub window container and webview for the tab
379 * Note: this methods operates through side-effects for now
380 * it sets both the subView and subViewContainer for the given tab
381 * @param tab tab to create the sub window for
382 * @param subView webview to be set as a subwindow for the tab
383 */
384 @Override
385 public void createSubWindow(Tab tab, WebView subView) {
386 View subViewContainer = mActivity.getLayoutInflater().inflate(
387 R.layout.browser_subwindow, null);
388 ViewGroup inner = (ViewGroup) subViewContainer
389 .findViewById(R.id.inner_container);
390 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
391 LayoutParams.MATCH_PARENT));
392 final ImageButton cancel = (ImageButton) subViewContainer
393 .findViewById(R.id.subwindow_close);
394 final WebView cancelSubView = subView;
395 cancel.setOnClickListener(new OnClickListener() {
396 public void onClick(View v) {
397 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
398 }
399 });
400 tab.setSubWebView(subView);
401 tab.setSubViewContainer(subViewContainer);
402 }
403
404 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700405 * Remove the sub window from the content view.
406 */
407 @Override
408 public void removeSubWindow(View subviewContainer) {
409 mContentView.removeView(subviewContainer);
410 mUiController.endActionMode();
411 }
412
413 /**
414 * Attach the sub window to the content view.
415 */
416 @Override
417 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800418 if (container.getParent() != null) {
419 // already attached, remove first
420 ((ViewGroup) container.getParent()).removeView(container);
421 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700422 mContentView.addView(container, COVER_SCREEN_PARAMS);
423 }
424
Michael Kolb11d19782011-03-20 10:17:40 -0700425 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700426 WebView web = getWebView();
427 if (web != null) {
428 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700429 }
430 }
431
Michael Kolb46f987e2011-04-05 10:39:10 -0700432 public void editUrl(boolean clearInput) {
433 if (mUiController.isInCustomActionMode()) {
434 mUiController.endActionMode();
435 }
436 showTitleBar();
437 getTitleBar().startEditingUrl(clearInput);
438 }
439
Michael Kolb7cdc4902011-02-03 17:54:40 -0800440 boolean canShowTitleBar() {
441 return !isTitleBarShowing()
442 && !isActivityPaused()
443 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700444 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800445 && !mUiController.isInCustomActionMode();
446 }
447
448 void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700449 if (canShowTitleBar()) {
450 getTitleBar().show();
451 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800452 }
453
454 protected void hideTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700455 if (getTitleBar().isShowing()) {
456 getTitleBar().hide();
457 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800458 }
459
460 protected boolean isTitleBarShowing() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700461 return getTitleBar().isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800462 }
463
464 protected abstract TitleBarBase getTitleBar();
465
466 protected void setTitleGravity(int gravity) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700467 WebView web = getWebView();
468 if (web != null) {
469 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700470 }
471 }
472
Michael Kolb66706532010-12-12 19:50:22 -0800473 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700474 public void showVoiceTitleBar(String title, List<String> results) {
475 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800476 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700477 }
478
Michael Kolb66706532010-12-12 19:50:22 -0800479 @Override
480 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700481 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800482 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800483 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700484 }
485
486 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700487 public void registerDropdownChangeListener(DropdownChangeListener d) {
488 getTitleBar().registerDropdownChangeListener(d);
489 }
490
491 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700492 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800493 if (mComboView != null) {
494 return;
495 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700496 mComboView = new CombinedBookmarkHistoryView(mActivity,
497 mUiController,
498 startWithHistory ?
499 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
500 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
501 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800502 FrameLayout wrapper =
503 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
504 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700505 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800506 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700507 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800508 if (mActiveTab != null) {
509 WebView web = mActiveTab.getWebView();
510 mActiveTab.putInBackground();
511 }
John Reck74830e12011-03-14 11:43:05 -0700512 mComboView.setAlpha(0f);
513 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
514 Resources res = mActivity.getResources();
515 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
516 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700517 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
518 }
519
Michael Kolbba238702011-03-08 10:40:50 -0800520 public boolean isComboViewShowing() {
521 return (mComboView != null);
522 }
523
Michael Kolb8233fac2010-10-26 16:08:53 -0700524 /**
525 * dismiss the ComboPage
526 */
527 @Override
528 public void hideComboView() {
529 if (mComboView != null) {
530 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800531 FrameLayout wrapper =
532 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
533 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700534 mComboView = null;
535 }
Michael Kolb3a696282010-12-05 13:23:24 -0800536 if (mActiveTab != null) {
537 mActiveTab.putInForeground();
538 }
John Reckb3417f02011-01-14 11:01:05 -0800539 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700540 }
541
542 @Override
543 public void showCustomView(View view,
544 WebChromeClient.CustomViewCallback callback) {
545 // if a view already exists then immediately terminate the new one
546 if (mCustomView != null) {
547 callback.onCustomViewHidden();
548 return;
549 }
550
551 // Add the custom view to its container.
552 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
553 mCustomView = view;
554 mCustomViewCallback = callback;
555 // Hide the content view.
556 mContentView.setVisibility(View.GONE);
557 // Finally show the custom view container.
558 setStatusBarVisibility(false);
559 mCustomViewContainer.setVisibility(View.VISIBLE);
560 mCustomViewContainer.bringToFront();
561 }
562
563 @Override
564 public void onHideCustomView() {
565 if (mCustomView == null)
566 return;
567
568 // Hide the custom view.
569 mCustomView.setVisibility(View.GONE);
570 // Remove the custom view from its container.
571 mCustomViewContainer.removeView(mCustomView);
572 mCustomView = null;
573 mCustomViewContainer.setVisibility(View.GONE);
574 mCustomViewCallback.onCustomViewHidden();
575 // Show the content view.
576 setStatusBarVisibility(true);
577 mContentView.setVisibility(View.VISIBLE);
578 }
579
580 @Override
581 public boolean isCustomViewShowing() {
582 return mCustomView != null;
583 }
584
Michael Kolb66706532010-12-12 19:50:22 -0800585 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800586 if (mInputManager.isActive()) {
587 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
588 0);
589 }
590 }
591
Michael Kolb66706532010-12-12 19:50:22 -0800592 @Override
593 public boolean showsWeb() {
594 return mCustomView == null
595 && mComboView == null;
596 }
597
Patrick Scott92066772011-03-10 08:46:27 -0500598 @Override
599 public void showAutoLogin(Tab tab) {
600 updateAutoLogin(tab, true);
601 }
602
603 @Override
604 public void hideAutoLogin(Tab tab) {
605 updateAutoLogin(tab, true);
606 }
607
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 // -------------------------------------------------------------------------
609
Michael Kolb5a72f182011-01-13 20:35:06 -0800610 protected void updateNavigationState(Tab tab) {
611 }
612
Michael Kolb11d19782011-03-20 10:17:40 -0700613 protected void updateAutoLogin(Tab tab, boolean animate) {
614 getTitleBar().updateAutoLogin(tab, animate);
615 }
Patrick Scott92066772011-03-10 08:46:27 -0500616
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 /**
618 * Update the lock icon to correspond to our latest state.
619 */
Michael Kolb66706532010-12-12 19:50:22 -0800620 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800621 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 updateLockIconImage(t.getLockIconType());
623 }
624 }
625
626 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700627 * Updates the lock-icon image in the title-bar.
628 */
John Reck30c714c2010-12-16 17:30:34 -0800629 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700630 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800631 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700632 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800633 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700634 d = mMixLockIcon;
635 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800636 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700637 }
638
John Reck30c714c2010-12-16 17:30:34 -0800639 protected void setUrlTitle(Tab tab) {
640 String url = tab.getUrl();
641 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800642 if (TextUtils.isEmpty(title)) {
643 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800644 }
Michael Kolb66706532010-12-12 19:50:22 -0800645 if (tab.isInVoiceSearchMode()) return;
646 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800647 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800648 }
649 }
650
651 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800652 protected void setFavicon(Tab tab) {
653 if (tab.inForeground()) {
654 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800655 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800656 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700657 }
658
659 @Override
660 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 }
662
Michael Kolb66706532010-12-12 19:50:22 -0800663 // active tabs page
664
665 public void showActiveTabsPage() {
666 }
667
668 /**
669 * Remove the active tabs page.
670 */
671 public void removeActiveTabsPage() {
672 }
673
Michael Kolb8233fac2010-10-26 16:08:53 -0700674 // menu handling callbacks
675
676 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800677 public boolean onPrepareOptionsMenu(Menu menu) {
678 return true;
679 }
680
681 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700682 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700683 }
684
685 @Override
686 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700687 }
688
689 @Override
690 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700691 }
692
693 @Override
694 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700695 }
696
697 @Override
698 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 }
700
701 @Override
702 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700703 }
704
705 // error console
706
707 @Override
708 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800709 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
711 if (flag) {
712 // Setting the show state of the console will cause it's the layout
713 // to be inflated.
714 if (errorConsole.numberOfErrors() > 0) {
715 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
716 } else {
717 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
718 }
719 if (errorConsole.getParent() != null) {
720 mErrorConsoleContainer.removeView(errorConsole);
721 }
722 // Now we can add it to the main view.
723 mErrorConsoleContainer.addView(errorConsole,
724 new LinearLayout.LayoutParams(
725 ViewGroup.LayoutParams.MATCH_PARENT,
726 ViewGroup.LayoutParams.WRAP_CONTENT));
727 } else {
728 mErrorConsoleContainer.removeView(errorConsole);
729 }
730 }
731
732 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800733 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
734 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
735 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700736 }
737
Michael Kolb8233fac2010-10-26 16:08:53 -0700738 // -------------------------------------------------------------------------
739 // Helper function for WebChromeClient
740 // -------------------------------------------------------------------------
741
742 @Override
743 public Bitmap getDefaultVideoPoster() {
744 if (mDefaultVideoPoster == null) {
745 mDefaultVideoPoster = BitmapFactory.decodeResource(
746 mActivity.getResources(), R.drawable.default_video_poster);
747 }
748 return mDefaultVideoPoster;
749 }
750
751 @Override
752 public View getVideoLoadingProgressView() {
753 if (mVideoProgressView == null) {
754 LayoutInflater inflater = LayoutInflater.from(mActivity);
755 mVideoProgressView = inflater.inflate(
756 R.layout.video_loading_progress, null);
757 }
758 return mVideoProgressView;
759 }
760
Michael Kolb843510f2010-12-09 10:51:49 -0800761 @Override
762 public void showMaxTabsWarning() {
763 Toast warning = Toast.makeText(mActivity,
764 mActivity.getString(R.string.max_tabs_warning),
765 Toast.LENGTH_SHORT);
766 warning.show();
767 }
768
Michael Kolbfdb70242011-03-24 09:41:11 -0700769 protected void captureTab(final Tab tab) {
770 captureTab(tab,
771 (int) mActivity.getResources()
772 .getDimension(R.dimen.qc_thumb_width),
773 (int) mActivity.getResources()
774 .getDimension(R.dimen.qc_thumb_height));
775 }
776
777 protected void captureTab(final Tab tab, int width, int height) {
778 if ((tab == null) || (tab.getWebView() == null)) return;
779 Bitmap sshot = Controller.createScreenshot(tab, width, height);
780 tab.setScreenshot(sshot);
781 }
782
Michael Kolb46f987e2011-04-05 10:39:10 -0700783 protected WebView getWebView() {
784 if (mActiveTab != null) {
785 return mActiveTab.getWebView();
786 } else {
787 return null;
788 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700789 }
790
Michael Kolbfedb4922011-04-20 16:45:33 -0700791 protected Menu getMenu() {
792 MenuBuilder menu = new MenuBuilder(mActivity);
793 mActivity.getMenuInflater().inflate(R.menu.browser, menu);
794 return menu;
795 }
796
Michael Kolbc38c6042011-04-27 10:46:06 -0700797 public void setFullscreen(boolean enabled) {
798 if (enabled) {
799 mActivity.getWindow().setFlags(
800 WindowManager.LayoutParams.FLAG_FULLSCREEN,
801 WindowManager.LayoutParams.FLAG_FULLSCREEN);
802 } else {
803 mActivity.getWindow().clearFlags(
804 WindowManager.LayoutParams.FLAG_FULLSCREEN);
805 }
806 }
807
Michael Kolb5a4372f2011-04-29 13:53:10 -0700808 protected Drawable getFaviconDrawable(Bitmap icon) {
809 Drawable[] array = new Drawable[3];
810 array[0] = new PaintDrawable(Color.BLACK);
811 PaintDrawable p = new PaintDrawable(Color.WHITE);
812 array[1] = p;
813 if (icon == null) {
814 array[2] = mGenericFavicon;
815 } else {
816 array[2] = new BitmapDrawable(icon);
817 }
818 LayerDrawable d = new LayerDrawable(array);
819 d.setLayerInset(1, 1, 1, 1, 1);
820 d.setLayerInset(2, 2, 2, 2, 2);
821 return d;
822 }
823
Michael Kolb8233fac2010-10-26 16:08:53 -0700824}