blob: 25a7d4a4b73e716aa9064fd9568713b64be04c4d [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 Kolb7a321d62011-09-23 15:54:22 -0700300 int ntth = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_titleheight);
Michael Kolbc3af0672011-08-09 10:24:41 -0700301 int toLeft = (mContentView.getWidth() - width) / 2;
Michael Kolb7a321d62011-09-23 15:54:22 -0700302 int toTop = ((fromBottom - (ntth + height)) / 2 + ntth);
Michael Kolbc3af0672011-08-09 10:24:41 -0700303 int toRight = toLeft + width;
304 int toBottom = toTop + height;
305 float scaleFactor = width / (float) mContentView.getWidth();
306 detachTab(mActiveTab);
307 mContentView.setVisibility(View.GONE);
Michael Kolba3194d02011-09-07 11:23:51 -0700308 AnimatorSet set1 = new AnimatorSet();
Michael Kolbc3af0672011-08-09 10:24:41 -0700309 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);
Michael Kolbc3af0672011-08-09 10:24:41 -0700320 ObjectAnimator sx = ObjectAnimator.ofFloat(ascreen, "scaleFactor",
321 1f, scaleFactor);
Michael Kolba3194d02011-09-07 11:23:51 -0700322 ObjectAnimator blend1 = ObjectAnimator.ofFloat(ascreen.mMain, "alpha", 1, 0);
323 blend1.setDuration(100);
324
325 inanim.playTogether(tx, ty, tr, tb, sx, title);
326 inanim.setDuration(200);
327 set1.addListener(new AnimatorListenerAdapter() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700328 @Override
329 public void onAnimationEnd(Animator anim) {
330 mCustomViewContainer.removeView(animView);
331 finishAnimationIn();
332 mUiController.setBlockEvents(false);
333 }
334 });
Michael Kolba3194d02011-09-07 11:23:51 -0700335 set1.playSequentially(inanim, blend1);
336 set1.start();
Michael Kolbc3af0672011-08-09 10:24:41 -0700337 }
338
339 private void finishAnimationIn() {
Michael Kolbb43f2f62011-08-17 10:39:31 -0700340 if (mNavScreen != null) {
341 // notify accessibility manager about the screen change
342 mNavScreen.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
343 mTabControl.setOnThumbnailUpdatedListener(mNavScreen);
344 }
Michael Kolbf2055602011-04-09 17:20:03 -0700345 }
346
Michael Kolba3194d02011-09-07 11:23:51 -0700347 void hideNavScreen(int position, boolean animate) {
Michael Kolb09bf24f2011-06-09 14:34:30 -0700348 if (mNavScreen == null) return;
Michael Kolba3194d02011-09-07 11:23:51 -0700349 final Tab tab = mUiController.getTabControl().getTab(position);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700350 if ((tab == null) || !animate) {
Michael Kolb365561d2011-08-18 09:56:25 -0700351 if (tab != null) {
352 setActiveTab(tab);
353 } else if (mTabControl.getTabCount() > 0) {
354 // use a fallback tab
355 setActiveTab(mTabControl.getCurrentTab());
356 }
Michael Kolbbf32cd02011-08-16 15:07:04 -0700357 mContentView.setVisibility(View.VISIBLE);
358 finishAnimateOut();
Michael Kolb8a009492011-08-15 15:37:30 -0700359 return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700360 }
Michael Kolba3194d02011-09-07 11:23:51 -0700361 NavTabView tabview = (NavTabView) mNavScreen.getTabView(position);
Michael Kolbc3af0672011-08-09 10:24:41 -0700362 if (tabview == null) {
Michael Kolb365561d2011-08-18 09:56:25 -0700363 if (mTabControl.getTabCount() > 0) {
364 // use a fallback tab
365 setActiveTab(mTabControl.getCurrentTab());
366 }
Michael Kolbbf32cd02011-08-16 15:07:04 -0700367 mContentView.setVisibility(View.VISIBLE);
368 finishAnimateOut();
Michael Kolb8a009492011-08-15 15:37:30 -0700369 return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700370 }
371 mUiController.setBlockEvents(true);
372 mUiController.setActiveTab(tab);
373 mContentView.setVisibility(View.VISIBLE);
374 final AnimScreen screen = new AnimScreen(mActivity, tab.getScreenshot());
Michael Kolba3194d02011-09-07 11:23:51 -0700375 mCustomViewContainer.addView(screen.mMain, COVER_SCREEN_PARAMS);
376 screen.mMain.layout(0, 0, mContentView.getWidth(),
377 mContentView.getHeight());
378 mNavScreen.mScroller.finishScroller();
379 ImageView target = tabview.mImage;
Michael Kolbc3af0672011-08-09 10:24:41 -0700380 int toLeft = 0;
381 int toTop = getTitleBar().getHeight();
382 int toRight = mContentView.getWidth();
Michael Kolba3194d02011-09-07 11:23:51 -0700383 int width = target.getDrawable().getIntrinsicWidth();
384 int height = target.getDrawable().getIntrinsicHeight();
385 int fromLeft = tabview.getLeft() + target.getLeft() - mNavScreen.mScroller.getScrollX();
386 int fromTop = tabview.getTop() + target.getTop() - mNavScreen.mScroller.getScrollY();
Michael Kolbc3af0672011-08-09 10:24:41 -0700387 int fromRight = fromLeft + width;
388 int fromBottom = fromTop + height;
389 float scaleFactor = mContentView.getWidth() / (float) width;
Michael Kolba3194d02011-09-07 11:23:51 -0700390 int toBottom = toTop + (int) (height * scaleFactor);
391 ObjectAnimator l1 = ObjectAnimator.ofInt(screen.mContent, "left",
392 fromLeft, fromLeft);
393 ObjectAnimator t1 = ObjectAnimator.ofInt(screen.mContent, "top",
394 fromTop, fromTop);
395 ObjectAnimator r1 = ObjectAnimator.ofInt(screen.mContent, "right",
396 fromRight, fromRight);
397 ObjectAnimator b1 = ObjectAnimator.ofInt(screen.mContent, "bottom",
398 fromBottom, fromBottom);
399 AnimatorSet set1 = new AnimatorSet();
400 ObjectAnimator fade2 = ObjectAnimator.ofFloat(screen.mMain, "alpha", 0f, 1f);
401 ObjectAnimator fade1 = ObjectAnimator.ofFloat(mNavScreen, "alpha", 1f, 0f);
402 set1.playTogether(l1, t1, r1, b1, fade1, fade2);
403 set1.setDuration(100);
404 AnimatorSet set2 = new AnimatorSet();
Michael Kolbc3af0672011-08-09 10:24:41 -0700405 ObjectAnimator l = ObjectAnimator.ofInt(screen.mContent, "left",
406 fromLeft, toLeft);
407 ObjectAnimator t = ObjectAnimator.ofInt(screen.mContent, "top",
408 fromTop, toTop);
409 ObjectAnimator r = ObjectAnimator.ofInt(screen.mContent, "right",
410 fromRight, toRight);
411 ObjectAnimator b = ObjectAnimator.ofInt(screen.mContent, "bottom",
412 fromBottom, toBottom);
413 ObjectAnimator scale = ObjectAnimator.ofFloat(screen, "scaleFactor",
414 1f, scaleFactor);
Michael Kolbc3af0672011-08-09 10:24:41 -0700415 ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f);
Michael Kolba3194d02011-09-07 11:23:51 -0700416 otheralpha.setDuration(100);
417 set2.playTogether(l, t, r, b, scale);
418 set2.setDuration(200);
419 AnimatorSet combo = new AnimatorSet();
420 combo.playSequentially(set1, set2, otheralpha);
421 combo.addListener(new AnimatorListenerAdapter() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700422 @Override
423 public void onAnimationEnd(Animator anim) {
424 mCustomViewContainer.removeView(screen.mMain);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700425 finishAnimateOut();
Michael Kolbc3af0672011-08-09 10:24:41 -0700426 mUiController.setBlockEvents(false);
427 }
428 });
Michael Kolba3194d02011-09-07 11:23:51 -0700429 combo.start();
Michael Kolbc3af0672011-08-09 10:24:41 -0700430 }
431
Michael Kolbbf32cd02011-08-16 15:07:04 -0700432 private void finishAnimateOut() {
John Reck8ee633f2011-08-09 16:00:35 -0700433 mTabControl.setOnThumbnailUpdatedListener(null);
Michael Kolbf2055602011-04-09 17:20:03 -0700434 mCustomViewContainer.removeView(mNavScreen);
Michael Kolbc3af0672011-08-09 10:24:41 -0700435 mCustomViewContainer.setAlpha(1f);
Michael Kolbf2055602011-04-09 17:20:03 -0700436 mNavScreen = null;
437 mCustomViewContainer.setVisibility(View.GONE);
Michael Kolbf2055602011-04-09 17:20:03 -0700438 }
439
John Reck6b4bd5f2011-07-12 10:14:38 -0700440 @Override
441 public boolean needsRestoreAllTabs() {
442 return false;
443 }
444
Michael Kolb20be26d2011-07-18 16:38:02 -0700445 public void toggleNavScreen() {
446 if (mNavScreen == null) {
447 showNavScreen();
448 } else {
Michael Kolba3194d02011-09-07 11:23:51 -0700449 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false);
Michael Kolb20be26d2011-07-18 16:38:02 -0700450 }
451 }
452
John Reck1cf4b792011-07-26 10:22:22 -0700453 @Override
454 public boolean shouldCaptureThumbnails() {
455 return true;
456 }
457
Michael Kolbc3af0672011-08-09 10:24:41 -0700458 static class AnimScreen {
John Reck3ba45532011-08-11 16:26:53 -0700459
Michael Kolbc3af0672011-08-09 10:24:41 -0700460 private View mMain;
461 private ImageView mTitle;
462 private ImageView mContent;
463 private float mScale;
464
465 public AnimScreen(Context ctx, TitleBar tbar, WebView web) {
466 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
467 null);
468 mContent = (ImageView) mMain.findViewById(R.id.content);
469 mContent.setTop(tbar.getHeight());
470
471 mTitle = (ImageView) mMain.findViewById(R.id.title);
472 Bitmap bm1 = Bitmap.createBitmap(tbar.getWidth(), tbar.getHeight(),
473 Bitmap.Config.RGB_565);
474 Canvas c1 = new Canvas(bm1);
475 tbar.draw(c1);
476 mTitle.setImageBitmap(bm1);
477 int h = web.getHeight() - tbar.getHeight();
478 Bitmap bm2 = Bitmap.createBitmap(web.getWidth(), h,
479 Bitmap.Config.RGB_565);
480 Canvas c2 = new Canvas(bm2);
481 int tx = web.getScrollX();
482 int ty = web.getScrollY();
483 c2.translate(-tx, -ty - tbar.getHeight());
484 web.draw(c2);
485 mContent.setImageBitmap(bm2);
486 mContent.setScaleType(ImageView.ScaleType.MATRIX);
487 mContent.setImageMatrix(new Matrix());
488 mScale = 1.0f;
489 setScaleFactor(getScaleFactor());
490 }
491
492 public AnimScreen(Context ctx, Bitmap image) {
493 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
494 null);
Michael Kolba3194d02011-09-07 11:23:51 -0700495 mTitle = (ImageView) mMain.findViewById(R.id.title);
496 mTitle.setVisibility(View.GONE);
Michael Kolbc3af0672011-08-09 10:24:41 -0700497 mContent = (ImageView) mMain.findViewById(R.id.content);
498 mContent.setImageBitmap(image);
499 mContent.setScaleType(ImageView.ScaleType.MATRIX);
500 mContent.setImageMatrix(new Matrix());
501 mScale = 1.0f;
502 setScaleFactor(getScaleFactor());
503 }
504
505 public void setScaleFactor(float sf) {
506 mScale = sf;
507 Matrix m = new Matrix();
508 m.postScale(sf,sf);
509 mContent.setImageMatrix(m);
510 }
511
512 public float getScaleFactor() {
513 return mScale;
514 }
515
John Reck3ba45532011-08-11 16:26:53 -0700516 }
517
Michael Kolb66706532010-12-12 19:50:22 -0800518}