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