blob: 009989bc366f518d164f221693345372cf6e22e9 [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;
Michael Kolb66706532010-12-12 19:50:22 -080029import android.view.ActionMode;
30import android.view.Gravity;
Michael Kolba4183062011-01-16 10:43:21 -080031import android.view.KeyEvent;
Michael Kolbc3af0672011-08-09 10:24:41 -070032import android.view.LayoutInflater;
Michael Kolb66706532010-12-12 19:50:22 -080033import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070034import android.view.MenuItem;
Michael Kolb66706532010-12-12 19:50:22 -080035import android.view.View;
Michael Kolb199e43c2011-08-17 10:45:45 -070036import android.view.ViewGroup;
Michael Kolb30adae62011-07-29 13:37:05 -070037import android.view.accessibility.AccessibilityEvent;
Michael Kolbc3af0672011-08-09 10:24:41 -070038import android.view.animation.DecelerateInterpolator;
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;
Michael Kolb66706532010-12-12 19:50:22 -080055
56 boolean mExtendedMenuOpen;
57 boolean mOptionsMenuOpen;
Michael Kolb08a687a2011-04-22 16:13:02 -070058 boolean mAnimating;
Michael Kolb66706532010-12-12 19:50:22 -080059
60 /**
61 * @param browser
62 * @param controller
63 */
64 public PhoneUi(Activity browser, UiController controller) {
65 super(browser, controller);
John Reck285ef042011-02-11 15:44:17 -080066 mActivity.getActionBar().hide();
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 Reck285ef042011-02-11 15:44:17 -080069 }
Michael Kolb66706532010-12-12 19:50:22 -080070
John Reck285ef042011-02-11 15:44:17 -080071 @Override
Michael Kolb66706532010-12-12 19:50:22 -080072 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080073 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080074 }
75
76 @Override
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080077 public void editUrl(boolean clearInput) {
Michael Kolb46f987e2011-04-05 10:39:10 -070078 if (mUseQuickControls) {
John Reck0f602f32011-07-07 15:38:43 -070079 mTitleBar.setShowProgressOnly(false);
Michael Kolb46f987e2011-04-05 10:39:10 -070080 }
81 super.editUrl(clearInput);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080082 }
83
84 @Override
Michael Kolb66706532010-12-12 19:50:22 -080085 public boolean onBackKey() {
Michael Kolb9ef259a2011-07-12 15:33:08 -070086 if (mNavScreen != null) {
Michael Kolbf2055602011-04-09 17:20:03 -070087 mNavScreen.close();
88 return true;
Michael Kolb66706532010-12-12 19:50:22 -080089 }
90 return super.onBackKey();
91 }
92
93 @Override
Michael Kolbf2055602011-04-09 17:20:03 -070094 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbf2055602011-04-09 17:20:03 -070095 return false;
96 }
97
98 @Override
John Reck30c714c2010-12-16 17:30:34 -080099 public void onProgressChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800100 if (tab.inForeground()) {
John Reck30c714c2010-12-16 17:30:34 -0800101 int progress = tab.getLoadProgress();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800102 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800103 if (progress == 100) {
104 if (!mOptionsMenuOpen || !mExtendedMenuOpen) {
John Reck5d43ce82011-06-21 17:16:51 -0700105 suggestHideTitleBar();
Michael Kolbc16c5952011-03-29 15:37:03 -0700106 if (mUseQuickControls) {
107 mTitleBar.setShowProgressOnly(false);
108 }
Michael Kolb66706532010-12-12 19:50:22 -0800109 }
110 } else {
111 if (!mOptionsMenuOpen || mExtendedMenuOpen) {
Michael Kolbc16c5952011-03-29 15:37:03 -0700112 if (mUseQuickControls && !mTitleBar.isEditingUrl()) {
113 mTitleBar.setShowProgressOnly(true);
114 setTitleGravity(Gravity.TOP);
115 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800116 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800117 }
118 }
119 }
120 }
121
122 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700123 public void setActiveTab(final Tab tab) {
John Reck8ee633f2011-08-09 16:00:35 -0700124 mTitleBar.cancelTitleBarAnimation(true);
125 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700126 super.setActiveTab(tab);
Michael Kolbfdb70242011-03-24 09:41:11 -0700127 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800128 // TabControl.setCurrentTab has been called before this,
129 // so the tab is guaranteed to have a webview
130 if (view == null) {
131 Log.e(LOGTAG, "active tab with no webview detected");
132 return;
133 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700134 // Request focus on the top window.
135 if (mUseQuickControls) {
136 mPieControl.forceToTop(mContentView);
Michael Kolbfdb70242011-03-24 09:41:11 -0700137 } else {
138 // check if title bar is already attached by animation
139 if (mTitleBar.getParent() == null) {
140 view.setEmbeddedTitleBar(mTitleBar);
141 }
142 }
Michael Kolb376b5412010-12-15 11:52:57 -0800143 if (tab.isInVoiceSearchMode()) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700144 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
Michael Kolb376b5412010-12-15 11:52:57 -0800145 } else {
146 revertVoiceTitleBar(tab);
147 }
Michael Kolb629b22c2011-07-13 16:26:47 -0700148 // update nav bar state
149 mNavigationBar.onStateChanged(StateListener.STATE_NORMAL);
Michael Kolbfdb70242011-03-24 09:41:11 -0700150 updateLockIconToLatest(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800151 tab.getTopWindow().requestFocus();
John Reck8ee633f2011-08-09 16:00:35 -0700152 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb376b5412010-12-15 11:52:57 -0800153 }
154
Michael Kolb66706532010-12-12 19:50:22 -0800155 // menu handling callbacks
156
157 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700158 public boolean onPrepareOptionsMenu(Menu menu) {
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700159 updateMenuState(mActiveTab, menu);
Michael Kolb3ca12752011-07-20 13:52:25 -0700160 return true;
161 }
162
163 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700164 public void updateMenuState(Tab tab, Menu menu) {
165 menu.setGroupVisible(R.id.NAV_MENU, (mNavScreen == null));
166 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
167 if (bm != null) {
168 bm.setVisible(mNavScreen == null);
169 }
170 MenuItem nt = menu.findItem(R.id.new_tab_menu_id);
171 if (nt != null) {
172 nt.setVisible(mNavScreen == null);
173 }
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700174 MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id);
175 if (abm != null) {
176 abm.setVisible((tab != null) && !tab.isSnapshot());
177 }
178 }
179
180 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700181 public boolean onOptionsItemSelected(MenuItem item) {
182 if (mNavScreen != null) {
183 hideNavScreen(false);
184 }
185 return false;
186 }
187
188 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800189 public void onContextMenuCreated(Menu menu) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800190 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800191 }
192
193 @Override
194 public void onContextMenuClosed(Menu menu, boolean inLoad) {
195 if (inLoad) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800196 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800197 }
198 }
199
200 // action mode callbacks
201
202 @Override
203 public void onActionModeStarted(ActionMode mode) {
Michael Kolb42c0c062011-08-02 12:56:06 -0700204 if (!isEditingUrl()) {
205 hideTitleBar();
206 }
Michael Kolb66706532010-12-12 19:50:22 -0800207 }
208
Michael Kolba4183062011-01-16 10:43:21 -0800209 @Override
John Reck6cda7b12011-03-18 15:57:13 -0700210 public void onActionModeFinished(boolean inLoad) {
Michael Kolbc16c5952011-03-29 15:37:03 -0700211 if (inLoad) {
212 if (mUseQuickControls) {
213 mTitleBar.setShowProgressOnly(true);
John Reck6cda7b12011-03-18 15:57:13 -0700214 }
Michael Kolbc16c5952011-03-29 15:37:03 -0700215 showTitleBar();
216 }
217 mActivity.getActionBar().hide();
John Reck6cda7b12011-03-18 15:57:13 -0700218 }
219
220 @Override
Michael Kolbfdb70242011-03-24 09:41:11 -0700221 protected void setTitleGravity(int gravity) {
222 if (mUseQuickControls) {
223 FrameLayout.LayoutParams lp =
John Reck0f602f32011-07-07 15:38:43 -0700224 (FrameLayout.LayoutParams) mTitleBar.getLayoutParams();
Michael Kolbfdb70242011-03-24 09:41:11 -0700225 lp.gravity = gravity;
John Reck0f602f32011-07-07 15:38:43 -0700226 mTitleBar.setLayoutParams(lp);
Michael Kolbfdb70242011-03-24 09:41:11 -0700227 } else {
228 super.setTitleGravity(gravity);
229 }
230 }
231
Michael Kolb0241e752011-07-07 14:58:50 -0700232 @Override
233 public void setUseQuickControls(boolean useQuickControls) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700234 mUseQuickControls = useQuickControls;
John Reck0f602f32011-07-07 15:38:43 -0700235 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolbfdb70242011-03-24 09:41:11 -0700236 if (useQuickControls) {
Michael Kolb0241e752011-07-07 14:58:50 -0700237 mPieControl = new PieControlPhone(mActivity, mUiController, this);
Michael Kolbfdb70242011-03-24 09:41:11 -0700238 mPieControl.attachToContainer(mContentView);
Michael Kolb46f987e2011-04-05 10:39:10 -0700239 WebView web = getWebView();
240 if (web != null) {
241 web.setEmbeddedTitleBar(null);
Michael Kolbfdb70242011-03-24 09:41:11 -0700242 }
243 } else {
Michael Kolbfdb70242011-03-24 09:41:11 -0700244 if (mPieControl != null) {
245 mPieControl.removeFromContainer(mContentView);
246 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700247 WebView web = getWebView();
Michael Kolbfdb70242011-03-24 09:41:11 -0700248 if (web != null) {
Michael Kolb199e43c2011-08-17 10:45:45 -0700249 // make sure we can re-parent titlebar
250 if ((mTitleBar != null) && (mTitleBar.getParent() != null)) {
251 ((ViewGroup) mTitleBar.getParent()).removeView(mTitleBar);
252 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700253 web.setEmbeddedTitleBar(mTitleBar);
254 }
255 setTitleGravity(Gravity.NO_GRAVITY);
256 }
John Reck718a24d2011-08-12 11:08:30 -0700257 updateUrlBarAutoShowManagerTarget();
Michael Kolbfdb70242011-03-24 09:41:11 -0700258 }
259
Michael Kolbc3af0672011-08-09 10:24:41 -0700260 @Override
261 public boolean isWebShowing() {
262 return super.isWebShowing() && mNavScreen == null;
263 }
264
265 @Override
266 public void showWeb(boolean animate) {
267 super.showWeb(animate);
268 hideNavScreen(animate);
269 }
270
Michael Kolbf2055602011-04-09 17:20:03 -0700271 void showNavScreen() {
Michael Kolbc3af0672011-08-09 10:24:41 -0700272 mUiController.setBlockEvents(true);
Michael Kolbf2055602011-04-09 17:20:03 -0700273 mNavScreen = new NavScreen(mActivity, mUiController, this);
Michael Kolbc3af0672011-08-09 10:24:41 -0700274 mActiveTab.capture();
275 // Add the custom view to its container
Michael Kolb2814a362011-05-19 15:49:41 -0700276 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
Michael Kolbc3af0672011-08-09 10:24:41 -0700277 AnimScreen ascreen = new AnimScreen(mActivity, getTitleBar(), getWebView());
278 final View animView = ascreen.mMain;
279 mCustomViewContainer.addView(animView, COVER_SCREEN_PARAMS);
Michael Kolbf2055602011-04-09 17:20:03 -0700280 mCustomViewContainer.setVisibility(View.VISIBLE);
281 mCustomViewContainer.bringToFront();
Michael Kolbc3af0672011-08-09 10:24:41 -0700282 View target = ((NavTabView) mNavScreen.mScroller.getSelectedView()).mImage;
283 int fromLeft = 0;
284 int fromTop = getTitleBar().getHeight();
285 int fromRight = mContentView.getWidth();
286 int fromBottom = mContentView.getHeight();
287 int width = target.getWidth();
288 int height = target.getHeight();
289 int toLeft = (mContentView.getWidth() - width) / 2;
290 int toTop = fromTop + (mContentView.getHeight() - fromTop - height) / 2;
291 int toRight = toLeft + width;
292 int toBottom = toTop + height;
293 float scaleFactor = width / (float) mContentView.getWidth();
294 detachTab(mActiveTab);
295 mContentView.setVisibility(View.GONE);
296 AnimatorSet inanim = new AnimatorSet();
297 ObjectAnimator tx = ObjectAnimator.ofInt(ascreen.mContent, "left",
298 fromLeft, toLeft);
299 ObjectAnimator ty = ObjectAnimator.ofInt(ascreen.mContent, "top",
300 fromTop, toTop);
301 ObjectAnimator tr = ObjectAnimator.ofInt(ascreen.mContent, "right",
302 fromRight, toRight);
303 ObjectAnimator tb = ObjectAnimator.ofInt(ascreen.mContent, "bottom",
304 fromBottom, toBottom);
305 ObjectAnimator title = ObjectAnimator.ofFloat(ascreen.mTitle, "alpha",
306 1f, 0f);
307 ObjectAnimator content = ObjectAnimator.ofFloat(ascreen.mContent, "alpha",
308 1f, 0f);
309 ObjectAnimator sx = ObjectAnimator.ofFloat(ascreen, "scaleFactor",
310 1f, scaleFactor);
311 inanim.playTogether(tx, ty, tr, tb, title, content, sx);
312 inanim.addListener(new AnimatorListenerAdapter() {
313 @Override
314 public void onAnimationEnd(Animator anim) {
315 mCustomViewContainer.removeView(animView);
316 finishAnimationIn();
317 mUiController.setBlockEvents(false);
318 }
319 });
320 inanim.setInterpolator(new DecelerateInterpolator(2f));
321 inanim.setDuration(300);
322 inanim.start();
323 }
324
325 private void finishAnimationIn() {
Michael Kolbb43f2f62011-08-17 10:39:31 -0700326 if (mNavScreen != null) {
327 // 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 Kolb2814a362011-05-19 15:49:41 -0700333 void hideNavScreen(boolean animate) {
Michael Kolb09bf24f2011-06-09 14:34:30 -0700334 if (mNavScreen == null) return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700335 final Tab tab = mNavScreen.getSelectedTab();
Michael Kolbbf32cd02011-08-16 15:07:04 -0700336 if ((tab == null) || !animate) {
337 mContentView.setVisibility(View.VISIBLE);
338 finishAnimateOut();
Michael Kolb8a009492011-08-15 15:37:30 -0700339 return;
Michael Kolbc3af0672011-08-09 10:24:41 -0700340 }
341 NavTabView tabview = (NavTabView) mNavScreen.getSelectedTabView();
342 if (tabview == null) {
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 }
347 mUiController.setBlockEvents(true);
348 mUiController.setActiveTab(tab);
349 mContentView.setVisibility(View.VISIBLE);
350 final AnimScreen screen = new AnimScreen(mActivity, tab.getScreenshot());
351 View target = ((NavTabView) mNavScreen.mScroller.getSelectedView()).mImage;
352 int toLeft = 0;
353 int toTop = getTitleBar().getHeight();
354 int toRight = mContentView.getWidth();
355 int width = target.getWidth();
356 int height = target.getHeight();
357 int[] pos = new int[2];
358 tabview.mImage.getLocationInWindow(pos);
359 int fromLeft = pos[0];
360 int fromTop = pos[1];
361 int fromRight = fromLeft + width;
362 int fromBottom = fromTop + height;
363 float scaleFactor = mContentView.getWidth() / (float) width;
364 int toBottom = (int) (height * scaleFactor);
365 screen.mMain.setAlpha(0f);
366 mCustomViewContainer.addView(screen.mMain, COVER_SCREEN_PARAMS);
367 AnimatorSet animSet = new AnimatorSet();
368 ObjectAnimator l = ObjectAnimator.ofInt(screen.mContent, "left",
369 fromLeft, toLeft);
370 ObjectAnimator t = ObjectAnimator.ofInt(screen.mContent, "top",
371 fromTop, toTop);
372 ObjectAnimator r = ObjectAnimator.ofInt(screen.mContent, "right",
373 fromRight, toRight);
374 ObjectAnimator b = ObjectAnimator.ofInt(screen.mContent, "bottom",
375 fromBottom, toBottom);
376 ObjectAnimator scale = ObjectAnimator.ofFloat(screen, "scaleFactor",
377 1f, scaleFactor);
378 ObjectAnimator alpha = ObjectAnimator.ofFloat(screen.mMain, "alpha", 1f, 1f);
379 ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f);
380 alpha.setStartDelay(100);
381 animSet.playTogether(l, t, r, b, scale, alpha, otheralpha);
382 animSet.addListener(new AnimatorListenerAdapter() {
383 @Override
384 public void onAnimationEnd(Animator anim) {
385 mCustomViewContainer.removeView(screen.mMain);
Michael Kolbbf32cd02011-08-16 15:07:04 -0700386 finishAnimateOut();
Michael Kolbc3af0672011-08-09 10:24:41 -0700387 mUiController.setBlockEvents(false);
388 }
389 });
390 animSet.setDuration(250);
391 animSet.start();
392 }
393
Michael Kolbbf32cd02011-08-16 15:07:04 -0700394 private void finishAnimateOut() {
John Reck8ee633f2011-08-09 16:00:35 -0700395 mTabControl.setOnThumbnailUpdatedListener(null);
Michael Kolbf2055602011-04-09 17:20:03 -0700396 mCustomViewContainer.removeView(mNavScreen);
Michael Kolbc3af0672011-08-09 10:24:41 -0700397 mCustomViewContainer.setAlpha(1f);
Michael Kolbf2055602011-04-09 17:20:03 -0700398 mNavScreen = null;
399 mCustomViewContainer.setVisibility(View.GONE);
Michael Kolbf2055602011-04-09 17:20:03 -0700400 }
401
John Reck6b4bd5f2011-07-12 10:14:38 -0700402 @Override
403 public boolean needsRestoreAllTabs() {
404 return false;
405 }
406
Michael Kolb20be26d2011-07-18 16:38:02 -0700407 public void toggleNavScreen() {
408 if (mNavScreen == null) {
409 showNavScreen();
410 } else {
411 hideNavScreen(false);
412 }
413 }
414
John Reck1cf4b792011-07-26 10:22:22 -0700415 @Override
416 public boolean shouldCaptureThumbnails() {
417 return true;
418 }
419
Michael Kolbc3af0672011-08-09 10:24:41 -0700420 static class AnimScreen {
John Reck3ba45532011-08-11 16:26:53 -0700421
Michael Kolbc3af0672011-08-09 10:24:41 -0700422 private View mMain;
423 private ImageView mTitle;
424 private ImageView mContent;
425 private float mScale;
426
427 public AnimScreen(Context ctx, TitleBar tbar, WebView web) {
428 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
429 null);
430 mContent = (ImageView) mMain.findViewById(R.id.content);
431 mContent.setTop(tbar.getHeight());
432
433 mTitle = (ImageView) mMain.findViewById(R.id.title);
434 Bitmap bm1 = Bitmap.createBitmap(tbar.getWidth(), tbar.getHeight(),
435 Bitmap.Config.RGB_565);
436 Canvas c1 = new Canvas(bm1);
437 tbar.draw(c1);
438 mTitle.setImageBitmap(bm1);
439 int h = web.getHeight() - tbar.getHeight();
440 Bitmap bm2 = Bitmap.createBitmap(web.getWidth(), h,
441 Bitmap.Config.RGB_565);
442 Canvas c2 = new Canvas(bm2);
443 int tx = web.getScrollX();
444 int ty = web.getScrollY();
445 c2.translate(-tx, -ty - tbar.getHeight());
446 web.draw(c2);
447 mContent.setImageBitmap(bm2);
448 mContent.setScaleType(ImageView.ScaleType.MATRIX);
449 mContent.setImageMatrix(new Matrix());
450 mScale = 1.0f;
451 setScaleFactor(getScaleFactor());
452 }
453
454 public AnimScreen(Context ctx, Bitmap image) {
455 mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen,
456 null);
457 mContent = (ImageView) mMain.findViewById(R.id.content);
458 mContent.setImageBitmap(image);
459 mContent.setScaleType(ImageView.ScaleType.MATRIX);
460 mContent.setImageMatrix(new Matrix());
461 mScale = 1.0f;
462 setScaleFactor(getScaleFactor());
463 }
464
465 public void setScaleFactor(float sf) {
466 mScale = sf;
467 Matrix m = new Matrix();
468 m.postScale(sf,sf);
469 mContent.setImageMatrix(m);
470 }
471
472 public float getScaleFactor() {
473 return mScale;
474 }
475
John Reck3ba45532011-08-11 16:26:53 -0700476 }
477
Michael Kolb66706532010-12-12 19:50:22 -0800478}