blob: 2fd9d3dfc5d9390d8d78d9396df9b2ffd26e9088 [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;
Michael Kolb5a72f182011-01-13 20:35:06 -080039import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040040import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040041
Michael Kolbcfa3af52010-12-14 10:36:11 -080042import java.util.List;
43
Leon Scroggins571b3762010-05-26 10:25:01 -040044/**
Michael Kolbfe251992010-07-08 15:41:55 -070045 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040046 */
Michael Kolbfe251992010-07-08 15:41:55 -070047public class TitleBarXLarge extends TitleBarBase
Michael Kolb31d469b2010-12-09 20:49:54 -080048 implements UrlInputListener, OnClickListener, OnFocusChangeListener,
49 TextWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040050
Michael Kolbfe251992010-07-08 15:41:55 -070051 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040052
Michael Kolb8233fac2010-10-26 16:08:53 -070053 private UiController mUiController;
Michael Kolb66706532010-12-12 19:50:22 -080054 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070055
Michael Kolba2b2ba82010-08-04 17:54:03 -070056 private Drawable mStopDrawable;
57 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070058
Michael Kolb3f65c382010-08-20 15:31:16 -070059 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080060 private ImageButton mBackButton;
61 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080062 private ImageView mStar;
Michael Kolb5b2299c2011-01-25 16:54:34 -080063 private ImageView mWebIcon;
Michael Kolba2b2ba82010-08-04 17:54:03 -070064 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080065 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070066 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070067 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070068 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070069 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080070 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080071 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070072 private PageProgressView mProgressView;
Michael Kolb31d469b2010-12-09 20:49:54 -080073 private UrlInputView mUrlInput;
Michael Kolbcfa3af52010-12-14 10:36:11 -080074 private Drawable mFocusDrawable;
75 private Drawable mUnfocusDrawable;
76 private boolean mInVoiceMode;
Michael Kolb81b6f832010-12-12 12:44:27 -080077
Michael Kolba2b2ba82010-08-04 17:54:03 -070078 private boolean mInLoad;
Michael Kolbcfa3af52010-12-14 10:36:11 -080079 private boolean mEditable;
Michael Kolb376b5412010-12-15 11:52:57 -080080 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070081
Michael Kolb81b6f832010-12-12 12:44:27 -080082 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080083 XLargeUi ui) {
Michael Kolb8233fac2010-10-26 16:08:53 -070084 super(activity);
Michael Kolb8233fac2010-10-26 16:08:53 -070085 mUiController = controller;
Michael Kolb81b6f832010-12-12 12:44:27 -080086 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070087 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080088 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
89 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080090 mFocusDrawable = resources.getDrawable(
91 R.drawable.textfield_active_holo_dark);
92 mUnfocusDrawable = resources.getDrawable(
93 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080094 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080095 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070096 }
Leon Scroggins571b3762010-05-26 10:25:01 -040097
John Reck1605bef2011-01-10 18:11:18 -080098 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -070099 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700100 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700101
Michael Kolb3f65c382010-08-20 15:31:16 -0700102 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800103 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700104 mAllButton = findViewById(R.id.all_btn);
105 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400106 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800107 mBackButton = (ImageButton) findViewById(R.id.back);
108 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb5b2299c2011-01-25 16:54:34 -0800109 mWebIcon = (ImageView) findViewById(R.id.web_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800110 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700111 mStopButton = (ImageView) findViewById(R.id.stop);
112 mSearchButton = findViewById(R.id.search);
113 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700114 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700115 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800116 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700117 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800118 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800119 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700120 mBackButton.setOnClickListener(this);
121 mForwardButton.setOnClickListener(this);
122 mStar.setOnClickListener(this);
123 mAllButton.setOnClickListener(this);
124 mStopButton.setOnClickListener(this);
125 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700126 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700127 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800128 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800129 mUrlContainer.setOnClickListener(this);
130 mUrlInput.setUrlInputListener(this);
131 mUrlInput.setContainer(mUrlContainer);
132 mUrlInput.setController(mUiController);
133 mUrlInput.setOnFocusChangeListener(this);
134 mUrlInput.setSelectAllOnFocus(true);
135 mUrlInput.addTextChangedListener(this);
136 setUrlMode(false);
137 }
138
Michael Kolb5a72f182011-01-13 20:35:06 -0800139 void updateNavigationState(Tab tab) {
140 WebView web = tab.getWebView();
141 if (web != null) {
142 mBackButton.setImageResource(web.canGoBack()
143 ? R.drawable.ic_back_holo_dark
144 : R.drawable.ic_back_disabled_holo_dark);
145 mForwardButton.setImageResource(web.canGoForward()
146 ? R.drawable.ic_forward_holo_dark
147 : R.drawable.ic_forward_disabled_holo_dark);
148 }
149 }
150
Michael Kolbcfa3af52010-12-14 10:36:11 -0800151 public void setEditable(boolean editable) {
152 mEditable = editable;
153 mUrlInput.setFocusable(mEditable);
154 if (!mEditable) {
155 mUrlInput.setOnClickListener(this);
156 } else {
157 mUrlContainer.setOnClickListener(null);
158 }
159 }
160
Michael Kolb376b5412010-12-15 11:52:57 -0800161 void setUseQuickControls(boolean useQuickControls) {
162 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800163 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800164 if (mUseQuickControls) {
165 mBackButton.setVisibility(View.GONE);
166 mForwardButton.setVisibility(View.GONE);
167 mStopButton.setVisibility(View.GONE);
168 mAllButton.setVisibility(View.GONE);
169 } else {
170 mBackButton.setVisibility(View.VISIBLE);
171 mForwardButton.setVisibility(View.VISIBLE);
172 mStopButton.setVisibility(View.VISIBLE);
173 mAllButton.setVisibility(View.VISIBLE);
174 }
175 }
176
177 void setShowProgressOnly(boolean progress) {
178 if (progress) {
179 mContainer.setVisibility(View.GONE);
180 } else {
181 mContainer.setVisibility(View.VISIBLE);
182 }
183 }
184
Michael Kolb31d469b2010-12-09 20:49:54 -0800185 @Override
186 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800187 if (!mEditable && hasFocus) {
188 mUi.editUrl(false);
189 } else {
190 setUrlMode(hasFocus);
191 }
192 mUrlContainer.setBackgroundDrawable(hasFocus
193 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700194 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700195
Leon Scroggins4cd97792010-12-03 15:31:56 -0500196 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800197 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500198 }
199
Michael Kolb81b6f832010-12-12 12:44:27 -0800200 /**
201 * called from the Ui when the user wants to edit
202 * Note: only the fake titlebar will get this callback
203 * independent of which input field started the edit mode
204 * @param clearInput clear the input field
205 */
206 void onEditUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800207 // editing takes preference of progress
208 mContainer.setVisibility(View.VISIBLE);
209 if (mUseQuickControls) {
210 mProgressView.setVisibility(View.GONE);
211 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800212 if (!mUrlInput.hasFocus()) {
213 mUrlInput.requestFocus();
214 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800215 if (clearInput) {
216 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800217 } else if (mInVoiceMode) {
218 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800219 }
220 }
221
222 boolean isEditingUrl() {
223 return mUrlInput.hasFocus();
224 }
225
Michael Kolba2b2ba82010-08-04 17:54:03 -0700226 @Override
227 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800228 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800229 mUi.editUrl(false);
230 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800231 if (!mUrlInput.hasFocus()) {
232 mUi.editUrl(false);
233 }
234 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700236 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700237 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700238 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700239 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400240 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700241 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700243 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800244 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700245 } else if (mStopButton == v) {
246 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700247 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800248 if (!TextUtils.isEmpty(mUrlInput.getText())) {
249 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800250 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700251 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700252 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800253 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800254 } else if (mVoiceSearch == v) {
255 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700256 }
257 }
258
Michael Kolb3f65c382010-08-20 15:31:16 -0700259 int getHeightWithoutProgress() {
260 return mContainer.getHeight();
261 }
262
Michael Kolba2b2ba82010-08-04 17:54:03 -0700263 @Override
264 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700265
Michael Kolb31d469b2010-12-09 20:49:54 -0800266 private void clearOrClose() {
267 if (TextUtils.isEmpty(mUrlInput.getText())) {
268 // close
269 setUrlMode(false);
270 } else {
271 // clear
272 mUrlInput.setText("");
273 }
274 }
275
Michael Kolbfe251992010-07-08 15:41:55 -0700276 // UrlInputListener implementation
277
Michael Kolb81b6f832010-12-12 12:44:27 -0800278 /**
279 * callback from suggestion dropdown
280 * user selected a suggestion
281 */
Michael Kolbfe251992010-07-08 15:41:55 -0700282 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800283 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700284 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800285 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700286 Intent i = new Intent();
Michael Kolbbd2dd642011-01-13 13:01:30 -0800287 String action = null;
288 if (UrlInputView.VOICE.equals(source)) {
289 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
290 source = null;
291 } else {
292 action = Intent.ACTION_SEARCH;
293 }
294 i.setAction(action);
Michael Kolbfe251992010-07-08 15:41:55 -0700295 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800296 if (extra != null) {
297 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
298 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800299 if (source != null) {
300 Bundle appData = new Bundle();
301 appData.putString(com.android.common.Search.SOURCE, source);
302 i.putExtra(SearchManager.APP_DATA, appData);
303 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700304 mUiController.handleNewIntent(i);
Michael Kolb513286f2010-09-09 12:55:12 -0700305 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700306 }
307
308 @Override
309 public void onDismiss() {
John Reckf93a7072011-01-26 14:51:40 -0800310 Tab currentTab = mUi.getActiveTab();
311 if (currentTab != null && currentTab.getWebView() != null) {
312 currentTab.getWebView().requestFocus();
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800313 }
Michael Kolb66706532010-12-12 19:50:22 -0800314 mUi.hideFakeTitleBar();
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800315 // if top != null current must be set
John Reckf93a7072011-01-26 14:51:40 -0800316 if ((currentTab != null) && !mInVoiceMode) {
317 setDisplayTitle(currentTab.getUrl());
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800318 }
Michael Kolb513286f2010-09-09 12:55:12 -0700319 }
320
Michael Kolb81b6f832010-12-12 12:44:27 -0800321 /**
322 * callback from the suggestion dropdown
323 * copy text to input field and stay in edit mode
324 */
Michael Kolb513286f2010-09-09 12:55:12 -0700325 @Override
326 public void onEdit(String text) {
John Reck4851f9e2010-12-22 16:40:36 -0800327 mUrlInput.setText(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700328 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800329 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700330 }
331 }
332
Michael Kolb81b6f832010-12-12 12:44:27 -0800333 void setUrlMode(boolean focused) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700334 if (focused) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800335 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
336 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700337 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800338 mStar.setVisibility(View.GONE);
339 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800340 if (mInVoiceMode) {
341 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
342 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800343 mWebIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb31d469b2010-12-09 20:49:54 -0800344 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700345 } else {
Michael Kolbaba92432011-01-27 14:01:53 -0800346 if (mUrlInput.hasFocus()) {
347 mUrlInput.clearFocus();
348 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700349 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800350 mVoiceSearch.setVisibility(View.GONE);
351 mStar.setVisibility(View.VISIBLE);
352 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800353 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800354 if (mUseQuickControls) {
355 mSearchButton.setVisibility(View.GONE);
356 } else {
357 mSearchButton.setVisibility(View.VISIBLE);
358 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800359 mWebIcon.setImageResource(R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700360 }
361 }
362
Michael Kolba2b2ba82010-08-04 17:54:03 -0700363 private void stopOrRefresh() {
364 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700365 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700366 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700367 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700368 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400369 }
370
371 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700372 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400373 */
Michael Kolbfe251992010-07-08 15:41:55 -0700374 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700375 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800376 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700377 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800378 if (!blockvisuals) {
379 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
380 mProgressView.setVisibility(View.GONE);
381 mStopButton.setImageDrawable(mReloadDrawable);
382 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700383 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700384 } else {
385 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800386 if (!blockvisuals) {
387 mProgressView.setVisibility(View.VISIBLE);
388 mStopButton.setImageDrawable(mStopDrawable);
389 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700390 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700391 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700392 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
393 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700394 }
Michael Kolbfe251992010-07-08 15:41:55 -0700395 }
396
Michael Kolb31d469b2010-12-09 20:49:54 -0800397 private void updateSearchMode() {
398 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
399 }
400
401 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800402 SearchEngine searchEngine = BrowserSettings.getInstance()
403 .getSearchEngine();
404 boolean showvoicebutton = voiceSearchEnabled &&
405 (searchEngine != null && searchEngine.supportsVoiceSearch());
406 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800407 View.GONE);
408 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
409 View.VISIBLE);
410 }
411
Michael Kolbfe251992010-07-08 15:41:55 -0700412 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400413 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800414 if (!isEditingUrl()) {
415 mUrlInput.setText(title, false);
416 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700417 }
418
Michael Kolb31d469b2010-12-09 20:49:54 -0800419 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500420
Michael Kolb31d469b2010-12-09 20:49:54 -0800421 @Override
422 public void afterTextChanged(Editable s) {
423 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800424 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800425 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800426 // clear voice mode when user types
427 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500428 }
429 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800430
431 @Override
432 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
433 }
434
435 @Override
436 public void onTextChanged(CharSequence s, int start, int before, int count) {
437 }
438
Michael Kolbcfa3af52010-12-14 10:36:11 -0800439 // voicesearch
440
441 @Override
442 public void setInVoiceMode(boolean voicemode) {
443 setInVoiceMode(voicemode, null);
444 }
445
446 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
447 mInVoiceMode = voicemode;
448 mUrlInput.setVoiceResults(voiceResults);
449 mVoiceSearchIndicator.setVisibility(mInVoiceMode
450 ? View.VISIBLE : View.GONE);
451 }
452
John Reck117f07d2011-01-24 09:39:03 -0800453 @Override
454 void setIncognitoMode(boolean incognito) {
455 mUrlInput.setIncognitoMode(incognito);
456 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400457}