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