blob: 0dcece60b4ed74705360b8eff213d1cd607d5bec [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);
Michael Kolb47171d82011-01-28 10:34:15 -0800136 setEditMode(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800137 }
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 {
Michael Kolb47171d82011-01-28 10:34:15 -0800190 if (hasFocus) {
191 setEditMode(hasFocus);
192 } else {
193 mUrlInput.stopEditing();
194 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800195 }
196 mUrlContainer.setBackgroundDrawable(hasFocus
197 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700198 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700199
Leon Scroggins4cd97792010-12-03 15:31:56 -0500200 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800201 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500202 }
203
Michael Kolb81b6f832010-12-12 12:44:27 -0800204 /**
205 * called from the Ui when the user wants to edit
206 * Note: only the fake titlebar will get this callback
207 * independent of which input field started the edit mode
208 * @param clearInput clear the input field
209 */
210 void onEditUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800211 // editing takes preference of progress
212 mContainer.setVisibility(View.VISIBLE);
213 if (mUseQuickControls) {
214 mProgressView.setVisibility(View.GONE);
215 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800216 if (!mUrlInput.hasFocus()) {
217 mUrlInput.requestFocus();
218 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800219 if (clearInput) {
220 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800221 } else if (mInVoiceMode) {
222 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800223 }
224 }
225
226 boolean isEditingUrl() {
227 return mUrlInput.hasFocus();
228 }
229
Michael Kolba2b2ba82010-08-04 17:54:03 -0700230 @Override
231 public void onClick(View v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800232 if (mUrlInput == v) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800233 mUi.editUrl(false);
234 } else if (mUrlContainer == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800235 if (!mUrlInput.hasFocus()) {
236 mUi.editUrl(false);
237 }
238 } else if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700239 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700240 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700242 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 mUiController.bookmarkCurrentPage(
Leon Scroggins88d08032010-10-21 15:17:10 -0400244 AddBookmarkPage.DEFAULT_FOLDER_ID);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700245 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700246 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700247 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800248 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700249 } else if (mStopButton == v) {
250 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700251 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800252 if (!TextUtils.isEmpty(mUrlInput.getText())) {
253 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800254 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700255 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700256 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800257 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800258 } else if (mVoiceSearch == v) {
259 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700260 }
261 }
262
Michael Kolb3f65c382010-08-20 15:31:16 -0700263 int getHeightWithoutProgress() {
264 return mContainer.getHeight();
265 }
266
Michael Kolba2b2ba82010-08-04 17:54:03 -0700267 @Override
268 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700269
Michael Kolb31d469b2010-12-09 20:49:54 -0800270 private void clearOrClose() {
271 if (TextUtils.isEmpty(mUrlInput.getText())) {
272 // close
Michael Kolb47171d82011-01-28 10:34:15 -0800273 mUrlInput.stopEditing();
Michael Kolb31d469b2010-12-09 20:49:54 -0800274 } else {
275 // clear
276 mUrlInput.setText("");
277 }
278 }
279
Michael Kolbfe251992010-07-08 15:41:55 -0700280 // UrlInputListener implementation
281
Michael Kolb81b6f832010-12-12 12:44:27 -0800282 /**
283 * callback from suggestion dropdown
284 * user selected a suggestion
285 */
Michael Kolbfe251992010-07-08 15:41:55 -0700286 @Override
Michael Kolb257cc2c2010-12-09 09:45:52 -0800287 public void onAction(String text, String extra, String source) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700288 mUiController.getCurrentTopWebView().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800289 mUi.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700290 Intent i = new Intent();
Michael Kolbbd2dd642011-01-13 13:01:30 -0800291 String action = null;
292 if (UrlInputView.VOICE.equals(source)) {
293 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
294 source = null;
295 } else {
296 action = Intent.ACTION_SEARCH;
297 }
298 i.setAction(action);
Michael Kolbfe251992010-07-08 15:41:55 -0700299 i.putExtra(SearchManager.QUERY, text);
John Reck40f720e2010-11-10 11:57:04 -0800300 if (extra != null) {
301 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
302 }
Michael Kolb257cc2c2010-12-09 09:45:52 -0800303 if (source != null) {
304 Bundle appData = new Bundle();
305 appData.putString(com.android.common.Search.SOURCE, source);
306 i.putExtra(SearchManager.APP_DATA, appData);
307 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700308 mUiController.handleNewIntent(i);
Michael Kolb513286f2010-09-09 12:55:12 -0700309 setDisplayTitle(text);
Michael Kolbfe251992010-07-08 15:41:55 -0700310 }
311
312 @Override
313 public void onDismiss() {
Michael Kolb47171d82011-01-28 10:34:15 -0800314 final Tab currentTab = mUi.getActiveTab();
Michael Kolb66706532010-12-12 19:50:22 -0800315 mUi.hideFakeTitleBar();
Michael Kolb47171d82011-01-28 10:34:15 -0800316 post(new Runnable() {
317 public void run() {
318 TitleBarXLarge.this.clearFocus();
319 if ((currentTab != null) && !mInVoiceMode) {
320 setDisplayTitle(currentTab.getUrl());
321 }
322 }
323 });
Michael Kolb513286f2010-09-09 12:55:12 -0700324 }
325
Michael Kolb81b6f832010-12-12 12:44:27 -0800326 /**
327 * callback from the suggestion dropdown
328 * copy text to input field and stay in edit mode
329 */
Michael Kolb513286f2010-09-09 12:55:12 -0700330 @Override
331 public void onEdit(String text) {
John Reck4851f9e2010-12-22 16:40:36 -0800332 mUrlInput.setText(text, true);
Michael Kolb513286f2010-09-09 12:55:12 -0700333 if (text != null) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800334 mUrlInput.setSelection(text.length());
Michael Kolb513286f2010-09-09 12:55:12 -0700335 }
336 }
337
Michael Kolb47171d82011-01-28 10:34:15 -0800338 void setEditMode(boolean edit) {
339 if (edit) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800340 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
341 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700342 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800343 mStar.setVisibility(View.GONE);
344 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800345 if (mInVoiceMode) {
346 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
347 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800348 mWebIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb31d469b2010-12-09 20:49:54 -0800349 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700350 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700351 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800352 mVoiceSearch.setVisibility(View.GONE);
353 mStar.setVisibility(View.VISIBLE);
354 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800355 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800356 if (mUseQuickControls) {
357 mSearchButton.setVisibility(View.GONE);
358 } else {
359 mSearchButton.setVisibility(View.VISIBLE);
360 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800361 mWebIcon.setImageResource(R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700362 }
363 }
364
Michael Kolba2b2ba82010-08-04 17:54:03 -0700365 private void stopOrRefresh() {
366 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700367 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700368 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700369 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700370 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400371 }
372
373 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700374 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400375 */
Michael Kolbfe251992010-07-08 15:41:55 -0700376 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700377 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800378 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700379 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800380 if (!blockvisuals) {
381 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
382 mProgressView.setVisibility(View.GONE);
383 mStopButton.setImageDrawable(mReloadDrawable);
384 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700385 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700386 } else {
387 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800388 if (!blockvisuals) {
389 mProgressView.setVisibility(View.VISIBLE);
390 mStopButton.setImageDrawable(mStopDrawable);
391 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700392 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700393 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700394 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
395 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700396 }
Michael Kolbfe251992010-07-08 15:41:55 -0700397 }
398
Michael Kolb31d469b2010-12-09 20:49:54 -0800399 private void updateSearchMode() {
400 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
401 }
402
403 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800404 SearchEngine searchEngine = BrowserSettings.getInstance()
405 .getSearchEngine();
406 boolean showvoicebutton = voiceSearchEnabled &&
407 (searchEngine != null && searchEngine.supportsVoiceSearch());
408 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800409 View.GONE);
410 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
411 View.VISIBLE);
412 }
413
Michael Kolbfe251992010-07-08 15:41:55 -0700414 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400415 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800416 if (!isEditingUrl()) {
417 mUrlInput.setText(title, false);
418 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700419 }
420
Michael Kolb31d469b2010-12-09 20:49:54 -0800421 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500422
Michael Kolb31d469b2010-12-09 20:49:54 -0800423 @Override
424 public void afterTextChanged(Editable s) {
425 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800426 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800427 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800428 // clear voice mode when user types
429 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500430 }
431 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800432
433 @Override
434 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
435 }
436
437 @Override
438 public void onTextChanged(CharSequence s, int start, int before, int count) {
439 }
440
Michael Kolbcfa3af52010-12-14 10:36:11 -0800441 // voicesearch
442
443 @Override
444 public void setInVoiceMode(boolean voicemode) {
445 setInVoiceMode(voicemode, null);
446 }
447
448 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
449 mInVoiceMode = voicemode;
450 mUrlInput.setVoiceResults(voiceResults);
451 mVoiceSearchIndicator.setVisibility(mInVoiceMode
452 ? View.VISIBLE : View.GONE);
453 }
454
John Reck117f07d2011-01-24 09:39:03 -0800455 @Override
456 void setIncognitoMode(boolean incognito) {
457 mUrlInput.setIncognitoMode(incognito);
458 }
Michael Kolb47171d82011-01-28 10:34:15 -0800459
Leon Scroggins571b3762010-05-26 10:25:01 -0400460}