blob: 14e7c72072e479451cdcc2844b3adfed9b528713 [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 if (mUseQuickControls) {
174 mBackButton.setVisibility(View.GONE);
175 mForwardButton.setVisibility(View.GONE);
176 mStopButton.setVisibility(View.GONE);
177 mAllButton.setVisibility(View.GONE);
178 } else {
179 mBackButton.setVisibility(View.VISIBLE);
180 mForwardButton.setVisibility(View.VISIBLE);
181 mStopButton.setVisibility(View.VISIBLE);
182 mAllButton.setVisibility(View.VISIBLE);
183 }
184 }
185
186 void setShowProgressOnly(boolean progress) {
187 if (progress) {
188 mContainer.setVisibility(View.GONE);
189 } else {
190 mContainer.setVisibility(View.VISIBLE);
191 }
192 }
193
Michael Kolb31d469b2010-12-09 20:49:54 -0800194 @Override
195 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800196 // if losing focus and not in touch mode, leave as is
197 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
198 setFocusState(hasFocus);
199 mUrlContainer.setBackgroundDrawable(hasFocus
200 ? mFocusDrawable : mUnfocusDrawable);
201 }
202 if (hasFocus) {
203 mUrlInput.forceIme();
204 if (mInVoiceMode) {
205 mUrlInput.forceFilter();
206 }
207 } else if (!mUrlInput.needsUpdate()) {
208 mUrlInput.dismissDropDown();
209 mUrlInput.hideIME();
210 }
211 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700212 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700213
John Reck94b7e042011-02-15 15:02:33 -0800214 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500215 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800216 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500217 }
218
Michael Kolb81b6f832010-12-12 12:44:27 -0800219 /**
220 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800221 * @param clearInput clear the input field
222 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800223 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800224 // editing takes preference of progress
225 mContainer.setVisibility(View.VISIBLE);
226 if (mUseQuickControls) {
227 mProgressView.setVisibility(View.GONE);
228 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800229 if (!mUrlInput.hasFocus()) {
230 mUrlInput.requestFocus();
231 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800232 if (clearInput) {
233 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800234 } else if (mInVoiceMode) {
235 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800236 }
237 }
238
239 boolean isEditingUrl() {
240 return mUrlInput.hasFocus();
241 }
242
Michael Kolb7cdc4902011-02-03 17:54:40 -0800243 void stopEditingUrl() {
244 mUrlInput.clearFocus();
245 }
246
Michael Kolba2b2ba82010-08-04 17:54:03 -0700247 @Override
248 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800249 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700251 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700253 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500255 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700256 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700258 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800259 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700260 } else if (mStopButton == v) {
261 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700262 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800263 if (!TextUtils.isEmpty(mUrlInput.getText())) {
264 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800265 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700266 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700267 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800268 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800269 } else if (mVoiceSearch == v) {
270 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700271 }
272 }
273
Michael Kolba2b2ba82010-08-04 17:54:03 -0700274 @Override
275 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700276
Michael Kolb31d469b2010-12-09 20:49:54 -0800277 private void clearOrClose() {
278 if (TextUtils.isEmpty(mUrlInput.getText())) {
279 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800280 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800281 } else {
282 // clear
283 mUrlInput.setText("");
284 }
285 }
286
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800287 private void setFocusState(boolean focus) {
288 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800289 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
290 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700291 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800292 mStar.setVisibility(View.GONE);
293 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800294 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800295 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700296 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700297 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800298 mVoiceSearch.setVisibility(View.GONE);
299 mStar.setVisibility(View.VISIBLE);
300 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800301 if (mUseQuickControls) {
302 mSearchButton.setVisibility(View.GONE);
303 } else {
304 mSearchButton.setVisibility(View.VISIBLE);
305 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800306 mUrlIcon.setImageResource(mInVoiceMode ?
307 R.drawable.ic_search_holo_dark
308 : 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 Kolb60a68f52011-02-24 11:02:52 -0800346 private void updateSearchMode(boolean userEdited) {
347 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800348 }
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 Kolb60a68f52011-02-24 11:02:52 -0800374 updateSearchMode(true);
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);
Michael Kolbe3524d82011-03-02 14:53:15 -0800398 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
Michael Kolbcfa3af52010-12-14 10:36:11 -0800399 }
400
John Reck117f07d2011-01-24 09:39:03 -0800401 @Override
402 void setIncognitoMode(boolean incognito) {
403 mUrlInput.setIncognitoMode(incognito);
404 }
Michael Kolb47171d82011-01-28 10:34:15 -0800405
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800406 @Override
407 public View focusSearch(View focused, int dir) {
408 if (FOCUS_DOWN == dir && hasFocus()) {
409 return getCurrentWebView();
410 }
411 return super.focusSearch(focused, dir);
412 }
413
414 @Override
415 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
416 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
417 // catch back key in order to do slightly more cleanup than usual
418 mUrlInput.clearFocus();
419 return true;
420 }
421 return super.dispatchKeyEventPreIme(evt);
422 }
423
424 private WebView getCurrentWebView() {
425 Tab t = mUi.getActiveTab();
426 if (t != null) {
427 return t.getWebView();
428 } else {
429 return null;
430 }
431 }
432
Leon Scroggins571b3762010-05-26 10:25:01 -0400433}