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; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 26 | import android.graphics.Matrix; |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 27 | import android.os.Bundle; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 28 | import android.util.Log; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 29 | import android.view.ActionMode; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 30 | import android.view.KeyEvent; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 32 | import android.view.Menu; |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 33 | import android.view.MenuItem; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 34 | import android.view.View; |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 35 | import android.view.ViewStub; |
Michael Kolb | 30adae6 | 2011-07-29 13:37:05 -0700 | [diff] [blame] | 36 | import android.view.accessibility.AccessibilityEvent; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 37 | import android.view.animation.DecelerateInterpolator; |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 38 | |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 39 | import org.codeaurora.swe.WebView; |
| 40 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 41 | import android.widget.ImageView; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 42 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 43 | import com.android.browser.UrlInputView.StateListener; |
Michael Kolb | 629b22c | 2011-07-13 16:26:47 -0700 | [diff] [blame] | 44 | |
Dany Rybnikov | bcd37da | 2015-04-20 11:43:15 +0300 | [diff] [blame] | 45 | import org.codeaurora.net.NetworkServices; |
Pankaj Garg | 7987849 | 2015-04-01 14:48:21 -0700 | [diff] [blame] | 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"; |
| 53 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 54 | private NavScreen mNavScreen; |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 55 | private AnimScreen mAnimScreen; |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 56 | private final NavigationBarPhone mNavigationBar; |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 57 | private boolean mNavScreenRequested = false; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 58 | |
yijunx.zhu | 2230a31 | 2012-07-27 13:37:00 -0400 | [diff] [blame] | 59 | boolean mShowNav = false; |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 60 | private ComboView mComboView; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 61 | |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame] | 62 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 63 | /** |
| 64 | * @param browser |
| 65 | * @param controller |
| 66 | */ |
| 67 | public PhoneUi(Activity browser, UiController controller) { |
| 68 | super(browser, controller); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 69 | mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar(); |
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(); |
Karthikeyan Periasamy | 5b8f575 | 2015-01-13 16:00:27 -0800 | [diff] [blame] | 75 | // Free the allocated memory for GC to clear it from the heap. |
| 76 | mAnimScreen = null; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | @Override |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 80 | public void editUrl(boolean clearInput, boolean forceIME) { |
yijunx.zhu | 2230a31 | 2012-07-27 13:37:00 -0400 | [diff] [blame] | 81 | //Do nothing while at Nav show screen. |
| 82 | if (mShowNav) return; |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 83 | super.editUrl(clearInput, forceIME); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 87 | public void showComboView(ComboViews startingView, Bundle extras) { |
| 88 | |
| 89 | if (mComboView == null) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 90 | if (mNavScreen != null) { |
| 91 | mNavScreen.setVisibility(View.GONE); |
| 92 | } |
| 93 | ViewStub stub = (ViewStub) mActivity.getWindow(). |
| 94 | getDecorView().findViewById(R.id.combo_view_stub); |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 95 | mComboView = (ComboView) stub.inflate(); |
| 96 | mComboView.setVisibility(View.GONE); |
| 97 | mComboView.setupViews(mActivity); |
| 98 | } |
| 99 | |
| 100 | Bundle b = new Bundle(); |
| 101 | b.putString(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name()); |
| 102 | b.putBundle(ComboViewActivity.EXTRA_COMBO_ARGS, extras); |
| 103 | Tab t = getActiveTab(); |
| 104 | if (t != null) { |
| 105 | b.putString(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl()); |
| 106 | } |
| 107 | |
| 108 | mComboView.showViews(mActivity, b); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void hideComboView() { |
| 113 | mComboView.hideViews(); |
| 114 | } |
| 115 | |
| 116 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 117 | public boolean onBackKey() { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 118 | if (showingNavScreen()) { |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 119 | mNavScreen.close(mUiController.getTabControl().getCurrentPosition()); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 120 | return true; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 121 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 122 | if (isComboViewShowing()) { |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 123 | hideComboView(); |
| 124 | return true; |
| 125 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 126 | return super.onBackKey(); |
| 127 | } |
| 128 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 129 | private boolean showingNavScreen() { |
| 130 | return mNavScreen != null && mNavScreen.getVisibility() == View.VISIBLE; |
| 131 | } |
| 132 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 133 | @Override |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 134 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 135 | return false; |
| 136 | } |
| 137 | |
| 138 | @Override |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 139 | public void setActiveTab(final Tab tab) { |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 140 | mTitleBar.cancelTitleBarAnimation(true); |
| 141 | mTitleBar.setSkipTitleBarAnimations(true); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 142 | super.setActiveTab(tab); |
yijunx.zhu | 2230a31 | 2012-07-27 13:37:00 -0400 | [diff] [blame] | 143 | |
| 144 | //if at Nav screen show, detach tab like what showNavScreen() do. |
| 145 | if (mShowNav) { |
| 146 | detachTab(mActiveTab); |
| 147 | } |
| 148 | |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 149 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 150 | // TabControl.setCurrentTab has been called before this, |
| 151 | // so the tab is guaranteed to have a webview |
| 152 | if (view == null) { |
| 153 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 154 | return; |
| 155 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 156 | // Request focus on the top window. |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 157 | view.setTitleBar(mTitleBar); |
| 158 | |
Michael Kolb | 629b22c | 2011-07-13 16:26:47 -0700 | [diff] [blame] | 159 | // update nav bar state |
| 160 | mNavigationBar.onStateChanged(StateListener.STATE_NORMAL); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 163 | // menu handling callbacks |
| 164 | |
| 165 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 166 | public boolean onPrepareOptionsMenu(Menu menu) { |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 167 | updateMenuState(mActiveTab, menu); |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 168 | return true; |
| 169 | } |
| 170 | |
| 171 | @Override |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 172 | public void updateMenuState(Tab tab, Menu menu) { |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 173 | MenuItem bm = menu.findItem(R.id.bookmarks_menu_id); |
| 174 | if (bm != null) { |
| 175 | bm.setVisible(!showingNavScreen()); |
| 176 | } |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 177 | MenuItem info = menu.findItem(R.id.page_info_menu_id); |
| 178 | if (info != null) { |
| 179 | info.setVisible(false); |
| 180 | } |
Pankaj Garg | 49b7925 | 2014-11-07 17:33:41 -0800 | [diff] [blame] | 181 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 182 | if (showingNavScreen()) { |
Pankaj Garg | 49b7925 | 2014-11-07 17:33:41 -0800 | [diff] [blame] | 183 | setMenuItemVisibility(menu, R.id.history_menu_id, false); |
| 184 | setMenuItemVisibility(menu, R.id.find_menu_id, false); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 185 | menu.setGroupVisible(R.id.LIVE_MENU, false); |
Pankaj Garg | 49b7925 | 2014-11-07 17:33:41 -0800 | [diff] [blame] | 186 | setMenuItemVisibility(menu, R.id.save_snapshot_menu_id, false); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 187 | menu.setGroupVisible(R.id.SNAPSHOT_MENU, false); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 188 | menu.setGroupVisible(R.id.NAV_MENU, false); |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 189 | } |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 190 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 191 | if (isComboViewShowing()) { |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 192 | menu.setGroupVisible(R.id.MAIN_MENU, false); |
| 193 | menu.setGroupEnabled(R.id.MAIN_MENU, false); |
| 194 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false); |
| 195 | } |
| 196 | |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 200 | public boolean onOptionsItemSelected(MenuItem item) { |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 201 | if (showingNavScreen() |
| 202 | && (item.getItemId() != R.id.history_menu_id) |
| 203 | && (item.getItemId() != R.id.snapshots_menu_id)) { |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 204 | hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false); |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 210 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 211 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
| 216 | if (inLoad) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 217 | showTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
| 221 | // action mode callbacks |
| 222 | |
| 223 | @Override |
| 224 | public void onActionModeStarted(ActionMode mode) { |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 225 | super.onActionModeStarted(mode); |
Michael Kolb | 42c0c06 | 2011-08-02 12:56:06 -0700 | [diff] [blame] | 226 | if (!isEditingUrl()) { |
| 227 | hideTitleBar(); |
| 228 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 231 | @Override |
John Reck | 6cda7b1 | 2011-03-18 15:57:13 -0700 | [diff] [blame] | 232 | public void onActionModeFinished(boolean inLoad) { |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 233 | super.onActionModeFinished(inLoad); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 234 | if (inLoad) { |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 235 | showTitleBar(); |
| 236 | } |
John Reck | 6cda7b1 | 2011-03-18 15:57:13 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 240 | public boolean isWebShowing() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 241 | return super.isWebShowing() && !showingNavScreen() && !isComboViewShowing(); |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public boolean isComboViewShowing() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 246 | return mComboView != null && mComboView.getVisibility() == View.VISIBLE; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public void showWeb(boolean animate) { |
| 251 | super.showWeb(animate); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 252 | hideNavScreen(mUiController.getTabControl().getCurrentPosition(), animate); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 255 | //Unblock touch events |
| 256 | private void unblockEvents() { |
| 257 | mUiController.setBlockEvents(false); |
| 258 | } |
| 259 | //Block touch events |
| 260 | private void blockEvents() { |
| 261 | mUiController.setBlockEvents(true); |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public void cancelNavScreenRequest() { |
| 266 | mNavScreenRequested = false; |
| 267 | } |
| 268 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 269 | void showNavScreen() { |
Pankaj Garg | 7987849 | 2015-04-01 14:48:21 -0700 | [diff] [blame] | 270 | blockEvents(); |
| 271 | mNavScreenRequested = true; |
| 272 | mTabControl.setOnThumbnailUpdatedListener( |
| 273 | new TabControl.OnThumbnailUpdatedListener() { |
| 274 | @Override |
| 275 | public void onThumbnailUpdated(Tab t) { |
| 276 | mTabControl.setOnThumbnailUpdatedListener(null); |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 277 | |
Pankaj Garg | 7987849 | 2015-04-01 14:48:21 -0700 | [diff] [blame] | 278 | // Discard the callback if the req is interrupted |
| 279 | if (!mNavScreenRequested) { |
| 280 | unblockEvents(); |
| 281 | return; |
Sudheer Koganti | 06cd42f | 2015-01-30 15:35:12 -0800 | [diff] [blame] | 282 | } |
Pankaj Garg | 7987849 | 2015-04-01 14:48:21 -0700 | [diff] [blame] | 283 | |
| 284 | Bitmap bm = t.getScreenshot(); |
| 285 | Bitmap sbm; |
| 286 | WebView webView = getWebView(); |
| 287 | if (webView != null) { |
| 288 | int view_width = webView.getWidth(); |
| 289 | int capture_width = mActivity.getResources().getDimensionPixelSize( |
| 290 | R.dimen.tab_thumbnail_width); |
| 291 | |
| 292 | float scale = (float) view_width / capture_width; |
| 293 | |
| 294 | //Upscale the low-res bitmap to the needed size |
| 295 | Matrix m = new Matrix(); |
| 296 | m.postScale(scale, scale); |
| 297 | sbm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), |
| 298 | bm.getHeight(), m, false); |
| 299 | } else { |
| 300 | sbm = bm; |
| 301 | } |
| 302 | |
| 303 | onShowNavScreenContinue(sbm); |
Sudheer Koganti | 06cd42f | 2015-01-30 15:35:12 -0800 | [diff] [blame] | 304 | } |
Pankaj Garg | 7987849 | 2015-04-01 14:48:21 -0700 | [diff] [blame] | 305 | }); |
Dany Rybnikov | bcd37da | 2015-04-20 11:43:15 +0300 | [diff] [blame] | 306 | if (!BrowserSettings.getInstance().isPowerSaveModeEnabled()) { |
| 307 | //Notify about anticipated network activity |
| 308 | NetworkServices.hintUpcomingUserActivity(); |
| 309 | } |
Pankaj Garg | 7987849 | 2015-04-01 14:48:21 -0700 | [diff] [blame] | 310 | mActiveTab.capture(); |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 313 | void onShowNavScreenContinue(Bitmap viewportBitmap) { |
| 314 | dismissIME(); |
| 315 | mShowNav = true; |
| 316 | mNavScreenRequested = false; |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 317 | if (mNavScreen == null) { |
| 318 | mNavScreen = new NavScreen(mActivity, mUiController, this); |
| 319 | mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS); |
| 320 | } else { |
| 321 | mNavScreen.setVisibility(View.VISIBLE); |
| 322 | mNavScreen.setAlpha(1f); |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 323 | mNavScreen.refreshAdapter(); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 324 | } |
Sagar Dhawan | 01493f6 | 2015-02-09 11:03:19 -0800 | [diff] [blame] | 325 | if (mAnimScreen == null) { |
| 326 | mAnimScreen = new AnimScreen(mActivity); |
| 327 | } else { |
| 328 | mAnimScreen.mMain.setAlpha(1f); |
| 329 | mAnimScreen.setScaleFactor(1f); |
| 330 | } |
| 331 | mAnimScreen.set(getTitleBar(), viewportBitmap); |
| 332 | if (mAnimScreen.mMain.getParent() == null) { |
| 333 | mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS); |
| 334 | } |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 335 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 336 | mCustomViewContainer.bringToFront(); |
Sagar Dhawan | 01493f6 | 2015-02-09 11:03:19 -0800 | [diff] [blame] | 337 | mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(), |
| 338 | mContentView.getHeight()); |
| 339 | int fromLeft = 0; |
| 340 | int fromTop = getTitleBar().getHeight(); |
| 341 | int fromRight = mContentView.getWidth(); |
| 342 | int fromBottom = mContentView.getHeight(); |
| 343 | int width = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_width); |
| 344 | int height = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_height); |
| 345 | int ntth = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_titleheight); |
| 346 | int toLeft = (mContentView.getWidth() - width) / 2; |
| 347 | int toTop = ((fromBottom - (ntth + height)) / 2 + ntth); |
| 348 | int toRight = toLeft + width; |
| 349 | int toBottom = toTop + height; |
| 350 | float toScaleFactor = width / (float) mContentView.getWidth(); |
| 351 | ObjectAnimator tx = ObjectAnimator.ofInt(mAnimScreen.mContent, "left", fromLeft, toLeft); |
| 352 | ObjectAnimator ty = ObjectAnimator.ofInt(mAnimScreen.mContent, "top", fromTop, toTop); |
| 353 | ObjectAnimator tr = ObjectAnimator.ofInt(mAnimScreen.mContent, "right", fromRight, toRight); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 354 | ObjectAnimator tb = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom", |
| 355 | fromBottom, toBottom); |
Sagar Dhawan | 01493f6 | 2015-02-09 11:03:19 -0800 | [diff] [blame] | 356 | ObjectAnimator sx = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor", 1f, toScaleFactor); |
| 357 | ObjectAnimator navTabsIn = mNavScreen.createToolbarInAnimator(); |
| 358 | mAnimScreen.mContent.layout(fromLeft, fromTop, fromRight, fromBottom); |
| 359 | mAnimScreen.setScaleFactor(1f); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 360 | |
Sagar Dhawan | 01493f6 | 2015-02-09 11:03:19 -0800 | [diff] [blame] | 361 | AnimatorSet inanim = new AnimatorSet(); |
| 362 | inanim.playTogether(tx, ty, tr, tb, sx, navTabsIn); |
| 363 | inanim.setInterpolator(new DecelerateInterpolator()); |
| 364 | inanim.setDuration(200); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 365 | |
Sagar Dhawan | 01493f6 | 2015-02-09 11:03:19 -0800 | [diff] [blame] | 366 | ObjectAnimator disappear = ObjectAnimator.ofFloat(mAnimScreen.mMain, "alpha", 1f, 0f); |
| 367 | disappear.setInterpolator(new DecelerateInterpolator()); |
| 368 | disappear.setDuration(100); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 369 | |
Sagar Dhawan | 01493f6 | 2015-02-09 11:03:19 -0800 | [diff] [blame] | 370 | AnimatorSet set1 = new AnimatorSet(); |
| 371 | set1.addListener(new AnimatorListenerAdapter() { |
| 372 | @Override |
| 373 | public void onAnimationStart(Animator animation) { |
| 374 | mContentView.setVisibility(View.GONE); |
| 375 | } |
| 376 | @Override |
| 377 | public void onAnimationEnd(Animator anim) { |
| 378 | mCustomViewContainer.removeView(mAnimScreen.mMain); |
| 379 | finishAnimationIn(); |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 380 | unblockEvents(); |
Sagar Dhawan | 01493f6 | 2015-02-09 11:03:19 -0800 | [diff] [blame] | 381 | } |
| 382 | }); |
| 383 | set1.playSequentially(inanim, disappear); |
| 384 | set1.start(); |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 385 | unblockEvents(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | private void finishAnimationIn() { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 389 | if (showingNavScreen()) { |
Michael Kolb | b43f2f6 | 2011-08-17 10:39:31 -0700 | [diff] [blame] | 390 | // notify accessibility manager about the screen change |
| 391 | mNavScreen.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Kolb | b43f2f6 | 2011-08-17 10:39:31 -0700 | [diff] [blame] | 392 | } |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 395 | void hideNavScreen(int position, boolean animate) { |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 396 | |
yijunx.zhu | 2230a31 | 2012-07-27 13:37:00 -0400 | [diff] [blame] | 397 | mShowNav = false; |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 398 | if (!showingNavScreen()) return; |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 399 | final Tab tab = mUiController.getTabControl().getTab(position); |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 400 | if ((tab == null) || !animate) { |
Michael Kolb | 365561d | 2011-08-18 09:56:25 -0700 | [diff] [blame] | 401 | if (tab != null) { |
| 402 | setActiveTab(tab); |
| 403 | } else if (mTabControl.getTabCount() > 0) { |
| 404 | // use a fallback tab |
| 405 | setActiveTab(mTabControl.getCurrentTab()); |
| 406 | } |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 407 | mContentView.setVisibility(View.VISIBLE); |
| 408 | finishAnimateOut(); |
Michael Kolb | 8a00949 | 2011-08-15 15:37:30 -0700 | [diff] [blame] | 409 | return; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 410 | } |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 411 | NavTabView tabview = (NavTabView) mNavScreen.getTabView(position); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 412 | if (tabview == null) { |
Michael Kolb | 365561d | 2011-08-18 09:56:25 -0700 | [diff] [blame] | 413 | if (mTabControl.getTabCount() > 0) { |
| 414 | // use a fallback tab |
| 415 | setActiveTab(mTabControl.getCurrentTab()); |
| 416 | } |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 417 | mContentView.setVisibility(View.VISIBLE); |
| 418 | finishAnimateOut(); |
Michael Kolb | 8a00949 | 2011-08-15 15:37:30 -0700 | [diff] [blame] | 419 | return; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 420 | } |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 421 | blockEvents(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 422 | mUiController.setActiveTab(tab); |
| 423 | mContentView.setVisibility(View.VISIBLE); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 424 | if (mAnimScreen == null) { |
| 425 | mAnimScreen = new AnimScreen(mActivity); |
| 426 | } |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 427 | ImageView target = tabview.mImage; |
| 428 | int width = target.getDrawable().getIntrinsicWidth(); |
| 429 | int height = target.getDrawable().getIntrinsicHeight(); |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame] | 430 | Bitmap bm = tab.getScreenshot(); |
Vivek Sekhar | c549e3a | 2014-06-05 16:19:26 -0700 | [diff] [blame] | 431 | if (bm == null) |
| 432 | bm = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); |
| 433 | mAnimScreen.set(bm); |
Michael Kolb | 0755fcd | 2012-01-10 10:19:50 -0800 | [diff] [blame] | 434 | if (mAnimScreen.mMain.getParent() == null) { |
| 435 | mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS); |
| 436 | } |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 437 | mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(), |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 438 | mContentView.getHeight()); |
Enrico Ros | 80c045a | 2014-11-24 15:23:12 -0800 | [diff] [blame] | 439 | mNavScreen.getScroller().finishScroller(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 440 | int toLeft = 0; |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 441 | int toTop = mTitleBar.calculateEmbeddedHeight(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 442 | int toRight = mContentView.getWidth(); |
Enrico Ros | 80c045a | 2014-11-24 15:23:12 -0800 | [diff] [blame] | 443 | int fromLeft = tabview.getLeft() + target.getLeft() - mNavScreen.getScroller().getScrollX(); |
| 444 | int fromTop = tabview.getTop() + target.getTop() - mNavScreen.getScroller().getScrollY(); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 445 | int fromRight = fromLeft + width; |
| 446 | int fromBottom = fromTop + height; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 447 | float scaleFactor = mContentView.getWidth() / (float) width; |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 448 | int toBottom = toTop + (int) (height * scaleFactor); |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 449 | mAnimScreen.mContent.setLeft(fromLeft); |
| 450 | mAnimScreen.mContent.setTop(fromTop); |
| 451 | mAnimScreen.mContent.setRight(fromRight); |
| 452 | mAnimScreen.mContent.setBottom(fromBottom); |
| 453 | mAnimScreen.setScaleFactor(1f); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 454 | //ObjectAnimator fade2 = ObjectAnimator.ofFloat(mNavScreen, "alpha", 1f, 0f); |
| 455 | //fade2.setDuration(100); |
| 456 | AnimatorSet set = new AnimatorSet(); |
| 457 | ObjectAnimator animAppear = ObjectAnimator.ofFloat(mAnimScreen.mMain, "alpha", 0f, 1f); |
| 458 | animAppear.setDuration(100); |
| 459 | ObjectAnimator l = ObjectAnimator.ofInt(mAnimScreen.mContent, "left", fromLeft, toLeft); |
| 460 | ObjectAnimator t = ObjectAnimator.ofInt(mAnimScreen.mContent, "top", fromTop, toTop); |
| 461 | ObjectAnimator r = ObjectAnimator.ofInt(mAnimScreen.mContent, "right", fromRight, toRight); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 462 | ObjectAnimator b = ObjectAnimator.ofInt(mAnimScreen.mContent, "bottom", |
| 463 | fromBottom, toBottom); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 464 | ObjectAnimator scale = ObjectAnimator.ofFloat(mAnimScreen, "scaleFactor", 1f, scaleFactor); |
| 465 | set.playTogether(animAppear, l, t, r, b, scale); |
| 466 | set.setInterpolator(new DecelerateInterpolator()); |
| 467 | set.setDuration(200); |
| 468 | set.addListener(new AnimatorListenerAdapter() { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 469 | @Override |
| 470 | public void onAnimationEnd(Animator anim) { |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 471 | checkTabReady(); |
| 472 | } |
| 473 | }); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 474 | set.start(); |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 475 | } |
| 476 | |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 477 | |
| 478 | private int mNumTries = 0; |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 479 | private void checkTabReady() { |
| 480 | boolean isready = true; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 481 | boolean zeroTries = mNumTries == 0; |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 482 | Tab tab = mUiController.getTabControl().getCurrentTab(); |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 483 | BrowserWebView webview = null; |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 484 | if (tab == null) |
| 485 | isready = false; |
| 486 | else { |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 487 | webview = (BrowserWebView)tab.getWebView(); |
| 488 | if (webview == null) { |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 489 | isready = false; |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 490 | } else { |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 491 | isready = webview.isReady(); |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 492 | } |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 493 | } |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 494 | // Post only when not ready and not crashed |
| 495 | if (!isready && mNumTries++ < 150) { |
| 496 | mCustomViewContainer.postDelayed(new Runnable() { |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 497 | public void run() { |
| 498 | checkTabReady(); |
| 499 | } |
| 500 | }, 17); //WebView is not ready. check again in for next frame. |
| 501 | return; |
| 502 | } |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 503 | mNumTries = 0; |
Vivek Sekhar | c70ae63 | 2015-04-08 17:54:05 -0700 | [diff] [blame] | 504 | final boolean hasCrashed = (webview == null) ? false :false; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 505 | // fast path: don't wait if we've been ready for a while |
| 506 | if (zeroTries) { |
Vivek Sekhar | c70ae63 | 2015-04-08 17:54:05 -0700 | [diff] [blame] | 507 | fadeOutCustomViewContainer(); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 508 | return; |
| 509 | } |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 510 | mCustomViewContainer.postDelayed(new Runnable() { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 511 | public void run() { |
Vivek Sekhar | c70ae63 | 2015-04-08 17:54:05 -0700 | [diff] [blame] | 512 | fadeOutCustomViewContainer(); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 513 | } |
| 514 | }, 32); //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] | 515 | } |
| 516 | |
Vivek Sekhar | c70ae63 | 2015-04-08 17:54:05 -0700 | [diff] [blame] | 517 | private void fadeOutCustomViewContainer() { |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 518 | ObjectAnimator otheralpha = ObjectAnimator.ofFloat(mCustomViewContainer, "alpha", 1f, 0f); |
Vivek Sekhar | c70ae63 | 2015-04-08 17:54:05 -0700 | [diff] [blame] | 519 | otheralpha.setDuration(100); |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 520 | otheralpha.addListener(new AnimatorListenerAdapter() { |
| 521 | @Override |
| 522 | public void onAnimationEnd(Animator anim) { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 523 | mCustomViewContainer.removeView(mAnimScreen.mMain); |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 524 | finishAnimateOut(); |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 525 | unblockEvents(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 526 | } |
| 527 | }); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 528 | otheralpha.setInterpolator(new DecelerateInterpolator()); |
Matthew Hui | 1eb7a83 | 2014-04-15 12:20:58 -0400 | [diff] [blame] | 529 | otheralpha.start(); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Michael Kolb | bf32cd0 | 2011-08-16 15:07:04 -0700 | [diff] [blame] | 532 | private void finishAnimateOut() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 533 | if (mNavScreen != null) { |
| 534 | mNavScreen.setVisibility(View.GONE); |
| 535 | } |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 536 | mCustomViewContainer.setAlpha(1f); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 537 | mCustomViewContainer.setVisibility(View.GONE); |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame] | 538 | mAnimScreen.set(null); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 539 | } |
| 540 | |
John Reck | 6b4bd5f | 2011-07-12 10:14:38 -0700 | [diff] [blame] | 541 | @Override |
| 542 | public boolean needsRestoreAllTabs() { |
| 543 | return false; |
| 544 | } |
| 545 | |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 546 | public void toggleNavScreen() { |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 547 | if (!showingNavScreen()) { |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 548 | showNavScreen(); |
| 549 | } else { |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 550 | hideNavScreen(mUiController.getTabControl().getCurrentPosition(), false); |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 554 | static class AnimScreen { |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 555 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 556 | private View mMain; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 557 | private ImageView mContent; |
| 558 | private float mScale; |
| 559 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 560 | public AnimScreen(Context ctx) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 561 | mMain = LayoutInflater.from(ctx).inflate(R.layout.anim_screen, null); |
| 562 | mMain.setOnClickListener(new View.OnClickListener() { |
| 563 | @Override |
| 564 | public void onClick(View v) { |
| 565 | // just eat clicks when this view is visible |
| 566 | } |
| 567 | }); |
| 568 | mContent = (ImageView) mMain.findViewById(R.id.anim_screen_content); |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 569 | mContent.setScaleType(ImageView.ScaleType.MATRIX); |
| 570 | mContent.setImageMatrix(new Matrix()); |
| 571 | mScale = 1.0f; |
| 572 | setScaleFactor(getScaleFactor()); |
| 573 | } |
| 574 | |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame] | 575 | public void set(TitleBar tbar, Bitmap viewportBitmap) { |
| 576 | if (tbar == null) { |
John Reck | 62077d8 | 2011-10-13 15:17:50 -0700 | [diff] [blame] | 577 | return; |
| 578 | } |
Tarun Nainani | ea28dde | 2014-08-27 17:25:09 -0700 | [diff] [blame] | 579 | mContent.setImageBitmap(viewportBitmap); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 580 | } |
| 581 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 582 | public void set(Bitmap image) { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 583 | mContent.setImageBitmap(image); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 584 | } |
| 585 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 586 | private void setScaleFactor(float sf) { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 587 | mScale = sf; |
| 588 | Matrix m = new Matrix(); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 589 | m.postScale(sf, sf); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 590 | mContent.setImageMatrix(m); |
| 591 | } |
| 592 | |
John Reck | cc0059c | 2011-10-07 13:53:13 -0700 | [diff] [blame] | 593 | private float getScaleFactor() { |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 594 | return mScale; |
| 595 | } |
| 596 | |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 599 | } |