blob: cbe666c8e9bf873a720754b221c8474fcd848e3c [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;
Narayan Kamath5119edd2011-02-23 15:49:17 +000020import com.android.browser.UI.DropdownChangeListener;
Michael Kolb793e05e2011-01-11 15:17:31 -080021import com.android.browser.search.SearchEngine;
Michael Kolbc7485ae2010-09-03 10:10:58 -070022
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
Leon Scroggins571b3762010-05-26 10:25:01 -040024import android.content.Context;
25import android.content.res.Resources;
Narayan Kamath5119edd2011-02-23 15:49:17 +000026import android.database.DataSetObserver;
Michael Kolbfe251992010-07-08 15:41:55 -070027import android.graphics.Bitmap;
Narayan Kamath5119edd2011-02-23 15:49:17 +000028import android.graphics.Rect;
Leon Scroggins571b3762010-05-26 10:25:01 -040029import android.graphics.drawable.Drawable;
Michael Kolb1ce78132010-09-23 15:50:53 -070030import android.text.TextUtils;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080031import android.view.KeyEvent;
Leon Scroggins571b3762010-05-26 10:25:01 -040032import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040033import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070034import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080035import android.view.View.OnFocusChangeListener;
Michael Kolb7cdc4902011-02-03 17:54:40 -080036import android.view.ViewGroup;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080037import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080038import android.widget.AbsoluteLayout;
39import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080040import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040041import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040042
Narayan Kamath5119edd2011-02-23 15:49:17 +000043import java.util.ArrayList;
Michael Kolbcfa3af52010-12-14 10:36:11 -080044import java.util.List;
45
Leon Scroggins571b3762010-05-26 10:25:01 -040046/**
Michael Kolbfe251992010-07-08 15:41:55 -070047 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040048 */
Michael Kolbfe251992010-07-08 15:41:55 -070049public class TitleBarXLarge extends TitleBarBase
Narayan Kamath80aad8d2011-02-23 12:01:13 +000050 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040051
Michael Kolb66706532010-12-12 19:50:22 -080052 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070053
Michael Kolba2b2ba82010-08-04 17:54:03 -070054 private Drawable mStopDrawable;
55 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070056
Michael Kolb3f65c382010-08-20 15:31:16 -070057 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080058 private ImageButton mBackButton;
59 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080060 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080061 private ImageView mUrlIcon;
62 private ImageView mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080063 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070064 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070065 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070066 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070067 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080068 private ImageView mVoiceSearch;
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 Kolbe3524d82011-03-02 14:53:15 -0800114 mUrlIcon = (ImageView) findViewById(R.id.url_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);
Michael Kolbe3524d82011-03-02 14:53:15 -0800117 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700118 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 Kolbe3524d82011-03-02 14:53:15 -0800121 mVoiceSearch = (ImageView) 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 Kolba2b2ba82010-08-04 17:54:03 -0700124 mBackButton.setOnClickListener(this);
125 mForwardButton.setOnClickListener(this);
126 mStar.setOnClickListener(this);
127 mAllButton.setOnClickListener(this);
128 mStopButton.setOnClickListener(this);
129 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700130 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700131 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800132 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800133 mUrlInput.setUrlInputListener(this);
134 mUrlInput.setContainer(mUrlContainer);
135 mUrlInput.setController(mUiController);
136 mUrlInput.setOnFocusChangeListener(this);
137 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000138 mUrlInput.addQueryTextWatcher(this);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800139 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800140 }
141
Michael Kolb5a72f182011-01-13 20:35:06 -0800142 void updateNavigationState(Tab tab) {
143 WebView web = tab.getWebView();
144 if (web != null) {
145 mBackButton.setImageResource(web.canGoBack()
146 ? R.drawable.ic_back_holo_dark
147 : R.drawable.ic_back_disabled_holo_dark);
148 mForwardButton.setImageResource(web.canGoForward()
149 ? R.drawable.ic_forward_holo_dark
150 : R.drawable.ic_forward_disabled_holo_dark);
151 }
152 }
153
Michael Kolb7cdc4902011-02-03 17:54:40 -0800154 private ViewGroup.LayoutParams makeLayoutParams() {
155 if (mUseQuickControls) {
156 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
157 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800158 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800159 return new AbsoluteLayout.LayoutParams(
160 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
161 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800162 }
163 }
164
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800165 @Override
166 public int getEmbeddedHeight() {
167 return mContainer.getHeight();
168 }
169
Michael Kolb376b5412010-12-15 11:52:57 -0800170 void setUseQuickControls(boolean useQuickControls) {
171 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800172 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800173 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800174 }
175
176 void setShowProgressOnly(boolean progress) {
177 if (progress) {
178 mContainer.setVisibility(View.GONE);
179 } else {
180 mContainer.setVisibility(View.VISIBLE);
181 }
182 }
183
Michael Kolb31d469b2010-12-09 20:49:54 -0800184 @Override
185 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800186 // if losing focus and not in touch mode, leave as is
187 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
188 setFocusState(hasFocus);
189 mUrlContainer.setBackgroundDrawable(hasFocus
190 ? mFocusDrawable : mUnfocusDrawable);
191 }
192 if (hasFocus) {
193 mUrlInput.forceIme();
194 if (mInVoiceMode) {
195 mUrlInput.forceFilter();
196 }
197 } else if (!mUrlInput.needsUpdate()) {
198 mUrlInput.dismissDropDown();
199 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800200 if (mUseQuickControls) {
201 mUi.hideTitleBar();
202 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800203 }
204 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700205 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700206
John Reck94b7e042011-02-15 15:02:33 -0800207 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500208 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800209 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500210 }
211
Michael Kolb81b6f832010-12-12 12:44:27 -0800212 /**
213 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800214 * @param clearInput clear the input field
215 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800216 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800217 // editing takes preference of progress
218 mContainer.setVisibility(View.VISIBLE);
219 if (mUseQuickControls) {
220 mProgressView.setVisibility(View.GONE);
221 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800222 if (!mUrlInput.hasFocus()) {
223 mUrlInput.requestFocus();
224 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800225 if (clearInput) {
226 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800227 } else if (mInVoiceMode) {
228 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800229 }
230 }
231
232 boolean isEditingUrl() {
233 return mUrlInput.hasFocus();
234 }
235
Michael Kolb7cdc4902011-02-03 17:54:40 -0800236 void stopEditingUrl() {
237 mUrlInput.clearFocus();
238 }
239
Michael Kolba2b2ba82010-08-04 17:54:03 -0700240 @Override
241 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800242 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700244 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700245 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700246 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500248 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700249 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700251 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800252 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700253 } else if (mStopButton == v) {
254 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700255 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800256 if (!TextUtils.isEmpty(mUrlInput.getText())) {
257 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800258 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700259 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700260 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800261 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800262 } else if (mVoiceSearch == v) {
263 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700264 }
265 }
266
Michael Kolba2b2ba82010-08-04 17:54:03 -0700267 @Override
268 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700269
Michael Kolb31d469b2010-12-09 20:49:54 -0800270 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000271 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800272 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800273 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800274 } else {
275 // clear
276 mUrlInput.setText("");
277 }
278 }
279
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800280 private void setFocusState(boolean focus) {
281 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800282 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
283 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700284 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800285 mStar.setVisibility(View.GONE);
286 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800287 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800288 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700289 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700290 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800291 mVoiceSearch.setVisibility(View.GONE);
292 mStar.setVisibility(View.VISIBLE);
293 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800294 if (mUseQuickControls) {
295 mSearchButton.setVisibility(View.GONE);
296 } else {
297 mSearchButton.setVisibility(View.VISIBLE);
298 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800299 mUrlIcon.setImageResource(mInVoiceMode ?
300 R.drawable.ic_search_holo_dark
301 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700302 }
303 }
304
Michael Kolba2b2ba82010-08-04 17:54:03 -0700305 private void stopOrRefresh() {
306 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700307 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700308 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700309 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700310 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400311 }
312
313 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700314 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400315 */
Michael Kolbfe251992010-07-08 15:41:55 -0700316 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700317 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800318 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700319 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800320 if (!blockvisuals) {
321 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
322 mProgressView.setVisibility(View.GONE);
323 mStopButton.setImageDrawable(mReloadDrawable);
324 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700325 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700326 } else {
327 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800328 if (!blockvisuals) {
329 mProgressView.setVisibility(View.VISIBLE);
330 mStopButton.setImageDrawable(mStopDrawable);
331 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700332 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700333 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700334 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
335 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700336 }
Michael Kolbfe251992010-07-08 15:41:55 -0700337 }
338
Michael Kolb60a68f52011-02-24 11:02:52 -0800339 private void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000340 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800341 }
342
343 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800344 SearchEngine searchEngine = BrowserSettings.getInstance()
345 .getSearchEngine();
346 boolean showvoicebutton = voiceSearchEnabled &&
347 (searchEngine != null && searchEngine.supportsVoiceSearch());
348 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800349 View.GONE);
350 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
351 View.VISIBLE);
352 }
353
Michael Kolbfe251992010-07-08 15:41:55 -0700354 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400355 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800356 if (!isEditingUrl()) {
357 mUrlInput.setText(title, false);
358 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700359 }
360
Michael Kolb31d469b2010-12-09 20:49:54 -0800361 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500362
Michael Kolb31d469b2010-12-09 20:49:54 -0800363 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000364 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800365 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800366 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800367 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800368 // clear voice mode when user types
369 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500370 }
371 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800372
Michael Kolbcfa3af52010-12-14 10:36:11 -0800373 // voicesearch
374
375 @Override
376 public void setInVoiceMode(boolean voicemode) {
377 setInVoiceMode(voicemode, null);
378 }
379
380 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
381 mInVoiceMode = voicemode;
382 mUrlInput.setVoiceResults(voiceResults);
Michael Kolbe3524d82011-03-02 14:53:15 -0800383 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
Michael Kolbcfa3af52010-12-14 10:36:11 -0800384 }
385
John Reck117f07d2011-01-24 09:39:03 -0800386 @Override
387 void setIncognitoMode(boolean incognito) {
388 mUrlInput.setIncognitoMode(incognito);
389 }
Michael Kolb47171d82011-01-28 10:34:15 -0800390
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800391 @Override
392 public View focusSearch(View focused, int dir) {
393 if (FOCUS_DOWN == dir && hasFocus()) {
394 return getCurrentWebView();
395 }
396 return super.focusSearch(focused, dir);
397 }
398
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000399 void clearCompletions() {
400 mUrlInput.setSuggestedText(null);
401 }
402
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800403 @Override
404 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
405 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
406 // catch back key in order to do slightly more cleanup than usual
407 mUrlInput.clearFocus();
408 return true;
409 }
410 return super.dispatchKeyEventPreIme(evt);
411 }
412
413 private WebView getCurrentWebView() {
414 Tab t = mUi.getActiveTab();
415 if (t != null) {
416 return t.getWebView();
417 } else {
418 return null;
419 }
420 }
421
Narayan Kamath5119edd2011-02-23 15:49:17 +0000422 void registerDropdownChangeListener(DropdownChangeListener d) {
423 mUrlInput.registerDropdownChangeListener(d);
424 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400425}