Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.AnimatorSet; |
| 22 | import android.animation.ObjectAnimator; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 23 | import android.app.Activity; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.graphics.Bitmap; |
| 26 | import android.graphics.Canvas; |
| 27 | import android.graphics.Matrix; |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 28 | import android.os.Message; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 29 | import android.util.Log; |
John Reck | aae029c | 2011-09-16 14:36:39 -0700 | [diff] [blame] | 30 | import android.util.TypedValue; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 31 | import android.view.ActionMode; |
| 32 | import android.view.Gravity; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 34 | import android.view.LayoutInflater; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 35 | import android.view.Menu; |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 36 | import android.view.MenuItem; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 37 | import android.view.View; |
Michael Kolb | 199e43c | 2011-08-17 10:45:45 -0700 | [diff] [blame] | 38 | import android.view.ViewGroup; |
Michael Kolb | 30adae6 | 2011-07-29 13:37:05 -0700 | [diff] [blame] | 39 | import android.view.accessibility.AccessibilityEvent; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 40 | import android.webkit.WebView; |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame] | 41 | import android.webkit.WebViewClassic; |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 42 | import android.widget.FrameLayout; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 43 | import android.widget.ImageView; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 44 | |
Michael Kolb | 629b22c | 2011-07-13 16:26:47 -0700 | [diff] [blame] | 45 | import com.android.browser.UrlInputView.StateListener; |
| 46 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 47 | /** |
| 48 | * Ui for regular phone screen sizes |
| 49 | */ |
| 50 | public class PhoneUi extends BaseUi { |
| 51 | |
| 52 | private static final String LOGTAG = "PhoneUi"; |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 53 | private static final int MSG_INIT_NAVSCREEN = 100; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 54 | |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 55 | private PieControlPhone mPieControl; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 56 | private NavScreen mNavScreen; |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 57 | private AnimScreen mAnimScreen; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 58 | private NavigationBarPhone mNavigationBar; |
John Reck | aae029c | 2011-09-16 14:36:39 -0700 | [diff] [blame] | 59 | private int mActionBarHeight; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 60 | |
| 61 | boolean mExtendedMenuOpen; |
| 62 | boolean mOptionsMenuOpen; |
Michael Kolb | 08a687a | 2011-04-22 16:13:02 -0700 | [diff] [blame] | 63 | boolean mAnimating; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * @param browser |
| 67 | * @param controller |
| 68 | */ |
| 69 | public PhoneUi(Activity browser, UiController controller) { |
| 70 | super(browser, controller); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 71 | setUseQuickControls(BrowserSettings.getInstance().useQuickControls()); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 72 | mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar(); |
John Reck | aae029c | 2011-09-16 14:36:39 -0700 | [diff] [blame] | 73 | TypedValue heightValue = new TypedValue(); |
| 74 | browser.getTheme().resolveAttribute( |
| 75 | com.android.internal.R.attr.actionBarSize, heightValue, true); |
| 76 | mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data, |
| 77 | browser.getResources().getDisplayMetrics()); |
John Reck | 285ef04 | 2011-02-11 15:44:17 -0800 | [diff] [blame] | 78 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 79 | |
John Reck | 285ef04 | 2011-02-11 15:44:17 -0800 | [diff] [blame] | 80 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 81 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 82 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 86 | public void editUrl(boolean clearInput) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 87 | if (mUseQuickControls) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 88 | mTitleBar.setShowProgressOnly(false); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 89 | } |
| 90 | super.editUrl(clearInput); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 94 | public boolean onBackKey() { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 95 | if (showingNavScreen()) { |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 96 | mNavScreen.close(mUiController.getTabControl().getCurrentPosition()); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 97 | return true; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 98 | } |
| 99 | return super.onBackKey(); |
| 100 | } |
| 101 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 102 | private boolean showingNavScreen() { |
| 103 | return mNavScreen != null && mNavScreen.getVisibility() == View.VISIBLE; |
| 104 | } |
| 105 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 106 | @Override |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 107 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | |
| 111 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 112 | public void onProgressChanged(Tab tab) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 113 | if (tab.inForeground()) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 114 | int progress = tab.getLoadProgress(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 115 | mTitleBar.setProgress(progress); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 116 | if (progress == 100) { |
| 117 | if (!mOptionsMenuOpen || !mExtendedMenuOpen) { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 118 | suggestHideTitleBar(); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 119 | if (mUseQuickControls) { |
| 120 | mTitleBar.setShowProgressOnly(false); |
| 121 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 122 | } |
| 123 | } else { |
| 124 | if (!mOptionsMenuOpen || mExtendedMenuOpen) { |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 125 | if (mUseQuickControls && !mTitleBar.isEditingUrl()) { |
| 126 | mTitleBar.setShowProgressOnly(true); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 127 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 128 | showTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | } |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 132 | if (mNavScreen == null && getTitleBar().getHeight() > 0) { |
| 133 | mHandler.sendEmptyMessage(MSG_INIT_NAVSCREEN); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | protected void handleMessage(Message msg) { |
| 139 | super.handleMessage(msg); |
| 140 | if (msg.what == MSG_INIT_NAVSCREEN) { |
| 141 | if (mNavScreen == null) { |
| 142 | mNavScreen = new NavScreen(mActivity, mUiController, this); |
| 143 | mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS); |
| 144 | mNavScreen.setVisibility(View.GONE); |
| 145 | } |
| 146 | if (mAnimScreen == null) { |
| 147 | mAnimScreen = new AnimScreen(mActivity); |
| 148 | // initialize bitmaps |
| 149 | mAnimScreen.set(getTitleBar(), getWebView()); |
| 150 | } |
| 151 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 155 | public void setActiveTab(final Tab tab) { |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 156 | mTitleBar.cancelTitleBarAnimation(true); |
| 157 | mTitleBar.setSkipTitleBarAnimations(true); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 158 | super.setActiveTab(tab); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 159 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 160 | // TabControl.setCurrentTab has been called before this, |
| 161 | // so the tab is guaranteed to have a webview |
| 162 | if (view == null) { |
| 163 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 164 | return; |
| 165 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 166 | // Request focus on the top window. |
| 167 | if (mUseQuickControls) { |
| 168 | mPieControl.forceToTop(mContentView); |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 169 | view.setTitleBar(null); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 170 | } else { |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 171 | view.setTitleBar(mTitleBar); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 172 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 173 | if (tab.isInVoiceSearchMode()) { |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 174 | showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 175 | } else { |
| 176 | revertVoiceTitleBar(tab); |
| 177 | } |
Michael Kolb | 629b22c | 2011-07-13 16:26:47 -0700 | [diff] [blame] | 178 | // update nav bar state |
| 179 | mNavigationBar.onStateChanged(StateListener.STATE_NORMAL); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 180 | updateLockIconToLatest(tab); |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 181 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 184 | // menu handling callbacks |
| 185 | |
| 186 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 187 | public boolean onPrepareOptionsMenu(Menu menu) { |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 188 | updateMenuState(mActiveTab, menu); |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 189 | return true; |
| 190 | } |
| 191 | |
| 192 | @Override |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 193 | public void updateMenuState(Tab tab, Menu menu) { |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 194 | MenuItem bm = menu.findItem(R.id.bookmarks_menu_id); |
| 195 | if (bm != null) { |
| 196 | bm.setVisible(!showingNavScreen()); |
| 197 | } |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 198 | MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id); |
| 199 | if (abm != null) { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 200 | abm.setVisible((tab != null) && !tab.isSnapshot() && !showingNavScreen()); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 201 | } |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 202 | MenuItem info = menu.findItem(R.id.page_info_menu_id); |
| 203 | if (info != null) { |
| 204 | info.setVisible(false); |
| 205 | } |
| 206 | MenuItem newtab = menu.findItem(R.id.new_tab_menu_id); |
| 207 | if (newtab != null && !mUseQuickControls) { |
| 208 | newtab.setVisible(false); |
| 209 | } |
| 210 | MenuItem incognito = menu.findItem(R.id.incognito_menu_id); |
| 211 | if (incognito != null) { |
| 212 | incognito.setVisible(showingNavScreen() || mUseQuickControls); |
| 213 | } |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 214 | if (showingNavScreen()) { |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 215 | menu.setGroupVisible(R.id.LIVE_MENU, false); |
| 216 | menu.setGroupVisible(R.id.SNAPSHOT_MENU, false); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 217 | menu.setGroupVisible(R.id.NAV_MENU, false); |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 218 | menu.setGroupVisible(R.id.COMBO_MENU, true); |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 223 | public boolean onOptionsItemSelected(MenuItem item) { |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 224 | if (showingNavScreen() |
| 225 | && (item.getItemId() != R.id.history_menu_id) |
| 226 | && (item.getItemId() != R.id.snapshots_menu_id)) { |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 227 | hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false); |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 228 | } |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 233 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 234 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
| 239 | if (inLoad) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 240 | showTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | // action mode callbacks |
| 245 | |
| 246 | @Override |
| 247 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 42c0c06 | 2011-08-02 12:56:06 -0700 | [diff] [blame] | 248 | if (!isEditingUrl()) { |
| 249 | hideTitleBar(); |
John Reck | aae029c | 2011-09-16 14:36:39 -0700 | [diff] [blame] | 250 | } else { |
| 251 | mTitleBar.animate().translationY(mActionBarHeight); |
Michael Kolb | 42c0c06 | 2011-08-02 12:56:06 -0700 | [diff] [blame] | 252 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 255 | @Override |
John Reck | 6cda7b1 | 2011-03-18 15:57:13 -0700 | [diff] [blame] | 256 | public void onActionModeFinished(boolean inLoad) { |
John Reck | aae029c | 2011-09-16 14:36:39 -0700 | [diff] [blame] | 257 | mTitleBar.animate().translationY(0); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 258 | if (inLoad) { |
| 259 | if (mUseQuickControls) { |
| 260 | mTitleBar.setShowProgressOnly(true); |
John Reck | 6cda7b1 | 2011-03-18 15:57:13 -0700 | [diff] [blame] | 261 | } |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 262 | showTitleBar(); |
| 263 | } |
John Reck | 6cda7b1 | 2011-03-18 15:57:13 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Override |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 267 | public void setUseQuickControls(boolean useQuickControls) { |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 268 | mUseQuickControls = useQuickControls; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 269 | mTitleBar.setUseQuickControls(mUseQuickControls); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 270 | if (useQuickControls) { |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 271 | mPieControl = new PieControlPhone(mActivity, mUiController, this); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 272 | mPieControl.attachToContainer(mContentView); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 273 | } else { |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 274 | if (mPieControl != null) { |
| 275 | mPieControl.removeFromContainer(mContentView); |
| 276 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 277 | } |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 278 | updateUrlBarAutoShowManagerTarget(); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 281 | @Override |
| 282 | public boolean isWebShowing() { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 283 | return super.isWebShowing() && !showingNavScreen(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void showWeb(boolean animate) { |
| 288 | super.showWeb(animate); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 289 | hideNavScreen(mUiController.getTabControl().getCurrentPosition(), animate); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 292 | void showNavScreen() { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 293 | mUiController.setBlockEvents(true); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 294 | if (mNavScreen == null) { |
| 295 | mNavScreen = new NavScreen(mActivity, mUiController, this); |
| 296 | mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS); |
| 297 | } else { |
| 298 | mNavScreen.setVisibility(View.VISIBLE); |
| 299 | mNavScreen.setAlpha(1f); |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 300 | mNavScreen.refreshAdapter(); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 301 | } |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 302 | mActiveTab.capture(); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 303 | if (mAnimScreen == null) { |
| 304 | mAnimScreen = new AnimScreen(mActivity); |
John Reck | ce8bcb0 | 2011-10-11 13:45:29 -0700 | [diff] [blame] | 305 | } else { |
| 306 | mAnimScreen.mMain.setAlpha(1f); |
| 307 | mAnimScreen.mTitle.setAlpha(1f); |
| 308 | mAnimScreen.setScaleFactor(1f); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 309 | } |
| 310 | mAnimScreen.set(getTitleBar(), getWebView()); |
Michael Kolb | a30e4fb | 2011-11-07 17:32:01 -0800 | [diff] [blame] | 311 | if (mAnimScreen.mMain.getParent() == null) { |
| 312 | mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS); |
| 313 | } |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 314 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 315 | mCustomViewContainer.bringToFront(); |
John Reck | ce8bcb0 | 2011-10-11 13:45:29 -0700 | [diff] [blame] | 316 | mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(), |
| 317 | mContentView.getHeight()); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 318 | int fromLeft = 0; |
| 319 | int fromTop = getTitleBar().getHeight(); |
| 320 | int fromRight = mContentView.getWidth(); |
| 321 | int fromBottom = mContentView.getHeight(); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 322 | int width = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_width); |
| 323 | int height = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_height); |
Michael Kolb | 7a321d6 | 2011-09-23 15:54:22 -0700 | [diff] [blame] | 324 | int ntth = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_titleheight); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 325 | int toLeft = (mContentView.getWidth() - width) / 2; |
Michael Kolb | 7a321d6 | 2011-09-23 15:54:22 -0700 | [diff] [blame] | 326 | int toTop = ((fromBottom - (ntth + height)) / 2 + ntth); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 327 | int toRight = toLeft + width; |
| 328 | int toBottom = toTop + height; |
| 329 | float scaleFactor = width / (float) mContentView.getWidth(); |
| 330 | detachTab(mActiveTab); |
| 331 | mContentView.setVisibility(View.GONE); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 332 | AnimatorSet set1 = new AnimatorSet(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 333 | AnimatorSet inanim = new AnimatorSet(); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 334 | ObjectAnimator tx = ObjectAnimator.ofInt(mAnimScreen.mContent, "left", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 335 | fromLeft, toLeft); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 336 | ObjectAnimator ty = ObjectAnimator.ofInt(mAnimScreen.mContent, "top", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 337 | fromTop, toTop); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 338 | ObjectAnimator tr = ObjectAnimator.ofInt(mAnimScreen.mContent, "right", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 339 | fromRight, toRight); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 340 | ObjectAnimator tb = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 341 | fromBottom, toBottom); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 342 | ObjectAnimator title = ObjectAnimator.ofFloat(mAnimScreen.mTitle, "alpha", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 343 | 1f, 0f); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 344 | ObjectAnimator sx = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 345 | 1f, scaleFactor); |
John Reck | 1adf030 | 2011-10-11 10:58:12 -0700 | [diff] [blame] | 346 | ObjectAnimator blend1 = ObjectAnimator.ofFloat(mAnimScreen.mMain, |
| 347 | "alpha", 1f, 0f); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 348 | blend1.setDuration(100); |
| 349 | |
| 350 | inanim.playTogether(tx, ty, tr, tb, sx, title); |
| 351 | inanim.setDuration(200); |
| 352 | set1.addListener(new AnimatorListenerAdapter() { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 353 | @Override |
| 354 | public void onAnimationEnd(Animator anim) { |
John Reck | 1adf030 | 2011-10-11 10:58:12 -0700 | [diff] [blame] | 355 | mCustomViewContainer.removeView(mAnimScreen.mMain); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 356 | finishAnimationIn(); |
| 357 | mUiController.setBlockEvents(false); |
| 358 | } |
| 359 | }); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 360 | set1.playSequentially(inanim, blend1); |
| 361 | set1.start(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | private void finishAnimationIn() { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 365 | if (showingNavScreen()) { |
Michael Kolb | b43f2f6 | 2011-08-17 10:39:31 -0700 | [diff] [blame] | 366 | // notify accessibility manager about the screen change |
| 367 | mNavScreen.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 368 | mTabControl.setOnThumbnailUpdatedListener(mNavScreen); |
| 369 | } |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 372 | void hideNavScreen(int position, boolean animate) { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 373 | if (!showingNavScreen()) return; |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 374 | final Tab tab = mUiController.getTabControl().getTab(position); |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 375 | if ((tab == null) || !animate) { |
Michael Kolb | 365561d | 2011-08-18 09:56:25 -0700 | [diff] [blame] | 376 | if (tab != null) { |
| 377 | setActiveTab(tab); |
| 378 | } else if (mTabControl.getTabCount() > 0) { |
| 379 | // use a fallback tab |
| 380 | setActiveTab(mTabControl.getCurrentTab()); |
| 381 | } |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 382 | mContentView.setVisibility(View.VISIBLE); |
| 383 | finishAnimateOut(); |
Michael Kolb | 8a00949 | 2011-08-15 15:37:30 -0700 | [diff] [blame] | 384 | return; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 385 | } |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 386 | NavTabView tabview = (NavTabView) mNavScreen.getTabView(position); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 387 | if (tabview == null) { |
Michael Kolb | 365561d | 2011-08-18 09:56:25 -0700 | [diff] [blame] | 388 | if (mTabControl.getTabCount() > 0) { |
| 389 | // use a fallback tab |
| 390 | setActiveTab(mTabControl.getCurrentTab()); |
| 391 | } |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 392 | mContentView.setVisibility(View.VISIBLE); |
| 393 | finishAnimateOut(); |
Michael Kolb | 8a00949 | 2011-08-15 15:37:30 -0700 | [diff] [blame] | 394 | return; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 395 | } |
| 396 | mUiController.setBlockEvents(true); |
| 397 | mUiController.setActiveTab(tab); |
| 398 | mContentView.setVisibility(View.VISIBLE); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 399 | if (mAnimScreen == null) { |
| 400 | mAnimScreen = new AnimScreen(mActivity); |
| 401 | } |
| 402 | mAnimScreen.set(tab.getScreenshot()); |
Michael Kolb | 0755fcd | 2012-01-10 10:19:50 -0800 | [diff] [blame] | 403 | if (mAnimScreen.mMain.getParent() == null) { |
| 404 | mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS); |
| 405 | } |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 406 | mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(), |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 407 | mContentView.getHeight()); |
| 408 | mNavScreen.mScroller.finishScroller(); |
| 409 | ImageView target = tabview.mImage; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 410 | int toLeft = 0; |
Michael Kolb | b7e1670 | 2011-12-15 11:59:40 -0800 | [diff] [blame] | 411 | int toTop = (tab.getWebView() != null) ? tab.getWebView().getVisibleTitleHeight() : 0; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 412 | int toRight = mContentView.getWidth(); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 413 | int width = target.getDrawable().getIntrinsicWidth(); |
| 414 | int height = target.getDrawable().getIntrinsicHeight(); |
| 415 | int fromLeft = tabview.getLeft() + target.getLeft() - mNavScreen.mScroller.getScrollX(); |
| 416 | int fromTop = tabview.getTop() + target.getTop() - mNavScreen.mScroller.getScrollY(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 417 | int fromRight = fromLeft + width; |
| 418 | int fromBottom = fromTop + height; |
| 419 | float scaleFactor = mContentView.getWidth() / (float) width; |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 420 | int toBottom = toTop + (int) (height * scaleFactor); |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 421 | mAnimScreen.mContent.setLeft(fromLeft); |
| 422 | mAnimScreen.mContent.setTop(fromTop); |
| 423 | mAnimScreen.mContent.setRight(fromRight); |
| 424 | mAnimScreen.mContent.setBottom(fromBottom); |
| 425 | mAnimScreen.setScaleFactor(1f); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 426 | AnimatorSet set1 = new AnimatorSet(); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 427 | ObjectAnimator fade2 = ObjectAnimator.ofFloat(mAnimScreen.mMain, "alpha", 0f, 1f); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 428 | ObjectAnimator fade1 = ObjectAnimator.ofFloat(mNavScreen, "alpha", 1f, 0f); |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 429 | set1.playTogether(fade1, fade2); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 430 | set1.setDuration(100); |
| 431 | AnimatorSet set2 = new AnimatorSet(); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 432 | ObjectAnimator l = ObjectAnimator.ofInt(mAnimScreen.mContent, "left", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 433 | fromLeft, toLeft); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 434 | ObjectAnimator t = ObjectAnimator.ofInt(mAnimScreen.mContent, "top", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 435 | fromTop, toTop); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 436 | ObjectAnimator r = ObjectAnimator.ofInt(mAnimScreen.mContent, "right", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 437 | fromRight, toRight); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 438 | ObjectAnimator b = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 439 | fromBottom, toBottom); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 440 | ObjectAnimator scale = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor", |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 441 | 1f, scaleFactor); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 442 | ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 443 | otheralpha.setDuration(100); |
| 444 | set2.playTogether(l, t, r, b, scale); |
| 445 | set2.setDuration(200); |
| 446 | AnimatorSet combo = new AnimatorSet(); |
| 447 | combo.playSequentially(set1, set2, otheralpha); |
| 448 | combo.addListener(new AnimatorListenerAdapter() { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 449 | @Override |
| 450 | public void onAnimationEnd(Animator anim) { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 451 | mCustomViewContainer.removeView(mAnimScreen.mMain); |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 452 | finishAnimateOut(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 453 | mUiController.setBlockEvents(false); |
| 454 | } |
| 455 | }); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 456 | combo.start(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 459 | private void finishAnimateOut() { |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 460 | mTabControl.setOnThumbnailUpdatedListener(null); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 461 | mNavScreen.setVisibility(View.GONE); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 462 | mCustomViewContainer.setAlpha(1f); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 463 | mCustomViewContainer.setVisibility(View.GONE); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 464 | } |
| 465 | |
John Reck | 6b4bd5f | 2011-07-12 10:14:38 -0700 | [diff] [blame] | 466 | @Override |
| 467 | public boolean needsRestoreAllTabs() { |
| 468 | return false; |
| 469 | } |
| 470 | |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 471 | public void toggleNavScreen() { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 472 | if (!showingNavScreen()) { |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 473 | showNavScreen(); |
| 474 | } else { |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 475 | hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false); |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 479 | @Override |
| 480 | public boolean shouldCaptureThumbnails() { |
| 481 | return true; |
| 482 | } |
| 483 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 484 | static class AnimScreen { |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 485 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 486 | private View mMain; |
| 487 | private ImageView mTitle; |
| 488 | private ImageView mContent; |
| 489 | private float mScale; |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 490 | private Bitmap mTitleBarBitmap; |
| 491 | private Bitmap mContentBitmap; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 492 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 493 | public AnimScreen(Context ctx) { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 494 | mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen, |
| 495 | null); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 496 | mTitle = (ImageView) mMain.findViewById(R.id.title); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 497 | mContent = (ImageView) mMain.findViewById(R.id.content); |
| 498 | mContent.setScaleType(ImageView.ScaleType.MATRIX); |
| 499 | mContent.setImageMatrix(new Matrix()); |
| 500 | mScale = 1.0f; |
| 501 | setScaleFactor(getScaleFactor()); |
| 502 | } |
| 503 | |
| 504 | public void set(TitleBar tbar, WebView web) { |
John Reck | 62077d8 | 2011-10-13 15:17:50 -0700 | [diff] [blame] | 505 | if (tbar == null || web == null) { |
| 506 | return; |
| 507 | } |
John Reck | 1adf030 | 2011-10-11 10:58:12 -0700 | [diff] [blame] | 508 | if (tbar.getWidth() > 0 && tbar.getEmbeddedHeight() > 0) { |
| 509 | if (mTitleBarBitmap == null |
| 510 | || mTitleBarBitmap.getWidth() != tbar.getWidth() |
| 511 | || mTitleBarBitmap.getHeight() != tbar.getEmbeddedHeight()) { |
John Reck | a98c83b | 2011-10-31 12:31:58 -0700 | [diff] [blame] | 512 | mTitleBarBitmap = safeCreateBitmap(tbar.getWidth(), |
| 513 | tbar.getEmbeddedHeight()); |
John Reck | 1adf030 | 2011-10-11 10:58:12 -0700 | [diff] [blame] | 514 | } |
John Reck | a98c83b | 2011-10-31 12:31:58 -0700 | [diff] [blame] | 515 | if (mTitleBarBitmap != null) { |
| 516 | Canvas c = new Canvas(mTitleBarBitmap); |
| 517 | tbar.draw(c); |
| 518 | c.setBitmap(null); |
| 519 | } |
John Reck | 1adf030 | 2011-10-11 10:58:12 -0700 | [diff] [blame] | 520 | } else { |
| 521 | mTitleBarBitmap = null; |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 522 | } |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 523 | mTitle.setImageBitmap(mTitleBarBitmap); |
| 524 | mTitle.setVisibility(View.VISIBLE); |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 525 | int h = web.getHeight() - tbar.getEmbeddedHeight(); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 526 | if (mContentBitmap == null |
| 527 | || mContentBitmap.getWidth() != web.getWidth() |
| 528 | || mContentBitmap.getHeight() != h) { |
John Reck | a98c83b | 2011-10-31 12:31:58 -0700 | [diff] [blame] | 529 | mContentBitmap = safeCreateBitmap(web.getWidth(), h); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 530 | } |
John Reck | a98c83b | 2011-10-31 12:31:58 -0700 | [diff] [blame] | 531 | if (mContentBitmap != null) { |
| 532 | Canvas c = new Canvas(mContentBitmap); |
| 533 | int tx = web.getScrollX(); |
| 534 | int ty = web.getScrollY(); |
| 535 | c.translate(-tx, -ty - tbar.getEmbeddedHeight()); |
| 536 | web.draw(c); |
| 537 | c.setBitmap(null); |
| 538 | } |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 539 | mContent.setImageBitmap(mContentBitmap); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 540 | } |
| 541 | |
John Reck | a98c83b | 2011-10-31 12:31:58 -0700 | [diff] [blame] | 542 | private Bitmap safeCreateBitmap(int width, int height) { |
| 543 | if (width <= 0 || height <= 0) { |
| 544 | Log.w(LOGTAG, "safeCreateBitmap failed! width: " + width |
| 545 | + ", height: " + height); |
| 546 | return null; |
| 547 | } |
| 548 | return Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); |
| 549 | } |
| 550 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 551 | public void set(Bitmap image) { |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 552 | mTitle.setVisibility(View.GONE); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 553 | mContent.setImageBitmap(image); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 554 | } |
| 555 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 556 | private void setScaleFactor(float sf) { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 557 | mScale = sf; |
| 558 | Matrix m = new Matrix(); |
| 559 | m.postScale(sf,sf); |
| 560 | mContent.setImageMatrix(m); |
| 561 | } |
| 562 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 563 | private float getScaleFactor() { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 564 | return mScale; |
| 565 | } |
| 566 | |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 569 | } |