blob: 85935a0e11b8f9ddd1186cabd89e2f91274fe97a [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 Kolb793e05e2011-01-11 15:17:31 -080019import com.android.browser.search.SearchEngine;
Michael Kolbc7485ae2010-09-03 10:10:58 -070020
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.app.Activity;
Leon Scroggins571b3762010-05-26 10:25:01 -040022import android.content.Context;
23import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070024import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040025import android.graphics.drawable.Drawable;
Michael Kolb31d469b2010-12-09 20:49:54 -080026import android.text.Editable;
Michael Kolb1ce78132010-09-23 15:50:53 -070027import android.text.TextUtils;
Michael Kolb31d469b2010-12-09 20:49:54 -080028import android.text.TextWatcher;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080029import android.util.Log;
30import android.view.KeyEvent;
Leon Scroggins571b3762010-05-26 10:25:01 -040031import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040032import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070033import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080034import android.view.View.OnFocusChangeListener;
Michael Kolb7cdc4902011-02-03 17:54:40 -080035import android.view.ViewGroup;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080036import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080037import android.widget.AbsoluteLayout;
38import android.widget.FrameLayout;
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
John Reck92026732011-02-15 10:12:30 -080048 implements OnClickListener, OnFocusChangeListener,
Michael Kolb31d469b2010-12-09 20:49:54 -080049 TextWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040050
Michael Kolb66706532010-12-12 19:50:22 -080051 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070052
Michael Kolba2b2ba82010-08-04 17:54:03 -070053 private Drawable mStopDrawable;
54 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070055
Michael Kolb3f65c382010-08-20 15:31:16 -070056 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080057 private ImageButton mBackButton;
58 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080059 private ImageView mStar;
Michael Kolb5b2299c2011-01-25 16:54:34 -080060 private ImageView mWebIcon;
Michael Kolba2b2ba82010-08-04 17:54:03 -070061 private View mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080062 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070063 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070064 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070065 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070066 private View mClearButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080067 private View mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080068 private View mVoiceSearchIndicator;
Michael Kolbc7485ae2010-09-03 10:10:58 -070069 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080070 private Drawable mFocusDrawable;
71 private Drawable mUnfocusDrawable;
Michael Kolb81b6f832010-12-12 12:44:27 -080072
Michael Kolba2b2ba82010-08-04 17:54:03 -070073 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080074 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070075
Michael Kolb81b6f832010-12-12 12:44:27 -080076 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080077 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080078 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080079 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070080 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080081 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
82 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080083 mFocusDrawable = resources.getDrawable(
84 R.drawable.textfield_active_holo_dark);
85 mUnfocusDrawable = resources.getDrawable(
86 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080087 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080088 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070089 }
Leon Scroggins571b3762010-05-26 10:25:01 -040090
Michael Kolb7cdc4902011-02-03 17:54:40 -080091 @Override
92 void setTitleGravity(int gravity) {
93 if (mUseQuickControls) {
94 FrameLayout.LayoutParams lp =
95 (FrameLayout.LayoutParams) getLayoutParams();
96 lp.gravity = gravity;
97 setLayoutParams(lp);
98 } else {
99 super.setTitleGravity(gravity);
100 }
101 }
102
John Reck1605bef2011-01-10 18:11:18 -0800103 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700104 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700105 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700106
Michael Kolb3f65c382010-08-20 15:31:16 -0700107 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800108 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700109 mAllButton = findViewById(R.id.all_btn);
110 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400111 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800112 mBackButton = (ImageButton) findViewById(R.id.back);
113 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb5b2299c2011-01-25 16:54:34 -0800114 mWebIcon = (ImageView) findViewById(R.id.web_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800115 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700116 mStopButton = (ImageView) findViewById(R.id.stop);
117 mSearchButton = findViewById(R.id.search);
118 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700119 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700120 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800121 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700122 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800123 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800124 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700125 mBackButton.setOnClickListener(this);
126 mForwardButton.setOnClickListener(this);
127 mStar.setOnClickListener(this);
128 mAllButton.setOnClickListener(this);
129 mStopButton.setOnClickListener(this);
130 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700131 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700132 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800133 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800134 mUrlInput.setUrlInputListener(this);
135 mUrlInput.setContainer(mUrlContainer);
136 mUrlInput.setController(mUiController);
137 mUrlInput.setOnFocusChangeListener(this);
138 mUrlInput.setSelectAllOnFocus(true);
139 mUrlInput.addTextChangedListener(this);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800140 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800141 }
142
Michael Kolb5a72f182011-01-13 20:35:06 -0800143 void updateNavigationState(Tab tab) {
144 WebView web = tab.getWebView();
145 if (web != null) {
146 mBackButton.setImageResource(web.canGoBack()
147 ? R.drawable.ic_back_holo_dark
148 : R.drawable.ic_back_disabled_holo_dark);
149 mForwardButton.setImageResource(web.canGoForward()
150 ? R.drawable.ic_forward_holo_dark
151 : R.drawable.ic_forward_disabled_holo_dark);
152 }
153 }
154
Michael Kolb7cdc4902011-02-03 17:54:40 -0800155 private ViewGroup.LayoutParams makeLayoutParams() {
156 if (mUseQuickControls) {
157 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
158 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800159 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800160 return new AbsoluteLayout.LayoutParams(
161 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
162 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800163 }
164 }
165
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800166 @Override
167 public int getEmbeddedHeight() {
168 return mContainer.getHeight();
169 }
170
Michael Kolb376b5412010-12-15 11:52:57 -0800171 void setUseQuickControls(boolean useQuickControls) {
172 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800173 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800174 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800175 if (mUseQuickControls) {
176 mBackButton.setVisibility(View.GONE);
177 mForwardButton.setVisibility(View.GONE);
178 mStopButton.setVisibility(View.GONE);
179 mAllButton.setVisibility(View.GONE);
180 } else {
181 mBackButton.setVisibility(View.VISIBLE);
182 mForwardButton.setVisibility(View.VISIBLE);
183 mStopButton.setVisibility(View.VISIBLE);
184 mAllButton.setVisibility(View.VISIBLE);
185 }
186 }
187
188 void setShowProgressOnly(boolean progress) {
189 if (progress) {
190 mContainer.setVisibility(View.GONE);
191 } else {
192 mContainer.setVisibility(View.VISIBLE);
193 }
194 }
195
Michael Kolb31d469b2010-12-09 20:49:54 -0800196 @Override
197 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800198 // if losing focus and not in touch mode, leave as is
199 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
200 setFocusState(hasFocus);
201 mUrlContainer.setBackgroundDrawable(hasFocus
202 ? mFocusDrawable : mUnfocusDrawable);
203 }
204 if (hasFocus) {
205 mUrlInput.forceIme();
206 if (mInVoiceMode) {
207 mUrlInput.forceFilter();
208 }
209 } else if (!mUrlInput.needsUpdate()) {
210 mUrlInput.dismissDropDown();
211 mUrlInput.hideIME();
212 }
213 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700214 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700215
John Reck94b7e042011-02-15 15:02:33 -0800216 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500217 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800218 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500219 }
220
Michael Kolb81b6f832010-12-12 12:44:27 -0800221 /**
222 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800223 * @param clearInput clear the input field
224 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800225 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800226 // editing takes preference of progress
227 mContainer.setVisibility(View.VISIBLE);
228 if (mUseQuickControls) {
229 mProgressView.setVisibility(View.GONE);
230 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800231 if (!mUrlInput.hasFocus()) {
232 mUrlInput.requestFocus();
233 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800234 if (clearInput) {
235 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800236 } else if (mInVoiceMode) {
237 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800238 }
239 }
240
241 boolean isEditingUrl() {
242 return mUrlInput.hasFocus();
243 }
244
Michael Kolb7cdc4902011-02-03 17:54:40 -0800245 void stopEditingUrl() {
246 mUrlInput.clearFocus();
247 }
248
Michael Kolba2b2ba82010-08-04 17:54:03 -0700249 @Override
250 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800251 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700253 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700255 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500257 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700258 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700260 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800261 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700262 } else if (mStopButton == v) {
263 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700264 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800265 if (!TextUtils.isEmpty(mUrlInput.getText())) {
266 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800267 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700268 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700269 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800270 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800271 } else if (mVoiceSearch == v) {
272 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700273 }
274 }
275
Michael Kolba2b2ba82010-08-04 17:54:03 -0700276 @Override
277 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700278
Michael Kolb31d469b2010-12-09 20:49:54 -0800279 private void clearOrClose() {
280 if (TextUtils.isEmpty(mUrlInput.getText())) {
281 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800282 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800283 } else {
284 // clear
285 mUrlInput.setText("");
286 }
287 }
288
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800289 private void setFocusState(boolean focus) {
290 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800291 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
292 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700293 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800294 mStar.setVisibility(View.GONE);
295 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800296 if (mInVoiceMode) {
297 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
298 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800299 mWebIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800300 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700301 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700302 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800303 mVoiceSearch.setVisibility(View.GONE);
304 mStar.setVisibility(View.VISIBLE);
305 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800306 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800307 if (mUseQuickControls) {
308 mSearchButton.setVisibility(View.GONE);
309 } else {
310 mSearchButton.setVisibility(View.VISIBLE);
311 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800312 mWebIcon.setImageResource(R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700313 }
314 }
315
Michael Kolba2b2ba82010-08-04 17:54:03 -0700316 private void stopOrRefresh() {
317 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700318 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700319 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700320 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700321 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400322 }
323
324 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700325 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400326 */
Michael Kolbfe251992010-07-08 15:41:55 -0700327 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700328 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800329 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700330 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800331 if (!blockvisuals) {
332 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
333 mProgressView.setVisibility(View.GONE);
334 mStopButton.setImageDrawable(mReloadDrawable);
335 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700336 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700337 } else {
338 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800339 if (!blockvisuals) {
340 mProgressView.setVisibility(View.VISIBLE);
341 mStopButton.setImageDrawable(mStopDrawable);
342 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700343 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700344 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700345 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
346 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700347 }
Michael Kolbfe251992010-07-08 15:41:55 -0700348 }
349
Michael Kolb60a68f52011-02-24 11:02:52 -0800350 private void updateSearchMode(boolean userEdited) {
351 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800352 }
353
354 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800355 SearchEngine searchEngine = BrowserSettings.getInstance()
356 .getSearchEngine();
357 boolean showvoicebutton = voiceSearchEnabled &&
358 (searchEngine != null && searchEngine.supportsVoiceSearch());
359 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800360 View.GONE);
361 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
362 View.VISIBLE);
363 }
364
Michael Kolbfe251992010-07-08 15:41:55 -0700365 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400366 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800367 if (!isEditingUrl()) {
368 mUrlInput.setText(title, false);
369 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700370 }
371
Michael Kolb31d469b2010-12-09 20:49:54 -0800372 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500373
Michael Kolb31d469b2010-12-09 20:49:54 -0800374 @Override
375 public void afterTextChanged(Editable s) {
376 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800377 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800378 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800379 // clear voice mode when user types
380 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500381 }
382 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800383
384 @Override
385 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
386 }
387
388 @Override
389 public void onTextChanged(CharSequence s, int start, int before, int count) {
390 }
391
Michael Kolbcfa3af52010-12-14 10:36:11 -0800392 // voicesearch
393
394 @Override
395 public void setInVoiceMode(boolean voicemode) {
396 setInVoiceMode(voicemode, null);
397 }
398
399 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
400 mInVoiceMode = voicemode;
401 mUrlInput.setVoiceResults(voiceResults);
402 mVoiceSearchIndicator.setVisibility(mInVoiceMode
403 ? View.VISIBLE : View.GONE);
Michael Kolb3a2a1642011-02-15 10:52:07 -0800404 mWebIcon.setVisibility(mInVoiceMode ? View.GONE : View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800405 }
406
John Reck117f07d2011-01-24 09:39:03 -0800407 @Override
408 void setIncognitoMode(boolean incognito) {
409 mUrlInput.setIncognitoMode(incognito);
410 }
Michael Kolb47171d82011-01-28 10:34:15 -0800411
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800412 @Override
413 public View focusSearch(View focused, int dir) {
414 if (FOCUS_DOWN == dir && hasFocus()) {
415 return getCurrentWebView();
416 }
417 return super.focusSearch(focused, dir);
418 }
419
420 @Override
421 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
422 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
423 // catch back key in order to do slightly more cleanup than usual
424 mUrlInput.clearFocus();
425 return true;
426 }
427 return super.dispatchKeyEventPreIme(evt);
428 }
429
430 private WebView getCurrentWebView() {
431 Tab t = mUi.getActiveTab();
432 if (t != null) {
433 return t.getWebView();
434 } else {
435 return null;
436 }
437 }
438
Leon Scroggins571b3762010-05-26 10:25:01 -0400439}