blob: 1b33084e3e3fb3912bb9795237c31bef3f1659f0 [file] [log] [blame]
Leon Scroggins571b3762010-05-26 10:25:01 -04001/*
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
Narayan Kamath80aad8d2011-02-23 12:01:13 +000019import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
Michael Kolb793e05e2011-01-11 15:17:31 -080020import com.android.browser.search.SearchEngine;
Michael Kolbc7485ae2010-09-03 10:10:58 -070021
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.app.Activity;
Leon Scroggins571b3762010-05-26 10:25:01 -040023import android.content.Context;
24import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040026import android.graphics.drawable.Drawable;
Michael Kolb1ce78132010-09-23 15:50:53 -070027import android.text.TextUtils;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080028import android.view.KeyEvent;
Leon Scroggins571b3762010-05-26 10:25:01 -040029import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040030import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070031import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080032import android.view.View.OnFocusChangeListener;
Michael Kolb7cdc4902011-02-03 17:54:40 -080033import android.view.ViewGroup;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080034import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080035import android.widget.AbsoluteLayout;
36import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080037import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040038import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040039
Michael Kolbcfa3af52010-12-14 10:36:11 -080040import java.util.List;
41
Leon Scroggins571b3762010-05-26 10:25:01 -040042/**
Michael Kolbfe251992010-07-08 15:41:55 -070043 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040044 */
Michael Kolbfe251992010-07-08 15:41:55 -070045public class TitleBarXLarge extends TitleBarBase
Narayan Kamath80aad8d2011-02-23 12:01:13 +000046 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040047
Michael Kolb66706532010-12-12 19:50:22 -080048 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070049
Michael Kolba2b2ba82010-08-04 17:54:03 -070050 private Drawable mStopDrawable;
51 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070052
Michael Kolb3f65c382010-08-20 15:31:16 -070053 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080054 private ImageButton mBackButton;
55 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080056 private ImageView mStar;
Michael Kolb5b2299c2011-01-25 16:54:34 -080057 private ImageView mWebIcon;
Michael Kolba2b2ba82010-08-04 17:54:03 -070058 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080059 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070060 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070061 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070062 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070063 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080064 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080065 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070066 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080067 private Drawable mFocusDrawable;
68 private Drawable mUnfocusDrawable;
Michael Kolb81b6f832010-12-12 12:44:27 -080069
Michael Kolba2b2ba82010-08-04 17:54:03 -070070 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080071 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070072
Michael Kolb81b6f832010-12-12 12:44:27 -080073 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080074 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080075 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080076 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070077 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080078 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
79 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080080 mFocusDrawable = resources.getDrawable(
81 R.drawable.textfield_active_holo_dark);
82 mUnfocusDrawable = resources.getDrawable(
83 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080084 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080085 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070086 }
Leon Scroggins571b3762010-05-26 10:25:01 -040087
Michael Kolb7cdc4902011-02-03 17:54:40 -080088 @Override
89 void setTitleGravity(int gravity) {
90 if (mUseQuickControls) {
91 FrameLayout.LayoutParams lp =
92 (FrameLayout.LayoutParams) getLayoutParams();
93 lp.gravity = gravity;
94 setLayoutParams(lp);
95 } else {
96 super.setTitleGravity(gravity);
97 }
98 }
99
John Reck1605bef2011-01-10 18:11:18 -0800100 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700101 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700102 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700103
Michael Kolb3f65c382010-08-20 15:31:16 -0700104 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800105 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700106 mAllButton = findViewById(R.id.all_btn);
107 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400108 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800109 mBackButton = (ImageButton) findViewById(R.id.back);
110 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb5b2299c2011-01-25 16:54:34 -0800111 mWebIcon = (ImageView) findViewById(R.id.web_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800112 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700113 mStopButton = (ImageView) findViewById(R.id.stop);
114 mSearchButton = findViewById(R.id.search);
115 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700116 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700117 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800118 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700119 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800120 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800121 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700122 mBackButton.setOnClickListener(this);
123 mForwardButton.setOnClickListener(this);
124 mStar.setOnClickListener(this);
125 mAllButton.setOnClickListener(this);
126 mStopButton.setOnClickListener(this);
127 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700128 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700129 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800130 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800131 mUrlInput.setUrlInputListener(this);
132 mUrlInput.setContainer(mUrlContainer);
133 mUrlInput.setController(mUiController);
134 mUrlInput.setOnFocusChangeListener(this);
135 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000136 mUrlInput.addQueryTextWatcher(this);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800137 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800138 }
139
Michael Kolb5a72f182011-01-13 20:35:06 -0800140 void updateNavigationState(Tab tab) {
141 WebView web = tab.getWebView();
142 if (web != null) {
143 mBackButton.setImageResource(web.canGoBack()
144 ? R.drawable.ic_back_holo_dark
145 : R.drawable.ic_back_disabled_holo_dark);
146 mForwardButton.setImageResource(web.canGoForward()
147 ? R.drawable.ic_forward_holo_dark
148 : R.drawable.ic_forward_disabled_holo_dark);
149 }
150 }
151
Michael Kolb7cdc4902011-02-03 17:54:40 -0800152 private ViewGroup.LayoutParams makeLayoutParams() {
153 if (mUseQuickControls) {
154 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
155 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800156 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800157 return new AbsoluteLayout.LayoutParams(
158 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
159 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800160 }
161 }
162
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800163 @Override
164 public int getEmbeddedHeight() {
165 return mContainer.getHeight();
166 }
167
Michael Kolb376b5412010-12-15 11:52:57 -0800168 void setUseQuickControls(boolean useQuickControls) {
169 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800170 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800171 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800172 if (mUseQuickControls) {
173 mBackButton.setVisibility(View.GONE);
174 mForwardButton.setVisibility(View.GONE);
175 mStopButton.setVisibility(View.GONE);
176 mAllButton.setVisibility(View.GONE);
177 } else {
178 mBackButton.setVisibility(View.VISIBLE);
179 mForwardButton.setVisibility(View.VISIBLE);
180 mStopButton.setVisibility(View.VISIBLE);
181 mAllButton.setVisibility(View.VISIBLE);
182 }
183 }
184
185 void setShowProgressOnly(boolean progress) {
186 if (progress) {
187 mContainer.setVisibility(View.GONE);
188 } else {
189 mContainer.setVisibility(View.VISIBLE);
190 }
191 }
192
Michael Kolb31d469b2010-12-09 20:49:54 -0800193 @Override
194 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800195 // if losing focus and not in touch mode, leave as is
196 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
197 setFocusState(hasFocus);
198 mUrlContainer.setBackgroundDrawable(hasFocus
199 ? mFocusDrawable : mUnfocusDrawable);
200 }
201 if (hasFocus) {
202 mUrlInput.forceIme();
203 if (mInVoiceMode) {
204 mUrlInput.forceFilter();
205 }
206 } else if (!mUrlInput.needsUpdate()) {
207 mUrlInput.dismissDropDown();
208 mUrlInput.hideIME();
209 }
210 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700211 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700212
John Reck94b7e042011-02-15 15:02:33 -0800213 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500214 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800215 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500216 }
217
Michael Kolb81b6f832010-12-12 12:44:27 -0800218 /**
219 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800220 * @param clearInput clear the input field
221 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800222 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800223 // editing takes preference of progress
224 mContainer.setVisibility(View.VISIBLE);
225 if (mUseQuickControls) {
226 mProgressView.setVisibility(View.GONE);
227 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800228 if (!mUrlInput.hasFocus()) {
229 mUrlInput.requestFocus();
230 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800231 if (clearInput) {
232 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800233 } else if (mInVoiceMode) {
234 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800235 }
236 }
237
238 boolean isEditingUrl() {
239 return mUrlInput.hasFocus();
240 }
241
Michael Kolb7cdc4902011-02-03 17:54:40 -0800242 void stopEditingUrl() {
243 mUrlInput.clearFocus();
244 }
245
Michael Kolba2b2ba82010-08-04 17:54:03 -0700246 @Override
247 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800248 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700250 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700251 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700252 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700253 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500254 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700255 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700257 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800258 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700259 } else if (mStopButton == v) {
260 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700261 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800262 if (!TextUtils.isEmpty(mUrlInput.getText())) {
263 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800264 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700265 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700266 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800267 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800268 } else if (mVoiceSearch == v) {
269 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700270 }
271 }
272
Michael Kolba2b2ba82010-08-04 17:54:03 -0700273 @Override
274 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700275
Michael Kolb31d469b2010-12-09 20:49:54 -0800276 private void clearOrClose() {
277 if (TextUtils.isEmpty(mUrlInput.getText())) {
278 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800279 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800280 } else {
281 // clear
282 mUrlInput.setText("");
283 }
284 }
285
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800286 private void setFocusState(boolean focus) {
287 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800288 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
289 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700290 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800291 mStar.setVisibility(View.GONE);
292 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800293 if (mInVoiceMode) {
294 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
295 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800296 mWebIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800297 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700298 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700299 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800300 mVoiceSearch.setVisibility(View.GONE);
301 mStar.setVisibility(View.VISIBLE);
302 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800303 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800304 if (mUseQuickControls) {
305 mSearchButton.setVisibility(View.GONE);
306 } else {
307 mSearchButton.setVisibility(View.VISIBLE);
308 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800309 mWebIcon.setImageResource(R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700310 }
311 }
312
Michael Kolba2b2ba82010-08-04 17:54:03 -0700313 private void stopOrRefresh() {
314 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700315 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700316 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700317 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700318 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400319 }
320
321 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700322 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400323 */
Michael Kolbfe251992010-07-08 15:41:55 -0700324 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700325 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800326 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700327 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800328 if (!blockvisuals) {
329 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
330 mProgressView.setVisibility(View.GONE);
331 mStopButton.setImageDrawable(mReloadDrawable);
332 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700333 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700334 } else {
335 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800336 if (!blockvisuals) {
337 mProgressView.setVisibility(View.VISIBLE);
338 mStopButton.setImageDrawable(mStopDrawable);
339 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700340 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700341 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700342 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
343 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700344 }
Michael Kolbfe251992010-07-08 15:41:55 -0700345 }
346
Michael Kolb60a68f52011-02-24 11:02:52 -0800347 private void updateSearchMode(boolean userEdited) {
348 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800349 }
350
351 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800352 SearchEngine searchEngine = BrowserSettings.getInstance()
353 .getSearchEngine();
354 boolean showvoicebutton = voiceSearchEnabled &&
355 (searchEngine != null && searchEngine.supportsVoiceSearch());
356 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800357 View.GONE);
358 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
359 View.VISIBLE);
360 }
361
Michael Kolbfe251992010-07-08 15:41:55 -0700362 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400363 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800364 if (!isEditingUrl()) {
365 mUrlInput.setText(title, false);
366 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700367 }
368
Michael Kolb31d469b2010-12-09 20:49:54 -0800369 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500370
Michael Kolb31d469b2010-12-09 20:49:54 -0800371 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000372 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800373 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800374 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800375 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800376 // clear voice mode when user types
377 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500378 }
379 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800380
Michael Kolbcfa3af52010-12-14 10:36:11 -0800381 // voicesearch
382
383 @Override
384 public void setInVoiceMode(boolean voicemode) {
385 setInVoiceMode(voicemode, null);
386 }
387
388 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
389 mInVoiceMode = voicemode;
390 mUrlInput.setVoiceResults(voiceResults);
391 mVoiceSearchIndicator.setVisibility(mInVoiceMode
392 ? View.VISIBLE : View.GONE);
Michael Kolb3a2a1642011-02-15 10:52:07 -0800393 mWebIcon.setVisibility(mInVoiceMode ? View.GONE : View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800394 }
395
John Reck117f07d2011-01-24 09:39:03 -0800396 @Override
397 void setIncognitoMode(boolean incognito) {
398 mUrlInput.setIncognitoMode(incognito);
399 }
Michael Kolb47171d82011-01-28 10:34:15 -0800400
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800401 @Override
402 public View focusSearch(View focused, int dir) {
403 if (FOCUS_DOWN == dir && hasFocus()) {
404 return getCurrentWebView();
405 }
406 return super.focusSearch(focused, dir);
407 }
408
409 @Override
410 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
411 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
412 // catch back key in order to do slightly more cleanup than usual
413 mUrlInput.clearFocus();
414 return true;
415 }
416 return super.dispatchKeyEventPreIme(evt);
417 }
418
419 private WebView getCurrentWebView() {
420 Tab t = mUi.getActiveTab();
421 if (t != null) {
422 return t.getWebView();
423 } else {
424 return null;
425 }
426 }
427
Leon Scroggins571b3762010-05-26 10:25:01 -0400428}