PhoneUi.java revision 629b22ce19f44e38ee470687cd2d9218d2066f85
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 17package com.android.browser; 18 19import android.app.Activity; 20import android.os.Bundle; 21import android.util.Log; 22import android.view.ActionMode; 23import android.view.Gravity; 24import android.view.KeyEvent; 25import android.view.Menu; 26import android.view.View; 27import android.webkit.WebView; 28import android.widget.FrameLayout; 29 30import com.android.browser.UrlInputView.StateListener; 31 32/** 33 * Ui for regular phone screen sizes 34 */ 35public class PhoneUi extends BaseUi { 36 37 private static final String LOGTAG = "PhoneUi"; 38 39 private PieControlPhone mPieControl; 40 private NavScreen mNavScreen; 41 private NavigationBarPhone mNavigationBar; 42 43 boolean mExtendedMenuOpen; 44 boolean mOptionsMenuOpen; 45 boolean mAnimating; 46 47 /** 48 * @param browser 49 * @param controller 50 */ 51 public PhoneUi(Activity browser, UiController controller) { 52 super(browser, controller); 53 mActivity.getActionBar().hide(); 54 setUseQuickControls(BrowserSettings.getInstance().useQuickControls()); 55 mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar(); 56 } 57 58 @Override 59 public void hideComboView() { 60 super.hideComboView(); 61 mActivity.getActionBar().hide(); 62 } 63 64 @Override 65 public void onDestroy() { 66 hideTitleBar(); 67 } 68 69 @Override 70 public void editUrl(boolean clearInput) { 71 if (mUseQuickControls) { 72 mTitleBar.setShowProgressOnly(false); 73 } 74 super.editUrl(clearInput); 75 } 76 77 @Override 78 public boolean onBackKey() { 79 if (mNavScreen != null) { 80 mNavScreen.close(); 81 return true; 82 } 83 return super.onBackKey(); 84 } 85 86 @Override 87 public boolean onMenuKey() { 88 if (!isComboViewShowing()) { 89 if (mNavScreen == null) { 90 showNavScreen(); 91 } else { 92 mNavScreen.close(); 93 } 94 return true; 95 } else { 96 return false; 97 } 98 } 99 100 @Override 101 public boolean dispatchKey(int code, KeyEvent event) { 102 if (!isComboViewShowing()) { 103 } 104 return false; 105 } 106 107 @Override 108 public void onProgressChanged(Tab tab) { 109 if (tab.inForeground()) { 110 int progress = tab.getLoadProgress(); 111 mTitleBar.setProgress(progress); 112 if (progress == 100) { 113 if (!mOptionsMenuOpen || !mExtendedMenuOpen) { 114 suggestHideTitleBar(); 115 if (mUseQuickControls) { 116 mTitleBar.setShowProgressOnly(false); 117 } 118 } 119 } else { 120 if (!mOptionsMenuOpen || mExtendedMenuOpen) { 121 if (mUseQuickControls && !mTitleBar.isEditingUrl()) { 122 mTitleBar.setShowProgressOnly(true); 123 setTitleGravity(Gravity.TOP); 124 } 125 showTitleBar(); 126 } 127 } 128 } 129 } 130 131 @Override 132 public void setActiveTab(final Tab tab) { 133 super.setActiveTab(tab); 134 BrowserWebView view = (BrowserWebView) tab.getWebView(); 135 // TabControl.setCurrentTab has been called before this, 136 // so the tab is guaranteed to have a webview 137 if (view == null) { 138 Log.e(LOGTAG, "active tab with no webview detected"); 139 return; 140 } 141 // Request focus on the top window. 142 if (mUseQuickControls) { 143 mPieControl.forceToTop(mContentView); 144 } else { 145 // check if title bar is already attached by animation 146 if (mTitleBar.getParent() == null) { 147 view.setEmbeddedTitleBar(mTitleBar); 148 } 149 } 150 if (tab.isInVoiceSearchMode()) { 151 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults()); 152 } else { 153 revertVoiceTitleBar(tab); 154 } 155 // update nav bar state 156 mNavigationBar.onStateChanged(StateListener.STATE_NORMAL); 157 updateLockIconToLatest(tab); 158 tab.getTopWindow().requestFocus(); 159 } 160 161 /** 162 * Suggest to the UI that the title bar can be hidden. The UI will then 163 * decide whether or not to hide based off a number of factors, such 164 * as if the user is editing the URL bar or if the page is loading 165 */ 166 @Override 167 public void suggestHideTitleBar() { 168 if (!mNavigationBar.isMenuShowing()) { 169 super.suggestHideTitleBar(); 170 } 171 } 172 173 @Override 174 public void showComboView(ComboViews startWith, Bundle extras) { 175 if (mNavScreen != null) { 176 hideNavScreen(false); 177 } 178 super.showComboView(startWith, extras); 179 } 180 181 // menu handling callbacks 182 183 @Override 184 public void onContextMenuCreated(Menu menu) { 185 hideTitleBar(); 186 } 187 188 @Override 189 public void onContextMenuClosed(Menu menu, boolean inLoad) { 190 if (inLoad) { 191 showTitleBar(); 192 } 193 } 194 195 // action mode callbacks 196 197 @Override 198 public void onActionModeStarted(ActionMode mode) { 199 hideTitleBar(); 200 } 201 202 @Override 203 public void onActionModeFinished(boolean inLoad) { 204 if (inLoad) { 205 if (mUseQuickControls) { 206 mTitleBar.setShowProgressOnly(true); 207 } 208 showTitleBar(); 209 } 210 mActivity.getActionBar().hide(); 211 } 212 213 @Override 214 protected void setTitleGravity(int gravity) { 215 if (mUseQuickControls) { 216 FrameLayout.LayoutParams lp = 217 (FrameLayout.LayoutParams) mTitleBar.getLayoutParams(); 218 lp.gravity = gravity; 219 mTitleBar.setLayoutParams(lp); 220 } else { 221 super.setTitleGravity(gravity); 222 } 223 } 224 225 @Override 226 public void setUseQuickControls(boolean useQuickControls) { 227 mUseQuickControls = useQuickControls; 228 mTitleBar.setUseQuickControls(mUseQuickControls); 229 if (useQuickControls) { 230 mPieControl = new PieControlPhone(mActivity, mUiController, this); 231 mPieControl.attachToContainer(mContentView); 232 WebView web = getWebView(); 233 if (web != null) { 234 web.setEmbeddedTitleBar(null); 235 // don't show url bar on scrolling 236 web.setOnTouchListener(null); 237 } 238 } else { 239 if (mPieControl != null) { 240 mPieControl.removeFromContainer(mContentView); 241 } 242 WebView web = getWebView(); 243 if (web != null) { 244 web.setEmbeddedTitleBar(mTitleBar); 245 // show url bar on scrolling 246 web.setOnTouchListener(this); 247 } 248 setTitleGravity(Gravity.NO_GRAVITY); 249 } 250 } 251 252 void showNavScreen() { 253 detachTab(mActiveTab); 254 mNavScreen = new NavScreen(mActivity, mUiController, this); 255 // Add the custom view to its container. 256 mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS); 257 mContentView.setVisibility(View.GONE); 258 mCustomViewContainer.setVisibility(View.VISIBLE); 259 mCustomViewContainer.bringToFront(); 260 } 261 262 void hideNavScreen(boolean animate) { 263 if (mNavScreen == null) return; 264 Tab tab = mNavScreen.getSelectedTab(); 265 mCustomViewContainer.removeView(mNavScreen); 266 mNavScreen = null; 267 mCustomViewContainer.setVisibility(View.GONE); 268 mUiController.setActiveTab(tab); 269 // Show the content view. 270 mContentView.setVisibility(View.VISIBLE); 271 } 272 273 @Override 274 public boolean needsRestoreAllTabs() { 275 return false; 276 } 277 278} 279