blob: 57cc7249cc0a8942af93ffd2453a3ffe8a5a9b1c [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);
John Reck1605bef2011-01-10 18:11:18 -080090 initLayout(activity);
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
John Reck1605bef2011-01-10 18:11:18 -080094 private void initLayout(Context context) {
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;
John Reck1605bef2011-01-10 18:11:18 -0800146 mUrlInput.setReverseResults(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800147 if (mUseQuickControls) {
148 mBackButton.setVisibility(View.GONE);
149 mForwardButton.setVisibility(View.GONE);
150 mStopButton.setVisibility(View.GONE);
151 mAllButton.setVisibility(View.GONE);
152 } else {
153 mBackButton.setVisibility(View.VISIBLE);
154 mForwardButton.setVisibility(View.VISIBLE);
155 mStopButton.setVisibility(View.VISIBLE);
156 mAllButton.setVisibility(View.VISIBLE);
157 }
158 }
159
160 void setShowProgressOnly(boolean progress) {
161 if (progress) {
162 mContainer.setVisibility(View.GONE);
163 } else {
164 mContainer.setVisibility(View.VISIBLE);
165 }
166 }
167
Michael Kolb31d469b2010-12-09 20:49:54 -0800168 @Override
169 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800170 if (!mEditable && hasFocus) {
171 mUi.editUrl(false);
172 } else {
173 setUrlMode(hasFocus);
174 }
175 mUrlContainer.setBackgroundDrawable(hasFocus
176 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700177 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700178
Leon Scroggins4cd97792010-12-03 15:31:56 -0500179 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800180 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500181 }
182
Michael Kolb81b6f832010-12-12 12:44:27 -0800183 /**
184 * called from the Ui when the user wants to edit
185 * Note: only the fake titlebar will get this callback
186 * independent of which input field started the edit mode
187 * @param clearInput clear the input field
188 */
189 void onEditUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800190 // editing takes preference of progress
191 mContainer.setVisibility(View.VISIBLE);
192 if (mUseQuickControls) {
193 mProgressView.setVisibility(View.GONE);
194 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800195 if (!mUrlInput.hasFocus()) {
196 mUrlInput.requestFocus();
197 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800198 if (clearInput) {
199 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800200 } else if (mInVoiceMode) {
201 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800202 }
203 }
204
205 boolean isEditingUrl() {
206 return mUrlInput.hasFocus();
207 }
208
Michael Kolba2b2ba82010-08-04 17:54:03 -0700209 @Override
210 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800211 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800212 mUi.editUrl(false);
213 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800214 if (!mUrlInput.hasFocus()) {
215 mUi.editUrl(false);
216 }
217 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700219 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700221 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400223 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700224 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700225 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700226 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800227 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700228 } else if (mStopButton == v) {
229 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700230 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800231 if (!TextUtils.isEmpty(mUrlInput.getText())) {
232 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800233 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700234 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700235 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800236 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800237 } else if (mVoiceSearch == v) {
238 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700239 }
240 }
241
Michael Kolb3f65c382010-08-20 15:31:16 -0700242 int getHeightWithoutProgress() {
243 return mContainer.getHeight();
244 }
245
Michael Kolba2b2ba82010-08-04 17:54:03 -0700246 @Override
247 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700248
Michael Kolb31d469b2010-12-09 20:49:54 -0800249 private void clearOrClose() {
250 if (TextUtils.isEmpty(mUrlInput.getText())) {
251 // close
252 setUrlMode(false);
253 } else {
254 // clear
255 mUrlInput.setText("");
256 }
257 }
258
Michael Kolbfe251992010-07-08 15:41:55 -0700259 // UrlInputListener implementation
260
Michael Kolb81b6f832010-12-12 12:44:27 -0800261 /**
262 * callback from suggestion dropdown
263 * user selected a suggestion
264 */
Michael Kolbfe251992010-07-08 15:41:55 -0700265 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800266 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700267 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800268 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700269 Intent i = new Intent();
270 i.setAction(Intent.ACTION_SEARCH);
271 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800272 if (extra != null) {
273 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
274 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800275 if (source != null) {
276 Bundle appData = new Bundle();
277 appData.putString(com.android.common.Search.SOURCE, source);
278 i.putExtra(SearchManager.APP_DATA, appData);
279 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700280 mUiController.handleNewIntent(i);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700281 setUrlMode(false);
Michael Kolb513286f2010-09-09 12:55:12 -0700282 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700283 }
284
285 @Override
286 public void onDismiss() {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800287 WebView top = mUiController.getCurrentTopWebView();
288 if (top != null) {
289 mUiController.getCurrentTopWebView().requestFocus();
290 }
Michael Kolb66706532010-12-12 19:50:22 -0800291 mUi.hideFakeTitleBar();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700292 setUrlMode(false);
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800293 // if top != null current must be set
Michael Kolbcfa3af52010-12-14 10:36:11 -0800294 if ((top != null) && !mInVoiceMode) {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800295 setDisplayTitle(mUiController.getCurrentWebView().getUrl());
296 }
Michael Kolb513286f2010-09-09 12:55:12 -0700297 }
298
Michael Kolb81b6f832010-12-12 12:44:27 -0800299 /**
300 * callback from the suggestion dropdown
301 * copy text to input field and stay in edit mode
302 */
Michael Kolb513286f2010-09-09 12:55:12 -0700303 @Override
304 public void onEdit(String text) {
John Reck4851f9e2010-12-22 16:40:36 -0800305 mUrlInput.setText(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700306 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800307 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700308 }
309 }
310
Michael Kolb81b6f832010-12-12 12:44:27 -0800311 void setUrlMode(boolean focused) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700312 if (focused) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800313 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
314 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700315 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800316 mStar.setVisibility(View.GONE);
317 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800318 if (mInVoiceMode) {
319 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
320 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800321 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700322 } else {
Michael Kolb31d469b2010-12-09 20:49:54 -0800323 mUrlInput.clearFocus();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700324 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800325 mVoiceSearch.setVisibility(View.GONE);
326 mStar.setVisibility(View.VISIBLE);
327 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800328 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800329 if (mUseQuickControls) {
330 mSearchButton.setVisibility(View.GONE);
331 } else {
332 mSearchButton.setVisibility(View.VISIBLE);
333 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700334 }
335 }
336
Michael Kolba2b2ba82010-08-04 17:54:03 -0700337 private void stopOrRefresh() {
338 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700339 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700340 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700341 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700342 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400343 }
344
345 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700346 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400347 */
Michael Kolbfe251992010-07-08 15:41:55 -0700348 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700349 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800350 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700351 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800352 if (!blockvisuals) {
353 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
354 mProgressView.setVisibility(View.GONE);
355 mStopButton.setImageDrawable(mReloadDrawable);
356 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700357 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700358 } else {
359 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800360 if (!blockvisuals) {
361 mProgressView.setVisibility(View.VISIBLE);
362 mStopButton.setImageDrawable(mStopDrawable);
363 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700364 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700365 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700366 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
367 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700368 }
Michael Kolbfe251992010-07-08 15:41:55 -0700369 }
370
Michael Kolb31d469b2010-12-09 20:49:54 -0800371 private void updateSearchMode() {
372 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
373 }
374
375 private void setSearchMode(boolean voiceSearchEnabled) {
376 mVoiceSearch.setVisibility(voiceSearchEnabled ? View.VISIBLE :
377 View.GONE);
378 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
379 View.VISIBLE);
380 }
381
Michael Kolbfe251992010-07-08 15:41:55 -0700382 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400383 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800384 if (!isEditingUrl()) {
385 mUrlInput.setText(title, false);
386 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700387 }
388
Michael Kolb31d469b2010-12-09 20:49:54 -0800389 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500390
Michael Kolb31d469b2010-12-09 20:49:54 -0800391 @Override
392 public void afterTextChanged(Editable s) {
393 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800394 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800395 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800396 // clear voice mode when user types
397 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500398 }
399 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800400
401 @Override
402 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
403 }
404
405 @Override
406 public void onTextChanged(CharSequence s, int start, int before, int count) {
407 }
408
Michael Kolbcfa3af52010-12-14 10:36:11 -0800409 // voicesearch
410
411 @Override
412 public void setInVoiceMode(boolean voicemode) {
413 setInVoiceMode(voicemode, null);
414 }
415
416 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
417 mInVoiceMode = voicemode;
418 mUrlInput.setVoiceResults(voiceResults);
419 mVoiceSearchIndicator.setVisibility(mInVoiceMode
420 ? View.VISIBLE : View.GONE);
421 }
422
Leon Scroggins571b3762010-05-26 10:25:01 -0400423}