blob: 453e1b88a596149b6367bf6f4598558930d6c915 [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 Kolb7cdc4902011-02-03 17:54:40 -080038import android.view.ViewGroup;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080039import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080040import android.widget.AbsoluteLayout;
41import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080042import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040043import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040044
Michael Kolbcfa3af52010-12-14 10:36:11 -080045import java.util.List;
46
Leon Scroggins571b3762010-05-26 10:25:01 -040047/**
Michael Kolbfe251992010-07-08 15:41:55 -070048 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040049 */
Michael Kolbfe251992010-07-08 15:41:55 -070050public class TitleBarXLarge extends TitleBarBase
Michael Kolb31d469b2010-12-09 20:49:54 -080051 implements UrlInputListener, OnClickListener, OnFocusChangeListener,
52 TextWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040053
Michael Kolbfe251992010-07-08 15:41:55 -070054 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040055
Michael Kolb8233fac2010-10-26 16:08:53 -070056 private UiController mUiController;
Michael Kolb66706532010-12-12 19:50:22 -080057 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070058
Michael Kolba2b2ba82010-08-04 17:54:03 -070059 private Drawable mStopDrawable;
60 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070061
Michael Kolb3f65c382010-08-20 15:31:16 -070062 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080063 private ImageButton mBackButton;
64 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080065 private ImageView mStar;
Michael Kolb5b2299c2011-01-25 16:54:34 -080066 private ImageView mWebIcon;
Michael Kolba2b2ba82010-08-04 17:54:03 -070067 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080068 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070069 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070070 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070071 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070072 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080073 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080074 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070075 private PageProgressView mProgressView;
Michael Kolb31d469b2010-12-09 20:49:54 -080076 private UrlInputView mUrlInput;
Michael Kolbcfa3af52010-12-14 10:36:11 -080077 private Drawable mFocusDrawable;
78 private Drawable mUnfocusDrawable;
79 private boolean mInVoiceMode;
Michael Kolb81b6f832010-12-12 12:44:27 -080080
Michael Kolba2b2ba82010-08-04 17:54:03 -070081 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080082 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070083
Michael Kolb81b6f832010-12-12 12:44:27 -080084 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080085 XLargeUi ui) {
Michael Kolb8233fac2010-10-26 16:08:53 -070086 super(activity);
Michael Kolb8233fac2010-10-26 16:08:53 -070087 mUiController = controller;
Michael Kolb81b6f832010-12-12 12:44:27 -080088 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070089 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080090 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
91 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080092 mFocusDrawable = resources.getDrawable(
93 R.drawable.textfield_active_holo_dark);
94 mUnfocusDrawable = resources.getDrawable(
95 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080096 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080097 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070098 }
Leon Scroggins571b3762010-05-26 10:25:01 -040099
Michael Kolb7cdc4902011-02-03 17:54:40 -0800100 @Override
101 void setTitleGravity(int gravity) {
102 if (mUseQuickControls) {
103 FrameLayout.LayoutParams lp =
104 (FrameLayout.LayoutParams) getLayoutParams();
105 lp.gravity = gravity;
106 setLayoutParams(lp);
107 } else {
108 super.setTitleGravity(gravity);
109 }
110 }
111
John Reck1605bef2011-01-10 18:11:18 -0800112 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700113 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700114 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700115
Michael Kolb3f65c382010-08-20 15:31:16 -0700116 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800117 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700118 mAllButton = findViewById(R.id.all_btn);
119 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400120 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800121 mBackButton = (ImageButton) findViewById(R.id.back);
122 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb5b2299c2011-01-25 16:54:34 -0800123 mWebIcon = (ImageView) findViewById(R.id.web_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800124 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700125 mStopButton = (ImageView) findViewById(R.id.stop);
126 mSearchButton = findViewById(R.id.search);
127 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700128 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700129 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800130 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700131 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800132 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800133 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700134 mBackButton.setOnClickListener(this);
135 mForwardButton.setOnClickListener(this);
136 mStar.setOnClickListener(this);
137 mAllButton.setOnClickListener(this);
138 mStopButton.setOnClickListener(this);
139 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700140 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700141 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800142 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800143 mUrlInput.setUrlInputListener(this);
144 mUrlInput.setContainer(mUrlContainer);
145 mUrlInput.setController(mUiController);
146 mUrlInput.setOnFocusChangeListener(this);
147 mUrlInput.setSelectAllOnFocus(true);
148 mUrlInput.addTextChangedListener(this);
Michael Kolb47171d82011-01-28 10:34:15 -0800149 setEditMode(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800150 }
151
Michael Kolb5a72f182011-01-13 20:35:06 -0800152 void updateNavigationState(Tab tab) {
153 WebView web = tab.getWebView();
154 if (web != null) {
155 mBackButton.setImageResource(web.canGoBack()
156 ? R.drawable.ic_back_holo_dark
157 : R.drawable.ic_back_disabled_holo_dark);
158 mForwardButton.setImageResource(web.canGoForward()
159 ? R.drawable.ic_forward_holo_dark
160 : R.drawable.ic_forward_disabled_holo_dark);
161 }
162 }
163
Michael Kolb7cdc4902011-02-03 17:54:40 -0800164 private ViewGroup.LayoutParams makeLayoutParams() {
165 if (mUseQuickControls) {
166 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
167 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800168 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800169 return new AbsoluteLayout.LayoutParams(
170 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
171 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800172 }
173 }
174
Michael Kolb376b5412010-12-15 11:52:57 -0800175 void setUseQuickControls(boolean useQuickControls) {
176 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800177 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800178 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800179 if (mUseQuickControls) {
180 mBackButton.setVisibility(View.GONE);
181 mForwardButton.setVisibility(View.GONE);
182 mStopButton.setVisibility(View.GONE);
183 mAllButton.setVisibility(View.GONE);
184 } else {
185 mBackButton.setVisibility(View.VISIBLE);
186 mForwardButton.setVisibility(View.VISIBLE);
187 mStopButton.setVisibility(View.VISIBLE);
188 mAllButton.setVisibility(View.VISIBLE);
189 }
190 }
191
192 void setShowProgressOnly(boolean progress) {
193 if (progress) {
194 mContainer.setVisibility(View.GONE);
195 } else {
196 mContainer.setVisibility(View.VISIBLE);
197 }
198 }
199
Michael Kolb31d469b2010-12-09 20:49:54 -0800200 @Override
201 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800202 setEditMode(hasFocus);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800203 mUrlContainer.setBackgroundDrawable(hasFocus
204 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700205 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700206
Leon Scroggins4cd97792010-12-03 15:31:56 -0500207 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800208 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500209 }
210
Michael Kolb81b6f832010-12-12 12:44:27 -0800211 /**
212 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800213 * @param clearInput clear the input field
214 */
215 void onEditUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800216 // editing takes preference of progress
217 mContainer.setVisibility(View.VISIBLE);
218 if (mUseQuickControls) {
219 mProgressView.setVisibility(View.GONE);
220 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800221 if (!mUrlInput.hasFocus()) {
222 mUrlInput.requestFocus();
223 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800224 if (clearInput) {
225 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800226 } else if (mInVoiceMode) {
227 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800228 }
229 }
230
231 boolean isEditingUrl() {
232 return mUrlInput.hasFocus();
233 }
234
Michael Kolb7cdc4902011-02-03 17:54:40 -0800235 void stopEditingUrl() {
236 mUrlInput.clearFocus();
237 }
238
Michael Kolba2b2ba82010-08-04 17:54:03 -0700239 @Override
240 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800241 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700243 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700245 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700246 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500247 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700248 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700250 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800251 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700252 } else if (mStopButton == v) {
253 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700254 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800255 if (!TextUtils.isEmpty(mUrlInput.getText())) {
256 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800257 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700258 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700259 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800260 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800261 } else if (mVoiceSearch == v) {
262 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700263 }
264 }
265
Michael Kolba2b2ba82010-08-04 17:54:03 -0700266 @Override
267 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700268
Michael Kolb31d469b2010-12-09 20:49:54 -0800269 private void clearOrClose() {
270 if (TextUtils.isEmpty(mUrlInput.getText())) {
271 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800272 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800273 } else {
274 // clear
275 mUrlInput.setText("");
276 }
277 }
278
Michael Kolbfe251992010-07-08 15:41:55 -0700279 // UrlInputListener implementation
280
Michael Kolb81b6f832010-12-12 12:44:27 -0800281 /**
282 * callback from suggestion dropdown
283 * user selected a suggestion
284 */
Michael Kolbfe251992010-07-08 15:41:55 -0700285 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800286 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700287 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800288 mUi.hideTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700289 Intent i = new Intent();
Michael Kolbbd2dd642011-01-13 13:01:30 -0800290 String action = null;
291 if (UrlInputView.VOICE.equals(source)) {
292 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
293 source = null;
294 } else {
295 action = Intent.ACTION_SEARCH;
296 }
297 i.setAction(action);
Michael Kolbfe251992010-07-08 15:41:55 -0700298 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800299 if (extra != null) {
300 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
301 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800302 if (source != null) {
303 Bundle appData = new Bundle();
304 appData.putString(com.android.common.Search.SOURCE, source);
305 i.putExtra(SearchManager.APP_DATA, appData);
306 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700307 mUiController.handleNewIntent(i);
Michael Kolb513286f2010-09-09 12:55:12 -0700308 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700309 }
310
311 @Override
312 public void onDismiss() {
Michael Kolb47171d82011-01-28 10:34:15 -0800313 final Tab currentTab = mUi.getActiveTab();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800314 mUi.hideTitleBar();
Michael Kolb47171d82011-01-28 10:34:15 -0800315 post(new Runnable() {
316 public void run() {
317 TitleBarXLarge.this.clearFocus();
318 if ((currentTab != null) && !mInVoiceMode) {
319 setDisplayTitle(currentTab.getUrl());
320 }
321 }
322 });
Michael Kolb513286f2010-09-09 12:55:12 -0700323 }
324
Michael Kolb81b6f832010-12-12 12:44:27 -0800325 /**
326 * callback from the suggestion dropdown
327 * copy text to input field and stay in edit mode
328 */
Michael Kolb513286f2010-09-09 12:55:12 -0700329 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800330 public void onCopySuggestion(String text) {
John Reck4851f9e2010-12-22 16:40:36 -0800331 mUrlInput.setText(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700332 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800333 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700334 }
335 }
336
Michael Kolb7cdc4902011-02-03 17:54:40 -0800337 private void setEditMode(boolean edit) {
Michael Kolb47171d82011-01-28 10:34:15 -0800338 if (edit) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800339 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
340 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700341 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800342 mStar.setVisibility(View.GONE);
343 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800344 if (mInVoiceMode) {
345 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
346 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800347 mWebIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb31d469b2010-12-09 20:49:54 -0800348 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700349 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700350 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800351 mVoiceSearch.setVisibility(View.GONE);
352 mStar.setVisibility(View.VISIBLE);
353 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800354 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800355 if (mUseQuickControls) {
356 mSearchButton.setVisibility(View.GONE);
357 } else {
358 mSearchButton.setVisibility(View.VISIBLE);
359 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800360 mWebIcon.setImageResource(R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700361 }
362 }
363
Michael Kolba2b2ba82010-08-04 17:54:03 -0700364 private void stopOrRefresh() {
365 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700366 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700367 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700368 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700369 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400370 }
371
372 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700373 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400374 */
Michael Kolbfe251992010-07-08 15:41:55 -0700375 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700376 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800377 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700378 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800379 if (!blockvisuals) {
380 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
381 mProgressView.setVisibility(View.GONE);
382 mStopButton.setImageDrawable(mReloadDrawable);
383 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700384 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700385 } else {
386 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800387 if (!blockvisuals) {
388 mProgressView.setVisibility(View.VISIBLE);
389 mStopButton.setImageDrawable(mStopDrawable);
390 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700391 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700392 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700393 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
394 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700395 }
Michael Kolbfe251992010-07-08 15:41:55 -0700396 }
397
Michael Kolb31d469b2010-12-09 20:49:54 -0800398 private void updateSearchMode() {
399 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
400 }
401
402 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800403 SearchEngine searchEngine = BrowserSettings.getInstance()
404 .getSearchEngine();
405 boolean showvoicebutton = voiceSearchEnabled &&
406 (searchEngine != null && searchEngine.supportsVoiceSearch());
407 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800408 View.GONE);
409 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
410 View.VISIBLE);
411 }
412
Michael Kolbfe251992010-07-08 15:41:55 -0700413 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400414 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800415 if (!isEditingUrl()) {
416 mUrlInput.setText(title, false);
417 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700418 }
419
Michael Kolb31d469b2010-12-09 20:49:54 -0800420 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500421
Michael Kolb31d469b2010-12-09 20:49:54 -0800422 @Override
423 public void afterTextChanged(Editable s) {
424 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800425 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800426 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800427 // clear voice mode when user types
428 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500429 }
430 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800431
432 @Override
433 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
434 }
435
436 @Override
437 public void onTextChanged(CharSequence s, int start, int before, int count) {
438 }
439
Michael Kolbcfa3af52010-12-14 10:36:11 -0800440 // voicesearch
441
442 @Override
443 public void setInVoiceMode(boolean voicemode) {
444 setInVoiceMode(voicemode, null);
445 }
446
447 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
448 mInVoiceMode = voicemode;
449 mUrlInput.setVoiceResults(voiceResults);
450 mVoiceSearchIndicator.setVisibility(mInVoiceMode
451 ? View.VISIBLE : View.GONE);
452 }
453
John Reck117f07d2011-01-24 09:39:03 -0800454 @Override
455 void setIncognitoMode(boolean incognito) {
456 mUrlInput.setIncognitoMode(incognito);
457 }
Michael Kolb47171d82011-01-28 10:34:15 -0800458
Leon Scroggins571b3762010-05-26 10:25:01 -0400459}