blob: 8be4df545a5d12c3de5a4b98b26a2d0a126b6ad4 [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;
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;
Michael Kolbfe251992010-07-08 15:41:55 -070023import android.app.SearchManager;
Leon Scroggins571b3762010-05-26 10:25:01 -040024import android.content.Context;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.content.Intent;
Leon Scroggins571b3762010-05-26 10:25:01 -040026import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070027import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040028import android.graphics.drawable.Drawable;
Michael Kolb257cc2c2010-12-09 09:45:52 -080029import android.os.Bundle;
Michael Kolb31d469b2010-12-09 20:49:54 -080030import android.text.Editable;
Michael Kolb1ce78132010-09-23 15:50:53 -070031import android.text.TextUtils;
Michael Kolb31d469b2010-12-09 20:49:54 -080032import android.text.TextWatcher;
Leon Scroggins571b3762010-05-26 10:25:01 -040033import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040034import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070035import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080036import android.view.View.OnFocusChangeListener;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080037import android.webkit.WebView;
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
Michael Kolb31d469b2010-12-09 20:49:54 -080046 implements UrlInputListener, OnClickListener, OnFocusChangeListener,
47 TextWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040048
Michael Kolbfe251992010-07-08 15:41:55 -070049 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040050
Michael Kolb8233fac2010-10-26 16:08:53 -070051 private UiController mUiController;
Michael Kolb66706532010-12-12 19:50:22 -080052 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070053
Michael Kolba2b2ba82010-08-04 17:54:03 -070054 private Drawable mStopDrawable;
55 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070056
Michael Kolb3f65c382010-08-20 15:31:16 -070057 private View mContainer;
Michael Kolba2b2ba82010-08-04 17:54:03 -070058 private View mBackButton;
59 private View mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080060 private ImageView mStar;
Michael Kolba2b2ba82010-08-04 17:54:03 -070061 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080062 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070063 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070064 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070065 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070066 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080067 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080068 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070069 private PageProgressView mProgressView;
Michael Kolb31d469b2010-12-09 20:49:54 -080070 private UrlInputView mUrlInput;
Michael Kolbcfa3af52010-12-14 10:36:11 -080071 private Drawable mFocusDrawable;
72 private Drawable mUnfocusDrawable;
73 private boolean mInVoiceMode;
Michael Kolb81b6f832010-12-12 12:44:27 -080074
Michael Kolba2b2ba82010-08-04 17:54:03 -070075 private boolean mInLoad;
Michael Kolbcfa3af52010-12-14 10:36:11 -080076 private boolean mEditable;
Michael Kolb376b5412010-12-15 11:52:57 -080077 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070078
Michael Kolb81b6f832010-12-12 12:44:27 -080079 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080080 XLargeUi ui) {
Michael Kolb8233fac2010-10-26 16:08:53 -070081 super(activity);
Michael Kolb8233fac2010-10-26 16:08:53 -070082 mUiController = controller;
Michael Kolb81b6f832010-12-12 12:44:27 -080083 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070084 Resources resources = activity.getResources();
Michael Kolbc7485ae2010-09-03 10:10:58 -070085 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal);
86 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal);
Michael Kolbcfa3af52010-12-14 10:36:11 -080087 mFocusDrawable = resources.getDrawable(
88 R.drawable.textfield_active_holo_dark);
89 mUnfocusDrawable = resources.getDrawable(
90 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080091 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080092 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070093 }
Leon Scroggins571b3762010-05-26 10:25:01 -040094
John Reck1605bef2011-01-10 18:11:18 -080095 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -070096 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -070097 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -070098
Michael Kolb3f65c382010-08-20 15:31:16 -070099 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800100 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700101 mAllButton = findViewById(R.id.all_btn);
102 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400103 // back/forward. Probably should be done inside onPageStarted.
104 mBackButton = findViewById(R.id.back);
105 mForwardButton = findViewById(R.id.forward);
Michael Kolb31d469b2010-12-09 20:49:54 -0800106 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700107 mStopButton = (ImageView) findViewById(R.id.stop);
108 mSearchButton = findViewById(R.id.search);
109 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700110 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700111 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800112 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700113 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800114 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800115 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700116 mBackButton.setOnClickListener(this);
117 mForwardButton.setOnClickListener(this);
118 mStar.setOnClickListener(this);
119 mAllButton.setOnClickListener(this);
120 mStopButton.setOnClickListener(this);
121 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700122 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700123 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800124 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800125 mUrlContainer.setOnClickListener(this);
126 mUrlInput.setUrlInputListener(this);
127 mUrlInput.setContainer(mUrlContainer);
128 mUrlInput.setController(mUiController);
129 mUrlInput.setOnFocusChangeListener(this);
130 mUrlInput.setSelectAllOnFocus(true);
131 mUrlInput.addTextChangedListener(this);
132 setUrlMode(false);
133 }
134
Michael Kolbcfa3af52010-12-14 10:36:11 -0800135 public void setEditable(boolean editable) {
136 mEditable = editable;
137 mUrlInput.setFocusable(mEditable);
138 if (!mEditable) {
139 mUrlInput.setOnClickListener(this);
140 } else {
141 mUrlContainer.setOnClickListener(null);
142 }
143 }
144
Michael Kolb376b5412010-12-15 11:52:57 -0800145 void setUseQuickControls(boolean useQuickControls) {
146 mUseQuickControls = useQuickControls;
John Reck1605bef2011-01-10 18:11:18 -0800147 mUrlInput.setReverseResults(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800148 if (mUseQuickControls) {
149 mBackButton.setVisibility(View.GONE);
150 mForwardButton.setVisibility(View.GONE);
151 mStopButton.setVisibility(View.GONE);
152 mAllButton.setVisibility(View.GONE);
153 } else {
154 mBackButton.setVisibility(View.VISIBLE);
155 mForwardButton.setVisibility(View.VISIBLE);
156 mStopButton.setVisibility(View.VISIBLE);
157 mAllButton.setVisibility(View.VISIBLE);
158 }
159 }
160
161 void setShowProgressOnly(boolean progress) {
162 if (progress) {
163 mContainer.setVisibility(View.GONE);
164 } else {
165 mContainer.setVisibility(View.VISIBLE);
166 }
167 }
168
Michael Kolb31d469b2010-12-09 20:49:54 -0800169 @Override
170 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800171 if (!mEditable && hasFocus) {
172 mUi.editUrl(false);
173 } else {
174 setUrlMode(hasFocus);
175 }
176 mUrlContainer.setBackgroundDrawable(hasFocus
177 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700178 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700179
Leon Scroggins4cd97792010-12-03 15:31:56 -0500180 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800181 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500182 }
183
Michael Kolb81b6f832010-12-12 12:44:27 -0800184 /**
185 * called from the Ui when the user wants to edit
186 * Note: only the fake titlebar will get this callback
187 * independent of which input field started the edit mode
188 * @param clearInput clear the input field
189 */
190 void onEditUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800191 // editing takes preference of progress
192 mContainer.setVisibility(View.VISIBLE);
193 if (mUseQuickControls) {
194 mProgressView.setVisibility(View.GONE);
195 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800196 if (!mUrlInput.hasFocus()) {
197 mUrlInput.requestFocus();
198 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800199 if (clearInput) {
200 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800201 } else if (mInVoiceMode) {
202 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800203 }
204 }
205
206 boolean isEditingUrl() {
207 return mUrlInput.hasFocus();
208 }
209
Michael Kolba2b2ba82010-08-04 17:54:03 -0700210 @Override
211 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800212 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800213 mUi.editUrl(false);
214 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800215 if (!mUrlInput.hasFocus()) {
216 mUi.editUrl(false);
217 }
218 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700220 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700222 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400224 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700225 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700227 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800228 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700229 } else if (mStopButton == v) {
230 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700231 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800232 if (!TextUtils.isEmpty(mUrlInput.getText())) {
233 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800234 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700235 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700236 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800237 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800238 } else if (mVoiceSearch == v) {
239 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700240 }
241 }
242
Michael Kolb3f65c382010-08-20 15:31:16 -0700243 int getHeightWithoutProgress() {
244 return mContainer.getHeight();
245 }
246
Michael Kolba2b2ba82010-08-04 17:54:03 -0700247 @Override
248 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700249
Michael Kolb31d469b2010-12-09 20:49:54 -0800250 private void clearOrClose() {
251 if (TextUtils.isEmpty(mUrlInput.getText())) {
252 // close
253 setUrlMode(false);
254 } else {
255 // clear
256 mUrlInput.setText("");
257 }
258 }
259
Michael Kolbfe251992010-07-08 15:41:55 -0700260 // UrlInputListener implementation
261
Michael Kolb81b6f832010-12-12 12:44:27 -0800262 /**
263 * callback from suggestion dropdown
264 * user selected a suggestion
265 */
Michael Kolbfe251992010-07-08 15:41:55 -0700266 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800267 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700268 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800269 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700270 Intent i = new Intent();
271 i.setAction(Intent.ACTION_SEARCH);
272 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800273 if (extra != null) {
274 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
275 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800276 if (source != null) {
277 Bundle appData = new Bundle();
278 appData.putString(com.android.common.Search.SOURCE, source);
279 i.putExtra(SearchManager.APP_DATA, appData);
280 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700281 mUiController.handleNewIntent(i);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700282 setUrlMode(false);
Michael Kolb513286f2010-09-09 12:55:12 -0700283 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700284 }
285
286 @Override
287 public void onDismiss() {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800288 WebView top = mUiController.getCurrentTopWebView();
289 if (top != null) {
290 mUiController.getCurrentTopWebView().requestFocus();
291 }
Michael Kolb66706532010-12-12 19:50:22 -0800292 mUi.hideFakeTitleBar();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700293 setUrlMode(false);
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800294 // if top != null current must be set
Michael Kolbcfa3af52010-12-14 10:36:11 -0800295 if ((top != null) && !mInVoiceMode) {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800296 setDisplayTitle(mUiController.getCurrentWebView().getUrl());
297 }
Michael Kolb513286f2010-09-09 12:55:12 -0700298 }
299
Michael Kolb81b6f832010-12-12 12:44:27 -0800300 /**
301 * callback from the suggestion dropdown
302 * copy text to input field and stay in edit mode
303 */
Michael Kolb513286f2010-09-09 12:55:12 -0700304 @Override
305 public void onEdit(String text) {
John Reck4851f9e2010-12-22 16:40:36 -0800306 mUrlInput.setText(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700307 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800308 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700309 }
310 }
311
Michael Kolb81b6f832010-12-12 12:44:27 -0800312 void setUrlMode(boolean focused) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700313 if (focused) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800314 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
315 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700316 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800317 mStar.setVisibility(View.GONE);
318 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800319 if (mInVoiceMode) {
320 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
321 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800322 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700323 } else {
Michael Kolb31d469b2010-12-09 20:49:54 -0800324 mUrlInput.clearFocus();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700325 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800326 mVoiceSearch.setVisibility(View.GONE);
327 mStar.setVisibility(View.VISIBLE);
328 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800329 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800330 if (mUseQuickControls) {
331 mSearchButton.setVisibility(View.GONE);
332 } else {
333 mSearchButton.setVisibility(View.VISIBLE);
334 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700335 }
336 }
337
Michael Kolba2b2ba82010-08-04 17:54:03 -0700338 private void stopOrRefresh() {
339 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700340 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700341 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700342 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700343 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400344 }
345
346 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700347 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400348 */
Michael Kolbfe251992010-07-08 15:41:55 -0700349 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700350 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800351 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700352 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800353 if (!blockvisuals) {
354 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
355 mProgressView.setVisibility(View.GONE);
356 mStopButton.setImageDrawable(mReloadDrawable);
357 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700358 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700359 } else {
360 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800361 if (!blockvisuals) {
362 mProgressView.setVisibility(View.VISIBLE);
363 mStopButton.setImageDrawable(mStopDrawable);
364 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700365 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700366 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700367 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
368 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700369 }
Michael Kolbfe251992010-07-08 15:41:55 -0700370 }
371
Michael Kolb31d469b2010-12-09 20:49:54 -0800372 private void updateSearchMode() {
373 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
374 }
375
376 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800377 SearchEngine searchEngine = BrowserSettings.getInstance()
378 .getSearchEngine();
379 boolean showvoicebutton = voiceSearchEnabled &&
380 (searchEngine != null && searchEngine.supportsVoiceSearch());
381 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800382 View.GONE);
383 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
384 View.VISIBLE);
385 }
386
Michael Kolbfe251992010-07-08 15:41:55 -0700387 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400388 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800389 if (!isEditingUrl()) {
390 mUrlInput.setText(title, false);
391 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700392 }
393
Michael Kolb31d469b2010-12-09 20:49:54 -0800394 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500395
Michael Kolb31d469b2010-12-09 20:49:54 -0800396 @Override
397 public void afterTextChanged(Editable s) {
398 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800399 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800400 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800401 // clear voice mode when user types
402 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500403 }
404 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800405
406 @Override
407 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
408 }
409
410 @Override
411 public void onTextChanged(CharSequence s, int start, int before, int count) {
412 }
413
Michael Kolbcfa3af52010-12-14 10:36:11 -0800414 // voicesearch
415
416 @Override
417 public void setInVoiceMode(boolean voicemode) {
418 setInVoiceMode(voicemode, null);
419 }
420
421 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
422 mInVoiceMode = voicemode;
423 mUrlInput.setVoiceResults(voiceResults);
424 mVoiceSearchIndicator.setVisibility(mInVoiceMode
425 ? View.VISIBLE : View.GONE);
426 }
427
Leon Scroggins571b3762010-05-26 10:25:01 -0400428}