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 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.app.Activity; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 20 | import android.util.Log; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 21 | import android.view.ActionMode; |
| 22 | import android.view.Gravity; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 23 | import android.view.KeyEvent; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 24 | import android.view.Menu; |
| 25 | import android.view.View; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 26 | import android.webkit.WebView; |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 27 | import android.widget.FrameLayout; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Ui for regular phone screen sizes |
| 31 | */ |
| 32 | public class PhoneUi extends BaseUi { |
| 33 | |
| 34 | private static final String LOGTAG = "PhoneUi"; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 35 | private static final float NAV_TAB_SCALE = 0.75f; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 36 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 37 | private TitleBarPhone mTitleBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 38 | private ActiveTabsPage mActiveTabsPage; |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 39 | private boolean mUseQuickControls; |
| 40 | private PieControl mPieControl; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 41 | private NavScreen mNavScreen; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 42 | |
| 43 | boolean mExtendedMenuOpen; |
| 44 | boolean mOptionsMenuOpen; |
Michael Kolb | 08a687a | 2011-04-22 16:13:02 -0700 | [diff] [blame] | 45 | boolean mAnimating; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * @param browser |
| 49 | * @param controller |
| 50 | */ |
| 51 | public PhoneUi(Activity browser, UiController controller) { |
| 52 | super(browser, controller); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 53 | mTitleBar = new TitleBarPhone(mActivity, mUiController, this, |
| 54 | mContentView); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 55 | // mTitleBar will be always be shown in the fully loaded mode on |
| 56 | // phone |
| 57 | mTitleBar.setProgress(100); |
John Reck | 285ef04 | 2011-02-11 15:44:17 -0800 | [diff] [blame] | 58 | mActivity.getActionBar().hide(); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 59 | setUseQuickControls(BrowserSettings.getInstance().useQuickControls()); |
John Reck | 285ef04 | 2011-02-11 15:44:17 -0800 | [diff] [blame] | 60 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 61 | |
John Reck | 285ef04 | 2011-02-11 15:44:17 -0800 | [diff] [blame] | 62 | @Override |
| 63 | public void hideComboView() { |
| 64 | super.hideComboView(); |
| 65 | mActivity.getActionBar().hide(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 68 | // lifecycle |
| 69 | |
| 70 | @Override |
| 71 | public void onPause() { |
| 72 | // FIXME: This removes the active tabs page and resets the menu to |
| 73 | // MAIN_MENU. A better solution might be to do this work in onNewIntent |
| 74 | // but then we would need to save it in onSaveInstanceState and restore |
| 75 | // it in onCreate/onRestoreInstanceState |
| 76 | if (mActiveTabsPage != null) { |
| 77 | mUiController.removeActiveTabsPage(true); |
| 78 | } |
| 79 | super.onPause(); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 84 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 88 | public void editUrl(boolean clearInput) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 89 | if (mUseQuickControls) { |
| 90 | getTitleBar().setShowProgressOnly(false); |
| 91 | } |
| 92 | super.editUrl(clearInput); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 96 | public boolean onBackKey() { |
| 97 | if (mActiveTabsPage != null) { |
| 98 | // if tab page is showing, hide it |
| 99 | mUiController.removeActiveTabsPage(true); |
| 100 | return true; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 101 | } else if (mNavScreen != null) { |
| 102 | mNavScreen.close(); |
| 103 | return true; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 104 | } |
| 105 | return super.onBackKey(); |
| 106 | } |
| 107 | |
| 108 | @Override |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 109 | public boolean onMenuKey() { |
| 110 | if (mNavScreen == null) { |
| 111 | showNavScreen(); |
| 112 | } else { |
| 113 | mNavScreen.close(); |
| 114 | } |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | @Override |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 119 | public boolean dispatchKey(int code, KeyEvent event) { |
| 120 | if (!isComboViewShowing()) { |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 121 | } |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 126 | public void onProgressChanged(Tab tab) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 127 | if (tab.inForeground()) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 128 | int progress = tab.getLoadProgress(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 129 | mTitleBar.setProgress(progress); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 130 | if (progress == 100) { |
| 131 | if (!mOptionsMenuOpen || !mExtendedMenuOpen) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 132 | hideTitleBar(); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 133 | if (mUseQuickControls) { |
| 134 | mTitleBar.setShowProgressOnly(false); |
| 135 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 136 | } |
| 137 | } else { |
| 138 | if (!mOptionsMenuOpen || mExtendedMenuOpen) { |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 139 | if (mUseQuickControls && !mTitleBar.isEditingUrl()) { |
| 140 | mTitleBar.setShowProgressOnly(true); |
| 141 | setTitleGravity(Gravity.TOP); |
| 142 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 143 | showTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | @Override |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 150 | public void setActiveTab(final Tab tab) { |
John Reck | 88a42b7 | 2011-03-21 16:30:12 -0700 | [diff] [blame] | 151 | captureTab(mActiveTab); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 152 | super.setActiveTab(tab, true); |
| 153 | setActiveTab(tab, true); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | void setActiveTab(Tab tab, boolean needsAttaching) { |
| 158 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 159 | // TabControl.setCurrentTab has been called before this, |
| 160 | // so the tab is guaranteed to have a webview |
| 161 | if (view == null) { |
| 162 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 163 | return; |
| 164 | } |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 165 | view.setNavMode(false); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 166 | // Request focus on the top window. |
| 167 | if (mUseQuickControls) { |
| 168 | mPieControl.forceToTop(mContentView); |
| 169 | view.setScrollListener(null); |
| 170 | } else { |
| 171 | // check if title bar is already attached by animation |
| 172 | if (mTitleBar.getParent() == null) { |
| 173 | view.setEmbeddedTitleBar(mTitleBar); |
| 174 | } |
| 175 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 176 | if (tab.isInVoiceSearchMode()) { |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 177 | showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 178 | } else { |
| 179 | revertVoiceTitleBar(tab); |
| 180 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 181 | updateLockIconToLatest(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 182 | tab.getTopWindow().requestFocus(); |
| 183 | } |
| 184 | |
| 185 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 186 | protected TitleBarBase getTitleBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 187 | return mTitleBar; |
| 188 | } |
| 189 | |
| 190 | // active tabs page |
| 191 | |
| 192 | @Override |
| 193 | public void showActiveTabsPage() { |
John Reck | 88a42b7 | 2011-03-21 16:30:12 -0700 | [diff] [blame] | 194 | captureTab(mActiveTab); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 195 | mActiveTabsPage = new ActiveTabsPage(mActivity, mUiController); |
| 196 | mTitleBar.setVisibility(View.GONE); |
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 | mContentView.addView(mActiveTabsPage, COVER_SCREEN_PARAMS); |
| 199 | mActiveTabsPage.requestFocus(); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Remove the active tabs page. |
| 204 | */ |
| 205 | @Override |
| 206 | public void removeActiveTabsPage() { |
| 207 | mContentView.removeView(mActiveTabsPage); |
| 208 | mTitleBar.setVisibility(View.VISIBLE); |
| 209 | mActiveTabsPage = null; |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public boolean showsWeb() { |
| 214 | return super.showsWeb() && mActiveTabsPage == null; |
| 215 | } |
| 216 | |
| 217 | // menu handling callbacks |
| 218 | |
| 219 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 220 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 221 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
| 226 | if (inLoad) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 227 | showTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | // action mode callbacks |
| 232 | |
| 233 | @Override |
| 234 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 235 | hideTitleBar(); |
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) { |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 240 | if (inLoad) { |
| 241 | if (mUseQuickControls) { |
| 242 | mTitleBar.setShowProgressOnly(true); |
John Reck | 6cda7b1 | 2011-03-18 15:57:13 -0700 | [diff] [blame] | 243 | } |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 244 | showTitleBar(); |
| 245 | } |
| 246 | mActivity.getActionBar().hide(); |
John Reck | 6cda7b1 | 2011-03-18 15:57:13 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Override |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 250 | protected void setTitleGravity(int gravity) { |
| 251 | if (mUseQuickControls) { |
| 252 | FrameLayout.LayoutParams lp = |
| 253 | (FrameLayout.LayoutParams) getTitleBar().getLayoutParams(); |
| 254 | lp.gravity = gravity; |
| 255 | getTitleBar().setLayoutParams(lp); |
| 256 | } else { |
| 257 | super.setTitleGravity(gravity); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | private void setUseQuickControls(boolean useQuickControls) { |
| 262 | mUseQuickControls = useQuickControls; |
| 263 | getTitleBar().setUseQuickControls(mUseQuickControls); |
| 264 | if (useQuickControls) { |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 265 | mPieControl = new PieControl(mActivity, mUiController, this); |
| 266 | mPieControl.attachToContainer(mContentView); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 267 | WebView web = getWebView(); |
| 268 | if (web != null) { |
| 269 | web.setEmbeddedTitleBar(null); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 270 | } |
| 271 | } else { |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 272 | if (mPieControl != null) { |
| 273 | mPieControl.removeFromContainer(mContentView); |
| 274 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 275 | WebView web = getWebView(); |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 276 | if (web != null) { |
| 277 | web.setEmbeddedTitleBar(mTitleBar); |
| 278 | } |
| 279 | setTitleGravity(Gravity.NO_GRAVITY); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | @Override |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 284 | protected void captureTab(final Tab tab) { |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 285 | if (tab == null) return; |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 286 | if (mUseQuickControls) { |
| 287 | super.captureTab(tab); |
| 288 | } else { |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 289 | BrowserWebView web = (BrowserWebView) tab.getWebView(); |
| 290 | if (web != null) { |
| 291 | tab.setScreenshot(web.capture()); |
| 292 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 295 | void showNavScreen() { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 296 | detachTab(mActiveTab); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 297 | mNavScreen = new NavScreen(mActivity, mUiController, this); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 298 | // Add the custom view to its container. |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 299 | mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 300 | mContentView.setVisibility(View.GONE); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 301 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 302 | mCustomViewContainer.bringToFront(); |
| 303 | } |
| 304 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 305 | void hideNavScreen(boolean animate) { |
| 306 | Tab tab = mNavScreen.getSelectedTab(); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 307 | mCustomViewContainer.removeView(mNavScreen); |
| 308 | mNavScreen = null; |
| 309 | mCustomViewContainer.setVisibility(View.GONE); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 310 | mUiController.setActiveTab(tab); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 311 | // Show the content view. |
| 312 | mContentView.setVisibility(View.VISIBLE); |
| 313 | } |
| 314 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 315 | } |