blob: f1c6c6b5c365ae7104e158391f5f4f9a270e4fcb [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
Michael Kolbc7485ae2010-09-03 10:10:58 -070019import com.android.browser.UrlInputView.UrlInputListener;
20
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.app.Activity;
Michael Kolbfe251992010-07-08 15:41:55 -070022import android.app.SearchManager;
Leon Scroggins571b3762010-05-26 10:25:01 -040023import android.content.Context;
Michael Kolbfe251992010-07-08 15:41:55 -070024import android.content.Intent;
Leon Scroggins571b3762010-05-26 10:25:01 -040025import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070026import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040027import android.graphics.drawable.Drawable;
Michael Kolb257cc2c2010-12-09 09:45:52 -080028import android.os.Bundle;
Michael Kolb31d469b2010-12-09 20:49:54 -080029import android.text.Editable;
Michael Kolb1ce78132010-09-23 15:50:53 -070030import android.text.TextUtils;
Michael Kolb31d469b2010-12-09 20:49:54 -080031import android.text.TextWatcher;
Leon Scroggins571b3762010-05-26 10:25:01 -040032import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040033import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070034import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080035import android.view.View.OnFocusChangeListener;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080036import android.webkit.WebView;
Leon Scroggins571b3762010-05-26 10:25:01 -040037import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040038
Michael Kolbcfa3af52010-12-14 10:36:11 -080039import java.util.List;
40
Leon Scroggins571b3762010-05-26 10:25:01 -040041/**
Michael Kolbfe251992010-07-08 15:41:55 -070042 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040043 */
Michael Kolbfe251992010-07-08 15:41:55 -070044public class TitleBarXLarge extends TitleBarBase
Michael Kolb31d469b2010-12-09 20:49:54 -080045 implements UrlInputListener, OnClickListener, OnFocusChangeListener,
46 TextWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040047
Michael Kolbfe251992010-07-08 15:41:55 -070048 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040049
Michael Kolb8233fac2010-10-26 16:08:53 -070050 private UiController mUiController;
Michael Kolb66706532010-12-12 19:50:22 -080051 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070052
Michael Kolba2b2ba82010-08-04 17:54:03 -070053 private Drawable mStopDrawable;
54 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070055
Michael Kolb3f65c382010-08-20 15:31:16 -070056 private View mContainer;
Michael Kolba2b2ba82010-08-04 17:54:03 -070057 private View mBackButton;
58 private View mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080059 private ImageView mStar;
Michael Kolba2b2ba82010-08-04 17:54:03 -070060 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080061 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070062 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070063 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070064 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070065 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080066 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080067 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070068 private PageProgressView mProgressView;
Michael Kolb31d469b2010-12-09 20:49:54 -080069 private UrlInputView mUrlInput;
Michael Kolbcfa3af52010-12-14 10:36:11 -080070 private Drawable mFocusDrawable;
71 private Drawable mUnfocusDrawable;
72 private boolean mInVoiceMode;
Michael Kolb81b6f832010-12-12 12:44:27 -080073
Michael Kolba2b2ba82010-08-04 17:54:03 -070074 private boolean mInLoad;
Michael Kolbcfa3af52010-12-14 10:36:11 -080075 private boolean mEditable;
Michael Kolb376b5412010-12-15 11:52:57 -080076 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070077
Michael Kolb81b6f832010-12-12 12:44:27 -080078 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080079 XLargeUi ui) {
Michael Kolb8233fac2010-10-26 16:08:53 -070080 super(activity);
Michael Kolb8233fac2010-10-26 16:08:53 -070081 mUiController = controller;
Michael Kolb81b6f832010-12-12 12:44:27 -080082 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070083 Resources resources = activity.getResources();
Michael Kolbc7485ae2010-09-03 10:10:58 -070084 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal);
85 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal);
Michael Kolbcfa3af52010-12-14 10:36:11 -080086 mFocusDrawable = resources.getDrawable(
87 R.drawable.textfield_active_holo_dark);
88 mUnfocusDrawable = resources.getDrawable(
89 R.drawable.textfield_default_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -070090 rebuildLayout(activity, true);
Michael Kolbcfa3af52010-12-14 10:36:11 -080091 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070092 }
Leon Scroggins571b3762010-05-26 10:25:01 -040093
Michael Kolbfe251992010-07-08 15:41:55 -070094 private void rebuildLayout(Context context, boolean rebuildData) {
Michael Kolbfe251992010-07-08 15:41:55 -070095 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -070096 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -070097
Michael Kolb3f65c382010-08-20 15:31:16 -070098 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -080099 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700100 mAllButton = findViewById(R.id.all_btn);
101 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400102 // back/forward. Probably should be done inside onPageStarted.
103 mBackButton = findViewById(R.id.back);
104 mForwardButton = findViewById(R.id.forward);
Michael Kolb31d469b2010-12-09 20:49:54 -0800105 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700106 mStopButton = (ImageView) findViewById(R.id.stop);
107 mSearchButton = findViewById(R.id.search);
108 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700109 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700110 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800111 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700112 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800113 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800114 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700115 mBackButton.setOnClickListener(this);
116 mForwardButton.setOnClickListener(this);
117 mStar.setOnClickListener(this);
118 mAllButton.setOnClickListener(this);
119 mStopButton.setOnClickListener(this);
120 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700121 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700122 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800123 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800124 mUrlContainer.setOnClickListener(this);
125 mUrlInput.setUrlInputListener(this);
126 mUrlInput.setContainer(mUrlContainer);
127 mUrlInput.setController(mUiController);
128 mUrlInput.setOnFocusChangeListener(this);
129 mUrlInput.setSelectAllOnFocus(true);
130 mUrlInput.addTextChangedListener(this);
131 setUrlMode(false);
132 }
133
Michael Kolbcfa3af52010-12-14 10:36:11 -0800134 public void setEditable(boolean editable) {
135 mEditable = editable;
136 mUrlInput.setFocusable(mEditable);
137 if (!mEditable) {
138 mUrlInput.setOnClickListener(this);
139 } else {
140 mUrlContainer.setOnClickListener(null);
141 }
142 }
143
Michael Kolb376b5412010-12-15 11:52:57 -0800144 void setUseQuickControls(boolean useQuickControls) {
145 mUseQuickControls = useQuickControls;
146 if (mUseQuickControls) {
147 mBackButton.setVisibility(View.GONE);
148 mForwardButton.setVisibility(View.GONE);
149 mStopButton.setVisibility(View.GONE);
150 mAllButton.setVisibility(View.GONE);
151 } else {
152 mBackButton.setVisibility(View.VISIBLE);
153 mForwardButton.setVisibility(View.VISIBLE);
154 mStopButton.setVisibility(View.VISIBLE);
155 mAllButton.setVisibility(View.VISIBLE);
156 }
157 }
158
159 void setShowProgressOnly(boolean progress) {
160 if (progress) {
161 mContainer.setVisibility(View.GONE);
162 } else {
163 mContainer.setVisibility(View.VISIBLE);
164 }
165 }
166
Michael Kolb31d469b2010-12-09 20:49:54 -0800167 @Override
168 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800169 if (!mEditable && hasFocus) {
170 mUi.editUrl(false);
171 } else {
172 setUrlMode(hasFocus);
173 }
174 mUrlContainer.setBackgroundDrawable(hasFocus
175 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700176 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700177
Leon Scroggins4cd97792010-12-03 15:31:56 -0500178 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800179 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500180 }
181
Michael Kolb81b6f832010-12-12 12:44:27 -0800182 /**
183 * called from the Ui when the user wants to edit
184 * Note: only the fake titlebar will get this callback
185 * independent of which input field started the edit mode
186 * @param clearInput clear the input field
187 */
188 void onEditUrl(boolean clearInput) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800189 if (!mUrlInput.hasFocus()) {
190 mUrlInput.requestFocus();
191 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800192 if (clearInput) {
193 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800194 } else if (mInVoiceMode) {
195 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800196 }
197 }
198
199 boolean isEditingUrl() {
200 return mUrlInput.hasFocus();
201 }
202
Michael Kolba2b2ba82010-08-04 17:54:03 -0700203 @Override
204 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800205 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800206 mUi.editUrl(false);
207 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800208 if (!mUrlInput.hasFocus()) {
209 mUi.editUrl(false);
210 }
211 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700213 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700214 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700215 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400217 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700218 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700220 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800221 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700222 } else if (mStopButton == v) {
223 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700224 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800225 if (!TextUtils.isEmpty(mUrlInput.getText())) {
226 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800227 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700228 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700229 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800230 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800231 } else if (mVoiceSearch == v) {
232 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700233 }
234 }
235
Michael Kolb3f65c382010-08-20 15:31:16 -0700236 int getHeightWithoutProgress() {
237 return mContainer.getHeight();
238 }
239
Michael Kolba2b2ba82010-08-04 17:54:03 -0700240 @Override
241 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700242
Michael Kolb31d469b2010-12-09 20:49:54 -0800243 private void clearOrClose() {
244 if (TextUtils.isEmpty(mUrlInput.getText())) {
245 // close
246 setUrlMode(false);
247 } else {
248 // clear
249 mUrlInput.setText("");
250 }
251 }
252
Michael Kolbfe251992010-07-08 15:41:55 -0700253 // UrlInputListener implementation
254
Michael Kolb81b6f832010-12-12 12:44:27 -0800255 /**
256 * callback from suggestion dropdown
257 * user selected a suggestion
258 */
Michael Kolbfe251992010-07-08 15:41:55 -0700259 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800260 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700261 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800262 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700263 Intent i = new Intent();
264 i.setAction(Intent.ACTION_SEARCH);
265 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800266 if (extra != null) {
267 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
268 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800269 if (source != null) {
270 Bundle appData = new Bundle();
271 appData.putString(com.android.common.Search.SOURCE, source);
272 i.putExtra(SearchManager.APP_DATA, appData);
273 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700274 mUiController.handleNewIntent(i);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700275 setUrlMode(false);
Michael Kolb513286f2010-09-09 12:55:12 -0700276 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700277 }
278
279 @Override
280 public void onDismiss() {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800281 WebView top = mUiController.getCurrentTopWebView();
282 if (top != null) {
283 mUiController.getCurrentTopWebView().requestFocus();
284 }
Michael Kolb66706532010-12-12 19:50:22 -0800285 mUi.hideFakeTitleBar();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700286 setUrlMode(false);
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800287 // if top != null current must be set
Michael Kolbcfa3af52010-12-14 10:36:11 -0800288 if ((top != null) && !mInVoiceMode) {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800289 setDisplayTitle(mUiController.getCurrentWebView().getUrl());
290 }
Michael Kolb513286f2010-09-09 12:55:12 -0700291 }
292
Michael Kolb81b6f832010-12-12 12:44:27 -0800293 /**
294 * callback from the suggestion dropdown
295 * copy text to input field and stay in edit mode
296 */
Michael Kolb513286f2010-09-09 12:55:12 -0700297 @Override
298 public void onEdit(String text) {
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700299 setDisplayTitle(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700300 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800301 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700302 }
303 }
304
Michael Kolb81b6f832010-12-12 12:44:27 -0800305 void setUrlMode(boolean focused) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700306 if (focused) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800307 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
308 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700309 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800310 mStar.setVisibility(View.GONE);
311 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800312 if (mInVoiceMode) {
313 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
314 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800315 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700316 } else {
Michael Kolb31d469b2010-12-09 20:49:54 -0800317 mUrlInput.clearFocus();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700318 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800319 mVoiceSearch.setVisibility(View.GONE);
320 mStar.setVisibility(View.VISIBLE);
321 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800322 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800323 if (mUseQuickControls) {
324 mSearchButton.setVisibility(View.GONE);
325 } else {
326 mSearchButton.setVisibility(View.VISIBLE);
327 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700328 }
329 }
330
Michael Kolba2b2ba82010-08-04 17:54:03 -0700331 private void stopOrRefresh() {
332 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700333 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700334 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700335 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700336 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400337 }
338
339 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700340 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400341 */
Michael Kolbfe251992010-07-08 15:41:55 -0700342 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700343 void setProgress(int newProgress) {
344 if (newProgress >= PROGRESS_MAX) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700345 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700346 mProgressView.setVisibility(View.GONE);
347 mInLoad = false;
348 mStopButton.setImageDrawable(mReloadDrawable);
349 } else {
350 if (!mInLoad) {
351 mProgressView.setVisibility(View.VISIBLE);
352 mInLoad = true;
353 mStopButton.setImageDrawable(mStopDrawable);
354 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700355 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
356 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700357 }
Michael Kolbfe251992010-07-08 15:41:55 -0700358 }
359
Michael Kolb31d469b2010-12-09 20:49:54 -0800360 private void updateSearchMode() {
361 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
362 }
363
364 private void setSearchMode(boolean voiceSearchEnabled) {
365 mVoiceSearch.setVisibility(voiceSearchEnabled ? View.VISIBLE :
366 View.GONE);
367 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
368 View.VISIBLE);
369 }
370
Michael Kolbfe251992010-07-08 15:41:55 -0700371 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400372 /* package */ void setDisplayTitle(String title) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800373 mUrlInput.setText(title, false);
Leon Scroggins571b3762010-05-26 10:25:01 -0400374 }
375
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700376 void setDisplayTitle(String title, boolean filter) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800377 mUrlInput.setText(title, filter);
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700378 }
379
Michael Kolb31d469b2010-12-09 20:49:54 -0800380 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500381
Michael Kolb31d469b2010-12-09 20:49:54 -0800382 @Override
383 public void afterTextChanged(Editable s) {
384 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800385 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800386 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800387 // clear voice mode when user types
388 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500389 }
390 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800391
392 @Override
393 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
394 }
395
396 @Override
397 public void onTextChanged(CharSequence s, int start, int before, int count) {
398 }
399
Michael Kolbcfa3af52010-12-14 10:36:11 -0800400 // voicesearch
401
402 @Override
403 public void setInVoiceMode(boolean voicemode) {
404 setInVoiceMode(voicemode, null);
405 }
406
407 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
408 mInVoiceMode = voicemode;
409 mUrlInput.setVoiceResults(voiceResults);
410 mVoiceSearchIndicator.setVisibility(mInVoiceMode
411 ? View.VISIBLE : View.GONE);
412 }
413
Leon Scroggins571b3762010-05-26 10:25:01 -0400414}