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