blob: 61acef52497487cc0cd9b6601737b009bb07ffca [file] [log] [blame]
Michael Kolb66706532010-12-12 19:50:22 -08001/*
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
Michael Kolbc3af0672011-08-09 10:24:41 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
21import android.animation.AnimatorSet;
22import android.animation.ObjectAnimator;
Michael Kolb66706532010-12-12 19:50:22 -080023import android.app.Activity;
Michael Kolbc3af0672011-08-09 10:24:41 -070024import android.content.Context;
25import android.graphics.Bitmap;
26import android.graphics.Canvas;
27import android.graphics.Matrix;
Michael Kolb376b5412010-12-15 11:52:57 -080028import android.util.Log;
John Reckaae029c2011-09-16 14:36:39 -070029import android.util.TypedValue;
Michael Kolb66706532010-12-12 19:50:22 -080030import android.view.ActionMode;
31import android.view.Gravity;
Michael Kolba4183062011-01-16 10:43:21 -080032import android.view.KeyEvent;
Michael Kolbc3af0672011-08-09 10:24:41 -070033import android.view.LayoutInflater;
Michael Kolb66706532010-12-12 19:50:22 -080034import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070035import android.view.MenuItem;
Michael Kolb66706532010-12-12 19:50:22 -080036import android.view.View;
Michael Kolb199e43c2011-08-17 10:45:45 -070037import android.view.ViewGroup;
Michael Kolb30adae62011-07-29 13:37:05 -070038import android.view.accessibility.AccessibilityEvent;
Michael Kolbc3af0672011-08-09 10:24:41 -070039import android.view.animation.DecelerateInterpolator;
Michael Kolb66706532010-12-12 19:50:22 -080040import android.webkit.WebView;
Michael Kolbfdb70242011-03-24 09:41:11 -070041import android.widget.FrameLayout;
Michael Kolbc3af0672011-08-09 10:24:41 -070042import android.widget.ImageView;
Michael Kolb66706532010-12-12 19:50:22 -080043
Michael Kolb629b22c2011-07-13 16:26:47 -070044import com.android.browser.UrlInputView.StateListener;
45
Michael Kolb66706532010-12-12 19:50:22 -080046/**
47 * Ui for regular phone screen sizes
48 */
49public class PhoneUi extends BaseUi {
50
51 private static final String LOGTAG = "PhoneUi";
52
Michael Kolb0241e752011-07-07 14:58:50 -070053 private PieControlPhone mPieControl;
Michael Kolbf2055602011-04-09 17:20:03 -070054 private NavScreen mNavScreen;
John Reck0f602f32011-07-07 15:38:43 -070055 private NavigationBarPhone mNavigationBar;
John Reckaae029c2011-09-16 14:36:39 -070056 private int mActionBarHeight;
Michael Kolb66706532010-12-12 19:50:22 -080057
58 boolean mExtendedMenuOpen;
59 boolean mOptionsMenuOpen;
Michael Kolb08a687a2011-04-22 16:13:02 -070060 boolean mAnimating;
Michael Kolb66706532010-12-12 19:50:22 -080061
62 /**
63 * @param browser
64 * @param controller
65 */
66 public PhoneUi(Activity browser, UiController controller) {
67 super(browser, controller);
Michael Kolbfdb70242011-03-24 09:41:11 -070068 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
John Reck0f602f32011-07-07 15:38:43 -070069 mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar();
John Reckaae029c2011-09-16 14:36:39 -070070 TypedValue heightValue = new TypedValue();
71 browser.getTheme().resolveAttribute(
72 com.android.internal.R.attr.actionBarSize, heightValue, true);
73 mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data,
74 browser.getResources().getDisplayMetrics());
John Reck285ef042011-02-11 15:44:17 -080075 }
Michael Kolb66706532010-12-12 19:50:22 -080076
John Reck285ef042011-02-11 15:44:17 -080077 @Override
Michael Kolb66706532010-12-12 19:50:22 -080078 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080079 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080080 }
81
82 @Override
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080083 public void editUrl(boolean clearInput) {
Michael Kolb46f987e2011-04-05 10:39:10 -070084 if (mUseQuickControls) {
John Reck0f602f32011-07-07 15:38:43 -070085 mTitleBar.setShowProgressOnly(false);
Michael Kolb46f987e2011-04-05 10:39:10 -070086 }
87 super.editUrl(clearInput);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080088 }
89
90 @Override
Michael Kolb66706532010-12-12 19:50:22 -080091 public boolean onBackKey() {
Michael Kolb9ef259a2011-07-12 15:33:08 -070092 if (mNavScreen != null) {
Michael Kolbf2055602011-04-09 17:20:03 -070093 mNavScreen.close();
94 return true;
Michael Kolb66706532010-12-12 19:50:22 -080095 }
96 return super.onBackKey();
97 }
98
99 @Override
Michael Kolbf2055602011-04-09 17:20:03 -0700100 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbf2055602011-04-09 17:20:03 -0700101 return false;
102 }
103
104 @Override
John Reck30c714c2010-12-16 17:30:34 -0800105 public void onProgressChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800106 if (tab.inForeground()) {
John Reck30c714c2010-12-16 17:30:34 -0800107 int progress = tab.getLoadProgress();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800108 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800109 if (progress == 100) {
110 if (!mOptionsMenuOpen || !mExtendedMenuOpen) {
John Reck5d43ce82011-06-21 17:16:51 -0700111 suggestHideTitleBar();
Michael Kolbc16c5952011-03-29 15:37:03 -0700112 if (mUseQuickControls) {
113 mTitleBar.setShowProgressOnly(false);
114 }
Michael Kolb66706532010-12-12 19:50:22 -0800115 }
116 } else {
117 if (!mOptionsMenuOpen || mExtendedMenuOpen) {
Michael Kolbc16c5952011-03-29 15:37:03 -0700118 if (mUseQuickControls && !mTitleBar.isEditingUrl()) {
119 mTitleBar.setShowProgressOnly(true);
120 setTitleGravity(Gravity.TOP);
121 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800122 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800123 }
124 }
125 }
126 }
127
128 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700129 public void setActiveTab(final Tab tab) {
John Reck8ee633f2011-08-09 16:00:35 -0700130 mTitleBar.cancelTitleBarAnimation(true);
131 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700132 super.setActiveTab(tab);
Michael Kolbfdb70242011-03-24 09:41:11 -0700133 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800134 // TabControl.setCurrentTab has been called before this,
135 // so the tab is guaranteed to have a webview
136 if (view == null) {
137 Log.e(LOGTAG, "active tab with no webview detected");
138 return;
139 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700140 // Request focus on the top window.
141 if (mUseQuickControls) {
142 mPieControl.forceToTop(mContentView);
Michael Kolbfdb70242011-03-24 09:41:11 -0700143 } else {
144 // check if title bar is already attached by animation
145 if (mTitleBar.getParent() == null) {
146 view.setEmbeddedTitleBar(mTitleBar);
147 }
148 }
Michael Kolb376b5412010-12-15 11:52:57 -0800149 if (tab.isInVoiceSearchMode()) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700150 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
Michael Kolb376b5412010-12-15 11:52:57 -0800151 } else {
152 revertVoiceTitleBar(tab);
153 }
Michael Kolb629b22c2011-07-13 16:26:47 -0700154 // update nav bar state
155 mNavigationBar.onStateChanged(StateListener.STATE_NORMAL);
Michael Kolbfdb70242011-03-24 09:41:11 -0700156 updateLockIconToLatest(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800157 tab.getTopWindow().requestFocus();
John Reck8ee633f2011-08-09 16:00:35 -0700158 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb376b5412010-12-15 11:52:57 -0800159 }
160
Michael Kolb66706532010-12-12 19:50:22 -0800161 // menu handling callbacks
162
163 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700164 public boolean onPrepareOptionsMenu(Menu menu) {
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700165 updateMenuState(mActiveTab, menu);
Michael Kolb3ca12752011-07-20 13:52:25 -0700166 return true;
167 }
168
169 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700170 public void updateMenuState(Tab tab, Menu menu) {
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700171 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
172 if (bm != null) {
173 bm.setVisible(mNavScreen == null);
174 }
175 MenuItem nt = menu.findItem(R.id.new_tab_menu_id);
176 if (nt != null) {
177 nt.setVisible(mNavScreen == null);
178 }
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700179 MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id);
180 if (abm != null) {
John Recke1a03a32011-09-14 17:04:16 -0700181 abm.setVisible((tab != null) && !tab.isSnapshot() && mNavScreen == null);
182 }
183 if (mNavScreen != null) {
184 menu.setGroupVisible(R.id.LIVE_MENU, false);
185 menu.setGroupVisible(R.id.SNAPSHOT_MENU, false);
186 menu.findItem(R.id.page_info_menu_id).setVisible(false);
187 menu.setGroupVisible(R.id.NAV_MENU, false);
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700188 }
189 }
190
191 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700192 public boolean onOptionsItemSelected(MenuItem item) {
193 if (mNavScreen != null) {
194 hideNavScreen(false);
195 }
196 return false;
197 }
198
199 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800200 public void onContextMenuCreated(Menu menu) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800201 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800202 }
203
204 @Override
205 public void onContextMenuClosed(Menu menu, boolean inLoad) {
206 if (inLoad) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800207 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800208 }
209 }
210
211 // action mode callbacks
212
213 @Override
214 public void onActionModeStarted(ActionMode mode) {
Michael Kolb42c0c062011-08-02 12:56:06 -0700215 if (!isEditingUrl()) {
216 hideTitleBar();
John Reckaae029c2011-09-16 14:36:39 -0700217 } else {
218 mTitleBar.animate().translationY(mActionBarHeight);
Michael Kolb42c0c062011-08-02 12:56:06 -0700219 }
Michael Kolb66706532010-12-12 19:50:22 -0800220 }
221
Michael Kolba4183062011-01-16 10:43:21 -0800222 @Override
John Reck6cda7b12011-03-18 15:57:13 -0700223 public void onActionModeFinished(boolean inLoad) {
John Reckaae029c2011-09-16 14:36:39 -0700224 mTitleBar.animate().translationY(0);
Michael Kolbc16c5952011-03-29 15:37:03 -0700225 if (inLoad) {
226 if (mUseQuickControls) {
227 mTitleBar.setShowProgressOnly(true);
John Reck6cda7b12011-03-18 15:57:13 -0700228 }
Michael Kolbc16c5952011-03-29 15:37:03 -0700229 showTitleBar();
230 }
John Reck6cda7b12011-03-18 15:57:13 -0700231 }
232
233 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700234 protected void setTitleGravity(int gravity) {
235 if (mUseQuickControls) {
236 FrameLayout.LayoutParams lp =
John Reck0f602f32011-07-07 15:38:43 -0700237 (FrameLayout.LayoutParams) mTitleBar.getLayoutParams();
Michael Kolbfdb70242011-03-24 09:41:11 -0700238 lp.gravity = gravity;
John Reck0f602f32011-07-07 15:38:43 -0700239 mTitleBar.setLayoutParams(lp);
Michael Kolbfdb70242011-03-24 09:41:11 -0700240 } else {
241 super.setTitleGravity(gravity);
242 }
243 }
244
Michael Kolb0241e752011-07-07 14:58:50 -0700245 @Override
246 public void setUseQuickControls(boolean useQuickControls) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700247 mUseQuickControls = useQuickControls;
John Reck0f602f32011-07-07 15:38:43 -0700248 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolbfdb70242011-03-24 09:41:11 -0700249 if (useQuickControls) {
Michael Kolb0241e752011-07-07 14:58:50 -0700250 mPieControl = new PieControlPhone(mActivity, mUiController, this);
Michael Kolbfdb70242011-03-24 09:41:11 -0700251 mPieControl.attachToContainer(mContentView);
Michael Kolb46f987e2011-04-05 10:39:10 -0700252 WebView web = getWebView();
253 if (web != null) {
254 web.setEmbeddedTitleBar(null);
Michael Kolbfdb70242011-03-24 09:41:11 -0700255 }
256 } else {
Michael Kolbfdb70242011-03-24 09:41:11 -0700257 if (mPieControl != null) {
258 mPieControl.removeFromContainer(mContentView);
259 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700260 WebView web = getWebView();
Michael Kolbfdb70242011-03-24 09:41:11 -0700261 if (web != null) {
Michael Kolb199e43c2011-08-17 10:45:45 -0700262 // make sure we can re-parent titlebar
263 if ((mTitleBar != null) && (mTitleBar.getParent() != null)) {
264 ((ViewGroup) mTitleBar.getParent()).removeView(mTitleBar);
265 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700266 web.setEmbeddedTitleBar(mTitleBar);
267 }
268 setTitleGravity(Gravity.NO_GRAVITY);
269 }
John Reck718a24d2011-08-12 11:08:30 -0700270 updateUrlBarAutoShowManagerTarget();
Michael Kolbfdb70242011-03-24 09:41:11 -0700271 }
272
Michael Kolbc3af0672011-08-09 10:24:41 -0700273 @Override
274 public boolean isWebShowing() {
275 return super.isWebShowing() && mNavScreen == null;
276 }
277
278 @Override
279 public void showWeb(boolean animate) {
280 super.showWeb(animate);
281 hideNavScreen(animate);
282 }
283
Michael Kolbf2055602011-04-09 17:20:03 -0700284 void showNavScreen() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700285 mUiController.setBlockEvents(true);
Michael Kolbf2055602011-04-09 17:20:03 -0700286 mNavScreen = new NavScreen(mActivity, mUiController, this);
Michael Kolbc3af0672011-08-09 10:24:41 -0700287 mActiveTab.capture();
288 // Add the custom view to its container
Michael Kolb2814a362011-05-19 15:49:41 -0700289 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
Michael Kolbc3af0672011-08-09 10:24:41 -0700290 AnimScreen ascreen = new AnimScreen(mActivity, getTitleBar(), getWebView());
291 final View animView = ascreen.mMain;
292 mCustomViewContainer.addView(animView, COVER_SCREEN_PARAMS);
Michael Kolbf2055602011-04-09 17:20:03 -0700293 mCustomViewContainer.setVisibility(View.VISIBLE);
294 mCustomViewContainer.bringToFront();
Michael Kolbc3af0672011-08-09 10:24:41 -0700295 View target = ((NavTabView) mNavScreen.mScroller.getSelectedView()).mImage;
296 int fromLeft = 0;
297 int fromTop = getTitleBar().getHeight();
298 int fromRight = mContentView.getWidth();
299 int fromBottom = mContentView.getHeight();
300 int width = target.getWidth();
301 int height = target.getHeight();
302 int toLeft = (mContentView.getWidth() - width) / 2;
303 int toTop = fromTop + (mContentView.getHeight() - fromTop - height) / 2;
304 int toRight = toLeft + width;
305 int toBottom = toTop + height;
306 float scaleFactor = width / (float) mContentView.getWidth();
307 detachTab(mActiveTab);
308 mContentView.setVisibility(View.GONE);
309 AnimatorSet inanim = new AnimatorSet();
310 ObjectAnimator tx = ObjectAnimator.ofInt(ascreen.mContent, "left",
311 fromLeft, toLeft);
312 ObjectAnimator ty = ObjectAnimator.ofInt(ascreen.mContent, "top",
313 fromTop, toTop);
314 ObjectAnimator tr = ObjectAnimator.ofInt(ascreen.mContent, "right",
315 fromRight, toRight);
316 ObjectAnimator tb = ObjectAnimator.ofInt(ascreen.mContent, "bottom",
317 fromBottom, toBottom);
318 ObjectAnimator title = ObjectAnimator.ofFloat(ascreen.mTitle, "alpha",
319 1f, 0f);
320 ObjectAnimator content = ObjectAnimator.ofFloat(ascreen.mContent, "alpha",
321 1f, 0f);
322 ObjectAnimator sx = ObjectAnimator.ofFloat(ascreen, "scaleFactor",
323 1f, scaleFactor);
324 inanim.playTogether(tx, ty, tr, tb, title, content, sx);
325 inanim.addListener(new AnimatorListenerAdapter() {
326 @Override
327 public void onAnimationEnd(Animator anim) {
328 mCustomViewContainer.removeView(animView);
329 finishAnimationIn();
330 mUiController.setBlockEvents(false);
331 }
332 });
333 inanim.setInterpolator(new DecelerateInterpolator(2f));
334 inanim.setDuration(300);
335 inanim.start();
336 }
337
338 private void finishAnimationIn() {
Michael Kolbb43f2f62011-08-17 10:39:31 -0700339 if (mNavScreen != null) {
340 // notify accessibility manager about the screen change
341 mNavScreen.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
342 mTabControl.setOnThumbnailUpdatedListener(mNavScreen);
343 }
Michael Kolbf2055602011-04-09 17:20:03 -0700344 }
345
Michael Kolb2814a362011-05-19 15:49:41 -0700346 void hideNavScreen(boolean animate) {
Michael Kolb09bf24f2011-06-09 14:34:30 -0700347 if (mNavScreen == null) return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700348 final Tab tab = mNavScreen.getSelectedTab();
Michael Kolbbf32cd02011-08-16 15:07:04 -0700349 if ((tab == null) || !animate) {
Michael Kolb365561d2011-08-18 09:56:25 -0700350 if (tab != null) {
351 setActiveTab(tab);
352 } else if (mTabControl.getTabCount() > 0) {
353 // use a fallback tab
354 setActiveTab(mTabControl.getCurrentTab());
355 }
Michael Kolbbf32cd02011-08-16 15:07:04 -0700356 mContentView.setVisibility(View.VISIBLE);
357 finishAnimateOut();
Michael Kolb8a009492011-08-15 15:37:30 -0700358 return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700359 }
360 NavTabView tabview = (NavTabView) mNavScreen.getSelectedTabView();
361 if (tabview == null) {
Michael Kolb365561d2011-08-18 09:56:25 -0700362 if (mTabControl.getTabCount() > 0) {
363 // use a fallback tab
364 setActiveTab(mTabControl.getCurrentTab());
365 }
Michael Kolbbf32cd02011-08-16 15:07:04 -0700366 mContentView.setVisibility(View.VISIBLE);
367 finishAnimateOut();
Michael Kolb8a009492011-08-15 15:37:30 -0700368 return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700369 }
370 mUiController.setBlockEvents(true);
371 mUiController.setActiveTab(tab);
372 mContentView.setVisibility(View.VISIBLE);
373 final AnimScreen screen = new AnimScreen(mActivity, tab.getScreenshot());
374 View target = ((NavTabView) mNavScreen.mScroller.getSelectedView()).mImage;
375 int toLeft = 0;
376 int toTop = getTitleBar().getHeight();
377 int toRight = mContentView.getWidth();
378 int width = target.getWidth();
379 int height = target.getHeight();
380 int[] pos = new int[2];
381 tabview.mImage.getLocationInWindow(pos);
382 int fromLeft = pos[0];
383 int fromTop = pos[1];
384 int fromRight = fromLeft + width;
385 int fromBottom = fromTop + height;
386 float scaleFactor = mContentView.getWidth() / (float) width;
387 int toBottom = (int) (height * scaleFactor);
388 screen.mMain.setAlpha(0f);
389 mCustomViewContainer.addView(screen.mMain, COVER_SCREEN_PARAMS);
390 AnimatorSet animSet = new AnimatorSet();
391 ObjectAnimator l = ObjectAnimator.ofInt(screen.mContent, "left",
392 fromLeft, toLeft);
393 ObjectAnimator t = ObjectAnimator.ofInt(screen.mContent, "top",
394 fromTop, toTop);
395 ObjectAnimator r = ObjectAnimator.ofInt(screen.mContent, "right",
396 fromRight, toRight);
397 ObjectAnimator b = ObjectAnimator.ofInt(screen.mContent, "bottom",
398 fromBottom, toBottom);
399 ObjectAnimator scale = ObjectAnimator.ofFloat(screen, "scaleFactor",
400 1f, scaleFactor);
401 ObjectAnimator alpha = ObjectAnimator.ofFloat(screen.mMain, "alpha", 1f, 1f);
402 ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f);
403 alpha.setStartDelay(100);
404 animSet.playTogether(l, t, r, b, scale, alpha, otheralpha);
405 animSet.addListener(new AnimatorListenerAdapter() {
406 @Override
407 public void onAnimationEnd(Animator anim) {
408 mCustomViewContainer.removeView(screen.mMain);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700409 finishAnimateOut();
Michael Kolbc3af0672011-08-09 10:24:41 -0700410 mUiController.setBlockEvents(false);
411 }
412 });
413 animSet.setDuration(250);
414 animSet.start();
415 }
416
Michael Kolbbf32cd02011-08-16 15:07:04 -0700417 private void finishAnimateOut() {
John Reck8ee633f2011-08-09 16:00:35 -0700418 mTabControl.setOnThumbnailUpdatedListener(null);
Michael Kolbf2055602011-04-09 17:20:03 -0700419 mCustomViewContainer.removeView(mNavScreen);
Michael Kolbc3af0672011-08-09 10:24:41 -0700420 mCustomViewContainer.setAlpha(1f);
Michael Kolbf2055602011-04-09 17:20:03 -0700421 mNavScreen = null;
422 mCustomViewContainer.setVisibility(View.GONE);
Michael Kolbf2055602011-04-09 17:20:03 -0700423 }
424
John Reck6b4bd5f2011-07-12 10:14:38 -0700425 @Override
426 public boolean needsRestoreAllTabs() {
427 return false;
428 }
429
Michael Kolb20be26d2011-07-18 16:38:02 -0700430 public void toggleNavScreen() {
431 if (mNavScreen == null) {
432 showNavScreen();
433 } else {
434 hideNavScreen(false);
435 }
436 }
437
John Reck1cf4b792011-07-26 10:22:22 -0700438 @Override
439 public boolean shouldCaptureThumbnails() {
440 return true;
441 }
442
Michael Kolbc3af0672011-08-09 10:24:41 -0700443 static class AnimScreen {
John Reck3ba45532011-08-11 16:26:53 -0700444
Michael Kolbc3af0672011-08-09 10:24:41 -0700445 private View mMain;
446 private ImageView mTitle;
447 private ImageView mContent;
448 private float mScale;
449
450 public AnimScreen(Context ctx, TitleBar tbar, WebView web) {
451 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
452 null);
453 mContent = (ImageView) mMain.findViewById(R.id.content);
454 mContent.setTop(tbar.getHeight());
455
456 mTitle = (ImageView) mMain.findViewById(R.id.title);
457 Bitmap bm1 = Bitmap.createBitmap(tbar.getWidth(), tbar.getHeight(),
458 Bitmap.Config.RGB_565);
459 Canvas c1 = new Canvas(bm1);
460 tbar.draw(c1);
461 mTitle.setImageBitmap(bm1);
462 int h = web.getHeight() - tbar.getHeight();
463 Bitmap bm2 = Bitmap.createBitmap(web.getWidth(), h,
464 Bitmap.Config.RGB_565);
465 Canvas c2 = new Canvas(bm2);
466 int tx = web.getScrollX();
467 int ty = web.getScrollY();
468 c2.translate(-tx, -ty - tbar.getHeight());
469 web.draw(c2);
470 mContent.setImageBitmap(bm2);
471 mContent.setScaleType(ImageView.ScaleType.MATRIX);
472 mContent.setImageMatrix(new Matrix());
473 mScale = 1.0f;
474 setScaleFactor(getScaleFactor());
475 }
476
477 public AnimScreen(Context ctx, Bitmap image) {
478 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
479 null);
480 mContent = (ImageView) mMain.findViewById(R.id.content);
481 mContent.setImageBitmap(image);
482 mContent.setScaleType(ImageView.ScaleType.MATRIX);
483 mContent.setImageMatrix(new Matrix());
484 mScale = 1.0f;
485 setScaleFactor(getScaleFactor());
486 }
487
488 public void setScaleFactor(float sf) {
489 mScale = sf;
490 Matrix m = new Matrix();
491 m.postScale(sf,sf);
492 mContent.setImageMatrix(m);
493 }
494
495 public float getScaleFactor() {
496 return mScale;
497 }
498
John Reck3ba45532011-08-11 16:26:53 -0700499 }
500
Michael Kolb66706532010-12-12 19:50:22 -0800501}