blob: 193538a9e0714eb10e207f95c2b20e94f1092c00 [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 Kamath5119edd2011-02-23 15:49:17 +000019import com.android.browser.UI.DropdownChangeListener;
Michael Kolb3aaef252011-03-09 18:13:56 -080020import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
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;
Michael Kolbfe251992010-07-08 15:41:55 -070026import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040027import android.graphics.drawable.Drawable;
Michael Kolb1ce78132010-09-23 15:50:53 -070028import android.text.TextUtils;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080029import android.view.KeyEvent;
Leon Scroggins571b3762010-05-26 10:25:01 -040030import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040031import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070032import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080033import android.view.View.OnFocusChangeListener;
Michael Kolb7cdc4902011-02-03 17:54:40 -080034import android.view.ViewGroup;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080035import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080036import android.widget.AbsoluteLayout;
37import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080038import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040039import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040040
Michael Kolbcfa3af52010-12-14 10:36:11 -080041import java.util.List;
42
Leon Scroggins571b3762010-05-26 10:25:01 -040043/**
Michael Kolbfe251992010-07-08 15:41:55 -070044 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040045 */
Michael Kolbfe251992010-07-08 15:41:55 -070046public class TitleBarXLarge extends TitleBarBase
Narayan Kamath80aad8d2011-02-23 12:01:13 +000047 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher {
Leon Scroggins571b3762010-05-26 10:25:01 -040048
Michael Kolb66706532010-12-12 19:50:22 -080049 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070050
Michael Kolba2b2ba82010-08-04 17:54:03 -070051 private Drawable mStopDrawable;
52 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070053
Michael Kolb3f65c382010-08-20 15:31:16 -070054 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080055 private ImageButton mBackButton;
56 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080057 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080058 private ImageView mUrlIcon;
59 private ImageView mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080060 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070061 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070062 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070063 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070064 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080065 private ImageView mVoiceSearch;
Michael Kolbc7485ae2010-09-03 10:10:58 -070066 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080067 private Drawable mFocusDrawable;
68 private Drawable mUnfocusDrawable;
Michael Kolb81b6f832010-12-12 12:44:27 -080069
Michael Kolba2b2ba82010-08-04 17:54:03 -070070 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080071 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070072
Michael Kolb81b6f832010-12-12 12:44:27 -080073 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080074 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080075 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080076 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070077 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080078 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
79 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080080 mFocusDrawable = resources.getDrawable(
81 R.drawable.textfield_active_holo_dark);
82 mUnfocusDrawable = resources.getDrawable(
83 R.drawable.textfield_default_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080084 mInVoiceMode = false;
Michael Kolb3aaef252011-03-09 18:13:56 -080085 initLayout(activity);
Michael Kolbfe251992010-07-08 15:41:55 -070086 }
Leon Scroggins571b3762010-05-26 10:25:01 -040087
Michael Kolb7cdc4902011-02-03 17:54:40 -080088 @Override
89 void setTitleGravity(int gravity) {
90 if (mUseQuickControls) {
91 FrameLayout.LayoutParams lp =
92 (FrameLayout.LayoutParams) getLayoutParams();
93 lp.gravity = gravity;
94 setLayoutParams(lp);
95 } else {
96 super.setTitleGravity(gravity);
97 }
98 }
99
John Reck1605bef2011-01-10 18:11:18 -0800100 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700101 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700102 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700103
Michael Kolb3f65c382010-08-20 15:31:16 -0700104 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800105 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700106 mAllButton = findViewById(R.id.all_btn);
107 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400108 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800109 mBackButton = (ImageButton) findViewById(R.id.back);
110 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -0800111 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800112 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700113 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -0800114 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700115 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700116 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700117 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -0800118 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700119 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800120 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700121 mBackButton.setOnClickListener(this);
122 mForwardButton.setOnClickListener(this);
123 mStar.setOnClickListener(this);
124 mAllButton.setOnClickListener(this);
125 mStopButton.setOnClickListener(this);
126 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700127 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700128 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800129 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800130 mUrlInput.setUrlInputListener(this);
131 mUrlInput.setContainer(mUrlContainer);
132 mUrlInput.setController(mUiController);
133 mUrlInput.setOnFocusChangeListener(this);
134 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000135 mUrlInput.addQueryTextWatcher(this);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800136 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800137 }
138
Michael Kolb5a72f182011-01-13 20:35:06 -0800139 void updateNavigationState(Tab tab) {
140 WebView web = tab.getWebView();
141 if (web != null) {
142 mBackButton.setImageResource(web.canGoBack()
143 ? R.drawable.ic_back_holo_dark
144 : R.drawable.ic_back_disabled_holo_dark);
145 mForwardButton.setImageResource(web.canGoForward()
146 ? R.drawable.ic_forward_holo_dark
147 : R.drawable.ic_forward_disabled_holo_dark);
148 }
149 }
150
Michael Kolb7cdc4902011-02-03 17:54:40 -0800151 private ViewGroup.LayoutParams makeLayoutParams() {
152 if (mUseQuickControls) {
153 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
154 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800155 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800156 return new AbsoluteLayout.LayoutParams(
157 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
158 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800159 }
160 }
161
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800162 @Override
163 public int getEmbeddedHeight() {
164 return mContainer.getHeight();
165 }
166
Michael Kolb376b5412010-12-15 11:52:57 -0800167 void setUseQuickControls(boolean useQuickControls) {
168 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800169 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800170 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800171 }
172
173 void setShowProgressOnly(boolean progress) {
174 if (progress) {
175 mContainer.setVisibility(View.GONE);
176 } else {
177 mContainer.setVisibility(View.VISIBLE);
178 }
179 }
180
Michael Kolb31d469b2010-12-09 20:49:54 -0800181 @Override
182 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800183 // if losing focus and not in touch mode, leave as is
184 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
185 setFocusState(hasFocus);
186 mUrlContainer.setBackgroundDrawable(hasFocus
187 ? mFocusDrawable : mUnfocusDrawable);
188 }
189 if (hasFocus) {
190 mUrlInput.forceIme();
191 if (mInVoiceMode) {
192 mUrlInput.forceFilter();
193 }
194 } else if (!mUrlInput.needsUpdate()) {
195 mUrlInput.dismissDropDown();
196 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800197 if (mUseQuickControls) {
198 mUi.hideTitleBar();
199 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800200 }
201 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700202 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700203
John Reck94b7e042011-02-15 15:02:33 -0800204 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500205 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800206 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500207 }
208
Michael Kolb81b6f832010-12-12 12:44:27 -0800209 /**
210 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800211 * @param clearInput clear the input field
212 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800213 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800214 // editing takes preference of progress
215 mContainer.setVisibility(View.VISIBLE);
216 if (mUseQuickControls) {
217 mProgressView.setVisibility(View.GONE);
218 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800219 if (!mUrlInput.hasFocus()) {
220 mUrlInput.requestFocus();
221 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800222 if (clearInput) {
223 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800224 } else if (mInVoiceMode) {
225 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800226 }
227 }
228
229 boolean isEditingUrl() {
230 return mUrlInput.hasFocus();
231 }
232
Michael Kolb7cdc4902011-02-03 17:54:40 -0800233 void stopEditingUrl() {
234 mUrlInput.clearFocus();
235 }
236
Michael Kolba2b2ba82010-08-04 17:54:03 -0700237 @Override
238 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800239 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700241 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700243 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500245 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700246 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700248 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800249 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700250 } else if (mStopButton == v) {
251 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700252 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800253 if (!TextUtils.isEmpty(mUrlInput.getText())) {
254 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800255 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700256 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700257 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800258 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800259 } else if (mVoiceSearch == v) {
260 mUiController.startVoiceSearch();
Michael Kolbfe251992010-07-08 15:41:55 -0700261 }
262 }
263
Michael Kolba2b2ba82010-08-04 17:54:03 -0700264 @Override
265 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700266
Michael Kolb31d469b2010-12-09 20:49:54 -0800267 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000268 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800269 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800270 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800271 } else {
272 // clear
273 mUrlInput.setText("");
274 }
275 }
276
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800277 private void setFocusState(boolean focus) {
278 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800279 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
280 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700281 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800282 mStar.setVisibility(View.GONE);
283 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800284 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800285 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700286 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700287 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800288 mVoiceSearch.setVisibility(View.GONE);
289 mStar.setVisibility(View.VISIBLE);
290 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800291 if (mUseQuickControls) {
292 mSearchButton.setVisibility(View.GONE);
293 } else {
294 mSearchButton.setVisibility(View.VISIBLE);
295 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800296 mUrlIcon.setImageResource(mInVoiceMode ?
297 R.drawable.ic_search_holo_dark
298 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700299 }
300 }
301
Michael Kolba2b2ba82010-08-04 17:54:03 -0700302 private void stopOrRefresh() {
303 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700304 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700305 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700306 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700307 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400308 }
309
310 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700311 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400312 */
Michael Kolbfe251992010-07-08 15:41:55 -0700313 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700314 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800315 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700316 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800317 if (!blockvisuals) {
318 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
319 mProgressView.setVisibility(View.GONE);
320 mStopButton.setImageDrawable(mReloadDrawable);
321 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700322 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700323 } else {
324 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800325 if (!blockvisuals) {
326 mProgressView.setVisibility(View.VISIBLE);
327 mStopButton.setImageDrawable(mStopDrawable);
328 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700329 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700330 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700331 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
332 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700333 }
Michael Kolbfe251992010-07-08 15:41:55 -0700334 }
335
Michael Kolb60a68f52011-02-24 11:02:52 -0800336 private void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000337 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800338 }
339
340 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800341 SearchEngine searchEngine = BrowserSettings.getInstance()
342 .getSearchEngine();
343 boolean showvoicebutton = voiceSearchEnabled &&
344 (searchEngine != null && searchEngine.supportsVoiceSearch());
345 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800346 View.GONE);
347 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
348 View.VISIBLE);
349 }
350
Michael Kolbfe251992010-07-08 15:41:55 -0700351 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400352 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800353 if (!isEditingUrl()) {
354 mUrlInput.setText(title, false);
355 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700356 }
357
Michael Kolb31d469b2010-12-09 20:49:54 -0800358 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500359
Michael Kolb31d469b2010-12-09 20:49:54 -0800360 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000361 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800362 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800363 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800364 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800365 // clear voice mode when user types
366 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500367 }
368 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800369
Michael Kolbcfa3af52010-12-14 10:36:11 -0800370 // voicesearch
371
372 @Override
373 public void setInVoiceMode(boolean voicemode) {
374 setInVoiceMode(voicemode, null);
375 }
376
377 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
378 mInVoiceMode = voicemode;
379 mUrlInput.setVoiceResults(voiceResults);
Michael Kolb3aaef252011-03-09 18:13:56 -0800380 if (voicemode) {
381 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
382 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800383 }
384
John Reck117f07d2011-01-24 09:39:03 -0800385 @Override
386 void setIncognitoMode(boolean incognito) {
387 mUrlInput.setIncognitoMode(incognito);
388 }
Michael Kolb47171d82011-01-28 10:34:15 -0800389
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800390 @Override
391 public View focusSearch(View focused, int dir) {
392 if (FOCUS_DOWN == dir && hasFocus()) {
393 return getCurrentWebView();
394 }
395 return super.focusSearch(focused, dir);
396 }
397
398 @Override
399 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
400 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
401 // catch back key in order to do slightly more cleanup than usual
402 mUrlInput.clearFocus();
403 return true;
404 }
405 return super.dispatchKeyEventPreIme(evt);
406 }
407
408 private WebView getCurrentWebView() {
409 Tab t = mUi.getActiveTab();
410 if (t != null) {
411 return t.getWebView();
412 } else {
413 return null;
414 }
415 }
416
Narayan Kamath5119edd2011-02-23 15:49:17 +0000417 void registerDropdownChangeListener(DropdownChangeListener d) {
418 mUrlInput.registerDropdownChangeListener(d);
419 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400420}