blob: b4791394a6a702807ac2666da32f3313a74a3e3e [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 Kolbbd018d42010-12-15 15:43:39 -0800189 // editing takes preference of progress
190 mContainer.setVisibility(View.VISIBLE);
191 if (mUseQuickControls) {
192 mProgressView.setVisibility(View.GONE);
193 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800194 if (!mUrlInput.hasFocus()) {
195 mUrlInput.requestFocus();
196 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800197 if (clearInput) {
198 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800199 } else if (mInVoiceMode) {
200 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800201 }
202 }
203
204 boolean isEditingUrl() {
205 return mUrlInput.hasFocus();
206 }
207
Michael Kolba2b2ba82010-08-04 17:54:03 -0700208 @Override
209 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800210 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800211 mUi.editUrl(false);
212 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800213 if (!mUrlInput.hasFocus()) {
214 mUi.editUrl(false);
215 }
216 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700218 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700220 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400222 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700223 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700224 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700225 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800226 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700227 } else if (mStopButton == v) {
228 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700229 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800230 if (!TextUtils.isEmpty(mUrlInput.getText())) {
231 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800232 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700233 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700234 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800235 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800236 } else if (mVoiceSearch == v) {
237 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700238 }
239 }
240
Michael Kolb3f65c382010-08-20 15:31:16 -0700241 int getHeightWithoutProgress() {
242 return mContainer.getHeight();
243 }
244
Michael Kolba2b2ba82010-08-04 17:54:03 -0700245 @Override
246 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700247
Michael Kolb31d469b2010-12-09 20:49:54 -0800248 private void clearOrClose() {
249 if (TextUtils.isEmpty(mUrlInput.getText())) {
250 // close
251 setUrlMode(false);
252 } else {
253 // clear
254 mUrlInput.setText("");
255 }
256 }
257
Michael Kolbfe251992010-07-08 15:41:55 -0700258 // UrlInputListener implementation
259
Michael Kolb81b6f832010-12-12 12:44:27 -0800260 /**
261 * callback from suggestion dropdown
262 * user selected a suggestion
263 */
Michael Kolbfe251992010-07-08 15:41:55 -0700264 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800265 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700266 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800267 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700268 Intent i = new Intent();
269 i.setAction(Intent.ACTION_SEARCH);
270 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800271 if (extra != null) {
272 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
273 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800274 if (source != null) {
275 Bundle appData = new Bundle();
276 appData.putString(com.android.common.Search.SOURCE, source);
277 i.putExtra(SearchManager.APP_DATA, appData);
278 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700279 mUiController.handleNewIntent(i);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700280 setUrlMode(false);
Michael Kolb513286f2010-09-09 12:55:12 -0700281 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700282 }
283
284 @Override
285 public void onDismiss() {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800286 WebView top = mUiController.getCurrentTopWebView();
287 if (top != null) {
288 mUiController.getCurrentTopWebView().requestFocus();
289 }
Michael Kolb66706532010-12-12 19:50:22 -0800290 mUi.hideFakeTitleBar();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700291 setUrlMode(false);
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800292 // if top != null current must be set
Michael Kolbcfa3af52010-12-14 10:36:11 -0800293 if ((top != null) && !mInVoiceMode) {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800294 setDisplayTitle(mUiController.getCurrentWebView().getUrl());
295 }
Michael Kolb513286f2010-09-09 12:55:12 -0700296 }
297
Michael Kolb81b6f832010-12-12 12:44:27 -0800298 /**
299 * callback from the suggestion dropdown
300 * copy text to input field and stay in edit mode
301 */
Michael Kolb513286f2010-09-09 12:55:12 -0700302 @Override
303 public void onEdit(String text) {
John Reck4851f9e2010-12-22 16:40:36 -0800304 mUrlInput.setText(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700305 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800306 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700307 }
308 }
309
Michael Kolb81b6f832010-12-12 12:44:27 -0800310 void setUrlMode(boolean focused) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700311 if (focused) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800312 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
313 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700314 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800315 mStar.setVisibility(View.GONE);
316 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800317 if (mInVoiceMode) {
318 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
319 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800320 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700321 } else {
Michael Kolb31d469b2010-12-09 20:49:54 -0800322 mUrlInput.clearFocus();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700323 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800324 mVoiceSearch.setVisibility(View.GONE);
325 mStar.setVisibility(View.VISIBLE);
326 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800327 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800328 if (mUseQuickControls) {
329 mSearchButton.setVisibility(View.GONE);
330 } else {
331 mSearchButton.setVisibility(View.VISIBLE);
332 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700333 }
334 }
335
Michael Kolba2b2ba82010-08-04 17:54:03 -0700336 private void stopOrRefresh() {
337 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700338 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700339 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700340 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700341 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400342 }
343
344 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700345 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400346 */
Michael Kolbfe251992010-07-08 15:41:55 -0700347 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700348 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800349 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700350 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800351 if (!blockvisuals) {
352 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
353 mProgressView.setVisibility(View.GONE);
354 mStopButton.setImageDrawable(mReloadDrawable);
355 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700356 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700357 } else {
358 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800359 if (!blockvisuals) {
360 mProgressView.setVisibility(View.VISIBLE);
361 mStopButton.setImageDrawable(mStopDrawable);
362 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700363 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700364 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700365 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
366 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700367 }
Michael Kolbfe251992010-07-08 15:41:55 -0700368 }
369
Michael Kolb31d469b2010-12-09 20:49:54 -0800370 private void updateSearchMode() {
371 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
372 }
373
374 private void setSearchMode(boolean voiceSearchEnabled) {
375 mVoiceSearch.setVisibility(voiceSearchEnabled ? View.VISIBLE :
376 View.GONE);
377 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
378 View.VISIBLE);
379 }
380
Michael Kolbfe251992010-07-08 15:41:55 -0700381 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400382 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800383 if (!isEditingUrl()) {
384 mUrlInput.setText(title, false);
385 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700386 }
387
Michael Kolb31d469b2010-12-09 20:49:54 -0800388 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500389
Michael Kolb31d469b2010-12-09 20:49:54 -0800390 @Override
391 public void afterTextChanged(Editable s) {
392 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800393 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800394 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800395 // clear voice mode when user types
396 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500397 }
398 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800399
400 @Override
401 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
402 }
403
404 @Override
405 public void onTextChanged(CharSequence s, int start, int before, int count) {
406 }
407
Michael Kolbcfa3af52010-12-14 10:36:11 -0800408 // voicesearch
409
410 @Override
411 public void setInVoiceMode(boolean voicemode) {
412 setInVoiceMode(voicemode, null);
413 }
414
415 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
416 mInVoiceMode = voicemode;
417 mUrlInput.setVoiceResults(voiceResults);
418 mVoiceSearchIndicator.setVisibility(mInVoiceMode
419 ? View.VISIBLE : View.GONE);
420 }
421
Leon Scroggins571b3762010-05-26 10:25:01 -0400422}