blob: 3931526af5f5157c5d24a7de2f0498f48338406e [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 Kolbfe251992010-07-08 15:41:55 -070051 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040052
Michael Kolb66706532010-12-12 19:50:22 -080053 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070054
Michael Kolba2b2ba82010-08-04 17:54:03 -070055 private Drawable mStopDrawable;
56 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070057
Michael Kolb3f65c382010-08-20 15:31:16 -070058 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080059 private ImageButton mBackButton;
60 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080061 private ImageView mStar;
Michael Kolb5b2299c2011-01-25 16:54:34 -080062 private ImageView mWebIcon;
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 Kolbcfa3af52010-12-14 10:36:11 -080072 private Drawable mFocusDrawable;
73 private Drawable mUnfocusDrawable;
Michael Kolb81b6f832010-12-12 12:44:27 -080074
Michael Kolba2b2ba82010-08-04 17:54:03 -070075 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080076 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070077
Michael Kolb81b6f832010-12-12 12:44:27 -080078 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080079 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080080 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080081 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070082 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080083 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
84 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080085 mFocusDrawable = resources.getDrawable(
86 R.drawable.textfield_active_holo_dark);
87 mUnfocusDrawable = resources.getDrawable(
88 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080089 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080090 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070091 }
Leon Scroggins571b3762010-05-26 10:25:01 -040092
Michael Kolb7cdc4902011-02-03 17:54:40 -080093 @Override
94 void setTitleGravity(int gravity) {
95 if (mUseQuickControls) {
96 FrameLayout.LayoutParams lp =
97 (FrameLayout.LayoutParams) getLayoutParams();
98 lp.gravity = gravity;
99 setLayoutParams(lp);
100 } else {
101 super.setTitleGravity(gravity);
102 }
103 }
104
John Reck1605bef2011-01-10 18:11:18 -0800105 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700106 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700107 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700108
Michael Kolb3f65c382010-08-20 15:31:16 -0700109 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800110 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700111 mAllButton = findViewById(R.id.all_btn);
112 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400113 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800114 mBackButton = (ImageButton) findViewById(R.id.back);
115 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb5b2299c2011-01-25 16:54:34 -0800116 mWebIcon = (ImageView) findViewById(R.id.web_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800117 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700118 mStopButton = (ImageView) findViewById(R.id.stop);
119 mSearchButton = findViewById(R.id.search);
120 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700121 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700122 mClearButton = findViewById(R.id.clear);
Michael Kolb31d469b2010-12-09 20:49:54 -0800123 mVoiceSearch = findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700124 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800125 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800126 mVoiceSearchIndicator = findViewById(R.id.voice_icon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700127 mBackButton.setOnClickListener(this);
128 mForwardButton.setOnClickListener(this);
129 mStar.setOnClickListener(this);
130 mAllButton.setOnClickListener(this);
131 mStopButton.setOnClickListener(this);
132 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700133 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700134 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800135 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800136 mUrlInput.setUrlInputListener(this);
137 mUrlInput.setContainer(mUrlContainer);
138 mUrlInput.setController(mUiController);
139 mUrlInput.setOnFocusChangeListener(this);
140 mUrlInput.setSelectAllOnFocus(true);
141 mUrlInput.addTextChangedListener(this);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800142 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800143 }
144
Michael Kolb5a72f182011-01-13 20:35:06 -0800145 void updateNavigationState(Tab tab) {
146 WebView web = tab.getWebView();
147 if (web != null) {
148 mBackButton.setImageResource(web.canGoBack()
149 ? R.drawable.ic_back_holo_dark
150 : R.drawable.ic_back_disabled_holo_dark);
151 mForwardButton.setImageResource(web.canGoForward()
152 ? R.drawable.ic_forward_holo_dark
153 : R.drawable.ic_forward_disabled_holo_dark);
154 }
155 }
156
Michael Kolb7cdc4902011-02-03 17:54:40 -0800157 private ViewGroup.LayoutParams makeLayoutParams() {
158 if (mUseQuickControls) {
159 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
160 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800161 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800162 return new AbsoluteLayout.LayoutParams(
163 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
164 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800165 }
166 }
167
Michael Kolb376b5412010-12-15 11:52:57 -0800168 void setUseQuickControls(boolean useQuickControls) {
169 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800170 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800171 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800172 if (mUseQuickControls) {
173 mBackButton.setVisibility(View.GONE);
174 mForwardButton.setVisibility(View.GONE);
175 mStopButton.setVisibility(View.GONE);
176 mAllButton.setVisibility(View.GONE);
177 } else {
178 mBackButton.setVisibility(View.VISIBLE);
179 mForwardButton.setVisibility(View.VISIBLE);
180 mStopButton.setVisibility(View.VISIBLE);
181 mAllButton.setVisibility(View.VISIBLE);
182 }
183 }
184
185 void setShowProgressOnly(boolean progress) {
186 if (progress) {
187 mContainer.setVisibility(View.GONE);
188 } else {
189 mContainer.setVisibility(View.VISIBLE);
190 }
191 }
192
Michael Kolb31d469b2010-12-09 20:49:54 -0800193 @Override
194 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800195 // if losing focus and not in touch mode, leave as is
196 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
197 setFocusState(hasFocus);
198 mUrlContainer.setBackgroundDrawable(hasFocus
199 ? mFocusDrawable : mUnfocusDrawable);
200 }
201 if (hasFocus) {
202 mUrlInput.forceIme();
203 if (mInVoiceMode) {
204 mUrlInput.forceFilter();
205 }
206 } else if (!mUrlInput.needsUpdate()) {
207 mUrlInput.dismissDropDown();
208 mUrlInput.hideIME();
209 }
210 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700211 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700212
Leon Scroggins4cd97792010-12-03 15:31:56 -0500213 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800214 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500215 }
216
Michael Kolb81b6f832010-12-12 12:44:27 -0800217 /**
218 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800219 * @param clearInput clear the input field
220 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800221 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800222 // editing takes preference of progress
223 mContainer.setVisibility(View.VISIBLE);
224 if (mUseQuickControls) {
225 mProgressView.setVisibility(View.GONE);
226 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800227 if (!mUrlInput.hasFocus()) {
228 mUrlInput.requestFocus();
229 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800230 if (clearInput) {
231 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800232 } else if (mInVoiceMode) {
233 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800234 }
235 }
236
237 boolean isEditingUrl() {
238 return mUrlInput.hasFocus();
239 }
240
Michael Kolb7cdc4902011-02-03 17:54:40 -0800241 void stopEditingUrl() {
242 mUrlInput.clearFocus();
243 }
244
Michael Kolba2b2ba82010-08-04 17:54:03 -0700245 @Override
246 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800247 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700249 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700251 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500253 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700254 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700256 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800257 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700258 } else if (mStopButton == v) {
259 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700260 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800261 if (!TextUtils.isEmpty(mUrlInput.getText())) {
262 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800263 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700264 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700265 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800266 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800267 } else if (mVoiceSearch == v) {
268 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700269 }
270 }
271
Michael Kolba2b2ba82010-08-04 17:54:03 -0700272 @Override
273 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700274
Michael Kolb31d469b2010-12-09 20:49:54 -0800275 private void clearOrClose() {
276 if (TextUtils.isEmpty(mUrlInput.getText())) {
277 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800278 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800279 } else {
280 // clear
281 mUrlInput.setText("");
282 }
283 }
284
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800285 private void setFocusState(boolean focus) {
286 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800287 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
288 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700289 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800290 mStar.setVisibility(View.GONE);
291 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800292 if (mInVoiceMode) {
293 mVoiceSearchIndicator.setVisibility(View.VISIBLE);
294 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800295 mWebIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb31d469b2010-12-09 20:49:54 -0800296 updateSearchMode();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700297 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700298 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800299 mVoiceSearch.setVisibility(View.GONE);
300 mStar.setVisibility(View.VISIBLE);
301 mClearButton.setVisibility(View.GONE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800302 mVoiceSearchIndicator.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800303 if (mUseQuickControls) {
304 mSearchButton.setVisibility(View.GONE);
305 } else {
306 mSearchButton.setVisibility(View.VISIBLE);
307 }
Michael Kolb5b2299c2011-01-25 16:54:34 -0800308 mWebIcon.setImageResource(R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700309 }
310 }
311
Michael Kolba2b2ba82010-08-04 17:54:03 -0700312 private void stopOrRefresh() {
313 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700314 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700315 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700316 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700317 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400318 }
319
320 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700321 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400322 */
Michael Kolbfe251992010-07-08 15:41:55 -0700323 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700324 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800325 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700326 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800327 if (!blockvisuals) {
328 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
329 mProgressView.setVisibility(View.GONE);
330 mStopButton.setImageDrawable(mReloadDrawable);
331 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700332 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700333 } else {
334 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800335 if (!blockvisuals) {
336 mProgressView.setVisibility(View.VISIBLE);
337 mStopButton.setImageDrawable(mStopDrawable);
338 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700339 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700340 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700341 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
342 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700343 }
Michael Kolbfe251992010-07-08 15:41:55 -0700344 }
345
Michael Kolb31d469b2010-12-09 20:49:54 -0800346 private void updateSearchMode() {
347 setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
348 }
349
350 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800351 SearchEngine searchEngine = BrowserSettings.getInstance()
352 .getSearchEngine();
353 boolean showvoicebutton = voiceSearchEnabled &&
354 (searchEngine != null && searchEngine.supportsVoiceSearch());
355 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800356 View.GONE);
357 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
358 View.VISIBLE);
359 }
360
Michael Kolbfe251992010-07-08 15:41:55 -0700361 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400362 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800363 if (!isEditingUrl()) {
364 mUrlInput.setText(title, false);
365 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700366 }
367
Michael Kolb31d469b2010-12-09 20:49:54 -0800368 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500369
Michael Kolb31d469b2010-12-09 20:49:54 -0800370 @Override
371 public void afterTextChanged(Editable s) {
372 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800373 // check if input field is empty and adjust voice search state
Michael Kolb31d469b2010-12-09 20:49:54 -0800374 updateSearchMode();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800375 // clear voice mode when user types
376 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500377 }
378 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800379
380 @Override
381 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
382 }
383
384 @Override
385 public void onTextChanged(CharSequence s, int start, int before, int count) {
386 }
387
Michael Kolbcfa3af52010-12-14 10:36:11 -0800388 // voicesearch
389
390 @Override
391 public void setInVoiceMode(boolean voicemode) {
392 setInVoiceMode(voicemode, null);
393 }
394
395 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
396 mInVoiceMode = voicemode;
397 mUrlInput.setVoiceResults(voiceResults);
398 mVoiceSearchIndicator.setVisibility(mInVoiceMode
399 ? View.VISIBLE : View.GONE);
Michael Kolb3a2a1642011-02-15 10:52:07 -0800400 mWebIcon.setVisibility(mInVoiceMode ? View.GONE : View.VISIBLE);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800401 }
402
John Reck117f07d2011-01-24 09:39:03 -0800403 @Override
404 void setIncognitoMode(boolean incognito) {
405 mUrlInput.setIncognitoMode(incognito);
406 }
Michael Kolb47171d82011-01-28 10:34:15 -0800407
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800408 @Override
409 public View focusSearch(View focused, int dir) {
410 if (FOCUS_DOWN == dir && hasFocus()) {
411 return getCurrentWebView();
412 }
413 return super.focusSearch(focused, dir);
414 }
415
416 @Override
417 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
418 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
419 // catch back key in order to do slightly more cleanup than usual
420 mUrlInput.clearFocus();
421 return true;
422 }
423 return super.dispatchKeyEventPreIme(evt);
424 }
425
426 private WebView getCurrentWebView() {
427 Tab t = mUi.getActiveTab();
428 if (t != null) {
429 return t.getWebView();
430 } else {
431 return null;
432 }
433 }
434
Leon Scroggins571b3762010-05-26 10:25:01 -0400435}