blob: b5a8032c28c128d947e3607fa4d2dcd22ff0b3ee [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 Kolbbd2dd642011-01-13 13:01:30 -080030import android.speech.RecognizerResultsIntent;
Michael Kolb31d469b2010-12-09 20:49:54 -080031import android.text.Editable;
Michael Kolb1ce78132010-09-23 15:50:53 -070032import android.text.TextUtils;
Michael Kolb31d469b2010-12-09 20:49:54 -080033import android.text.TextWatcher;
Leon Scroggins571b3762010-05-26 10:25:01 -040034import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040035import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070036import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080037import android.view.View.OnFocusChangeListener;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080038import android.webkit.WebView;
Leon Scroggins571b3762010-05-26 10:25:01 -040039import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040040
Michael Kolbcfa3af52010-12-14 10:36:11 -080041import java.util.List;
42
Leon Scroggins571b3762010-05-26 10:25:01 -040043/**
Michael Kolbfe251992010-07-08 15:41:55 -070044 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040045 */
Michael Kolbfe251992010-07-08 15:41:55 -070046public class TitleBarXLarge extends TitleBarBase
Michael Kolb31d469b2010-12-09 20:49:54 -080047 implements UrlInputListener, OnClickListener, OnFocusChangeListener,
48 TextWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040049
Michael Kolbfe251992010-07-08 15:41:55 -070050 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040051
Michael Kolb8233fac2010-10-26 16:08:53 -070052 private UiController mUiController;
Michael Kolb66706532010-12-12 19:50:22 -080053 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070054
Michael Kolba2b2ba82010-08-04 17:54:03 -070055 private Drawable mStopDrawable;
56 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070057
Michael Kolb3f65c382010-08-20 15:31:16 -070058 private View mContainer;
Michael Kolba2b2ba82010-08-04 17:54:03 -070059 private View mBackButton;
60 private View mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080061 private ImageView mStar;
Michael Kolba2b2ba82010-08-04 17:54:03 -070062 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080063 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070064 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070065 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070066 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070067 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080068 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080069 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070070 private PageProgressView mProgressView;
Michael Kolb31d469b2010-12-09 20:49:54 -080071 private UrlInputView mUrlInput;
Michael Kolbcfa3af52010-12-14 10:36:11 -080072 private Drawable mFocusDrawable;
73 private Drawable mUnfocusDrawable;
74 private boolean mInVoiceMode;
Michael Kolb81b6f832010-12-12 12:44:27 -080075
Michael Kolba2b2ba82010-08-04 17:54:03 -070076 private boolean mInLoad;
Michael Kolbcfa3af52010-12-14 10:36:11 -080077 private boolean mEditable;
Michael Kolb376b5412010-12-15 11:52:57 -080078 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070079
Michael Kolb81b6f832010-12-12 12:44:27 -080080 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080081 XLargeUi ui) {
Michael Kolb8233fac2010-10-26 16:08:53 -070082 super(activity);
Michael Kolb8233fac2010-10-26 16:08:53 -070083 mUiController = controller;
Michael Kolb81b6f832010-12-12 12:44:27 -080084 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070085 Resources resources = activity.getResources();
Michael Kolbc7485ae2010-09-03 10:10:58 -070086 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal);
87 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal);
Michael Kolbcfa3af52010-12-14 10:36:11 -080088 mFocusDrawable = resources.getDrawable(
89 R.drawable.textfield_active_holo_dark);
90 mUnfocusDrawable = resources.getDrawable(
91 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080092 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080093 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070094 }
Leon Scroggins571b3762010-05-26 10:25:01 -040095
John Reck1605bef2011-01-10 18:11:18 -080096 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -070097 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -070098 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -070099
Michael Kolb3f65c382010-08-20 15:31:16 -0700100 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800101 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700102 mAllButton = findViewById(R.id.all_btn);
103 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400104 // back/forward. Probably should be done inside onPageStarted.
105 mBackButton = findViewById(R.id.back);
106 mForwardButton = findViewById(R.id.forward);
Michael Kolb31d469b2010-12-09 20:49:54 -0800107 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700108 mStopButton = (ImageView) findViewById(R.id.stop);
109 mSearchButton = findViewById(R.id.search);
110 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700111 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700112 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800113 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700114 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800115 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800116 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700117 mBackButton.setOnClickListener(this);
118 mForwardButton.setOnClickListener(this);
119 mStar.setOnClickListener(this);
120 mAllButton.setOnClickListener(this);
121 mStopButton.setOnClickListener(this);
122 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700123 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700124 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800125 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800126 mUrlContainer.setOnClickListener(this);
127 mUrlInput.setUrlInputListener(this);
128 mUrlInput.setContainer(mUrlContainer);
129 mUrlInput.setController(mUiController);
130 mUrlInput.setOnFocusChangeListener(this);
131 mUrlInput.setSelectAllOnFocus(true);
132 mUrlInput.addTextChangedListener(this);
133 setUrlMode(false);
134 }
135
Michael Kolbcfa3af52010-12-14 10:36:11 -0800136 public void setEditable(boolean editable) {
137 mEditable = editable;
138 mUrlInput.setFocusable(mEditable);
139 if (!mEditable) {
140 mUrlInput.setOnClickListener(this);
141 } else {
142 mUrlContainer.setOnClickListener(null);
143 }
144 }
145
Michael Kolb376b5412010-12-15 11:52:57 -0800146 void setUseQuickControls(boolean useQuickControls) {
147 mUseQuickControls = useQuickControls;
John Reck1605bef2011-01-10 18:11:18 -0800148 mUrlInput.setReverseResults(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800149 if (mUseQuickControls) {
150 mBackButton.setVisibility(View.GONE);
151 mForwardButton.setVisibility(View.GONE);
152 mStopButton.setVisibility(View.GONE);
153 mAllButton.setVisibility(View.GONE);
154 } else {
155 mBackButton.setVisibility(View.VISIBLE);
156 mForwardButton.setVisibility(View.VISIBLE);
157 mStopButton.setVisibility(View.VISIBLE);
158 mAllButton.setVisibility(View.VISIBLE);
159 }
160 }
161
162 void setShowProgressOnly(boolean progress) {
163 if (progress) {
164 mContainer.setVisibility(View.GONE);
165 } else {
166 mContainer.setVisibility(View.VISIBLE);
167 }
168 }
169
Michael Kolb31d469b2010-12-09 20:49:54 -0800170 @Override
171 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800172 if (!mEditable && hasFocus) {
173 mUi.editUrl(false);
174 } else {
175 setUrlMode(hasFocus);
176 }
177 mUrlContainer.setBackgroundDrawable(hasFocus
178 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700179 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700180
Leon Scroggins4cd97792010-12-03 15:31:56 -0500181 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800182 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500183 }
184
Michael Kolb81b6f832010-12-12 12:44:27 -0800185 /**
186 * called from the Ui when the user wants to edit
187 * Note: only the fake titlebar will get this callback
188 * independent of which input field started the edit mode
189 * @param clearInput clear the input field
190 */
191 void onEditUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800192 // editing takes preference of progress
193 mContainer.setVisibility(View.VISIBLE);
194 if (mUseQuickControls) {
195 mProgressView.setVisibility(View.GONE);
196 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800197 if (!mUrlInput.hasFocus()) {
198 mUrlInput.requestFocus();
199 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800200 if (clearInput) {
201 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800202 } else if (mInVoiceMode) {
203 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800204 }
205 }
206
207 boolean isEditingUrl() {
208 return mUrlInput.hasFocus();
209 }
210
Michael Kolba2b2ba82010-08-04 17:54:03 -0700211 @Override
212 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800213 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800214 mUi.editUrl(false);
215 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800216 if (!mUrlInput.hasFocus()) {
217 mUi.editUrl(false);
218 }
219 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700221 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700223 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700224 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400225 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700226 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700228 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800229 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700230 } else if (mStopButton == v) {
231 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700232 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800233 if (!TextUtils.isEmpty(mUrlInput.getText())) {
234 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800235 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700236 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700237 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800238 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800239 } else if (mVoiceSearch == v) {
240 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700241 }
242 }
243
Michael Kolb3f65c382010-08-20 15:31:16 -0700244 int getHeightWithoutProgress() {
245 return mContainer.getHeight();
246 }
247
Michael Kolba2b2ba82010-08-04 17:54:03 -0700248 @Override
249 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700250
Michael Kolb31d469b2010-12-09 20:49:54 -0800251 private void clearOrClose() {
252 if (TextUtils.isEmpty(mUrlInput.getText())) {
253 // close
254 setUrlMode(false);
255 } else {
256 // clear
257 mUrlInput.setText("");
258 }
259 }
260
Michael Kolbfe251992010-07-08 15:41:55 -0700261 // UrlInputListener implementation
262
Michael Kolb81b6f832010-12-12 12:44:27 -0800263 /**
264 * callback from suggestion dropdown
265 * user selected a suggestion
266 */
Michael Kolbfe251992010-07-08 15:41:55 -0700267 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800268 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800270 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700271 Intent i = new Intent();
Michael Kolbbd2dd642011-01-13 13:01:30 -0800272 String action = null;
273 if (UrlInputView.VOICE.equals(source)) {
274 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
275 source = null;
276 } else {
277 action = Intent.ACTION_SEARCH;
278 }
279 i.setAction(action);
Michael Kolbfe251992010-07-08 15:41:55 -0700280 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800281 if (extra != null) {
282 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
283 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800284 if (source != null) {
285 Bundle appData = new Bundle();
286 appData.putString(com.android.common.Search.SOURCE, source);
287 i.putExtra(SearchManager.APP_DATA, appData);
288 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700289 mUiController.handleNewIntent(i);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700290 setUrlMode(false);
Michael Kolb513286f2010-09-09 12:55:12 -0700291 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700292 }
293
294 @Override
295 public void onDismiss() {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800296 WebView top = mUiController.getCurrentTopWebView();
297 if (top != null) {
298 mUiController.getCurrentTopWebView().requestFocus();
299 }
Michael Kolb66706532010-12-12 19:50:22 -0800300 mUi.hideFakeTitleBar();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700301 setUrlMode(false);
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800302 // if top != null current must be set
Michael Kolbcfa3af52010-12-14 10:36:11 -0800303 if ((top != null) && !mInVoiceMode) {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800304 setDisplayTitle(mUiController.getCurrentWebView().getUrl());
305 }
Michael Kolb513286f2010-09-09 12:55:12 -0700306 }
307
Michael Kolb81b6f832010-12-12 12:44:27 -0800308 /**
309 * callback from the suggestion dropdown
310 * copy text to input field and stay in edit mode
311 */
Michael Kolb513286f2010-09-09 12:55:12 -0700312 @Override
313 public void onEdit(String text) {
John Reck4851f9e2010-12-22 16:40:36 -0800314 mUrlInput.setText(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700315 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800316 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700317 }
318 }
319
Michael Kolb81b6f832010-12-12 12:44:27 -0800320 void setUrlMode(boolean focused) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700321 if (focused) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800322 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
323 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700324 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800325 mStar.setVisibility(View.GONE);
326 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800327 if (mInVoiceMode) {
328 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
329 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800330 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700331 } else {
Michael Kolb31d469b2010-12-09 20:49:54 -0800332 mUrlInput.clearFocus();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700333 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800334 mVoiceSearch.setVisibility(View.GONE);
335 mStar.setVisibility(View.VISIBLE);
336 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800337 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800338 if (mUseQuickControls) {
339 mSearchButton.setVisibility(View.GONE);
340 } else {
341 mSearchButton.setVisibility(View.VISIBLE);
342 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700343 }
344 }
345
Michael Kolba2b2ba82010-08-04 17:54:03 -0700346 private void stopOrRefresh() {
347 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700348 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700349 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700350 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700351 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400352 }
353
354 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700355 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400356 */
Michael Kolbfe251992010-07-08 15:41:55 -0700357 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700358 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800359 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700360 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800361 if (!blockvisuals) {
362 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
363 mProgressView.setVisibility(View.GONE);
364 mStopButton.setImageDrawable(mReloadDrawable);
365 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700366 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700367 } else {
368 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800369 if (!blockvisuals) {
370 mProgressView.setVisibility(View.VISIBLE);
371 mStopButton.setImageDrawable(mStopDrawable);
372 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700373 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700374 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700375 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
376 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700377 }
Michael Kolbfe251992010-07-08 15:41:55 -0700378 }
379
Michael Kolb31d469b2010-12-09 20:49:54 -0800380 private void updateSearchMode() {
381 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
382 }
383
384 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800385 SearchEngine searchEngine = BrowserSettings.getInstance()
386 .getSearchEngine();
387 boolean showvoicebutton = voiceSearchEnabled &&
388 (searchEngine != null && searchEngine.supportsVoiceSearch());
389 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800390 View.GONE);
391 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
392 View.VISIBLE);
393 }
394
Michael Kolbfe251992010-07-08 15:41:55 -0700395 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400396 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800397 if (!isEditingUrl()) {
398 mUrlInput.setText(title, false);
399 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700400 }
401
Michael Kolb31d469b2010-12-09 20:49:54 -0800402 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500403
Michael Kolb31d469b2010-12-09 20:49:54 -0800404 @Override
405 public void afterTextChanged(Editable s) {
406 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800407 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800408 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800409 // clear voice mode when user types
410 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500411 }
412 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800413
414 @Override
415 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
416 }
417
418 @Override
419 public void onTextChanged(CharSequence s, int start, int before, int count) {
420 }
421
Michael Kolbcfa3af52010-12-14 10:36:11 -0800422 // voicesearch
423
424 @Override
425 public void setInVoiceMode(boolean voicemode) {
426 setInVoiceMode(voicemode, null);
427 }
428
429 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
430 mInVoiceMode = voicemode;
431 mUrlInput.setVoiceResults(voiceResults);
432 mVoiceSearchIndicator.setVisibility(mInVoiceMode
433 ? View.VISIBLE : View.GONE);
434 }
435
Leon Scroggins571b3762010-05-26 10:25:01 -0400436}