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