blob: 20195addfa376c942c90d545082ab55f3be792ff [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
Michael Kolbfedb4922011-04-20 16:45:33 -070020import com.android.internal.view.menu.MenuBuilder;
John Reck30c714c2010-12-16 17:30:34 -080021
John Reck74830e12011-03-14 11:43:05 -070022import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070024import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.res.Configuration;
26import android.content.res.Resources;
27import android.graphics.Bitmap;
28import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.Color;
30import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070032import android.graphics.drawable.LayerDrawable;
33import android.graphics.drawable.PaintDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.os.Bundle;
35import android.text.TextUtils;
36import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.Gravity;
38import android.view.LayoutInflater;
39import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080041import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.webkit.WebView;
48import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080049import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.LinearLayout;
51import android.widget.Toast;
52
Michael Kolb1bf23132010-11-19 12:55:12 -080053import java.util.List;
54
Michael Kolb8233fac2010-10-26 16:08:53 -070055/**
56 * UI interface definitions
57 */
Michael Kolb66706532010-12-12 19:50:22 -080058public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070059
60 private static final String LOGTAG = "BaseUi";
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT);
66
Michael Kolb66706532010-12-12 19:50:22 -080067 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070068 new FrameLayout.LayoutParams(
69 ViewGroup.LayoutParams.MATCH_PARENT,
70 ViewGroup.LayoutParams.MATCH_PARENT,
71 Gravity.CENTER);
72
73 Activity mActivity;
74 UiController mUiController;
75 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080076 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080077 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070078
79 private Drawable mSecLockIcon;
80 private Drawable mMixLockIcon;
Michael Kolb5a4372f2011-04-29 13:53:10 -070081 protected Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080084 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070085 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070086
87 private View mCustomView;
88 private WebChromeClient.CustomViewCallback mCustomViewCallback;
89
90 private CombinedBookmarkHistoryView mComboView;
91
92 private LinearLayout mErrorConsoleContainer = null;
93
94 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
Michael Kolb5a4372f2011-04-29 13:53:10 -070096
Michael Kolb8233fac2010-10-26 16:08:53 -070097 // the default <video> poster
98 private Bitmap mDefaultVideoPoster;
99 // the video progress view
100 private View mVideoProgressView;
101
Michael Kolb8233fac2010-10-26 16:08:53 -0700102 private boolean mActivityPaused;
103
104 public BaseUi(Activity browser, UiController controller) {
105 mActivity = browser;
106 mUiController = controller;
107 mTabControl = controller.getTabControl();
108 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800109 mInputManager = (InputMethodManager)
110 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800111 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
113
Michael Kolb8233fac2010-10-26 16:08:53 -0700114 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
115 .getDecorView().findViewById(android.R.id.content);
116 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
117 .inflate(R.layout.custom_screen, null);
118 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
119 R.id.main_content);
120 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
121 .findViewById(R.id.error_console);
122 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
123 .findViewById(R.id.fullscreen_custom_content);
124 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolbc38c6042011-04-27 10:46:06 -0700125 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700126 mGenericFavicon = res.getDrawable(
127 R.drawable.app_web_browser_sm);
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 }
129
John Reckb9a051b2011-03-18 11:55:48 -0700130 @Override
131 public WebView createWebView(boolean privateBrowsing) {
132 // Create a new WebView
133 BrowserWebView w = new BrowserWebView(mActivity, null,
134 android.R.attr.webViewStyle, privateBrowsing);
135 initWebViewSettings(w);
136 return w;
137 }
138
139 @Override
140 public WebView createSubWebView(boolean privateBrowsing) {
141 return createWebView(privateBrowsing);
142 }
143
Michael Kolb66706532010-12-12 19:50:22 -0800144 /**
145 * common webview initialization
146 * @param w the webview to initialize
147 */
148 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700149 w.setScrollbarFadingEnabled(true);
150 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
151 w.setMapTrackballToArrowKeys(false); // use trackball directly
152 // Enable the built-in zoom
153 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700154 boolean supportsMultiTouch = mActivity.getPackageManager()
155 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
156 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
157 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700158
159 // Add this WebView to the settings observer list and update the
160 // settings
161 final BrowserSettings s = BrowserSettings.getInstance();
John Reck35e9dd62011-04-25 09:01:54 -0700162 s.startManagingSettings(w.getSettings());
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 }
164
165 private void cancelStopToast() {
166 if (mStopToast != null) {
167 mStopToast.cancel();
168 mStopToast = null;
169 }
170 }
171
172 // lifecycle
173
174 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800175 if (isCustomViewShowing()) {
176 onHideCustomView();
177 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 cancelStopToast();
179 mActivityPaused = true;
180 }
181
182 public void onResume() {
183 mActivityPaused = false;
184 }
185
Michael Kolb66706532010-12-12 19:50:22 -0800186 protected boolean isActivityPaused() {
187 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 }
189
190 public void onConfigurationChanged(Configuration config) {
191 }
192
193 // key handling
194
195 @Override
196 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700197 if (mComboView != null) {
198 if (!mComboView.onBackPressed()) {
199 mUiController.removeComboView();
200 }
201 return true;
202 }
203 if (mCustomView != null) {
204 mUiController.hideCustomView();
205 return true;
206 }
207 return false;
208 }
209
John Reck30c714c2010-12-16 17:30:34 -0800210 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 @Override
John Reck30c714c2010-12-16 17:30:34 -0800212 public void onTabDataChanged(Tab tab) {
213 setUrlTitle(tab);
214 setFavicon(tab);
215 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800216 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 }
218
219 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500220 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800221 if (tab.inForeground()) {
222 boolean isBookmark = tab.isBookmarkedSite();
223 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
224 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500225 }
226
227 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 public void onPageStopped(Tab tab) {
229 cancelStopToast();
230 if (tab.inForeground()) {
231 mStopToast = Toast
232 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
233 mStopToast.show();
234 }
235 }
236
237 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800238 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700239 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800240 }
241
242 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 }
245
246 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800247 public void setActiveTab(final Tab tab) {
248 setActiveTab(tab, true);
249 }
250
251 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800252 if ((tab != mActiveTab) && (mActiveTab != null)) {
253 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 }
Michael Kolb77df4562010-11-19 14:49:34 -0800255 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800256 if (needsAttaching) {
257 attachTabToContentView(tab);
258 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800260 onTabDataChanged(tab);
261 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800262 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800263 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500264 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 }
266
Michael Kolbcfa3af52010-12-14 10:36:11 -0800267 Tab getActiveTab() {
268 return mActiveTab;
269 }
270
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800272 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800273 }
274
275 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700276 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800277 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700278 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800279 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700280 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700281 }
282
283 @Override
284 public void detachTab(Tab tab) {
285 removeTabFromContentView(tab);
286 }
287
288 @Override
289 public void attachTab(Tab tab) {
290 attachTabToContentView(tab);
291 }
292
Michael Kolb377ea312011-02-17 14:36:56 -0800293 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800294 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700295 return;
296 }
297 View container = tab.getViewContainer();
298 WebView mainView = tab.getWebView();
299 // Attach the WebView to the container and then attach the
300 // container to the content view.
301 FrameLayout wrapper =
302 (FrameLayout) container.findViewById(R.id.webview_wrapper);
303 ViewGroup parent = (ViewGroup) mainView.getParent();
304 if (parent != wrapper) {
305 if (parent != null) {
306 Log.w(LOGTAG, "mMainView already has a parent in"
307 + " attachTabToContentView!");
308 parent.removeView(mainView);
309 }
310 wrapper.addView(mainView);
311 } else {
312 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
313 + " attachTabToContentView!");
314 }
315 parent = (ViewGroup) container.getParent();
316 if (parent != mContentView) {
317 if (parent != null) {
318 Log.w(LOGTAG, "mContainer already has a parent in"
319 + " attachTabToContentView!");
320 parent.removeView(container);
321 }
322 mContentView.addView(container, COVER_SCREEN_PARAMS);
323 } else {
324 Log.w(LOGTAG, "mContainer is already attached to content in"
325 + " attachTabToContentView!");
326 }
327 mUiController.attachSubWindow(tab);
328 }
329
330 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800331 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 // Remove the container that contains the main WebView.
333 WebView mainView = tab.getWebView();
334 View container = tab.getViewContainer();
335 if (mainView == null) {
336 return;
337 }
338 // Remove the container from the content and then remove the
339 // WebView from the container. This will trigger a focus change
340 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800341 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700342 FrameLayout wrapper =
343 (FrameLayout) container.findViewById(R.id.webview_wrapper);
344 wrapper.removeView(mainView);
345 mContentView.removeView(container);
346 mUiController.endActionMode();
347 mUiController.removeSubWindow(tab);
348 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
349 if (errorConsole != null) {
350 mErrorConsoleContainer.removeView(errorConsole);
351 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700352 }
353
Michael Kolba713ec82010-11-29 17:27:06 -0800354 @Override
355 public void onSetWebView(Tab tab, WebView webView) {
356 View container = tab.getViewContainer();
357 if (container == null) {
358 // The tab consists of a container view, which contains the main
359 // WebView, as well as any other UI elements associated with the tab.
360 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
361 null);
362 tab.setViewContainer(container);
363 }
364 if (tab.getWebView() != webView) {
365 // Just remove the old one.
366 FrameLayout wrapper =
367 (FrameLayout) container.findViewById(R.id.webview_wrapper);
368 wrapper.removeView(tab.getWebView());
369 }
370 }
371
Michael Kolb8233fac2010-10-26 16:08:53 -0700372 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800373 * create a sub window container and webview for the tab
374 * Note: this methods operates through side-effects for now
375 * it sets both the subView and subViewContainer for the given tab
376 * @param tab tab to create the sub window for
377 * @param subView webview to be set as a subwindow for the tab
378 */
379 @Override
380 public void createSubWindow(Tab tab, WebView subView) {
381 View subViewContainer = mActivity.getLayoutInflater().inflate(
382 R.layout.browser_subwindow, null);
383 ViewGroup inner = (ViewGroup) subViewContainer
384 .findViewById(R.id.inner_container);
385 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
386 LayoutParams.MATCH_PARENT));
387 final ImageButton cancel = (ImageButton) subViewContainer
388 .findViewById(R.id.subwindow_close);
389 final WebView cancelSubView = subView;
390 cancel.setOnClickListener(new OnClickListener() {
391 public void onClick(View v) {
392 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
393 }
394 });
395 tab.setSubWebView(subView);
396 tab.setSubViewContainer(subViewContainer);
397 }
398
399 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700400 * Remove the sub window from the content view.
401 */
402 @Override
403 public void removeSubWindow(View subviewContainer) {
404 mContentView.removeView(subviewContainer);
405 mUiController.endActionMode();
406 }
407
408 /**
409 * Attach the sub window to the content view.
410 */
411 @Override
412 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800413 if (container.getParent() != null) {
414 // already attached, remove first
415 ((ViewGroup) container.getParent()).removeView(container);
416 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 mContentView.addView(container, COVER_SCREEN_PARAMS);
418 }
419
Michael Kolb11d19782011-03-20 10:17:40 -0700420 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700421 WebView web = getWebView();
422 if (web != null) {
423 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700424 }
425 }
426
Michael Kolb46f987e2011-04-05 10:39:10 -0700427 public void editUrl(boolean clearInput) {
428 if (mUiController.isInCustomActionMode()) {
429 mUiController.endActionMode();
430 }
431 showTitleBar();
432 getTitleBar().startEditingUrl(clearInput);
433 }
434
Michael Kolb7cdc4902011-02-03 17:54:40 -0800435 boolean canShowTitleBar() {
436 return !isTitleBarShowing()
437 && !isActivityPaused()
438 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700439 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800440 && !mUiController.isInCustomActionMode();
441 }
442
443 void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700444 if (canShowTitleBar()) {
445 getTitleBar().show();
446 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800447 }
448
449 protected void hideTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700450 if (getTitleBar().isShowing()) {
451 getTitleBar().hide();
452 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800453 }
454
455 protected boolean isTitleBarShowing() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700456 return getTitleBar().isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800457 }
458
459 protected abstract TitleBarBase getTitleBar();
460
461 protected void setTitleGravity(int gravity) {
Michael Kolbd463a722011-04-08 10:17:49 -0700462 // update the titlebar layout params
463 // required to avoid scroll to top when focused
464 getTitleBar().setTitleGravity(gravity);
Michael Kolb46f987e2011-04-05 10:39:10 -0700465 WebView web = getWebView();
466 if (web != null) {
467 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700468 }
469 }
470
Michael Kolb66706532010-12-12 19:50:22 -0800471 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700472 public void showVoiceTitleBar(String title, List<String> results) {
473 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800474 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700475 }
476
Michael Kolb66706532010-12-12 19:50:22 -0800477 @Override
478 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700479 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800480 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800481 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700482 }
483
484 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700485 public void registerDropdownChangeListener(DropdownChangeListener d) {
486 getTitleBar().registerDropdownChangeListener(d);
487 }
488
489 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700490 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800491 if (mComboView != null) {
492 return;
493 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700494 mComboView = new CombinedBookmarkHistoryView(mActivity,
495 mUiController,
496 startWithHistory ?
497 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
498 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
499 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800500 FrameLayout wrapper =
501 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
502 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700503 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800504 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700505 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800506 if (mActiveTab != null) {
507 WebView web = mActiveTab.getWebView();
508 mActiveTab.putInBackground();
509 }
John Reck74830e12011-03-14 11:43:05 -0700510 mComboView.setAlpha(0f);
511 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
512 Resources res = mActivity.getResources();
513 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
514 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700515 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
516 }
517
Michael Kolbba238702011-03-08 10:40:50 -0800518 public boolean isComboViewShowing() {
519 return (mComboView != null);
520 }
521
Michael Kolb8233fac2010-10-26 16:08:53 -0700522 /**
523 * dismiss the ComboPage
524 */
525 @Override
526 public void hideComboView() {
527 if (mComboView != null) {
528 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800529 FrameLayout wrapper =
530 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
531 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700532 mComboView = null;
533 }
Michael Kolb3a696282010-12-05 13:23:24 -0800534 if (mActiveTab != null) {
535 mActiveTab.putInForeground();
536 }
John Reckb3417f02011-01-14 11:01:05 -0800537 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700538 }
539
540 @Override
541 public void showCustomView(View view,
542 WebChromeClient.CustomViewCallback callback) {
543 // if a view already exists then immediately terminate the new one
544 if (mCustomView != null) {
545 callback.onCustomViewHidden();
546 return;
547 }
548
549 // Add the custom view to its container.
550 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
551 mCustomView = view;
552 mCustomViewCallback = callback;
553 // Hide the content view.
554 mContentView.setVisibility(View.GONE);
555 // Finally show the custom view container.
556 setStatusBarVisibility(false);
557 mCustomViewContainer.setVisibility(View.VISIBLE);
558 mCustomViewContainer.bringToFront();
559 }
560
561 @Override
562 public void onHideCustomView() {
563 if (mCustomView == null)
564 return;
565
566 // Hide the custom view.
567 mCustomView.setVisibility(View.GONE);
568 // Remove the custom view from its container.
569 mCustomViewContainer.removeView(mCustomView);
570 mCustomView = null;
571 mCustomViewContainer.setVisibility(View.GONE);
572 mCustomViewCallback.onCustomViewHidden();
573 // Show the content view.
574 setStatusBarVisibility(true);
575 mContentView.setVisibility(View.VISIBLE);
576 }
577
578 @Override
579 public boolean isCustomViewShowing() {
580 return mCustomView != null;
581 }
582
Michael Kolb66706532010-12-12 19:50:22 -0800583 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800584 if (mInputManager.isActive()) {
585 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
586 0);
587 }
588 }
589
Michael Kolb66706532010-12-12 19:50:22 -0800590 @Override
591 public boolean showsWeb() {
592 return mCustomView == null
593 && mComboView == null;
594 }
595
Patrick Scott92066772011-03-10 08:46:27 -0500596 @Override
597 public void showAutoLogin(Tab tab) {
598 updateAutoLogin(tab, true);
599 }
600
601 @Override
602 public void hideAutoLogin(Tab tab) {
603 updateAutoLogin(tab, true);
604 }
605
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 // -------------------------------------------------------------------------
607
Michael Kolb5a72f182011-01-13 20:35:06 -0800608 protected void updateNavigationState(Tab tab) {
609 }
610
Michael Kolb11d19782011-03-20 10:17:40 -0700611 protected void updateAutoLogin(Tab tab, boolean animate) {
612 getTitleBar().updateAutoLogin(tab, animate);
613 }
Patrick Scott92066772011-03-10 08:46:27 -0500614
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 /**
616 * Update the lock icon to correspond to our latest state.
617 */
Michael Kolb66706532010-12-12 19:50:22 -0800618 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800619 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 updateLockIconImage(t.getLockIconType());
621 }
622 }
623
624 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 * Updates the lock-icon image in the title-bar.
626 */
John Reck30c714c2010-12-16 17:30:34 -0800627 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700628 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800629 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700630 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800631 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700632 d = mMixLockIcon;
633 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800634 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 }
636
John Reck30c714c2010-12-16 17:30:34 -0800637 protected void setUrlTitle(Tab tab) {
638 String url = tab.getUrl();
639 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800640 if (TextUtils.isEmpty(title)) {
641 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800642 }
Michael Kolb66706532010-12-12 19:50:22 -0800643 if (tab.isInVoiceSearchMode()) return;
644 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800645 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800646 }
647 }
648
649 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800650 protected void setFavicon(Tab tab) {
651 if (tab.inForeground()) {
652 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800653 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800654 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 }
656
657 @Override
658 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 }
660
Michael Kolb66706532010-12-12 19:50:22 -0800661 // active tabs page
662
663 public void showActiveTabsPage() {
664 }
665
666 /**
667 * Remove the active tabs page.
668 */
669 public void removeActiveTabsPage() {
670 }
671
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 // menu handling callbacks
673
674 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800675 public boolean onPrepareOptionsMenu(Menu menu) {
676 return true;
677 }
678
679 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700680 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700681 }
682
683 @Override
684 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700685 }
686
687 @Override
688 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700689 }
690
691 @Override
692 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700693 }
694
695 @Override
696 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700697 }
698
699 @Override
700 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700701 }
702
703 // error console
704
705 @Override
706 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800707 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700708 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
709 if (flag) {
710 // Setting the show state of the console will cause it's the layout
711 // to be inflated.
712 if (errorConsole.numberOfErrors() > 0) {
713 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
714 } else {
715 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
716 }
717 if (errorConsole.getParent() != null) {
718 mErrorConsoleContainer.removeView(errorConsole);
719 }
720 // Now we can add it to the main view.
721 mErrorConsoleContainer.addView(errorConsole,
722 new LinearLayout.LayoutParams(
723 ViewGroup.LayoutParams.MATCH_PARENT,
724 ViewGroup.LayoutParams.WRAP_CONTENT));
725 } else {
726 mErrorConsoleContainer.removeView(errorConsole);
727 }
728 }
729
730 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800731 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
732 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
733 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 }
735
Michael Kolb8233fac2010-10-26 16:08:53 -0700736 // -------------------------------------------------------------------------
737 // Helper function for WebChromeClient
738 // -------------------------------------------------------------------------
739
740 @Override
741 public Bitmap getDefaultVideoPoster() {
742 if (mDefaultVideoPoster == null) {
743 mDefaultVideoPoster = BitmapFactory.decodeResource(
744 mActivity.getResources(), R.drawable.default_video_poster);
745 }
746 return mDefaultVideoPoster;
747 }
748
749 @Override
750 public View getVideoLoadingProgressView() {
751 if (mVideoProgressView == null) {
752 LayoutInflater inflater = LayoutInflater.from(mActivity);
753 mVideoProgressView = inflater.inflate(
754 R.layout.video_loading_progress, null);
755 }
756 return mVideoProgressView;
757 }
758
Michael Kolb843510f2010-12-09 10:51:49 -0800759 @Override
760 public void showMaxTabsWarning() {
761 Toast warning = Toast.makeText(mActivity,
762 mActivity.getString(R.string.max_tabs_warning),
763 Toast.LENGTH_SHORT);
764 warning.show();
765 }
766
Michael Kolbfdb70242011-03-24 09:41:11 -0700767 protected void captureTab(final Tab tab) {
768 captureTab(tab,
769 (int) mActivity.getResources()
770 .getDimension(R.dimen.qc_thumb_width),
771 (int) mActivity.getResources()
772 .getDimension(R.dimen.qc_thumb_height));
773 }
774
775 protected void captureTab(final Tab tab, int width, int height) {
776 if ((tab == null) || (tab.getWebView() == null)) return;
777 Bitmap sshot = Controller.createScreenshot(tab, width, height);
778 tab.setScreenshot(sshot);
779 }
780
Michael Kolb46f987e2011-04-05 10:39:10 -0700781 protected WebView getWebView() {
782 if (mActiveTab != null) {
783 return mActiveTab.getWebView();
784 } else {
785 return null;
786 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700787 }
788
Michael Kolbfedb4922011-04-20 16:45:33 -0700789 protected Menu getMenu() {
790 MenuBuilder menu = new MenuBuilder(mActivity);
791 mActivity.getMenuInflater().inflate(R.menu.browser, menu);
792 return menu;
793 }
794
Michael Kolbc38c6042011-04-27 10:46:06 -0700795 public void setFullscreen(boolean enabled) {
796 if (enabled) {
797 mActivity.getWindow().setFlags(
798 WindowManager.LayoutParams.FLAG_FULLSCREEN,
799 WindowManager.LayoutParams.FLAG_FULLSCREEN);
800 } else {
801 mActivity.getWindow().clearFlags(
802 WindowManager.LayoutParams.FLAG_FULLSCREEN);
803 }
804 }
805
Michael Kolb5a4372f2011-04-29 13:53:10 -0700806 protected Drawable getFaviconDrawable(Bitmap icon) {
807 Drawable[] array = new Drawable[3];
808 array[0] = new PaintDrawable(Color.BLACK);
809 PaintDrawable p = new PaintDrawable(Color.WHITE);
810 array[1] = p;
811 if (icon == null) {
812 array[2] = mGenericFavicon;
813 } else {
814 array[2] = new BitmapDrawable(icon);
815 }
816 LayerDrawable d = new LayerDrawable(array);
817 d.setLayerInset(1, 1, 1, 1, 1);
818 d.setLayerInset(2, 2, 2, 2, 2);
819 return d;
820 }
821
Michael Kolb8233fac2010-10-26 16:08:53 -0700822}