blob: 4822cc077621b693e0aaa67726ea674e18cd1dc3 [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 Kolba2b2ba82010-08-04 17:54:03 -070063 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080064 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070065 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070066 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070067 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070068 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080069 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080070 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070071 private PageProgressView mProgressView;
Michael Kolb31d469b2010-12-09 20:49:54 -080072 private UrlInputView mUrlInput;
Michael Kolbcfa3af52010-12-14 10:36:11 -080073 private Drawable mFocusDrawable;
74 private Drawable mUnfocusDrawable;
75 private boolean mInVoiceMode;
Michael Kolb81b6f832010-12-12 12:44:27 -080076
Michael Kolba2b2ba82010-08-04 17:54:03 -070077 private boolean mInLoad;
Michael Kolbcfa3af52010-12-14 10:36:11 -080078 private boolean mEditable;
Michael Kolb376b5412010-12-15 11:52:57 -080079 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070080
Michael Kolb81b6f832010-12-12 12:44:27 -080081 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080082 XLargeUi ui) {
Michael Kolb8233fac2010-10-26 16:08:53 -070083 super(activity);
Michael Kolb8233fac2010-10-26 16:08:53 -070084 mUiController = controller;
Michael Kolb81b6f832010-12-12 12:44:27 -080085 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070086 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080087 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
88 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080089 mFocusDrawable = resources.getDrawable(
90 R.drawable.textfield_active_holo_dark);
91 mUnfocusDrawable = resources.getDrawable(
92 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080093 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080094 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070095 }
Leon Scroggins571b3762010-05-26 10:25:01 -040096
John Reck1605bef2011-01-10 18:11:18 -080097 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -070098 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -070099 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700100
Michael Kolb3f65c382010-08-20 15:31:16 -0700101 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800102 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700103 mAllButton = findViewById(R.id.all_btn);
104 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400105 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800106 mBackButton = (ImageButton) findViewById(R.id.back);
107 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb31d469b2010-12-09 20:49:54 -0800108 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700109 mStopButton = (ImageView) findViewById(R.id.stop);
110 mSearchButton = findViewById(R.id.search);
111 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700112 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700113 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800114 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700115 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800116 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800117 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700118 mBackButton.setOnClickListener(this);
119 mForwardButton.setOnClickListener(this);
120 mStar.setOnClickListener(this);
121 mAllButton.setOnClickListener(this);
122 mStopButton.setOnClickListener(this);
123 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700124 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700125 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800126 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800127 mUrlContainer.setOnClickListener(this);
128 mUrlInput.setUrlInputListener(this);
129 mUrlInput.setContainer(mUrlContainer);
130 mUrlInput.setController(mUiController);
131 mUrlInput.setOnFocusChangeListener(this);
132 mUrlInput.setSelectAllOnFocus(true);
133 mUrlInput.addTextChangedListener(this);
134 setUrlMode(false);
135 }
136
Michael Kolb5a72f182011-01-13 20:35:06 -0800137 void updateNavigationState(Tab tab) {
138 WebView web = tab.getWebView();
139 if (web != null) {
140 mBackButton.setImageResource(web.canGoBack()
141 ? R.drawable.ic_back_holo_dark
142 : R.drawable.ic_back_disabled_holo_dark);
143 mForwardButton.setImageResource(web.canGoForward()
144 ? R.drawable.ic_forward_holo_dark
145 : R.drawable.ic_forward_disabled_holo_dark);
146 }
147 }
148
Michael Kolbcfa3af52010-12-14 10:36:11 -0800149 public void setEditable(boolean editable) {
150 mEditable = editable;
151 mUrlInput.setFocusable(mEditable);
152 if (!mEditable) {
153 mUrlInput.setOnClickListener(this);
154 } else {
155 mUrlContainer.setOnClickListener(null);
156 }
157 }
158
Michael Kolb376b5412010-12-15 11:52:57 -0800159 void setUseQuickControls(boolean useQuickControls) {
160 mUseQuickControls = useQuickControls;
John Reck1605bef2011-01-10 18:11:18 -0800161 mUrlInput.setReverseResults(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800162 if (mUseQuickControls) {
163 mBackButton.setVisibility(View.GONE);
164 mForwardButton.setVisibility(View.GONE);
165 mStopButton.setVisibility(View.GONE);
166 mAllButton.setVisibility(View.GONE);
167 } else {
168 mBackButton.setVisibility(View.VISIBLE);
169 mForwardButton.setVisibility(View.VISIBLE);
170 mStopButton.setVisibility(View.VISIBLE);
171 mAllButton.setVisibility(View.VISIBLE);
172 }
173 }
174
175 void setShowProgressOnly(boolean progress) {
176 if (progress) {
177 mContainer.setVisibility(View.GONE);
178 } else {
179 mContainer.setVisibility(View.VISIBLE);
180 }
181 }
182
Michael Kolb31d469b2010-12-09 20:49:54 -0800183 @Override
184 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800185 if (!mEditable && hasFocus) {
186 mUi.editUrl(false);
187 } else {
188 setUrlMode(hasFocus);
189 }
190 mUrlContainer.setBackgroundDrawable(hasFocus
191 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700192 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700193
Leon Scroggins4cd97792010-12-03 15:31:56 -0500194 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800195 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500196 }
197
Michael Kolb81b6f832010-12-12 12:44:27 -0800198 /**
199 * called from the Ui when the user wants to edit
200 * Note: only the fake titlebar will get this callback
201 * independent of which input field started the edit mode
202 * @param clearInput clear the input field
203 */
204 void onEditUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800205 // editing takes preference of progress
206 mContainer.setVisibility(View.VISIBLE);
207 if (mUseQuickControls) {
208 mProgressView.setVisibility(View.GONE);
209 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800210 if (!mUrlInput.hasFocus()) {
211 mUrlInput.requestFocus();
212 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800213 if (clearInput) {
214 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800215 } else if (mInVoiceMode) {
216 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800217 }
218 }
219
220 boolean isEditingUrl() {
221 return mUrlInput.hasFocus();
222 }
223
Michael Kolba2b2ba82010-08-04 17:54:03 -0700224 @Override
225 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800226 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800227 mUi.editUrl(false);
228 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800229 if (!mUrlInput.hasFocus()) {
230 mUi.editUrl(false);
231 }
232 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700234 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700236 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700237 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400238 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700239 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700241 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800242 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700243 } else if (mStopButton == v) {
244 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700245 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800246 if (!TextUtils.isEmpty(mUrlInput.getText())) {
247 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800248 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700249 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700250 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800251 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800252 } else if (mVoiceSearch == v) {
253 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700254 }
255 }
256
Michael Kolb3f65c382010-08-20 15:31:16 -0700257 int getHeightWithoutProgress() {
258 return mContainer.getHeight();
259 }
260
Michael Kolba2b2ba82010-08-04 17:54:03 -0700261 @Override
262 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700263
Michael Kolb31d469b2010-12-09 20:49:54 -0800264 private void clearOrClose() {
265 if (TextUtils.isEmpty(mUrlInput.getText())) {
266 // close
267 setUrlMode(false);
268 } else {
269 // clear
270 mUrlInput.setText("");
271 }
272 }
273
Michael Kolbfe251992010-07-08 15:41:55 -0700274 // UrlInputListener implementation
275
Michael Kolb81b6f832010-12-12 12:44:27 -0800276 /**
277 * callback from suggestion dropdown
278 * user selected a suggestion
279 */
Michael Kolbfe251992010-07-08 15:41:55 -0700280 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800281 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700282 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800283 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700284 Intent i = new Intent();
Michael Kolbbd2dd642011-01-13 13:01:30 -0800285 String action = null;
286 if (UrlInputView.VOICE.equals(source)) {
287 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
288 source = null;
289 } else {
290 action = Intent.ACTION_SEARCH;
291 }
292 i.setAction(action);
Michael Kolbfe251992010-07-08 15:41:55 -0700293 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800294 if (extra != null) {
295 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
296 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800297 if (source != null) {
298 Bundle appData = new Bundle();
299 appData.putString(com.android.common.Search.SOURCE, source);
300 i.putExtra(SearchManager.APP_DATA, appData);
301 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700302 mUiController.handleNewIntent(i);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700303 setUrlMode(false);
Michael Kolb513286f2010-09-09 12:55:12 -0700304 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700305 }
306
307 @Override
308 public void onDismiss() {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800309 WebView top = mUiController.getCurrentTopWebView();
310 if (top != null) {
311 mUiController.getCurrentTopWebView().requestFocus();
312 }
Michael Kolb66706532010-12-12 19:50:22 -0800313 mUi.hideFakeTitleBar();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700314 setUrlMode(false);
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800315 // if top != null current must be set
Michael Kolbcfa3af52010-12-14 10:36:11 -0800316 if ((top != null) && !mInVoiceMode) {
Michael Kolbb6bc32c2010-12-10 11:51:54 -0800317 setDisplayTitle(mUiController.getCurrentWebView().getUrl());
318 }
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 Kolb31d469b2010-12-09 20:49:54 -0800343 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700344 } else {
Michael Kolb31d469b2010-12-09 20:49:54 -0800345 mUrlInput.clearFocus();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700346 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800347 mVoiceSearch.setVisibility(View.GONE);
348 mStar.setVisibility(View.VISIBLE);
349 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800350 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800351 if (mUseQuickControls) {
352 mSearchButton.setVisibility(View.GONE);
353 } else {
354 mSearchButton.setVisibility(View.VISIBLE);
355 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700356 }
357 }
358
Michael Kolba2b2ba82010-08-04 17:54:03 -0700359 private void stopOrRefresh() {
360 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700361 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700362 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700363 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700364 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400365 }
366
367 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700368 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400369 */
Michael Kolbfe251992010-07-08 15:41:55 -0700370 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700371 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800372 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700373 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800374 if (!blockvisuals) {
375 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
376 mProgressView.setVisibility(View.GONE);
377 mStopButton.setImageDrawable(mReloadDrawable);
378 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700379 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700380 } else {
381 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800382 if (!blockvisuals) {
383 mProgressView.setVisibility(View.VISIBLE);
384 mStopButton.setImageDrawable(mStopDrawable);
385 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700386 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700387 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700388 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
389 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700390 }
Michael Kolbfe251992010-07-08 15:41:55 -0700391 }
392
Michael Kolb31d469b2010-12-09 20:49:54 -0800393 private void updateSearchMode() {
394 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
395 }
396
397 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800398 SearchEngine searchEngine = BrowserSettings.getInstance()
399 .getSearchEngine();
400 boolean showvoicebutton = voiceSearchEnabled &&
401 (searchEngine != null && searchEngine.supportsVoiceSearch());
402 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800403 View.GONE);
404 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
405 View.VISIBLE);
406 }
407
Michael Kolbfe251992010-07-08 15:41:55 -0700408 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400409 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800410 if (!isEditingUrl()) {
411 mUrlInput.setText(title, false);
412 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700413 }
414
Michael Kolb31d469b2010-12-09 20:49:54 -0800415 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500416
Michael Kolb31d469b2010-12-09 20:49:54 -0800417 @Override
418 public void afterTextChanged(Editable s) {
419 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800420 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800421 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800422 // clear voice mode when user types
423 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500424 }
425 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800426
427 @Override
428 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
429 }
430
431 @Override
432 public void onTextChanged(CharSequence s, int start, int before, int count) {
433 }
434
Michael Kolbcfa3af52010-12-14 10:36:11 -0800435 // voicesearch
436
437 @Override
438 public void setInVoiceMode(boolean voicemode) {
439 setInVoiceMode(voicemode, null);
440 }
441
442 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
443 mInVoiceMode = voicemode;
444 mUrlInput.setVoiceResults(voiceResults);
445 mVoiceSearchIndicator.setVisibility(mInVoiceMode
446 ? View.VISIBLE : View.GONE);
447 }
448
John Reck117f07d2011-01-24 09:39:03 -0800449 @Override
450 void setIncognitoMode(boolean incognito) {
451 mUrlInput.setIncognitoMode(incognito);
452 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400453}