blob: 73c1b9998777045cd7780036178f0f5c81397b2f [file] [log] [blame]
Michael Kolb66706532010-12-12 19:50:22 -08001/*
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;
Michael Kolb376b5412010-12-15 11:52:57 -080020import android.util.Log;
Michael Kolb66706532010-12-12 19:50:22 -080021import android.view.ActionMode;
22import android.view.Gravity;
Michael Kolba4183062011-01-16 10:43:21 -080023import android.view.KeyEvent;
Michael Kolb66706532010-12-12 19:50:22 -080024import android.view.Menu;
25import android.view.View;
Michael Kolb66706532010-12-12 19:50:22 -080026import android.webkit.WebView;
27
28/**
29 * Ui for regular phone screen sizes
30 */
31public class PhoneUi extends BaseUi {
32
33 private static final String LOGTAG = "PhoneUi";
34
35 private TitleBar mTitleBar;
Michael Kolb66706532010-12-12 19:50:22 -080036 private ActiveTabsPage mActiveTabsPage;
37
38 boolean mExtendedMenuOpen;
39 boolean mOptionsMenuOpen;
40
41 /**
42 * @param browser
43 * @param controller
44 */
45 public PhoneUi(Activity browser, UiController controller) {
46 super(browser, controller);
47 mTitleBar = new TitleBar(mActivity, mUiController);
48 // mTitleBar will be always be shown in the fully loaded mode on
49 // phone
50 mTitleBar.setProgress(100);
John Reck285ef042011-02-11 15:44:17 -080051 mActivity.getActionBar().hide();
52 }
Michael Kolb66706532010-12-12 19:50:22 -080053
John Reck285ef042011-02-11 15:44:17 -080054 @Override
55 public void hideComboView() {
56 super.hideComboView();
57 mActivity.getActionBar().hide();
Michael Kolb66706532010-12-12 19:50:22 -080058 }
59
60 // webview factory
61
62 @Override
63 public WebView createWebView(boolean privateBrowsing) {
64 // Create a new WebView
65 WebView w = new WebView(mActivity, null,
66 android.R.attr.webViewStyle, privateBrowsing);
67 initWebViewSettings(w);
68 return w;
69 }
70
71 @Override
72 public WebView createSubWebView(boolean privateBrowsing) {
73 WebView web = createWebView(privateBrowsing);
74 return web;
75 }
76
77 // lifecycle
78
79 @Override
80 public void onPause() {
81 // FIXME: This removes the active tabs page and resets the menu to
82 // MAIN_MENU. A better solution might be to do this work in onNewIntent
83 // but then we would need to save it in onSaveInstanceState and restore
84 // it in onCreate/onRestoreInstanceState
85 if (mActiveTabsPage != null) {
86 mUiController.removeActiveTabsPage(true);
87 }
88 super.onPause();
89 }
90
91 @Override
92 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080093 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080094 }
95
96 @Override
97 public boolean onBackKey() {
98 if (mActiveTabsPage != null) {
99 // if tab page is showing, hide it
100 mUiController.removeActiveTabsPage(true);
101 return true;
102 }
103 return super.onBackKey();
104 }
105
106 @Override
John Reck30c714c2010-12-16 17:30:34 -0800107 public void onProgressChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800108 if (tab.inForeground()) {
John Reck30c714c2010-12-16 17:30:34 -0800109 int progress = tab.getLoadProgress();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800110 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800111 if (progress == 100) {
112 if (!mOptionsMenuOpen || !mExtendedMenuOpen) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800113 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800114 }
115 } else {
116 if (!mOptionsMenuOpen || mExtendedMenuOpen) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800117 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800118 }
119 }
120 }
121 }
122
123 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800124 public void setActiveTab(Tab tab) {
125 super.setActiveTab(tab);
126 WebView view = tab.getWebView();
127 // TabControl.setCurrentTab has been called before this,
128 // so the tab is guaranteed to have a webview
129 if (view == null) {
130 Log.e(LOGTAG, "active tab with no webview detected");
131 return;
132 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800133 view.setEmbeddedTitleBar(getTitleBar());
Michael Kolb376b5412010-12-15 11:52:57 -0800134 if (tab.isInVoiceSearchMode()) {
135 showVoiceTitleBar(tab.getVoiceDisplayTitle());
136 } else {
137 revertVoiceTitleBar(tab);
138 }
Michael Kolb376b5412010-12-15 11:52:57 -0800139 tab.getTopWindow().requestFocus();
140 }
141
142 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800143 void showTitleBar() {
144 if (canShowTitleBar()) {
145 setTitleGravity(Gravity.TOP);
146 super.showTitleBar();
147 }
Michael Kolb66706532010-12-12 19:50:22 -0800148 }
149
150 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800151 protected void hideTitleBar() {
152 if (isTitleBarShowing()) {
153 setTitleGravity(Gravity.NO_GRAVITY);
154 super.hideTitleBar();
155 }
Michael Kolb66706532010-12-12 19:50:22 -0800156 }
157
158 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800159 protected TitleBarBase getTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800160 return mTitleBar;
161 }
162
163 // active tabs page
164
165 @Override
166 public void showActiveTabsPage() {
167 mActiveTabsPage = new ActiveTabsPage(mActivity, mUiController);
168 mTitleBar.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800169 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800170 mContentView.addView(mActiveTabsPage, COVER_SCREEN_PARAMS);
171 mActiveTabsPage.requestFocus();
172 }
173
174 /**
175 * Remove the active tabs page.
176 */
177 @Override
178 public void removeActiveTabsPage() {
179 mContentView.removeView(mActiveTabsPage);
180 mTitleBar.setVisibility(View.VISIBLE);
181 mActiveTabsPage = null;
182 }
183
184 @Override
185 public boolean showsWeb() {
186 return super.showsWeb() && mActiveTabsPage == null;
187 }
188
189 // menu handling callbacks
190
191 @Override
192 public void onOptionsMenuOpened() {
193 mOptionsMenuOpen = true;
194 // options menu opened, show fake title bar
Michael Kolb7cdc4902011-02-03 17:54:40 -0800195 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800196 }
197
198 @Override
199 public void onExtendedMenuOpened() {
200 // Switching the menu to expanded view, so hide the
201 // title bar.
202 mExtendedMenuOpen = true;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800203 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800204 }
205
206 @Override
207 public void onOptionsMenuClosed(boolean inLoad) {
208 mOptionsMenuOpen = false;
209 if (!inLoad) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800210 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800211 }
212 }
213
214 @Override
215 public void onExtendedMenuClosed(boolean inLoad) {
216 mExtendedMenuOpen = false;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800217 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800218 }
219
220 @Override
221 public void onContextMenuCreated(Menu menu) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800222 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800223 }
224
225 @Override
226 public void onContextMenuClosed(Menu menu, boolean inLoad) {
227 if (inLoad) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800228 showTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800229 }
230 }
231
232 // action mode callbacks
233
234 @Override
235 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800236 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800237 }
238
Michael Kolba4183062011-01-16 10:43:21 -0800239 @Override
240 public boolean dispatchKey(int code, KeyEvent event) {
241 return false;
242 }
243
Michael Kolb66706532010-12-12 19:50:22 -0800244}