blob: 4772ff171393ba498c6e1d69a6fbce476439424d [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 Kolb66706532010-12-12 19:50:22 -080039import android.webkit.WebView;
Michael Kolbfdb70242011-03-24 09:41:11 -070040import android.widget.FrameLayout;
Michael Kolbc3af0672011-08-09 10:24:41 -070041import android.widget.ImageView;
Michael Kolb66706532010-12-12 19:50:22 -080042
Michael Kolb629b22c2011-07-13 16:26:47 -070043import com.android.browser.UrlInputView.StateListener;
44
Michael Kolb66706532010-12-12 19:50:22 -080045/**
46 * Ui for regular phone screen sizes
47 */
48public class PhoneUi extends BaseUi {
49
50 private static final String LOGTAG = "PhoneUi";
51
Michael Kolb0241e752011-07-07 14:58:50 -070052 private PieControlPhone mPieControl;
Michael Kolbf2055602011-04-09 17:20:03 -070053 private NavScreen mNavScreen;
John Reck0f602f32011-07-07 15:38:43 -070054 private NavigationBarPhone mNavigationBar;
John Reckaae029c2011-09-16 14:36:39 -070055 private int mActionBarHeight;
Michael Kolb66706532010-12-12 19:50:22 -080056
57 boolean mExtendedMenuOpen;
58 boolean mOptionsMenuOpen;
Michael Kolb08a687a2011-04-22 16:13:02 -070059 boolean mAnimating;
Michael Kolb66706532010-12-12 19:50:22 -080060
61 /**
62 * @param browser
63 * @param controller
64 */
65 public PhoneUi(Activity browser, UiController controller) {
66 super(browser, controller);
Michael Kolbfdb70242011-03-24 09:41:11 -070067 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
John Reck0f602f32011-07-07 15:38:43 -070068 mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar();
John Reckaae029c2011-09-16 14:36:39 -070069 TypedValue heightValue = new TypedValue();
70 browser.getTheme().resolveAttribute(
71 com.android.internal.R.attr.actionBarSize, heightValue, true);
72 mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data,
73 browser.getResources().getDisplayMetrics());
John Reck285ef042011-02-11 15:44:17 -080074 }
Michael Kolb66706532010-12-12 19:50:22 -080075
John Reck285ef042011-02-11 15:44:17 -080076 @Override
Michael Kolb66706532010-12-12 19:50:22 -080077 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080078 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080079 }
80
81 @Override
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080082 public void editUrl(boolean clearInput) {
Michael Kolb46f987e2011-04-05 10:39:10 -070083 if (mUseQuickControls) {
John Reck0f602f32011-07-07 15:38:43 -070084 mTitleBar.setShowProgressOnly(false);
Michael Kolb46f987e2011-04-05 10:39:10 -070085 }
86 super.editUrl(clearInput);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080087 }
88
89 @Override
Michael Kolb66706532010-12-12 19:50:22 -080090 public boolean onBackKey() {
Michael Kolb9ef259a2011-07-12 15:33:08 -070091 if (mNavScreen != null) {
Michael Kolba3194d02011-09-07 11:23:51 -070092 mNavScreen.close(mUiController.getTabControl().getCurrentPosition());
Michael Kolbf2055602011-04-09 17:20:03 -070093 return true;
Michael Kolb66706532010-12-12 19:50:22 -080094 }
95 return super.onBackKey();
96 }
97
98 @Override
Michael Kolbf2055602011-04-09 17:20:03 -070099 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbf2055602011-04-09 17:20:03 -0700100 return false;
101 }
102
103 @Override
John Reck30c714c2010-12-16 17:30:34 -0800104 public void onProgressChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800105 if (tab.inForeground()) {
John Reck30c714c2010-12-16 17:30:34 -0800106 int progress = tab.getLoadProgress();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800107 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800108 if (progress == 100) {
109 if (!mOptionsMenuOpen || !mExtendedMenuOpen) {
John Reck5d43ce82011-06-21 17:16:51 -0700110 suggestHideTitleBar();
Michael Kolbc16c5952011-03-29 15:37:03 -0700111 if (mUseQuickControls) {
112 mTitleBar.setShowProgressOnly(false);
113 }
Michael Kolb66706532010-12-12 19:50:22 -0800114 }
115 } else {
116 if (!mOptionsMenuOpen || mExtendedMenuOpen) {
Michael Kolbc16c5952011-03-29 15:37:03 -0700117 if (mUseQuickControls && !mTitleBar.isEditingUrl()) {
118 mTitleBar.setShowProgressOnly(true);
119 setTitleGravity(Gravity.TOP);
120 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800121 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800122 }
123 }
124 }
125 }
126
127 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700128 public void setActiveTab(final Tab tab) {
John Reck8ee633f2011-08-09 16:00:35 -0700129 mTitleBar.cancelTitleBarAnimation(true);
130 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700131 super.setActiveTab(tab);
Michael Kolbfdb70242011-03-24 09:41:11 -0700132 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800133 // TabControl.setCurrentTab has been called before this,
134 // so the tab is guaranteed to have a webview
135 if (view == null) {
136 Log.e(LOGTAG, "active tab with no webview detected");
137 return;
138 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700139 // Request focus on the top window.
140 if (mUseQuickControls) {
141 mPieControl.forceToTop(mContentView);
Michael Kolbfdb70242011-03-24 09:41:11 -0700142 } else {
143 // check if title bar is already attached by animation
144 if (mTitleBar.getParent() == null) {
145 view.setEmbeddedTitleBar(mTitleBar);
146 }
147 }
Michael Kolb376b5412010-12-15 11:52:57 -0800148 if (tab.isInVoiceSearchMode()) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700149 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
Michael Kolb376b5412010-12-15 11:52:57 -0800150 } else {
151 revertVoiceTitleBar(tab);
152 }
Michael Kolb629b22c2011-07-13 16:26:47 -0700153 // update nav bar state
154 mNavigationBar.onStateChanged(StateListener.STATE_NORMAL);
Michael Kolbfdb70242011-03-24 09:41:11 -0700155 updateLockIconToLatest(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800156 tab.getTopWindow().requestFocus();
John Reck8ee633f2011-08-09 16:00:35 -0700157 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb376b5412010-12-15 11:52:57 -0800158 }
159
Michael Kolb66706532010-12-12 19:50:22 -0800160 // menu handling callbacks
161
162 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700163 public boolean onPrepareOptionsMenu(Menu menu) {
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700164 updateMenuState(mActiveTab, menu);
Michael Kolb3ca12752011-07-20 13:52:25 -0700165 return true;
166 }
167
168 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700169 public void updateMenuState(Tab tab, Menu menu) {
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700170 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
171 if (bm != null) {
172 bm.setVisible(mNavScreen == null);
173 }
174 MenuItem nt = menu.findItem(R.id.new_tab_menu_id);
175 if (nt != null) {
176 nt.setVisible(mNavScreen == null);
177 }
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700178 MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id);
179 if (abm != null) {
John Recke1a03a32011-09-14 17:04:16 -0700180 abm.setVisible((tab != null) && !tab.isSnapshot() && mNavScreen == null);
181 }
182 if (mNavScreen != null) {
183 menu.setGroupVisible(R.id.LIVE_MENU, false);
184 menu.setGroupVisible(R.id.SNAPSHOT_MENU, false);
185 menu.findItem(R.id.page_info_menu_id).setVisible(false);
186 menu.setGroupVisible(R.id.NAV_MENU, false);
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700187 }
188 }
189
190 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700191 public boolean onOptionsItemSelected(MenuItem item) {
192 if (mNavScreen != null) {
Michael Kolba3194d02011-09-07 11:23:51 -0700193 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false);
Michael Kolb3ca12752011-07-20 13:52:25 -0700194 }
195 return false;
196 }
197
198 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800199 public void onContextMenuCreated(Menu menu) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800200 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800201 }
202
203 @Override
204 public void onContextMenuClosed(Menu menu, boolean inLoad) {
205 if (inLoad) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800206 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800207 }
208 }
209
210 // action mode callbacks
211
212 @Override
213 public void onActionModeStarted(ActionMode mode) {
Michael Kolb42c0c062011-08-02 12:56:06 -0700214 if (!isEditingUrl()) {
215 hideTitleBar();
John Reckaae029c2011-09-16 14:36:39 -0700216 } else {
217 mTitleBar.animate().translationY(mActionBarHeight);
Michael Kolb42c0c062011-08-02 12:56:06 -0700218 }
Michael Kolb66706532010-12-12 19:50:22 -0800219 }
220
Michael Kolba4183062011-01-16 10:43:21 -0800221 @Override
John Reck6cda7b12011-03-18 15:57:13 -0700222 public void onActionModeFinished(boolean inLoad) {
John Reckaae029c2011-09-16 14:36:39 -0700223 mTitleBar.animate().translationY(0);
Michael Kolbc16c5952011-03-29 15:37:03 -0700224 if (inLoad) {
225 if (mUseQuickControls) {
226 mTitleBar.setShowProgressOnly(true);
John Reck6cda7b12011-03-18 15:57:13 -0700227 }
Michael Kolbc16c5952011-03-29 15:37:03 -0700228 showTitleBar();
229 }
John Reck6cda7b12011-03-18 15:57:13 -0700230 }
231
232 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700233 protected void setTitleGravity(int gravity) {
234 if (mUseQuickControls) {
235 FrameLayout.LayoutParams lp =
John Reck0f602f32011-07-07 15:38:43 -0700236 (FrameLayout.LayoutParams) mTitleBar.getLayoutParams();
Michael Kolbfdb70242011-03-24 09:41:11 -0700237 lp.gravity = gravity;
John Reck0f602f32011-07-07 15:38:43 -0700238 mTitleBar.setLayoutParams(lp);
Michael Kolbfdb70242011-03-24 09:41:11 -0700239 } else {
240 super.setTitleGravity(gravity);
241 }
242 }
243
Michael Kolb0241e752011-07-07 14:58:50 -0700244 @Override
245 public void setUseQuickControls(boolean useQuickControls) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700246 mUseQuickControls = useQuickControls;
John Reck0f602f32011-07-07 15:38:43 -0700247 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolbfdb70242011-03-24 09:41:11 -0700248 if (useQuickControls) {
Michael Kolb0241e752011-07-07 14:58:50 -0700249 mPieControl = new PieControlPhone(mActivity, mUiController, this);
Michael Kolbfdb70242011-03-24 09:41:11 -0700250 mPieControl.attachToContainer(mContentView);
Michael Kolb46f987e2011-04-05 10:39:10 -0700251 WebView web = getWebView();
252 if (web != null) {
253 web.setEmbeddedTitleBar(null);
Michael Kolbfdb70242011-03-24 09:41:11 -0700254 }
255 } else {
Michael Kolbfdb70242011-03-24 09:41:11 -0700256 if (mPieControl != null) {
257 mPieControl.removeFromContainer(mContentView);
258 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700259 WebView web = getWebView();
Michael Kolbfdb70242011-03-24 09:41:11 -0700260 if (web != null) {
Michael Kolb199e43c2011-08-17 10:45:45 -0700261 // make sure we can re-parent titlebar
262 if ((mTitleBar != null) && (mTitleBar.getParent() != null)) {
263 ((ViewGroup) mTitleBar.getParent()).removeView(mTitleBar);
264 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700265 web.setEmbeddedTitleBar(mTitleBar);
266 }
267 setTitleGravity(Gravity.NO_GRAVITY);
268 }
John Reck718a24d2011-08-12 11:08:30 -0700269 updateUrlBarAutoShowManagerTarget();
Michael Kolbfdb70242011-03-24 09:41:11 -0700270 }
271
Michael Kolbc3af0672011-08-09 10:24:41 -0700272 @Override
273 public boolean isWebShowing() {
274 return super.isWebShowing() && mNavScreen == null;
275 }
276
277 @Override
278 public void showWeb(boolean animate) {
279 super.showWeb(animate);
Michael Kolba3194d02011-09-07 11:23:51 -0700280 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), animate);
Michael Kolbc3af0672011-08-09 10:24:41 -0700281 }
282
Michael Kolbf2055602011-04-09 17:20:03 -0700283 void showNavScreen() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700284 mUiController.setBlockEvents(true);
Michael Kolbf2055602011-04-09 17:20:03 -0700285 mNavScreen = new NavScreen(mActivity, mUiController, this);
Michael Kolbc3af0672011-08-09 10:24:41 -0700286 mActiveTab.capture();
287 // Add the custom view to its container
Michael Kolb2814a362011-05-19 15:49:41 -0700288 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
Michael Kolbc3af0672011-08-09 10:24:41 -0700289 AnimScreen ascreen = new AnimScreen(mActivity, getTitleBar(), getWebView());
290 final View animView = ascreen.mMain;
291 mCustomViewContainer.addView(animView, COVER_SCREEN_PARAMS);
Michael Kolbf2055602011-04-09 17:20:03 -0700292 mCustomViewContainer.setVisibility(View.VISIBLE);
293 mCustomViewContainer.bringToFront();
Michael Kolbc3af0672011-08-09 10:24:41 -0700294 int fromLeft = 0;
295 int fromTop = getTitleBar().getHeight();
296 int fromRight = mContentView.getWidth();
297 int fromBottom = mContentView.getHeight();
Michael Kolba3194d02011-09-07 11:23:51 -0700298 int width = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_width);
299 int height = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_height);
Michael Kolbc3af0672011-08-09 10:24:41 -0700300 int toLeft = (mContentView.getWidth() - width) / 2;
Michael Kolba3194d02011-09-07 11:23:51 -0700301 int toTop = ((fromBottom - (fromTop + height)) / 2 + fromTop);
Michael Kolbc3af0672011-08-09 10:24:41 -0700302 int toRight = toLeft + width;
303 int toBottom = toTop + height;
304 float scaleFactor = width / (float) mContentView.getWidth();
305 detachTab(mActiveTab);
306 mContentView.setVisibility(View.GONE);
Michael Kolba3194d02011-09-07 11:23:51 -0700307 AnimatorSet set1 = new AnimatorSet();
Michael Kolbc3af0672011-08-09 10:24:41 -0700308 AnimatorSet inanim = new AnimatorSet();
309 ObjectAnimator tx = ObjectAnimator.ofInt(ascreen.mContent, "left",
310 fromLeft, toLeft);
311 ObjectAnimator ty = ObjectAnimator.ofInt(ascreen.mContent, "top",
312 fromTop, toTop);
313 ObjectAnimator tr = ObjectAnimator.ofInt(ascreen.mContent, "right",
314 fromRight, toRight);
315 ObjectAnimator tb = ObjectAnimator.ofInt(ascreen.mContent, "bottom",
316 fromBottom, toBottom);
317 ObjectAnimator title = ObjectAnimator.ofFloat(ascreen.mTitle, "alpha",
318 1f, 0f);
Michael Kolbc3af0672011-08-09 10:24:41 -0700319 ObjectAnimator sx = ObjectAnimator.ofFloat(ascreen, "scaleFactor",
320 1f, scaleFactor);
Michael Kolba3194d02011-09-07 11:23:51 -0700321 ObjectAnimator blend1 = ObjectAnimator.ofFloat(ascreen.mMain, "alpha", 1, 0);
322 blend1.setDuration(100);
323
324 inanim.playTogether(tx, ty, tr, tb, sx, title);
325 inanim.setDuration(200);
326 set1.addListener(new AnimatorListenerAdapter() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700327 @Override
328 public void onAnimationEnd(Animator anim) {
329 mCustomViewContainer.removeView(animView);
330 finishAnimationIn();
331 mUiController.setBlockEvents(false);
332 }
333 });
Michael Kolba3194d02011-09-07 11:23:51 -0700334 set1.playSequentially(inanim, blend1);
335 set1.start();
Michael Kolbc3af0672011-08-09 10:24:41 -0700336 }
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 Kolba3194d02011-09-07 11:23:51 -0700346 void hideNavScreen(int position, boolean animate) {
Michael Kolb09bf24f2011-06-09 14:34:30 -0700347 if (mNavScreen == null) return;
Michael Kolba3194d02011-09-07 11:23:51 -0700348 final Tab tab = mUiController.getTabControl().getTab(position);
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 }
Michael Kolba3194d02011-09-07 11:23:51 -0700360 NavTabView tabview = (NavTabView) mNavScreen.getTabView(position);
Michael Kolbc3af0672011-08-09 10:24:41 -0700361 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());
Michael Kolba3194d02011-09-07 11:23:51 -0700374 mCustomViewContainer.addView(screen.mMain, COVER_SCREEN_PARAMS);
375 screen.mMain.layout(0, 0, mContentView.getWidth(),
376 mContentView.getHeight());
377 mNavScreen.mScroller.finishScroller();
378 ImageView target = tabview.mImage;
Michael Kolbc3af0672011-08-09 10:24:41 -0700379 int toLeft = 0;
380 int toTop = getTitleBar().getHeight();
381 int toRight = mContentView.getWidth();
Michael Kolba3194d02011-09-07 11:23:51 -0700382 int width = target.getDrawable().getIntrinsicWidth();
383 int height = target.getDrawable().getIntrinsicHeight();
384 int fromLeft = tabview.getLeft() + target.getLeft() - mNavScreen.mScroller.getScrollX();
385 int fromTop = tabview.getTop() + target.getTop() - mNavScreen.mScroller.getScrollY();
Michael Kolbc3af0672011-08-09 10:24:41 -0700386 int fromRight = fromLeft + width;
387 int fromBottom = fromTop + height;
388 float scaleFactor = mContentView.getWidth() / (float) width;
Michael Kolba3194d02011-09-07 11:23:51 -0700389 int toBottom = toTop + (int) (height * scaleFactor);
390 ObjectAnimator l1 = ObjectAnimator.ofInt(screen.mContent, "left",
391 fromLeft, fromLeft);
392 ObjectAnimator t1 = ObjectAnimator.ofInt(screen.mContent, "top",
393 fromTop, fromTop);
394 ObjectAnimator r1 = ObjectAnimator.ofInt(screen.mContent, "right",
395 fromRight, fromRight);
396 ObjectAnimator b1 = ObjectAnimator.ofInt(screen.mContent, "bottom",
397 fromBottom, fromBottom);
398 AnimatorSet set1 = new AnimatorSet();
399 ObjectAnimator fade2 = ObjectAnimator.ofFloat(screen.mMain, "alpha", 0f, 1f);
400 ObjectAnimator fade1 = ObjectAnimator.ofFloat(mNavScreen, "alpha", 1f, 0f);
401 set1.playTogether(l1, t1, r1, b1, fade1, fade2);
402 set1.setDuration(100);
403 AnimatorSet set2 = new AnimatorSet();
Michael Kolbc3af0672011-08-09 10:24:41 -0700404 ObjectAnimator l = ObjectAnimator.ofInt(screen.mContent, "left",
405 fromLeft, toLeft);
406 ObjectAnimator t = ObjectAnimator.ofInt(screen.mContent, "top",
407 fromTop, toTop);
408 ObjectAnimator r = ObjectAnimator.ofInt(screen.mContent, "right",
409 fromRight, toRight);
410 ObjectAnimator b = ObjectAnimator.ofInt(screen.mContent, "bottom",
411 fromBottom, toBottom);
412 ObjectAnimator scale = ObjectAnimator.ofFloat(screen, "scaleFactor",
413 1f, scaleFactor);
Michael Kolbc3af0672011-08-09 10:24:41 -0700414 ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f);
Michael Kolba3194d02011-09-07 11:23:51 -0700415 otheralpha.setDuration(100);
416 set2.playTogether(l, t, r, b, scale);
417 set2.setDuration(200);
418 AnimatorSet combo = new AnimatorSet();
419 combo.playSequentially(set1, set2, otheralpha);
420 combo.addListener(new AnimatorListenerAdapter() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700421 @Override
422 public void onAnimationEnd(Animator anim) {
423 mCustomViewContainer.removeView(screen.mMain);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700424 finishAnimateOut();
Michael Kolbc3af0672011-08-09 10:24:41 -0700425 mUiController.setBlockEvents(false);
426 }
427 });
Michael Kolba3194d02011-09-07 11:23:51 -0700428 combo.start();
Michael Kolbc3af0672011-08-09 10:24:41 -0700429 }
430
Michael Kolbbf32cd02011-08-16 15:07:04 -0700431 private void finishAnimateOut() {
John Reck8ee633f2011-08-09 16:00:35 -0700432 mTabControl.setOnThumbnailUpdatedListener(null);
Michael Kolbf2055602011-04-09 17:20:03 -0700433 mCustomViewContainer.removeView(mNavScreen);
Michael Kolbc3af0672011-08-09 10:24:41 -0700434 mCustomViewContainer.setAlpha(1f);
Michael Kolbf2055602011-04-09 17:20:03 -0700435 mNavScreen = null;
436 mCustomViewContainer.setVisibility(View.GONE);
Michael Kolbf2055602011-04-09 17:20:03 -0700437 }
438
John Reck6b4bd5f2011-07-12 10:14:38 -0700439 @Override
440 public boolean needsRestoreAllTabs() {
441 return false;
442 }
443
Michael Kolb20be26d2011-07-18 16:38:02 -0700444 public void toggleNavScreen() {
445 if (mNavScreen == null) {
446 showNavScreen();
447 } else {
Michael Kolba3194d02011-09-07 11:23:51 -0700448 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false);
Michael Kolb20be26d2011-07-18 16:38:02 -0700449 }
450 }
451
John Reck1cf4b792011-07-26 10:22:22 -0700452 @Override
453 public boolean shouldCaptureThumbnails() {
454 return true;
455 }
456
Michael Kolbc3af0672011-08-09 10:24:41 -0700457 static class AnimScreen {
John Reck3ba45532011-08-11 16:26:53 -0700458
Michael Kolbc3af0672011-08-09 10:24:41 -0700459 private View mMain;
460 private ImageView mTitle;
461 private ImageView mContent;
462 private float mScale;
463
464 public AnimScreen(Context ctx, TitleBar tbar, WebView web) {
465 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
466 null);
467 mContent = (ImageView) mMain.findViewById(R.id.content);
468 mContent.setTop(tbar.getHeight());
469
470 mTitle = (ImageView) mMain.findViewById(R.id.title);
471 Bitmap bm1 = Bitmap.createBitmap(tbar.getWidth(), tbar.getHeight(),
472 Bitmap.Config.RGB_565);
473 Canvas c1 = new Canvas(bm1);
474 tbar.draw(c1);
475 mTitle.setImageBitmap(bm1);
476 int h = web.getHeight() - tbar.getHeight();
477 Bitmap bm2 = Bitmap.createBitmap(web.getWidth(), h,
478 Bitmap.Config.RGB_565);
479 Canvas c2 = new Canvas(bm2);
480 int tx = web.getScrollX();
481 int ty = web.getScrollY();
482 c2.translate(-tx, -ty - tbar.getHeight());
483 web.draw(c2);
484 mContent.setImageBitmap(bm2);
485 mContent.setScaleType(ImageView.ScaleType.MATRIX);
486 mContent.setImageMatrix(new Matrix());
487 mScale = 1.0f;
488 setScaleFactor(getScaleFactor());
489 }
490
491 public AnimScreen(Context ctx, Bitmap image) {
492 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
493 null);
Michael Kolba3194d02011-09-07 11:23:51 -0700494 mTitle = (ImageView) mMain.findViewById(R.id.title);
495 mTitle.setVisibility(View.GONE);
Michael Kolbc3af0672011-08-09 10:24:41 -0700496 mContent = (ImageView) mMain.findViewById(R.id.content);
497 mContent.setImageBitmap(image);
498 mContent.setScaleType(ImageView.ScaleType.MATRIX);
499 mContent.setImageMatrix(new Matrix());
500 mScale = 1.0f;
501 setScaleFactor(getScaleFactor());
502 }
503
504 public void setScaleFactor(float sf) {
505 mScale = sf;
506 Matrix m = new Matrix();
507 m.postScale(sf,sf);
508 mContent.setImageMatrix(m);
509 }
510
511 public float getScaleFactor() {
512 return mScale;
513 }
514
John Reck3ba45532011-08-11 16:26:53 -0700515 }
516
Michael Kolb66706532010-12-12 19:50:22 -0800517}