blob: 7e0c5da318a87f4848d7048e7790f7adbc5d8be8 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
20
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
27import android.os.Bundle;
28import android.text.TextUtils;
29import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.view.Gravity;
31import android.view.LayoutInflater;
32import android.view.Menu;
33import android.view.MenuItem;
34import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080035import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080037import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080039import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.webkit.WebChromeClient;
41import android.webkit.WebHistoryItem;
42import android.webkit.WebView;
43import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080044import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070045import android.widget.LinearLayout;
46import android.widget.Toast;
47
Michael Kolb1bf23132010-11-19 12:55:12 -080048import java.util.List;
49
Michael Kolb8233fac2010-10-26 16:08:53 -070050/**
51 * UI interface definitions
52 */
Michael Kolb66706532010-12-12 19:50:22 -080053public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070054
55 private static final String LOGTAG = "BaseUi";
56
Michael Kolb66706532010-12-12 19:50:22 -080057 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070058 new FrameLayout.LayoutParams(
59 ViewGroup.LayoutParams.MATCH_PARENT,
60 ViewGroup.LayoutParams.MATCH_PARENT);
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT,
66 Gravity.CENTER);
67
68 Activity mActivity;
69 UiController mUiController;
70 TabControl mTabControl;
Michael Kolb77df4562010-11-19 14:49:34 -080071 private Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080072 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070073
74 private Drawable mSecLockIcon;
75 private Drawable mMixLockIcon;
76
Michael Kolb8233fac2010-10-26 16:08:53 -070077 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080078 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070079 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070080
81 private View mCustomView;
82 private WebChromeClient.CustomViewCallback mCustomViewCallback;
83
84 private CombinedBookmarkHistoryView mComboView;
85
86 private LinearLayout mErrorConsoleContainer = null;
87
88 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070089
90 // the default <video> poster
91 private Bitmap mDefaultVideoPoster;
92 // the video progress view
93 private View mVideoProgressView;
94
Michael Kolb8233fac2010-10-26 16:08:53 -070095 private boolean mActivityPaused;
96
97 public BaseUi(Activity browser, UiController controller) {
98 mActivity = browser;
99 mUiController = controller;
100 mTabControl = controller.getTabControl();
101 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800102 mInputManager = (InputMethodManager)
103 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700104 mSecLockIcon = res.getDrawable(R.drawable.ic_secure);
105 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
108 .getDecorView().findViewById(android.R.id.content);
109 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
110 .inflate(R.layout.custom_screen, null);
111 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
112 R.id.main_content);
113 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
114 .findViewById(R.id.error_console);
115 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
116 .findViewById(R.id.fullscreen_custom_content);
117 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
118
Michael Kolb8233fac2010-10-26 16:08:53 -0700119 }
120
Michael Kolb66706532010-12-12 19:50:22 -0800121 /**
122 * common webview initialization
123 * @param w the webview to initialize
124 */
125 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700126 w.setScrollbarFadingEnabled(true);
127 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
128 w.setMapTrackballToArrowKeys(false); // use trackball directly
129 // Enable the built-in zoom
130 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700131
132 // Add this WebView to the settings observer list and update the
133 // settings
134 final BrowserSettings s = BrowserSettings.getInstance();
135 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 }
137
138 private void cancelStopToast() {
139 if (mStopToast != null) {
140 mStopToast.cancel();
141 mStopToast = null;
142 }
143 }
144
145 // lifecycle
146
147 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800148 if (isCustomViewShowing()) {
149 onHideCustomView();
150 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700151 cancelStopToast();
152 mActivityPaused = true;
153 }
154
155 public void onResume() {
156 mActivityPaused = false;
157 }
158
Michael Kolb66706532010-12-12 19:50:22 -0800159 protected boolean isActivityPaused() {
160 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700161 }
162
163 public void onConfigurationChanged(Configuration config) {
164 }
165
166 // key handling
167
168 @Override
169 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700170 if (mComboView != null) {
171 if (!mComboView.onBackPressed()) {
172 mUiController.removeComboView();
173 }
174 return true;
175 }
176 if (mCustomView != null) {
177 mUiController.hideCustomView();
178 return true;
179 }
180 return false;
181 }
182
John Reck30c714c2010-12-16 17:30:34 -0800183 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700184 @Override
John Reck30c714c2010-12-16 17:30:34 -0800185 public void onTabDataChanged(Tab tab) {
186 setUrlTitle(tab);
187 setFavicon(tab);
188 updateLockIconToLatest(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 }
190
191 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500192 public void bookmarkedStatusHasChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800193 // no op in base case
Leon Scroggins4cd97792010-12-03 15:31:56 -0500194 }
195
196 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700197 public void onPageStopped(Tab tab) {
198 cancelStopToast();
199 if (tab.inForeground()) {
200 mStopToast = Toast
201 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
202 mStopToast.show();
203 }
204 }
205
206 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800207 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800208 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800209 }
210
211 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700213 }
214
215 @Override
216 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800217 if ((tab != mActiveTab) && (mActiveTab != null)) {
218 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 }
Michael Kolb77df4562010-11-19 14:49:34 -0800220 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 attachTabToContentView(tab);
222 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800223 onTabDataChanged(tab);
224 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700225 }
226
Michael Kolbcfa3af52010-12-14 10:36:11 -0800227 Tab getActiveTab() {
228 return mActiveTab;
229 }
230
Michael Kolb8233fac2010-10-26 16:08:53 -0700231 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800232 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800233 }
234
235 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800237 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800239 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 }
242
243 @Override
244 public void detachTab(Tab tab) {
245 removeTabFromContentView(tab);
246 }
247
248 @Override
249 public void attachTab(Tab tab) {
250 attachTabToContentView(tab);
251 }
252
253 private void attachTabToContentView(Tab tab) {
254 if (tab.getWebView() == null) {
255 return;
256 }
257 View container = tab.getViewContainer();
258 WebView mainView = tab.getWebView();
259 // Attach the WebView to the container and then attach the
260 // container to the content view.
261 FrameLayout wrapper =
262 (FrameLayout) container.findViewById(R.id.webview_wrapper);
263 ViewGroup parent = (ViewGroup) mainView.getParent();
264 if (parent != wrapper) {
265 if (parent != null) {
266 Log.w(LOGTAG, "mMainView already has a parent in"
267 + " attachTabToContentView!");
268 parent.removeView(mainView);
269 }
270 wrapper.addView(mainView);
271 } else {
272 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
273 + " attachTabToContentView!");
274 }
275 parent = (ViewGroup) container.getParent();
276 if (parent != mContentView) {
277 if (parent != null) {
278 Log.w(LOGTAG, "mContainer already has a parent in"
279 + " attachTabToContentView!");
280 parent.removeView(container);
281 }
282 mContentView.addView(container, COVER_SCREEN_PARAMS);
283 } else {
284 Log.w(LOGTAG, "mContainer is already attached to content in"
285 + " attachTabToContentView!");
286 }
287 mUiController.attachSubWindow(tab);
288 }
289
290 private void removeTabFromContentView(Tab tab) {
291 // Remove the container that contains the main WebView.
292 WebView mainView = tab.getWebView();
293 View container = tab.getViewContainer();
294 if (mainView == null) {
295 return;
296 }
297 // Remove the container from the content and then remove the
298 // WebView from the container. This will trigger a focus change
299 // needed by WebView.
300 FrameLayout wrapper =
301 (FrameLayout) container.findViewById(R.id.webview_wrapper);
302 wrapper.removeView(mainView);
303 mContentView.removeView(container);
304 mUiController.endActionMode();
305 mUiController.removeSubWindow(tab);
306 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
307 if (errorConsole != null) {
308 mErrorConsoleContainer.removeView(errorConsole);
309 }
310 mainView.setEmbeddedTitleBar(null);
311 }
312
Michael Kolba713ec82010-11-29 17:27:06 -0800313 @Override
314 public void onSetWebView(Tab tab, WebView webView) {
315 View container = tab.getViewContainer();
316 if (container == null) {
317 // The tab consists of a container view, which contains the main
318 // WebView, as well as any other UI elements associated with the tab.
319 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
320 null);
321 tab.setViewContainer(container);
322 }
323 if (tab.getWebView() != webView) {
324 // Just remove the old one.
325 FrameLayout wrapper =
326 (FrameLayout) container.findViewById(R.id.webview_wrapper);
327 wrapper.removeView(tab.getWebView());
328 }
329 }
330
Michael Kolb8233fac2010-10-26 16:08:53 -0700331 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800332 * create a sub window container and webview for the tab
333 * Note: this methods operates through side-effects for now
334 * it sets both the subView and subViewContainer for the given tab
335 * @param tab tab to create the sub window for
336 * @param subView webview to be set as a subwindow for the tab
337 */
338 @Override
339 public void createSubWindow(Tab tab, WebView subView) {
340 View subViewContainer = mActivity.getLayoutInflater().inflate(
341 R.layout.browser_subwindow, null);
342 ViewGroup inner = (ViewGroup) subViewContainer
343 .findViewById(R.id.inner_container);
344 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
345 LayoutParams.MATCH_PARENT));
346 final ImageButton cancel = (ImageButton) subViewContainer
347 .findViewById(R.id.subwindow_close);
348 final WebView cancelSubView = subView;
349 cancel.setOnClickListener(new OnClickListener() {
350 public void onClick(View v) {
351 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
352 }
353 });
354 tab.setSubWebView(subView);
355 tab.setSubViewContainer(subViewContainer);
356 }
357
358 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700359 * Remove the sub window from the content view.
360 */
361 @Override
362 public void removeSubWindow(View subviewContainer) {
363 mContentView.removeView(subviewContainer);
364 mUiController.endActionMode();
365 }
366
367 /**
368 * Attach the sub window to the content view.
369 */
370 @Override
371 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800372 if (container.getParent() != null) {
373 // already attached, remove first
374 ((ViewGroup) container.getParent()).removeView(container);
375 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700376 mContentView.addView(container, COVER_SCREEN_PARAMS);
377 }
378
379 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800380 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 WebView mainView = mUiController.getCurrentWebView();
382 // if there is no current WebView, don't show the faked title bar;
383 if (mainView == null) {
384 return;
385 }
386 // Do not need to check for null, since the current tab will have
387 // at least a main WebView, or we would have returned above.
388 if (mUiController.isInCustomActionMode()) {
389 // Do not show the fake title bar, while a custom ActionMode
390 // (i.e. find or select) is showing.
391 return;
392 }
Michael Kolb66706532010-12-12 19:50:22 -0800393 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700394 }
395 }
396
Michael Kolb66706532010-12-12 19:50:22 -0800397 protected abstract void attachFakeTitleBar(WebView mainView);
398
399 protected abstract void hideFakeTitleBar();
400
401 protected abstract boolean isFakeTitleBarShowing();
402
403 protected abstract TitleBarBase getFakeTitleBar();
404
405 protected abstract TitleBarBase getEmbeddedTitleBar();
406
407 @Override
408 public void showVoiceTitleBar(String title) {
409 getEmbeddedTitleBar().setInVoiceMode(true);
410 getEmbeddedTitleBar().setDisplayTitle(title);
411 getFakeTitleBar().setInVoiceMode(true);
412 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700413 }
414
Michael Kolb66706532010-12-12 19:50:22 -0800415 @Override
416 public void revertVoiceTitleBar(Tab tab) {
417 getEmbeddedTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800418 String url = tab.getUrl();
Michael Kolb66706532010-12-12 19:50:22 -0800419 getEmbeddedTitleBar().setDisplayTitle(url);
420 getFakeTitleBar().setInVoiceMode(false);
421 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700422 }
423
424 @Override
425 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800426 if (mComboView != null) {
427 return;
428 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700429 mComboView = new CombinedBookmarkHistoryView(mActivity,
430 mUiController,
431 startWithHistory ?
432 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
433 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
434 extras);
Michael Kolb66706532010-12-12 19:50:22 -0800435 getEmbeddedTitleBar().setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700436 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800437 dismissIME();
438 if (mActiveTab != null) {
439 WebView web = mActiveTab.getWebView();
440 mActiveTab.putInBackground();
441 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700442 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
443 }
444
445 /**
446 * dismiss the ComboPage
447 */
448 @Override
449 public void hideComboView() {
450 if (mComboView != null) {
451 mContentView.removeView(mComboView);
Michael Kolb66706532010-12-12 19:50:22 -0800452 getEmbeddedTitleBar().setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700453 mComboView = null;
454 }
Michael Kolb3a696282010-12-05 13:23:24 -0800455 if (mActiveTab != null) {
456 mActiveTab.putInForeground();
457 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700458 }
459
460 @Override
461 public void showCustomView(View view,
462 WebChromeClient.CustomViewCallback callback) {
463 // if a view already exists then immediately terminate the new one
464 if (mCustomView != null) {
465 callback.onCustomViewHidden();
466 return;
467 }
468
469 // Add the custom view to its container.
470 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
471 mCustomView = view;
472 mCustomViewCallback = callback;
473 // Hide the content view.
474 mContentView.setVisibility(View.GONE);
475 // Finally show the custom view container.
476 setStatusBarVisibility(false);
477 mCustomViewContainer.setVisibility(View.VISIBLE);
478 mCustomViewContainer.bringToFront();
479 }
480
481 @Override
482 public void onHideCustomView() {
483 if (mCustomView == null)
484 return;
485
486 // Hide the custom view.
487 mCustomView.setVisibility(View.GONE);
488 // Remove the custom view from its container.
489 mCustomViewContainer.removeView(mCustomView);
490 mCustomView = null;
491 mCustomViewContainer.setVisibility(View.GONE);
492 mCustomViewCallback.onCustomViewHidden();
493 // Show the content view.
494 setStatusBarVisibility(true);
495 mContentView.setVisibility(View.VISIBLE);
496 }
497
498 @Override
499 public boolean isCustomViewShowing() {
500 return mCustomView != null;
501 }
502
Michael Kolb66706532010-12-12 19:50:22 -0800503 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800504 if (mInputManager.isActive()) {
505 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
506 0);
507 }
508 }
509
Michael Kolb66706532010-12-12 19:50:22 -0800510 @Override
511 public boolean showsWeb() {
512 return mCustomView == null
513 && mComboView == null;
514 }
515
Michael Kolb8233fac2010-10-26 16:08:53 -0700516 // -------------------------------------------------------------------------
517
Michael Kolb8233fac2010-10-26 16:08:53 -0700518 /**
519 * Update the lock icon to correspond to our latest state.
520 */
Michael Kolb66706532010-12-12 19:50:22 -0800521 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800522 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700523 updateLockIconImage(t.getLockIconType());
524 }
525 }
526
527 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700528 * Updates the lock-icon image in the title-bar.
529 */
John Reck30c714c2010-12-16 17:30:34 -0800530 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700531 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800532 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700533 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800534 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700535 d = mMixLockIcon;
536 }
Michael Kolb66706532010-12-12 19:50:22 -0800537 getEmbeddedTitleBar().setLock(d);
538 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700539 }
540
John Reck30c714c2010-12-16 17:30:34 -0800541 protected void setUrlTitle(Tab tab) {
542 String url = tab.getUrl();
543 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800544 if (TextUtils.isEmpty(title)) {
545 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800546 }
Michael Kolb66706532010-12-12 19:50:22 -0800547 if (tab.isInVoiceSearchMode()) return;
548 if (tab.inForeground()) {
549 getEmbeddedTitleBar().setDisplayTitle(url);
550 getFakeTitleBar().setDisplayTitle(url);
551 }
552 }
553
554 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800555 protected void setFavicon(Tab tab) {
556 if (tab.inForeground()) {
557 Bitmap icon = tab.getFavicon();
558 getEmbeddedTitleBar().setFavicon(icon);
559 getFakeTitleBar().setFavicon(icon);
560 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700561 }
562
563 @Override
564 public void onActionModeFinished(boolean inLoad) {
565 if (inLoad) {
566 // the titlebar was removed when the CAB was shown
567 // if the page is loading, show it again
568 showFakeTitleBar();
569 }
570 }
571
Michael Kolb66706532010-12-12 19:50:22 -0800572 // active tabs page
573
574 public void showActiveTabsPage() {
575 }
576
577 /**
578 * Remove the active tabs page.
579 */
580 public void removeActiveTabsPage() {
581 }
582
Michael Kolb8233fac2010-10-26 16:08:53 -0700583 // menu handling callbacks
584
585 @Override
586 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700587 }
588
589 @Override
590 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700591 }
592
593 @Override
594 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700595 }
596
597 @Override
598 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700599 }
600
601 @Override
602 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 }
604
605 @Override
606 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 }
608
609 // error console
610
611 @Override
612 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
613 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
614 if (flag) {
615 // Setting the show state of the console will cause it's the layout
616 // to be inflated.
617 if (errorConsole.numberOfErrors() > 0) {
618 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
619 } else {
620 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
621 }
622 if (errorConsole.getParent() != null) {
623 mErrorConsoleContainer.removeView(errorConsole);
624 }
625 // Now we can add it to the main view.
626 mErrorConsoleContainer.addView(errorConsole,
627 new LinearLayout.LayoutParams(
628 ViewGroup.LayoutParams.MATCH_PARENT,
629 ViewGroup.LayoutParams.WRAP_CONTENT));
630 } else {
631 mErrorConsoleContainer.removeView(errorConsole);
632 }
633 }
634
635 private void setStatusBarVisibility(boolean visible) {
636 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
637 mActivity.getWindow().setFlags(flag,
638 WindowManager.LayoutParams.FLAG_FULLSCREEN);
639 }
640
641 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 public void onPrepareOptionsMenu(Menu menu) {
Michael Kolb66706532010-12-12 19:50:22 -0800643 final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
644 newtab.setEnabled(mUiController.getTabControl().canCreateNewTab());
Michael Kolb8233fac2010-10-26 16:08:53 -0700645 }
646
647 // -------------------------------------------------------------------------
648 // Helper function for WebChromeClient
649 // -------------------------------------------------------------------------
650
651 @Override
652 public Bitmap getDefaultVideoPoster() {
653 if (mDefaultVideoPoster == null) {
654 mDefaultVideoPoster = BitmapFactory.decodeResource(
655 mActivity.getResources(), R.drawable.default_video_poster);
656 }
657 return mDefaultVideoPoster;
658 }
659
660 @Override
661 public View getVideoLoadingProgressView() {
662 if (mVideoProgressView == null) {
663 LayoutInflater inflater = LayoutInflater.from(mActivity);
664 mVideoProgressView = inflater.inflate(
665 R.layout.video_loading_progress, null);
666 }
667 return mVideoProgressView;
668 }
669
Michael Kolb843510f2010-12-09 10:51:49 -0800670 @Override
671 public void showMaxTabsWarning() {
672 Toast warning = Toast.makeText(mActivity,
673 mActivity.getString(R.string.max_tabs_warning),
674 Toast.LENGTH_SHORT);
675 warning.show();
676 }
677
Michael Kolb8233fac2010-10-26 16:08:53 -0700678}