blob: ed63daac5e0b5fdd090bda808ba832ace22ddaff [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;
John Reck9c5004e2011-10-07 16:00:12 -070028import android.os.Message;
Michael Kolb376b5412010-12-15 11:52:57 -080029import android.util.Log;
John Reckaae029c2011-09-16 14:36:39 -070030import android.util.TypedValue;
Michael Kolb66706532010-12-12 19:50:22 -080031import android.view.ActionMode;
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 Kolb30adae62011-07-29 13:37:05 -070037import android.view.accessibility.AccessibilityEvent;
Michael Kolb66706532010-12-12 19:50:22 -080038import android.webkit.WebView;
Michael Kolbc3af0672011-08-09 10:24:41 -070039import android.widget.ImageView;
Michael Kolb66706532010-12-12 19:50:22 -080040
Michael Kolb629b22c2011-07-13 16:26:47 -070041import com.android.browser.UrlInputView.StateListener;
42
Michael Kolb66706532010-12-12 19:50:22 -080043/**
44 * Ui for regular phone screen sizes
45 */
46public class PhoneUi extends BaseUi {
47
48 private static final String LOGTAG = "PhoneUi";
John Reck9c5004e2011-10-07 16:00:12 -070049 private static final int MSG_INIT_NAVSCREEN = 100;
Michael Kolb66706532010-12-12 19:50:22 -080050
Michael Kolbf2055602011-04-09 17:20:03 -070051 private NavScreen mNavScreen;
John Reckcc0059c2011-10-07 13:53:13 -070052 private AnimScreen mAnimScreen;
John Reck0f602f32011-07-07 15:38:43 -070053 private NavigationBarPhone mNavigationBar;
John Reckaae029c2011-09-16 14:36:39 -070054 private int mActionBarHeight;
Michael Kolb66706532010-12-12 19:50:22 -080055
Michael Kolb08a687a2011-04-22 16:13:02 -070056 boolean mAnimating;
Michael Kolb66706532010-12-12 19:50:22 -080057
58 /**
59 * @param browser
60 * @param controller
61 */
62 public PhoneUi(Activity browser, UiController controller) {
63 super(browser, controller);
Michael Kolbfdb70242011-03-24 09:41:11 -070064 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
John Reck0f602f32011-07-07 15:38:43 -070065 mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar();
John Reckaae029c2011-09-16 14:36:39 -070066 TypedValue heightValue = new TypedValue();
67 browser.getTheme().resolveAttribute(
68 com.android.internal.R.attr.actionBarSize, heightValue, true);
69 mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data,
70 browser.getResources().getDisplayMetrics());
John Reck285ef042011-02-11 15:44:17 -080071 }
Michael Kolb66706532010-12-12 19:50:22 -080072
John Reck285ef042011-02-11 15:44:17 -080073 @Override
Michael Kolb66706532010-12-12 19:50:22 -080074 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080075 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080076 }
77
78 @Override
Michael Kolb1f9b3562012-04-24 14:38:34 -070079 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -070080 if (mUseQuickControls) {
John Reck0f602f32011-07-07 15:38:43 -070081 mTitleBar.setShowProgressOnly(false);
Michael Kolb46f987e2011-04-05 10:39:10 -070082 }
Michael Kolb1f9b3562012-04-24 14:38:34 -070083 super.editUrl(clearInput, forceIME);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080084 }
85
86 @Override
Michael Kolb66706532010-12-12 19:50:22 -080087 public boolean onBackKey() {
John Reckcc0059c2011-10-07 13:53:13 -070088 if (showingNavScreen()) {
Michael Kolba3194d02011-09-07 11:23:51 -070089 mNavScreen.close(mUiController.getTabControl().getCurrentPosition());
Michael Kolbf2055602011-04-09 17:20:03 -070090 return true;
Michael Kolb66706532010-12-12 19:50:22 -080091 }
92 return super.onBackKey();
93 }
94
John Reckcc0059c2011-10-07 13:53:13 -070095 private boolean showingNavScreen() {
96 return mNavScreen != null && mNavScreen.getVisibility() == View.VISIBLE;
97 }
98
Michael Kolb66706532010-12-12 19:50:22 -080099 @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 Kolbe8a82332012-04-25 14:14:26 -0700106 super.onProgressChanged(tab);
John Reck9c5004e2011-10-07 16:00:12 -0700107 if (mNavScreen == null && getTitleBar().getHeight() > 0) {
108 mHandler.sendEmptyMessage(MSG_INIT_NAVSCREEN);
109 }
110 }
111
112 @Override
113 protected void handleMessage(Message msg) {
114 super.handleMessage(msg);
115 if (msg.what == MSG_INIT_NAVSCREEN) {
116 if (mNavScreen == null) {
117 mNavScreen = new NavScreen(mActivity, mUiController, this);
118 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
119 mNavScreen.setVisibility(View.GONE);
120 }
121 if (mAnimScreen == null) {
122 mAnimScreen = new AnimScreen(mActivity);
123 // initialize bitmaps
124 mAnimScreen.set(getTitleBar(), getWebView());
125 }
126 }
Michael Kolb66706532010-12-12 19:50:22 -0800127 }
128
129 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700130 public void setActiveTab(final Tab tab) {
John Reck8ee633f2011-08-09 16:00:35 -0700131 mTitleBar.cancelTitleBarAnimation(true);
132 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700133 super.setActiveTab(tab);
Michael Kolbfdb70242011-03-24 09:41:11 -0700134 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800135 // TabControl.setCurrentTab has been called before this,
136 // so the tab is guaranteed to have a webview
137 if (view == null) {
138 Log.e(LOGTAG, "active tab with no webview detected");
139 return;
140 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700141 // Request focus on the top window.
142 if (mUseQuickControls) {
143 mPieControl.forceToTop(mContentView);
Michael Kolb4923c222012-04-02 16:18:36 -0700144 view.setTitleBar(null);
Michael Kolbe8a82332012-04-25 14:14:26 -0700145 mTitleBar.setShowProgressOnly(true);
Michael Kolbfdb70242011-03-24 09:41:11 -0700146 } else {
Michael Kolb4923c222012-04-02 16:18:36 -0700147 view.setTitleBar(mTitleBar);
Michael Kolbfdb70242011-03-24 09:41:11 -0700148 }
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);
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 Kolb0d0245f2011-12-05 16:36:05 -0800170 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
171 if (bm != null) {
172 bm.setVisible(!showingNavScreen());
173 }
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700174 MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id);
175 if (abm != null) {
John Reckcc0059c2011-10-07 13:53:13 -0700176 abm.setVisible((tab != null) && !tab.isSnapshot() && !showingNavScreen());
John Recke1a03a32011-09-14 17:04:16 -0700177 }
Michael Kolb315d5022011-10-13 12:47:11 -0700178 MenuItem info = menu.findItem(R.id.page_info_menu_id);
179 if (info != null) {
180 info.setVisible(false);
181 }
182 MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
183 if (newtab != null && !mUseQuickControls) {
184 newtab.setVisible(false);
185 }
186 MenuItem incognito = menu.findItem(R.id.incognito_menu_id);
187 if (incognito != null) {
188 incognito.setVisible(showingNavScreen() || mUseQuickControls);
189 }
John Reckcc0059c2011-10-07 13:53:13 -0700190 if (showingNavScreen()) {
John Recke1a03a32011-09-14 17:04:16 -0700191 menu.setGroupVisible(R.id.LIVE_MENU, false);
192 menu.setGroupVisible(R.id.SNAPSHOT_MENU, false);
John Recke1a03a32011-09-14 17:04:16 -0700193 menu.setGroupVisible(R.id.NAV_MENU, false);
Michael Kolb315d5022011-10-13 12:47:11 -0700194 menu.setGroupVisible(R.id.COMBO_MENU, true);
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700195 }
196 }
197
198 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700199 public boolean onOptionsItemSelected(MenuItem item) {
Michael Kolb315d5022011-10-13 12:47:11 -0700200 if (showingNavScreen()
201 && (item.getItemId() != R.id.history_menu_id)
202 && (item.getItemId() != R.id.snapshots_menu_id)) {
Michael Kolba3194d02011-09-07 11:23:51 -0700203 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false);
Michael Kolb3ca12752011-07-20 13:52:25 -0700204 }
205 return false;
206 }
207
208 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800209 public void onContextMenuCreated(Menu menu) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800210 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800211 }
212
213 @Override
214 public void onContextMenuClosed(Menu menu, boolean inLoad) {
215 if (inLoad) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800216 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800217 }
218 }
219
220 // action mode callbacks
221
222 @Override
223 public void onActionModeStarted(ActionMode mode) {
Michael Kolb42c0c062011-08-02 12:56:06 -0700224 if (!isEditingUrl()) {
225 hideTitleBar();
John Reckaae029c2011-09-16 14:36:39 -0700226 } else {
227 mTitleBar.animate().translationY(mActionBarHeight);
Michael Kolb42c0c062011-08-02 12:56:06 -0700228 }
Michael Kolb66706532010-12-12 19:50:22 -0800229 }
230
Michael Kolba4183062011-01-16 10:43:21 -0800231 @Override
John Reck6cda7b12011-03-18 15:57:13 -0700232 public void onActionModeFinished(boolean inLoad) {
John Reckaae029c2011-09-16 14:36:39 -0700233 mTitleBar.animate().translationY(0);
Michael Kolbc16c5952011-03-29 15:37:03 -0700234 if (inLoad) {
235 if (mUseQuickControls) {
236 mTitleBar.setShowProgressOnly(true);
John Reck6cda7b12011-03-18 15:57:13 -0700237 }
Michael Kolbc16c5952011-03-29 15:37:03 -0700238 showTitleBar();
239 }
John Reck6cda7b12011-03-18 15:57:13 -0700240 }
241
242 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -0700243 public boolean isWebShowing() {
John Reckcc0059c2011-10-07 13:53:13 -0700244 return super.isWebShowing() && !showingNavScreen();
Michael Kolbc3af0672011-08-09 10:24:41 -0700245 }
246
247 @Override
248 public void showWeb(boolean animate) {
249 super.showWeb(animate);
Michael Kolba3194d02011-09-07 11:23:51 -0700250 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), animate);
Michael Kolbc3af0672011-08-09 10:24:41 -0700251 }
252
Michael Kolbf2055602011-04-09 17:20:03 -0700253 void showNavScreen() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700254 mUiController.setBlockEvents(true);
John Reckcc0059c2011-10-07 13:53:13 -0700255 if (mNavScreen == null) {
256 mNavScreen = new NavScreen(mActivity, mUiController, this);
257 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
258 } else {
259 mNavScreen.setVisibility(View.VISIBLE);
260 mNavScreen.setAlpha(1f);
John Reck9c5004e2011-10-07 16:00:12 -0700261 mNavScreen.refreshAdapter();
John Reckcc0059c2011-10-07 13:53:13 -0700262 }
Michael Kolbc3af0672011-08-09 10:24:41 -0700263 mActiveTab.capture();
John Reckcc0059c2011-10-07 13:53:13 -0700264 if (mAnimScreen == null) {
265 mAnimScreen = new AnimScreen(mActivity);
John Reckce8bcb02011-10-11 13:45:29 -0700266 } else {
267 mAnimScreen.mMain.setAlpha(1f);
268 mAnimScreen.mTitle.setAlpha(1f);
269 mAnimScreen.setScaleFactor(1f);
John Reckcc0059c2011-10-07 13:53:13 -0700270 }
271 mAnimScreen.set(getTitleBar(), getWebView());
Michael Kolba30e4fb2011-11-07 17:32:01 -0800272 if (mAnimScreen.mMain.getParent() == null) {
273 mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS);
274 }
Michael Kolbf2055602011-04-09 17:20:03 -0700275 mCustomViewContainer.setVisibility(View.VISIBLE);
276 mCustomViewContainer.bringToFront();
John Reckce8bcb02011-10-11 13:45:29 -0700277 mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(),
278 mContentView.getHeight());
Michael Kolbc3af0672011-08-09 10:24:41 -0700279 int fromLeft = 0;
280 int fromTop = getTitleBar().getHeight();
281 int fromRight = mContentView.getWidth();
282 int fromBottom = mContentView.getHeight();
Michael Kolba3194d02011-09-07 11:23:51 -0700283 int width = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_width);
284 int height = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_height);
Michael Kolb7a321d62011-09-23 15:54:22 -0700285 int ntth = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_titleheight);
Michael Kolbc3af0672011-08-09 10:24:41 -0700286 int toLeft = (mContentView.getWidth() - width) / 2;
Michael Kolb7a321d62011-09-23 15:54:22 -0700287 int toTop = ((fromBottom - (ntth + height)) / 2 + ntth);
Michael Kolbc3af0672011-08-09 10:24:41 -0700288 int toRight = toLeft + width;
289 int toBottom = toTop + height;
290 float scaleFactor = width / (float) mContentView.getWidth();
291 detachTab(mActiveTab);
292 mContentView.setVisibility(View.GONE);
Michael Kolba3194d02011-09-07 11:23:51 -0700293 AnimatorSet set1 = new AnimatorSet();
Michael Kolbc3af0672011-08-09 10:24:41 -0700294 AnimatorSet inanim = new AnimatorSet();
John Reckcc0059c2011-10-07 13:53:13 -0700295 ObjectAnimator tx = ObjectAnimator.ofInt(mAnimScreen.mContent, "left",
Michael Kolbc3af0672011-08-09 10:24:41 -0700296 fromLeft, toLeft);
John Reckcc0059c2011-10-07 13:53:13 -0700297 ObjectAnimator ty = ObjectAnimator.ofInt(mAnimScreen.mContent, "top",
Michael Kolbc3af0672011-08-09 10:24:41 -0700298 fromTop, toTop);
John Reckcc0059c2011-10-07 13:53:13 -0700299 ObjectAnimator tr = ObjectAnimator.ofInt(mAnimScreen.mContent, "right",
Michael Kolbc3af0672011-08-09 10:24:41 -0700300 fromRight, toRight);
John Reckcc0059c2011-10-07 13:53:13 -0700301 ObjectAnimator tb = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom",
Michael Kolbc3af0672011-08-09 10:24:41 -0700302 fromBottom, toBottom);
John Reckcc0059c2011-10-07 13:53:13 -0700303 ObjectAnimator title = ObjectAnimator.ofFloat(mAnimScreen.mTitle, "alpha",
Michael Kolbc3af0672011-08-09 10:24:41 -0700304 1f, 0f);
John Reckcc0059c2011-10-07 13:53:13 -0700305 ObjectAnimator sx = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor",
Michael Kolbc3af0672011-08-09 10:24:41 -0700306 1f, scaleFactor);
John Reck1adf0302011-10-11 10:58:12 -0700307 ObjectAnimator blend1 = ObjectAnimator.ofFloat(mAnimScreen.mMain,
308 "alpha", 1f, 0f);
Michael Kolba3194d02011-09-07 11:23:51 -0700309 blend1.setDuration(100);
310
311 inanim.playTogether(tx, ty, tr, tb, sx, title);
312 inanim.setDuration(200);
313 set1.addListener(new AnimatorListenerAdapter() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700314 @Override
315 public void onAnimationEnd(Animator anim) {
John Reck1adf0302011-10-11 10:58:12 -0700316 mCustomViewContainer.removeView(mAnimScreen.mMain);
Michael Kolbc3af0672011-08-09 10:24:41 -0700317 finishAnimationIn();
318 mUiController.setBlockEvents(false);
319 }
320 });
Michael Kolba3194d02011-09-07 11:23:51 -0700321 set1.playSequentially(inanim, blend1);
322 set1.start();
Michael Kolbc3af0672011-08-09 10:24:41 -0700323 }
324
325 private void finishAnimationIn() {
John Reckcc0059c2011-10-07 13:53:13 -0700326 if (showingNavScreen()) {
Michael Kolbb43f2f62011-08-17 10:39:31 -0700327 // notify accessibility manager about the screen change
328 mNavScreen.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
329 mTabControl.setOnThumbnailUpdatedListener(mNavScreen);
330 }
Michael Kolbf2055602011-04-09 17:20:03 -0700331 }
332
Michael Kolba3194d02011-09-07 11:23:51 -0700333 void hideNavScreen(int position, boolean animate) {
John Reckcc0059c2011-10-07 13:53:13 -0700334 if (!showingNavScreen()) return;
Michael Kolba3194d02011-09-07 11:23:51 -0700335 final Tab tab = mUiController.getTabControl().getTab(position);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700336 if ((tab == null) || !animate) {
Michael Kolb365561d2011-08-18 09:56:25 -0700337 if (tab != null) {
338 setActiveTab(tab);
339 } else if (mTabControl.getTabCount() > 0) {
340 // use a fallback tab
341 setActiveTab(mTabControl.getCurrentTab());
342 }
Michael Kolbbf32cd02011-08-16 15:07:04 -0700343 mContentView.setVisibility(View.VISIBLE);
344 finishAnimateOut();
Michael Kolb8a009492011-08-15 15:37:30 -0700345 return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700346 }
Michael Kolba3194d02011-09-07 11:23:51 -0700347 NavTabView tabview = (NavTabView) mNavScreen.getTabView(position);
Michael Kolbc3af0672011-08-09 10:24:41 -0700348 if (tabview == null) {
Michael Kolb365561d2011-08-18 09:56:25 -0700349 if (mTabControl.getTabCount() > 0) {
350 // use a fallback tab
351 setActiveTab(mTabControl.getCurrentTab());
352 }
Michael Kolbbf32cd02011-08-16 15:07:04 -0700353 mContentView.setVisibility(View.VISIBLE);
354 finishAnimateOut();
Michael Kolb8a009492011-08-15 15:37:30 -0700355 return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700356 }
357 mUiController.setBlockEvents(true);
358 mUiController.setActiveTab(tab);
359 mContentView.setVisibility(View.VISIBLE);
John Reckcc0059c2011-10-07 13:53:13 -0700360 if (mAnimScreen == null) {
361 mAnimScreen = new AnimScreen(mActivity);
362 }
363 mAnimScreen.set(tab.getScreenshot());
Michael Kolb0755fcd2012-01-10 10:19:50 -0800364 if (mAnimScreen.mMain.getParent() == null) {
365 mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS);
366 }
John Reckcc0059c2011-10-07 13:53:13 -0700367 mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(),
Michael Kolba3194d02011-09-07 11:23:51 -0700368 mContentView.getHeight());
369 mNavScreen.mScroller.finishScroller();
370 ImageView target = tabview.mImage;
Michael Kolbc3af0672011-08-09 10:24:41 -0700371 int toLeft = 0;
Michael Kolbb7e16702011-12-15 11:59:40 -0800372 int toTop = (tab.getWebView() != null) ? tab.getWebView().getVisibleTitleHeight() : 0;
Michael Kolbc3af0672011-08-09 10:24:41 -0700373 int toRight = mContentView.getWidth();
Michael Kolba3194d02011-09-07 11:23:51 -0700374 int width = target.getDrawable().getIntrinsicWidth();
375 int height = target.getDrawable().getIntrinsicHeight();
376 int fromLeft = tabview.getLeft() + target.getLeft() - mNavScreen.mScroller.getScrollX();
377 int fromTop = tabview.getTop() + target.getTop() - mNavScreen.mScroller.getScrollY();
Michael Kolbc3af0672011-08-09 10:24:41 -0700378 int fromRight = fromLeft + width;
379 int fromBottom = fromTop + height;
380 float scaleFactor = mContentView.getWidth() / (float) width;
Michael Kolba3194d02011-09-07 11:23:51 -0700381 int toBottom = toTop + (int) (height * scaleFactor);
John Reck9c5004e2011-10-07 16:00:12 -0700382 mAnimScreen.mContent.setLeft(fromLeft);
383 mAnimScreen.mContent.setTop(fromTop);
384 mAnimScreen.mContent.setRight(fromRight);
385 mAnimScreen.mContent.setBottom(fromBottom);
386 mAnimScreen.setScaleFactor(1f);
Michael Kolba3194d02011-09-07 11:23:51 -0700387 AnimatorSet set1 = new AnimatorSet();
John Reckcc0059c2011-10-07 13:53:13 -0700388 ObjectAnimator fade2 = ObjectAnimator.ofFloat(mAnimScreen.mMain, "alpha", 0f, 1f);
Michael Kolba3194d02011-09-07 11:23:51 -0700389 ObjectAnimator fade1 = ObjectAnimator.ofFloat(mNavScreen, "alpha", 1f, 0f);
John Reck9c5004e2011-10-07 16:00:12 -0700390 set1.playTogether(fade1, fade2);
Michael Kolba3194d02011-09-07 11:23:51 -0700391 set1.setDuration(100);
392 AnimatorSet set2 = new AnimatorSet();
John Reckcc0059c2011-10-07 13:53:13 -0700393 ObjectAnimator l = ObjectAnimator.ofInt(mAnimScreen.mContent, "left",
Michael Kolbc3af0672011-08-09 10:24:41 -0700394 fromLeft, toLeft);
John Reckcc0059c2011-10-07 13:53:13 -0700395 ObjectAnimator t = ObjectAnimator.ofInt(mAnimScreen.mContent, "top",
Michael Kolbc3af0672011-08-09 10:24:41 -0700396 fromTop, toTop);
John Reckcc0059c2011-10-07 13:53:13 -0700397 ObjectAnimator r = ObjectAnimator.ofInt(mAnimScreen.mContent, "right",
Michael Kolbc3af0672011-08-09 10:24:41 -0700398 fromRight, toRight);
John Reckcc0059c2011-10-07 13:53:13 -0700399 ObjectAnimator b = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom",
Michael Kolbc3af0672011-08-09 10:24:41 -0700400 fromBottom, toBottom);
John Reckcc0059c2011-10-07 13:53:13 -0700401 ObjectAnimator scale = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor",
Michael Kolbc3af0672011-08-09 10:24:41 -0700402 1f, scaleFactor);
Michael Kolbc3af0672011-08-09 10:24:41 -0700403 ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f);
Michael Kolba3194d02011-09-07 11:23:51 -0700404 otheralpha.setDuration(100);
405 set2.playTogether(l, t, r, b, scale);
406 set2.setDuration(200);
407 AnimatorSet combo = new AnimatorSet();
408 combo.playSequentially(set1, set2, otheralpha);
409 combo.addListener(new AnimatorListenerAdapter() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700410 @Override
411 public void onAnimationEnd(Animator anim) {
John Reckcc0059c2011-10-07 13:53:13 -0700412 mCustomViewContainer.removeView(mAnimScreen.mMain);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700413 finishAnimateOut();
Michael Kolbc3af0672011-08-09 10:24:41 -0700414 mUiController.setBlockEvents(false);
415 }
416 });
Michael Kolba3194d02011-09-07 11:23:51 -0700417 combo.start();
Michael Kolbc3af0672011-08-09 10:24:41 -0700418 }
419
Michael Kolbbf32cd02011-08-16 15:07:04 -0700420 private void finishAnimateOut() {
John Reck8ee633f2011-08-09 16:00:35 -0700421 mTabControl.setOnThumbnailUpdatedListener(null);
John Reckcc0059c2011-10-07 13:53:13 -0700422 mNavScreen.setVisibility(View.GONE);
Michael Kolbc3af0672011-08-09 10:24:41 -0700423 mCustomViewContainer.setAlpha(1f);
Michael Kolbf2055602011-04-09 17:20:03 -0700424 mCustomViewContainer.setVisibility(View.GONE);
Michael Kolbf2055602011-04-09 17:20:03 -0700425 }
426
John Reck6b4bd5f2011-07-12 10:14:38 -0700427 @Override
428 public boolean needsRestoreAllTabs() {
429 return false;
430 }
431
Michael Kolb20be26d2011-07-18 16:38:02 -0700432 public void toggleNavScreen() {
John Reckcc0059c2011-10-07 13:53:13 -0700433 if (!showingNavScreen()) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700434 showNavScreen();
435 } else {
Michael Kolba3194d02011-09-07 11:23:51 -0700436 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false);
Michael Kolb20be26d2011-07-18 16:38:02 -0700437 }
438 }
439
John Reck1cf4b792011-07-26 10:22:22 -0700440 @Override
441 public boolean shouldCaptureThumbnails() {
442 return true;
443 }
444
Michael Kolbc3af0672011-08-09 10:24:41 -0700445 static class AnimScreen {
John Reck3ba45532011-08-11 16:26:53 -0700446
Michael Kolbc3af0672011-08-09 10:24:41 -0700447 private View mMain;
448 private ImageView mTitle;
449 private ImageView mContent;
450 private float mScale;
John Reckcc0059c2011-10-07 13:53:13 -0700451 private Bitmap mTitleBarBitmap;
452 private Bitmap mContentBitmap;
Michael Kolbc3af0672011-08-09 10:24:41 -0700453
John Reckcc0059c2011-10-07 13:53:13 -0700454 public AnimScreen(Context ctx) {
Michael Kolbc3af0672011-08-09 10:24:41 -0700455 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
456 null);
Michael Kolbc3af0672011-08-09 10:24:41 -0700457 mTitle = (ImageView) mMain.findViewById(R.id.title);
John Reckcc0059c2011-10-07 13:53:13 -0700458 mContent = (ImageView) mMain.findViewById(R.id.content);
459 mContent.setScaleType(ImageView.ScaleType.MATRIX);
460 mContent.setImageMatrix(new Matrix());
461 mScale = 1.0f;
462 setScaleFactor(getScaleFactor());
463 }
464
465 public void set(TitleBar tbar, WebView web) {
John Reck62077d82011-10-13 15:17:50 -0700466 if (tbar == null || web == null) {
467 return;
468 }
John Reck1adf0302011-10-11 10:58:12 -0700469 if (tbar.getWidth() > 0 && tbar.getEmbeddedHeight() > 0) {
470 if (mTitleBarBitmap == null
471 || mTitleBarBitmap.getWidth() != tbar.getWidth()
472 || mTitleBarBitmap.getHeight() != tbar.getEmbeddedHeight()) {
John Recka98c83b2011-10-31 12:31:58 -0700473 mTitleBarBitmap = safeCreateBitmap(tbar.getWidth(),
474 tbar.getEmbeddedHeight());
John Reck1adf0302011-10-11 10:58:12 -0700475 }
John Recka98c83b2011-10-31 12:31:58 -0700476 if (mTitleBarBitmap != null) {
477 Canvas c = new Canvas(mTitleBarBitmap);
478 tbar.draw(c);
479 c.setBitmap(null);
480 }
John Reck1adf0302011-10-11 10:58:12 -0700481 } else {
482 mTitleBarBitmap = null;
John Reckcc0059c2011-10-07 13:53:13 -0700483 }
John Reckcc0059c2011-10-07 13:53:13 -0700484 mTitle.setImageBitmap(mTitleBarBitmap);
485 mTitle.setVisibility(View.VISIBLE);
John Reck9c5004e2011-10-07 16:00:12 -0700486 int h = web.getHeight() - tbar.getEmbeddedHeight();
John Reckcc0059c2011-10-07 13:53:13 -0700487 if (mContentBitmap == null
488 || mContentBitmap.getWidth() != web.getWidth()
489 || mContentBitmap.getHeight() != h) {
John Recka98c83b2011-10-31 12:31:58 -0700490 mContentBitmap = safeCreateBitmap(web.getWidth(), h);
John Reckcc0059c2011-10-07 13:53:13 -0700491 }
John Recka98c83b2011-10-31 12:31:58 -0700492 if (mContentBitmap != null) {
493 Canvas c = new Canvas(mContentBitmap);
494 int tx = web.getScrollX();
495 int ty = web.getScrollY();
496 c.translate(-tx, -ty - tbar.getEmbeddedHeight());
497 web.draw(c);
498 c.setBitmap(null);
499 }
John Reckcc0059c2011-10-07 13:53:13 -0700500 mContent.setImageBitmap(mContentBitmap);
Michael Kolbc3af0672011-08-09 10:24:41 -0700501 }
502
John Recka98c83b2011-10-31 12:31:58 -0700503 private Bitmap safeCreateBitmap(int width, int height) {
504 if (width <= 0 || height <= 0) {
505 Log.w(LOGTAG, "safeCreateBitmap failed! width: " + width
506 + ", height: " + height);
507 return null;
508 }
509 return Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
510 }
511
John Reckcc0059c2011-10-07 13:53:13 -0700512 public void set(Bitmap image) {
Michael Kolba3194d02011-09-07 11:23:51 -0700513 mTitle.setVisibility(View.GONE);
Michael Kolbc3af0672011-08-09 10:24:41 -0700514 mContent.setImageBitmap(image);
Michael Kolbc3af0672011-08-09 10:24:41 -0700515 }
516
John Reckcc0059c2011-10-07 13:53:13 -0700517 private void setScaleFactor(float sf) {
Michael Kolbc3af0672011-08-09 10:24:41 -0700518 mScale = sf;
519 Matrix m = new Matrix();
520 m.postScale(sf,sf);
521 mContent.setImageMatrix(m);
522 }
523
John Reckcc0059c2011-10-07 13:53:13 -0700524 private float getScaleFactor() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700525 return mScale;
526 }
527
John Reck3ba45532011-08-11 16:26:53 -0700528 }
529
Michael Kolb66706532010-12-12 19:50:22 -0800530}