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