blob: 89eae708c384f57aa194ee3b460b874c240a2593 [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;
yijunx.zhu2230a312012-07-27 13:37:00 -040057 boolean mShowNav = false;
Michael Kolb66706532010-12-12 19:50:22 -080058
59 /**
60 * @param browser
61 * @param controller
62 */
63 public PhoneUi(Activity browser, UiController controller) {
64 super(browser, controller);
Michael Kolbfdb70242011-03-24 09:41:11 -070065 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
John Reck0f602f32011-07-07 15:38:43 -070066 mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar();
John Reckaae029c2011-09-16 14:36:39 -070067 TypedValue heightValue = new TypedValue();
68 browser.getTheme().resolveAttribute(
69 com.android.internal.R.attr.actionBarSize, heightValue, true);
70 mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data,
71 browser.getResources().getDisplayMetrics());
John Reck285ef042011-02-11 15:44:17 -080072 }
Michael Kolb66706532010-12-12 19:50:22 -080073
John Reck285ef042011-02-11 15:44:17 -080074 @Override
Michael Kolb66706532010-12-12 19:50:22 -080075 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080076 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080077 }
78
79 @Override
Michael Kolb1f9b3562012-04-24 14:38:34 -070080 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -070081 if (mUseQuickControls) {
John Reck0f602f32011-07-07 15:38:43 -070082 mTitleBar.setShowProgressOnly(false);
Michael Kolb46f987e2011-04-05 10:39:10 -070083 }
yijunx.zhu2230a312012-07-27 13:37:00 -040084 //Do nothing while at Nav show screen.
85 if (mShowNav) return;
Michael Kolb1f9b3562012-04-24 14:38:34 -070086 super.editUrl(clearInput, forceIME);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080087 }
88
89 @Override
Michael Kolb66706532010-12-12 19:50:22 -080090 public boolean onBackKey() {
John Reckcc0059c2011-10-07 13:53:13 -070091 if (showingNavScreen()) {
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
John Reckcc0059c2011-10-07 13:53:13 -070098 private boolean showingNavScreen() {
99 return mNavScreen != null && mNavScreen.getVisibility() == View.VISIBLE;
100 }
101
Michael Kolb66706532010-12-12 19:50:22 -0800102 @Override
Michael Kolbf2055602011-04-09 17:20:03 -0700103 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbf2055602011-04-09 17:20:03 -0700104 return false;
105 }
106
107 @Override
John Reck30c714c2010-12-16 17:30:34 -0800108 public void onProgressChanged(Tab tab) {
Michael Kolbe8a82332012-04-25 14:14:26 -0700109 super.onProgressChanged(tab);
John Reck9c5004e2011-10-07 16:00:12 -0700110 if (mNavScreen == null && getTitleBar().getHeight() > 0) {
111 mHandler.sendEmptyMessage(MSG_INIT_NAVSCREEN);
112 }
113 }
114
115 @Override
116 protected void handleMessage(Message msg) {
117 super.handleMessage(msg);
118 if (msg.what == MSG_INIT_NAVSCREEN) {
119 if (mNavScreen == null) {
120 mNavScreen = new NavScreen(mActivity, mUiController, this);
121 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
122 mNavScreen.setVisibility(View.GONE);
123 }
124 if (mAnimScreen == null) {
125 mAnimScreen = new AnimScreen(mActivity);
126 // initialize bitmaps
127 mAnimScreen.set(getTitleBar(), getWebView());
128 }
129 }
Michael Kolb66706532010-12-12 19:50:22 -0800130 }
131
132 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700133 public void setActiveTab(final Tab tab) {
John Reck8ee633f2011-08-09 16:00:35 -0700134 mTitleBar.cancelTitleBarAnimation(true);
135 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700136 super.setActiveTab(tab);
yijunx.zhu2230a312012-07-27 13:37:00 -0400137
138 //if at Nav screen show, detach tab like what showNavScreen() do.
139 if (mShowNav) {
140 detachTab(mActiveTab);
141 }
142
Michael Kolbfdb70242011-03-24 09:41:11 -0700143 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800144 // TabControl.setCurrentTab has been called before this,
145 // so the tab is guaranteed to have a webview
146 if (view == null) {
147 Log.e(LOGTAG, "active tab with no webview detected");
148 return;
149 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700150 // Request focus on the top window.
151 if (mUseQuickControls) {
152 mPieControl.forceToTop(mContentView);
Michael Kolb4923c222012-04-02 16:18:36 -0700153 view.setTitleBar(null);
Michael Kolbe8a82332012-04-25 14:14:26 -0700154 mTitleBar.setShowProgressOnly(true);
Michael Kolbfdb70242011-03-24 09:41:11 -0700155 } else {
Michael Kolb4923c222012-04-02 16:18:36 -0700156 view.setTitleBar(mTitleBar);
Michael Kolbfdb70242011-03-24 09:41:11 -0700157 }
Michael Kolb629b22c2011-07-13 16:26:47 -0700158 // update nav bar state
159 mNavigationBar.onStateChanged(StateListener.STATE_NORMAL);
Michael Kolbfdb70242011-03-24 09:41:11 -0700160 updateLockIconToLatest(tab);
John Reck8ee633f2011-08-09 16:00:35 -0700161 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb376b5412010-12-15 11:52:57 -0800162 }
163
Michael Kolb66706532010-12-12 19:50:22 -0800164 // menu handling callbacks
165
166 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700167 public boolean onPrepareOptionsMenu(Menu menu) {
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700168 updateMenuState(mActiveTab, menu);
Michael Kolb3ca12752011-07-20 13:52:25 -0700169 return true;
170 }
171
172 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700173 public void updateMenuState(Tab tab, Menu menu) {
Michael Kolb0d0245f2011-12-05 16:36:05 -0800174 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
175 if (bm != null) {
176 bm.setVisible(!showingNavScreen());
177 }
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700178 MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id);
179 if (abm != null) {
John Reckcc0059c2011-10-07 13:53:13 -0700180 abm.setVisible((tab != null) && !tab.isSnapshot() && !showingNavScreen());
John Recke1a03a32011-09-14 17:04:16 -0700181 }
Michael Kolb315d5022011-10-13 12:47:11 -0700182 MenuItem info = menu.findItem(R.id.page_info_menu_id);
183 if (info != null) {
184 info.setVisible(false);
185 }
186 MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
187 if (newtab != null && !mUseQuickControls) {
188 newtab.setVisible(false);
189 }
190 MenuItem incognito = menu.findItem(R.id.incognito_menu_id);
191 if (incognito != null) {
192 incognito.setVisible(showingNavScreen() || mUseQuickControls);
193 }
Afzal Najamd4e33312012-04-26 01:54:01 -0400194 MenuItem closeOthers = menu.findItem(R.id.close_other_tabs_id);
195 if (closeOthers != null) {
196 boolean isLastTab = true;
197 if (tab != null) {
198 isLastTab = (mTabControl.getTabCount() <= 1);
199 }
200 closeOthers.setEnabled(!isLastTab);
201 }
John Reckcc0059c2011-10-07 13:53:13 -0700202 if (showingNavScreen()) {
John Recke1a03a32011-09-14 17:04:16 -0700203 menu.setGroupVisible(R.id.LIVE_MENU, false);
204 menu.setGroupVisible(R.id.SNAPSHOT_MENU, false);
John Recke1a03a32011-09-14 17:04:16 -0700205 menu.setGroupVisible(R.id.NAV_MENU, false);
Michael Kolb315d5022011-10-13 12:47:11 -0700206 menu.setGroupVisible(R.id.COMBO_MENU, true);
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700207 }
208 }
209
210 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700211 public boolean onOptionsItemSelected(MenuItem item) {
Michael Kolb315d5022011-10-13 12:47:11 -0700212 if (showingNavScreen()
213 && (item.getItemId() != R.id.history_menu_id)
214 && (item.getItemId() != R.id.snapshots_menu_id)) {
Michael Kolba3194d02011-09-07 11:23:51 -0700215 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false);
Michael Kolb3ca12752011-07-20 13:52:25 -0700216 }
217 return false;
218 }
219
220 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800221 public void onContextMenuCreated(Menu menu) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800222 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800223 }
224
225 @Override
226 public void onContextMenuClosed(Menu menu, boolean inLoad) {
227 if (inLoad) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800228 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800229 }
230 }
231
232 // action mode callbacks
233
234 @Override
235 public void onActionModeStarted(ActionMode mode) {
Michael Kolb42c0c062011-08-02 12:56:06 -0700236 if (!isEditingUrl()) {
237 hideTitleBar();
John Reckaae029c2011-09-16 14:36:39 -0700238 } else {
239 mTitleBar.animate().translationY(mActionBarHeight);
Michael Kolb42c0c062011-08-02 12:56:06 -0700240 }
Michael Kolb66706532010-12-12 19:50:22 -0800241 }
242
Michael Kolba4183062011-01-16 10:43:21 -0800243 @Override
John Reck6cda7b12011-03-18 15:57:13 -0700244 public void onActionModeFinished(boolean inLoad) {
John Reckaae029c2011-09-16 14:36:39 -0700245 mTitleBar.animate().translationY(0);
Michael Kolbc16c5952011-03-29 15:37:03 -0700246 if (inLoad) {
247 if (mUseQuickControls) {
248 mTitleBar.setShowProgressOnly(true);
John Reck6cda7b12011-03-18 15:57:13 -0700249 }
Michael Kolbc16c5952011-03-29 15:37:03 -0700250 showTitleBar();
251 }
John Reck6cda7b12011-03-18 15:57:13 -0700252 }
253
254 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -0700255 public boolean isWebShowing() {
John Reckcc0059c2011-10-07 13:53:13 -0700256 return super.isWebShowing() && !showingNavScreen();
Michael Kolbc3af0672011-08-09 10:24:41 -0700257 }
258
259 @Override
260 public void showWeb(boolean animate) {
261 super.showWeb(animate);
Michael Kolba3194d02011-09-07 11:23:51 -0700262 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), animate);
Michael Kolbc3af0672011-08-09 10:24:41 -0700263 }
264
Michael Kolbf2055602011-04-09 17:20:03 -0700265 void showNavScreen() {
yijunx.zhu2230a312012-07-27 13:37:00 -0400266 mShowNav = true;
Michael Kolbc3af0672011-08-09 10:24:41 -0700267 mUiController.setBlockEvents(true);
John Reckcc0059c2011-10-07 13:53:13 -0700268 if (mNavScreen == null) {
269 mNavScreen = new NavScreen(mActivity, mUiController, this);
270 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
271 } else {
272 mNavScreen.setVisibility(View.VISIBLE);
273 mNavScreen.setAlpha(1f);
John Reck9c5004e2011-10-07 16:00:12 -0700274 mNavScreen.refreshAdapter();
John Reckcc0059c2011-10-07 13:53:13 -0700275 }
Michael Kolbc3af0672011-08-09 10:24:41 -0700276 mActiveTab.capture();
John Reckcc0059c2011-10-07 13:53:13 -0700277 if (mAnimScreen == null) {
278 mAnimScreen = new AnimScreen(mActivity);
John Reckce8bcb02011-10-11 13:45:29 -0700279 } else {
280 mAnimScreen.mMain.setAlpha(1f);
281 mAnimScreen.mTitle.setAlpha(1f);
282 mAnimScreen.setScaleFactor(1f);
John Reckcc0059c2011-10-07 13:53:13 -0700283 }
284 mAnimScreen.set(getTitleBar(), getWebView());
Michael Kolba30e4fb2011-11-07 17:32:01 -0800285 if (mAnimScreen.mMain.getParent() == null) {
286 mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS);
287 }
Michael Kolbf2055602011-04-09 17:20:03 -0700288 mCustomViewContainer.setVisibility(View.VISIBLE);
289 mCustomViewContainer.bringToFront();
John Reckce8bcb02011-10-11 13:45:29 -0700290 mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(),
291 mContentView.getHeight());
Michael Kolbc3af0672011-08-09 10:24:41 -0700292 int fromLeft = 0;
293 int fromTop = getTitleBar().getHeight();
294 int fromRight = mContentView.getWidth();
295 int fromBottom = mContentView.getHeight();
Michael Kolba3194d02011-09-07 11:23:51 -0700296 int width = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_width);
297 int height = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_height);
Michael Kolb7a321d62011-09-23 15:54:22 -0700298 int ntth = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_titleheight);
Michael Kolbc3af0672011-08-09 10:24:41 -0700299 int toLeft = (mContentView.getWidth() - width) / 2;
Michael Kolb7a321d62011-09-23 15:54:22 -0700300 int toTop = ((fromBottom - (ntth + height)) / 2 + ntth);
Michael Kolbc3af0672011-08-09 10:24:41 -0700301 int toRight = toLeft + width;
302 int toBottom = toTop + height;
303 float scaleFactor = width / (float) mContentView.getWidth();
304 detachTab(mActiveTab);
305 mContentView.setVisibility(View.GONE);
Michael Kolba3194d02011-09-07 11:23:51 -0700306 AnimatorSet set1 = new AnimatorSet();
Michael Kolbc3af0672011-08-09 10:24:41 -0700307 AnimatorSet inanim = new AnimatorSet();
John Reckcc0059c2011-10-07 13:53:13 -0700308 ObjectAnimator tx = ObjectAnimator.ofInt(mAnimScreen.mContent, "left",
Michael Kolbc3af0672011-08-09 10:24:41 -0700309 fromLeft, toLeft);
John Reckcc0059c2011-10-07 13:53:13 -0700310 ObjectAnimator ty = ObjectAnimator.ofInt(mAnimScreen.mContent, "top",
Michael Kolbc3af0672011-08-09 10:24:41 -0700311 fromTop, toTop);
John Reckcc0059c2011-10-07 13:53:13 -0700312 ObjectAnimator tr = ObjectAnimator.ofInt(mAnimScreen.mContent, "right",
Michael Kolbc3af0672011-08-09 10:24:41 -0700313 fromRight, toRight);
John Reckcc0059c2011-10-07 13:53:13 -0700314 ObjectAnimator tb = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom",
Michael Kolbc3af0672011-08-09 10:24:41 -0700315 fromBottom, toBottom);
John Reckcc0059c2011-10-07 13:53:13 -0700316 ObjectAnimator title = ObjectAnimator.ofFloat(mAnimScreen.mTitle, "alpha",
Michael Kolbc3af0672011-08-09 10:24:41 -0700317 1f, 0f);
John Reckcc0059c2011-10-07 13:53:13 -0700318 ObjectAnimator sx = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor",
Michael Kolbc3af0672011-08-09 10:24:41 -0700319 1f, scaleFactor);
John Reck1adf0302011-10-11 10:58:12 -0700320 ObjectAnimator blend1 = ObjectAnimator.ofFloat(mAnimScreen.mMain,
321 "alpha", 1f, 0f);
Michael Kolba3194d02011-09-07 11:23:51 -0700322 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) {
John Reck1adf0302011-10-11 10:58:12 -0700329 mCustomViewContainer.removeView(mAnimScreen.mMain);
Michael Kolbc3af0672011-08-09 10:24:41 -0700330 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() {
John Reckcc0059c2011-10-07 13:53:13 -0700339 if (showingNavScreen()) {
Michael Kolbb43f2f62011-08-17 10:39:31 -0700340 // 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) {
yijunx.zhu2230a312012-07-27 13:37:00 -0400347 mShowNav = false;
John Reckcc0059c2011-10-07 13:53:13 -0700348 if (!showingNavScreen()) 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);
John Reckcc0059c2011-10-07 13:53:13 -0700374 if (mAnimScreen == null) {
375 mAnimScreen = new AnimScreen(mActivity);
376 }
377 mAnimScreen.set(tab.getScreenshot());
Michael Kolb0755fcd2012-01-10 10:19:50 -0800378 if (mAnimScreen.mMain.getParent() == null) {
379 mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS);
380 }
John Reckcc0059c2011-10-07 13:53:13 -0700381 mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(),
Michael Kolba3194d02011-09-07 11:23:51 -0700382 mContentView.getHeight());
383 mNavScreen.mScroller.finishScroller();
384 ImageView target = tabview.mImage;
Michael Kolbc3af0672011-08-09 10:24:41 -0700385 int toLeft = 0;
Michael Kolbb7e16702011-12-15 11:59:40 -0800386 int toTop = (tab.getWebView() != null) ? tab.getWebView().getVisibleTitleHeight() : 0;
Michael Kolbc3af0672011-08-09 10:24:41 -0700387 int toRight = mContentView.getWidth();
Michael Kolba3194d02011-09-07 11:23:51 -0700388 int width = target.getDrawable().getIntrinsicWidth();
389 int height = target.getDrawable().getIntrinsicHeight();
390 int fromLeft = tabview.getLeft() + target.getLeft() - mNavScreen.mScroller.getScrollX();
391 int fromTop = tabview.getTop() + target.getTop() - mNavScreen.mScroller.getScrollY();
Michael Kolbc3af0672011-08-09 10:24:41 -0700392 int fromRight = fromLeft + width;
393 int fromBottom = fromTop + height;
394 float scaleFactor = mContentView.getWidth() / (float) width;
Michael Kolba3194d02011-09-07 11:23:51 -0700395 int toBottom = toTop + (int) (height * scaleFactor);
John Reck9c5004e2011-10-07 16:00:12 -0700396 mAnimScreen.mContent.setLeft(fromLeft);
397 mAnimScreen.mContent.setTop(fromTop);
398 mAnimScreen.mContent.setRight(fromRight);
399 mAnimScreen.mContent.setBottom(fromBottom);
400 mAnimScreen.setScaleFactor(1f);
Michael Kolba3194d02011-09-07 11:23:51 -0700401 AnimatorSet set1 = new AnimatorSet();
John Reckcc0059c2011-10-07 13:53:13 -0700402 ObjectAnimator fade2 = ObjectAnimator.ofFloat(mAnimScreen.mMain, "alpha", 0f, 1f);
Michael Kolba3194d02011-09-07 11:23:51 -0700403 ObjectAnimator fade1 = ObjectAnimator.ofFloat(mNavScreen, "alpha", 1f, 0f);
John Reck9c5004e2011-10-07 16:00:12 -0700404 set1.playTogether(fade1, fade2);
Michael Kolba3194d02011-09-07 11:23:51 -0700405 set1.setDuration(100);
406 AnimatorSet set2 = new AnimatorSet();
John Reckcc0059c2011-10-07 13:53:13 -0700407 ObjectAnimator l = ObjectAnimator.ofInt(mAnimScreen.mContent, "left",
Michael Kolbc3af0672011-08-09 10:24:41 -0700408 fromLeft, toLeft);
John Reckcc0059c2011-10-07 13:53:13 -0700409 ObjectAnimator t = ObjectAnimator.ofInt(mAnimScreen.mContent, "top",
Michael Kolbc3af0672011-08-09 10:24:41 -0700410 fromTop, toTop);
John Reckcc0059c2011-10-07 13:53:13 -0700411 ObjectAnimator r = ObjectAnimator.ofInt(mAnimScreen.mContent, "right",
Michael Kolbc3af0672011-08-09 10:24:41 -0700412 fromRight, toRight);
John Reckcc0059c2011-10-07 13:53:13 -0700413 ObjectAnimator b = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom",
Michael Kolbc3af0672011-08-09 10:24:41 -0700414 fromBottom, toBottom);
John Reckcc0059c2011-10-07 13:53:13 -0700415 ObjectAnimator scale = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor",
Michael Kolbc3af0672011-08-09 10:24:41 -0700416 1f, scaleFactor);
Michael Kolbc3af0672011-08-09 10:24:41 -0700417 ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f);
Michael Kolba3194d02011-09-07 11:23:51 -0700418 otheralpha.setDuration(100);
419 set2.playTogether(l, t, r, b, scale);
420 set2.setDuration(200);
421 AnimatorSet combo = new AnimatorSet();
422 combo.playSequentially(set1, set2, otheralpha);
423 combo.addListener(new AnimatorListenerAdapter() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700424 @Override
425 public void onAnimationEnd(Animator anim) {
John Reckcc0059c2011-10-07 13:53:13 -0700426 mCustomViewContainer.removeView(mAnimScreen.mMain);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700427 finishAnimateOut();
Michael Kolbc3af0672011-08-09 10:24:41 -0700428 mUiController.setBlockEvents(false);
429 }
430 });
Michael Kolba3194d02011-09-07 11:23:51 -0700431 combo.start();
Michael Kolbc3af0672011-08-09 10:24:41 -0700432 }
433
Michael Kolbbf32cd02011-08-16 15:07:04 -0700434 private void finishAnimateOut() {
John Reck8ee633f2011-08-09 16:00:35 -0700435 mTabControl.setOnThumbnailUpdatedListener(null);
John Reckcc0059c2011-10-07 13:53:13 -0700436 mNavScreen.setVisibility(View.GONE);
Michael Kolbc3af0672011-08-09 10:24:41 -0700437 mCustomViewContainer.setAlpha(1f);
Michael Kolbf2055602011-04-09 17:20:03 -0700438 mCustomViewContainer.setVisibility(View.GONE);
Michael Kolbf2055602011-04-09 17:20:03 -0700439 }
440
John Reck6b4bd5f2011-07-12 10:14:38 -0700441 @Override
442 public boolean needsRestoreAllTabs() {
443 return false;
444 }
445
Michael Kolb20be26d2011-07-18 16:38:02 -0700446 public void toggleNavScreen() {
John Reckcc0059c2011-10-07 13:53:13 -0700447 if (!showingNavScreen()) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700448 showNavScreen();
449 } else {
Michael Kolba3194d02011-09-07 11:23:51 -0700450 hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false);
Michael Kolb20be26d2011-07-18 16:38:02 -0700451 }
452 }
453
John Reck1cf4b792011-07-26 10:22:22 -0700454 @Override
455 public boolean shouldCaptureThumbnails() {
456 return true;
457 }
458
Michael Kolbc3af0672011-08-09 10:24:41 -0700459 static class AnimScreen {
John Reck3ba45532011-08-11 16:26:53 -0700460
Michael Kolbc3af0672011-08-09 10:24:41 -0700461 private View mMain;
462 private ImageView mTitle;
463 private ImageView mContent;
464 private float mScale;
John Reckcc0059c2011-10-07 13:53:13 -0700465 private Bitmap mTitleBarBitmap;
466 private Bitmap mContentBitmap;
Michael Kolbc3af0672011-08-09 10:24:41 -0700467
John Reckcc0059c2011-10-07 13:53:13 -0700468 public AnimScreen(Context ctx) {
Michael Kolbc3af0672011-08-09 10:24:41 -0700469 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
470 null);
Michael Kolbc3af0672011-08-09 10:24:41 -0700471 mTitle = (ImageView) mMain.findViewById(R.id.title);
John Reckcc0059c2011-10-07 13:53:13 -0700472 mContent = (ImageView) mMain.findViewById(R.id.content);
473 mContent.setScaleType(ImageView.ScaleType.MATRIX);
474 mContent.setImageMatrix(new Matrix());
475 mScale = 1.0f;
476 setScaleFactor(getScaleFactor());
477 }
478
479 public void set(TitleBar tbar, WebView web) {
John Reck62077d82011-10-13 15:17:50 -0700480 if (tbar == null || web == null) {
481 return;
482 }
John Reck1adf0302011-10-11 10:58:12 -0700483 if (tbar.getWidth() > 0 && tbar.getEmbeddedHeight() > 0) {
484 if (mTitleBarBitmap == null
485 || mTitleBarBitmap.getWidth() != tbar.getWidth()
486 || mTitleBarBitmap.getHeight() != tbar.getEmbeddedHeight()) {
John Recka98c83b2011-10-31 12:31:58 -0700487 mTitleBarBitmap = safeCreateBitmap(tbar.getWidth(),
488 tbar.getEmbeddedHeight());
John Reck1adf0302011-10-11 10:58:12 -0700489 }
John Recka98c83b2011-10-31 12:31:58 -0700490 if (mTitleBarBitmap != null) {
491 Canvas c = new Canvas(mTitleBarBitmap);
492 tbar.draw(c);
493 c.setBitmap(null);
494 }
John Reck1adf0302011-10-11 10:58:12 -0700495 } else {
496 mTitleBarBitmap = null;
John Reckcc0059c2011-10-07 13:53:13 -0700497 }
John Reckcc0059c2011-10-07 13:53:13 -0700498 mTitle.setImageBitmap(mTitleBarBitmap);
499 mTitle.setVisibility(View.VISIBLE);
John Reck9c5004e2011-10-07 16:00:12 -0700500 int h = web.getHeight() - tbar.getEmbeddedHeight();
John Reckcc0059c2011-10-07 13:53:13 -0700501 if (mContentBitmap == null
502 || mContentBitmap.getWidth() != web.getWidth()
503 || mContentBitmap.getHeight() != h) {
John Recka98c83b2011-10-31 12:31:58 -0700504 mContentBitmap = safeCreateBitmap(web.getWidth(), h);
John Reckcc0059c2011-10-07 13:53:13 -0700505 }
John Recka98c83b2011-10-31 12:31:58 -0700506 if (mContentBitmap != null) {
507 Canvas c = new Canvas(mContentBitmap);
508 int tx = web.getScrollX();
509 int ty = web.getScrollY();
510 c.translate(-tx, -ty - tbar.getEmbeddedHeight());
511 web.draw(c);
512 c.setBitmap(null);
513 }
John Reckcc0059c2011-10-07 13:53:13 -0700514 mContent.setImageBitmap(mContentBitmap);
Michael Kolbc3af0672011-08-09 10:24:41 -0700515 }
516
John Recka98c83b2011-10-31 12:31:58 -0700517 private Bitmap safeCreateBitmap(int width, int height) {
518 if (width <= 0 || height <= 0) {
519 Log.w(LOGTAG, "safeCreateBitmap failed! width: " + width
520 + ", height: " + height);
521 return null;
522 }
523 return Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
524 }
525
John Reckcc0059c2011-10-07 13:53:13 -0700526 public void set(Bitmap image) {
Michael Kolba3194d02011-09-07 11:23:51 -0700527 mTitle.setVisibility(View.GONE);
Michael Kolbc3af0672011-08-09 10:24:41 -0700528 mContent.setImageBitmap(image);
Michael Kolbc3af0672011-08-09 10:24:41 -0700529 }
530
John Reckcc0059c2011-10-07 13:53:13 -0700531 private void setScaleFactor(float sf) {
Michael Kolbc3af0672011-08-09 10:24:41 -0700532 mScale = sf;
533 Matrix m = new Matrix();
534 m.postScale(sf,sf);
535 mContent.setImageMatrix(m);
536 }
537
John Reckcc0059c2011-10-07 13:53:13 -0700538 private float getScaleFactor() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700539 return mScale;
540 }
541
John Reck3ba45532011-08-11 16:26:53 -0700542 }
543
Michael Kolb66706532010-12-12 19:50:22 -0800544}