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