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