blob: c0df47ce0d977f9c18721460381fa35fc26bb858 [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
Narayan Kamath80aad8d2011-02-23 12:01:13 +000019import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
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;
Leon Scroggins571b3762010-05-26 10:25:01 -040023import android.content.Context;
24import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040026import android.graphics.drawable.Drawable;
Michael Kolb1ce78132010-09-23 15:50:53 -070027import android.text.TextUtils;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080028import android.view.KeyEvent;
Leon Scroggins571b3762010-05-26 10:25:01 -040029import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040030import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070031import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080032import android.view.View.OnFocusChangeListener;
Michael Kolb7cdc4902011-02-03 17:54:40 -080033import android.view.ViewGroup;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080034import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080035import android.widget.AbsoluteLayout;
36import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080037import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040038import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040039
Michael Kolbcfa3af52010-12-14 10:36:11 -080040import java.util.List;
41
Leon Scroggins571b3762010-05-26 10:25:01 -040042/**
Michael Kolbfe251992010-07-08 15:41:55 -070043 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040044 */
Michael Kolbfe251992010-07-08 15:41:55 -070045public class TitleBarXLarge extends TitleBarBase
Narayan Kamath80aad8d2011-02-23 12:01:13 +000046 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040047
Michael Kolb66706532010-12-12 19:50:22 -080048 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070049
Michael Kolba2b2ba82010-08-04 17:54:03 -070050 private Drawable mStopDrawable;
51 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070052
Michael Kolb3f65c382010-08-20 15:31:16 -070053 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080054 private ImageButton mBackButton;
55 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080056 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080057 private ImageView mUrlIcon;
58 private ImageView mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080059 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070060 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070061 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070062 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070063 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080064 private ImageView mVoiceSearch;
Michael Kolbc7485ae2010-09-03 10:10:58 -070065 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080066 private Drawable mFocusDrawable;
67 private Drawable mUnfocusDrawable;
Michael Kolb81b6f832010-12-12 12:44:27 -080068
Michael Kolba2b2ba82010-08-04 17:54:03 -070069 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080070 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070071
Michael Kolb81b6f832010-12-12 12:44:27 -080072 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080073 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080074 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080075 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070076 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080077 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
78 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080079 mFocusDrawable = resources.getDrawable(
80 R.drawable.textfield_active_holo_dark);
81 mUnfocusDrawable = resources.getDrawable(
82 R.drawable.textfield_default_holo_dark);
John Reck1605bef2011-01-10 18:11:18 -080083 initLayout(activity);
Michael Kolbcfa3af52010-12-14 10:36:11 -080084 mInVoiceMode = false;
Michael Kolbfe251992010-07-08 15:41:55 -070085 }
Leon Scroggins571b3762010-05-26 10:25:01 -040086
Michael Kolb7cdc4902011-02-03 17:54:40 -080087 @Override
88 void setTitleGravity(int gravity) {
89 if (mUseQuickControls) {
90 FrameLayout.LayoutParams lp =
91 (FrameLayout.LayoutParams) getLayoutParams();
92 lp.gravity = gravity;
93 setLayoutParams(lp);
94 } else {
95 super.setTitleGravity(gravity);
96 }
97 }
98
John Reck1605bef2011-01-10 18:11:18 -080099 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700100 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700101 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700102
Michael Kolb3f65c382010-08-20 15:31:16 -0700103 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800104 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700105 mAllButton = findViewById(R.id.all_btn);
106 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400107 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800108 mBackButton = (ImageButton) findViewById(R.id.back);
109 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -0800110 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800111 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700112 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -0800113 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700114 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700115 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700116 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -0800117 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700118 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800119 mUrlContainer = findViewById(R.id.urlbar_focused);
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 mUrlInput.setUrlInputListener(this);
130 mUrlInput.setContainer(mUrlContainer);
131 mUrlInput.setController(mUiController);
132 mUrlInput.setOnFocusChangeListener(this);
133 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000134 mUrlInput.addQueryTextWatcher(this);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800135 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800136 }
137
Michael Kolb5a72f182011-01-13 20:35:06 -0800138 void updateNavigationState(Tab tab) {
139 WebView web = tab.getWebView();
140 if (web != null) {
141 mBackButton.setImageResource(web.canGoBack()
142 ? R.drawable.ic_back_holo_dark
143 : R.drawable.ic_back_disabled_holo_dark);
144 mForwardButton.setImageResource(web.canGoForward()
145 ? R.drawable.ic_forward_holo_dark
146 : R.drawable.ic_forward_disabled_holo_dark);
147 }
148 }
149
Michael Kolb7cdc4902011-02-03 17:54:40 -0800150 private ViewGroup.LayoutParams makeLayoutParams() {
151 if (mUseQuickControls) {
152 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
153 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800154 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800155 return new AbsoluteLayout.LayoutParams(
156 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
157 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800158 }
159 }
160
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800161 @Override
162 public int getEmbeddedHeight() {
163 return mContainer.getHeight();
164 }
165
Michael Kolb376b5412010-12-15 11:52:57 -0800166 void setUseQuickControls(boolean useQuickControls) {
167 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800168 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800169 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800170 }
171
172 void setShowProgressOnly(boolean progress) {
173 if (progress) {
174 mContainer.setVisibility(View.GONE);
175 } else {
176 mContainer.setVisibility(View.VISIBLE);
177 }
178 }
179
Michael Kolb31d469b2010-12-09 20:49:54 -0800180 @Override
181 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800182 // if losing focus and not in touch mode, leave as is
183 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
184 setFocusState(hasFocus);
185 mUrlContainer.setBackgroundDrawable(hasFocus
186 ? mFocusDrawable : mUnfocusDrawable);
187 }
188 if (hasFocus) {
189 mUrlInput.forceIme();
190 if (mInVoiceMode) {
191 mUrlInput.forceFilter();
192 }
193 } else if (!mUrlInput.needsUpdate()) {
194 mUrlInput.dismissDropDown();
195 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800196 if (mUseQuickControls) {
197 mUi.hideTitleBar();
198 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800199 }
200 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700201 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700202
John Reck94b7e042011-02-15 15:02:33 -0800203 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500204 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800205 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500206 }
207
Michael Kolb81b6f832010-12-12 12:44:27 -0800208 /**
209 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800210 * @param clearInput clear the input field
211 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800212 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800213 // editing takes preference of progress
214 mContainer.setVisibility(View.VISIBLE);
215 if (mUseQuickControls) {
216 mProgressView.setVisibility(View.GONE);
217 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800218 if (!mUrlInput.hasFocus()) {
219 mUrlInput.requestFocus();
220 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800221 if (clearInput) {
222 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800223 } else if (mInVoiceMode) {
224 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800225 }
226 }
227
228 boolean isEditingUrl() {
229 return mUrlInput.hasFocus();
230 }
231
Michael Kolb7cdc4902011-02-03 17:54:40 -0800232 void stopEditingUrl() {
233 mUrlInput.clearFocus();
234 }
235
Michael Kolba2b2ba82010-08-04 17:54:03 -0700236 @Override
237 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800238 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 Scrogginsbdff8a72011-02-11 15:49:04 -0500244 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
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 Kolba2b2ba82010-08-04 17:54:03 -0700263 @Override
264 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700265
Michael Kolb31d469b2010-12-09 20:49:54 -0800266 private void clearOrClose() {
267 if (TextUtils.isEmpty(mUrlInput.getText())) {
268 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800269 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800270 } else {
271 // clear
272 mUrlInput.setText("");
273 }
274 }
275
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800276 private void setFocusState(boolean focus) {
277 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800278 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
279 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700280 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800281 mStar.setVisibility(View.GONE);
282 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800283 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800284 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700285 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700286 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800287 mVoiceSearch.setVisibility(View.GONE);
288 mStar.setVisibility(View.VISIBLE);
289 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800290 if (mUseQuickControls) {
291 mSearchButton.setVisibility(View.GONE);
292 } else {
293 mSearchButton.setVisibility(View.VISIBLE);
294 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800295 mUrlIcon.setImageResource(mInVoiceMode ?
296 R.drawable.ic_search_holo_dark
297 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700298 }
299 }
300
Michael Kolba2b2ba82010-08-04 17:54:03 -0700301 private void stopOrRefresh() {
302 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700303 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700304 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700305 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700306 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400307 }
308
309 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700310 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400311 */
Michael Kolbfe251992010-07-08 15:41:55 -0700312 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700313 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800314 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700315 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800316 if (!blockvisuals) {
317 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
318 mProgressView.setVisibility(View.GONE);
319 mStopButton.setImageDrawable(mReloadDrawable);
320 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700321 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700322 } else {
323 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800324 if (!blockvisuals) {
325 mProgressView.setVisibility(View.VISIBLE);
326 mStopButton.setImageDrawable(mStopDrawable);
327 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700328 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700329 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700330 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
331 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700332 }
Michael Kolbfe251992010-07-08 15:41:55 -0700333 }
334
Michael Kolb60a68f52011-02-24 11:02:52 -0800335 private void updateSearchMode(boolean userEdited) {
336 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800337 }
338
339 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800340 SearchEngine searchEngine = BrowserSettings.getInstance()
341 .getSearchEngine();
342 boolean showvoicebutton = voiceSearchEnabled &&
343 (searchEngine != null && searchEngine.supportsVoiceSearch());
344 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800345 View.GONE);
346 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
347 View.VISIBLE);
348 }
349
Michael Kolbfe251992010-07-08 15:41:55 -0700350 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400351 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800352 if (!isEditingUrl()) {
353 mUrlInput.setText(title, false);
354 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700355 }
356
Michael Kolb31d469b2010-12-09 20:49:54 -0800357 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500358
Michael Kolb31d469b2010-12-09 20:49:54 -0800359 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000360 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800361 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800362 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800363 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800364 // clear voice mode when user types
365 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500366 }
367 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800368
Michael Kolbcfa3af52010-12-14 10:36:11 -0800369 // voicesearch
370
371 @Override
372 public void setInVoiceMode(boolean voicemode) {
373 setInVoiceMode(voicemode, null);
374 }
375
376 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
377 mInVoiceMode = voicemode;
378 mUrlInput.setVoiceResults(voiceResults);
Michael Kolbe3524d82011-03-02 14:53:15 -0800379 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
Michael Kolbcfa3af52010-12-14 10:36:11 -0800380 }
381
John Reck117f07d2011-01-24 09:39:03 -0800382 @Override
383 void setIncognitoMode(boolean incognito) {
384 mUrlInput.setIncognitoMode(incognito);
385 }
Michael Kolb47171d82011-01-28 10:34:15 -0800386
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800387 @Override
388 public View focusSearch(View focused, int dir) {
389 if (FOCUS_DOWN == dir && hasFocus()) {
390 return getCurrentWebView();
391 }
392 return super.focusSearch(focused, dir);
393 }
394
395 @Override
396 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
397 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
398 // catch back key in order to do slightly more cleanup than usual
399 mUrlInput.clearFocus();
400 return true;
401 }
402 return super.dispatchKeyEventPreIme(evt);
403 }
404
405 private WebView getCurrentWebView() {
406 Tab t = mUi.getActiveTab();
407 if (t != null) {
408 return t.getWebView();
409 } else {
410 return null;
411 }
412 }
413
Leon Scroggins571b3762010-05-26 10:25:01 -0400414}