blob: d5a6f9735a512b1138306611c01971f78af75c33 [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 Kolbe3524d82011-03-02 14:53:15 -080060 private ImageView mUrlIcon;
61 private ImageView 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 Kolbe3524d82011-03-02 14:53:15 -080067 private ImageView mVoiceSearch;
Michael Kolbc7485ae2010-09-03 10:10:58 -070068 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080069 private Drawable mFocusDrawable;
70 private Drawable mUnfocusDrawable;
Michael Kolb81b6f832010-12-12 12:44:27 -080071
Michael Kolba2b2ba82010-08-04 17:54:03 -070072 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080073 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070074
Michael Kolb81b6f832010-12-12 12:44:27 -080075 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080076 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080077 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080078 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070079 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080080 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
81 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080082 mFocusDrawable = resources.getDrawable(
83 R.drawable.textfield_active_holo_dark);
84 mUnfocusDrawable = resources.getDrawable(
85 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080086 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080087 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070088 }
Leon Scroggins571b3762010-05-26 10:25:01 -040089
Michael Kolb7cdc4902011-02-03 17:54:40 -080090 @Override
91 void setTitleGravity(int gravity) {
92 if (mUseQuickControls) {
93 FrameLayout.LayoutParams lp =
94 (FrameLayout.LayoutParams) getLayoutParams();
95 lp.gravity = gravity;
96 setLayoutParams(lp);
97 } else {
98 super.setTitleGravity(gravity);
99 }
100 }
101
John Reck1605bef2011-01-10 18:11:18 -0800102 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700103 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700104 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700105
Michael Kolb3f65c382010-08-20 15:31:16 -0700106 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800107 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700108 mAllButton = findViewById(R.id.all_btn);
109 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400110 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800111 mBackButton = (ImageButton) findViewById(R.id.back);
112 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -0800113 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800114 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700115 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -0800116 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700117 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700118 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700119 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -0800120 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700121 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800122 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700123 mBackButton.setOnClickListener(this);
124 mForwardButton.setOnClickListener(this);
125 mStar.setOnClickListener(this);
126 mAllButton.setOnClickListener(this);
127 mStopButton.setOnClickListener(this);
128 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700129 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700130 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800131 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800132 mUrlInput.setUrlInputListener(this);
133 mUrlInput.setContainer(mUrlContainer);
134 mUrlInput.setController(mUiController);
135 mUrlInput.setOnFocusChangeListener(this);
136 mUrlInput.setSelectAllOnFocus(true);
137 mUrlInput.addTextChangedListener(this);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800138 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800139 }
140
Michael Kolb5a72f182011-01-13 20:35:06 -0800141 void updateNavigationState(Tab tab) {
142 WebView web = tab.getWebView();
143 if (web != null) {
144 mBackButton.setImageResource(web.canGoBack()
145 ? R.drawable.ic_back_holo_dark
146 : R.drawable.ic_back_disabled_holo_dark);
147 mForwardButton.setImageResource(web.canGoForward()
148 ? R.drawable.ic_forward_holo_dark
149 : R.drawable.ic_forward_disabled_holo_dark);
150 }
151 }
152
Michael Kolb7cdc4902011-02-03 17:54:40 -0800153 private ViewGroup.LayoutParams makeLayoutParams() {
154 if (mUseQuickControls) {
155 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
156 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800157 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800158 return new AbsoluteLayout.LayoutParams(
159 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
160 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800161 }
162 }
163
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800164 @Override
165 public int getEmbeddedHeight() {
166 return mContainer.getHeight();
167 }
168
Michael Kolb376b5412010-12-15 11:52:57 -0800169 void setUseQuickControls(boolean useQuickControls) {
170 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800171 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800172 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800173 }
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 Kolbdc2ee1b2011-02-14 14:34:40 -0800185 // if losing focus and not in touch mode, leave as is
186 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
187 setFocusState(hasFocus);
188 mUrlContainer.setBackgroundDrawable(hasFocus
189 ? mFocusDrawable : mUnfocusDrawable);
190 }
191 if (hasFocus) {
192 mUrlInput.forceIme();
193 if (mInVoiceMode) {
194 mUrlInput.forceFilter();
195 }
196 } else if (!mUrlInput.needsUpdate()) {
197 mUrlInput.dismissDropDown();
198 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800199 if (mUseQuickControls) {
200 mUi.hideTitleBar();
201 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800202 }
203 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700204 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700205
John Reck94b7e042011-02-15 15:02:33 -0800206 @Override
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 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800215 void startEditingUrl(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 Kolbdc2ee1b2011-02-14 14:34:40 -0800279 private void setFocusState(boolean focus) {
280 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800281 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
282 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700283 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800284 mStar.setVisibility(View.GONE);
285 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800286 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800287 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700288 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700289 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800290 mVoiceSearch.setVisibility(View.GONE);
291 mStar.setVisibility(View.VISIBLE);
292 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800293 if (mUseQuickControls) {
294 mSearchButton.setVisibility(View.GONE);
295 } else {
296 mSearchButton.setVisibility(View.VISIBLE);
297 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800298 mUrlIcon.setImageResource(mInVoiceMode ?
299 R.drawable.ic_search_holo_dark
300 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700301 }
302 }
303
Michael Kolba2b2ba82010-08-04 17:54:03 -0700304 private void stopOrRefresh() {
305 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700306 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700307 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700308 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700309 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400310 }
311
312 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700313 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400314 */
Michael Kolbfe251992010-07-08 15:41:55 -0700315 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700316 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800317 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700318 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800319 if (!blockvisuals) {
320 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
321 mProgressView.setVisibility(View.GONE);
322 mStopButton.setImageDrawable(mReloadDrawable);
323 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700324 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700325 } else {
326 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800327 if (!blockvisuals) {
328 mProgressView.setVisibility(View.VISIBLE);
329 mStopButton.setImageDrawable(mStopDrawable);
330 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700331 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700332 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700333 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
334 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700335 }
Michael Kolbfe251992010-07-08 15:41:55 -0700336 }
337
Michael Kolb60a68f52011-02-24 11:02:52 -0800338 private void updateSearchMode(boolean userEdited) {
339 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800340 }
341
342 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800343 SearchEngine searchEngine = BrowserSettings.getInstance()
344 .getSearchEngine();
345 boolean showvoicebutton = voiceSearchEnabled &&
346 (searchEngine != null && searchEngine.supportsVoiceSearch());
347 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800348 View.GONE);
349 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
350 View.VISIBLE);
351 }
352
Michael Kolbfe251992010-07-08 15:41:55 -0700353 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400354 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800355 if (!isEditingUrl()) {
356 mUrlInput.setText(title, false);
357 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700358 }
359
Michael Kolb31d469b2010-12-09 20:49:54 -0800360 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500361
Michael Kolb31d469b2010-12-09 20:49:54 -0800362 @Override
363 public void afterTextChanged(Editable s) {
364 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800365 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800366 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800367 // clear voice mode when user types
368 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500369 }
370 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800371
372 @Override
373 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
374 }
375
376 @Override
377 public void onTextChanged(CharSequence s, int start, int before, int count) {
378 }
379
Michael Kolbcfa3af52010-12-14 10:36:11 -0800380 // voicesearch
381
382 @Override
383 public void setInVoiceMode(boolean voicemode) {
384 setInVoiceMode(voicemode, null);
385 }
386
387 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
388 mInVoiceMode = voicemode;
389 mUrlInput.setVoiceResults(voiceResults);
Michael Kolbe3524d82011-03-02 14:53:15 -0800390 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
Michael Kolbcfa3af52010-12-14 10:36:11 -0800391 }
392
John Reck117f07d2011-01-24 09:39:03 -0800393 @Override
394 void setIncognitoMode(boolean incognito) {
395 mUrlInput.setIncognitoMode(incognito);
396 }
Michael Kolb47171d82011-01-28 10:34:15 -0800397
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800398 @Override
399 public View focusSearch(View focused, int dir) {
400 if (FOCUS_DOWN == dir && hasFocus()) {
401 return getCurrentWebView();
402 }
403 return super.focusSearch(focused, dir);
404 }
405
406 @Override
407 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
408 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
409 // catch back key in order to do slightly more cleanup than usual
410 mUrlInput.clearFocus();
411 return true;
412 }
413 return super.dispatchKeyEventPreIme(evt);
414 }
415
416 private WebView getCurrentWebView() {
417 Tab t = mUi.getActiveTab();
418 if (t != null) {
419 return t.getWebView();
420 } else {
421 return null;
422 }
423 }
424
Leon Scroggins571b3762010-05-26 10:25:01 -0400425}