blob: 9fce5112450160568197970214a0e1b224a48144 [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;
Patrick Scott92066772011-03-10 08:46:27 -050029import android.view.animation.Animation;
30import android.view.animation.Animation.AnimationListener;
31import android.view.animation.AnimationUtils;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080032import android.view.KeyEvent;
Leon Scroggins571b3762010-05-26 10:25:01 -040033import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040034import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070035import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080036import android.view.View.OnFocusChangeListener;
Michael Kolb7cdc4902011-02-03 17:54:40 -080037import android.view.ViewGroup;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080038import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080039import android.widget.AbsoluteLayout;
Patrick Scott92066772011-03-10 08:46:27 -050040import android.widget.Button;
Michael Kolb7cdc4902011-02-03 17:54:40 -080041import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080042import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040043import android.widget.ImageView;
Patrick Scott92066772011-03-10 08:46:27 -050044import android.widget.ProgressBar;
45import android.widget.TextView;
Leon Scroggins571b3762010-05-26 10:25:01 -040046
Michael Kolbcfa3af52010-12-14 10:36:11 -080047import java.util.List;
48
Leon Scroggins571b3762010-05-26 10:25:01 -040049/**
Michael Kolbfe251992010-07-08 15:41:55 -070050 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040051 */
Michael Kolbfe251992010-07-08 15:41:55 -070052public class TitleBarXLarge extends TitleBarBase
Patrick Scott92066772011-03-10 08:46:27 -050053 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher,
54 DeviceAccountLogin.AutoLoginCallback {
Leon Scroggins571b3762010-05-26 10:25:01 -040055
Michael Kolb66706532010-12-12 19:50:22 -080056 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070057
Michael Kolba2b2ba82010-08-04 17:54:03 -070058 private Drawable mStopDrawable;
59 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070060
Michael Kolb3f65c382010-08-20 15:31:16 -070061 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080062 private ImageButton mBackButton;
63 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080064 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080065 private ImageView mUrlIcon;
66 private ImageView mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080067 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070068 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070069 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070070 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070071 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080072 private ImageView mVoiceSearch;
Michael Kolbc7485ae2010-09-03 10:10:58 -070073 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080074 private Drawable mFocusDrawable;
75 private Drawable mUnfocusDrawable;
Patrick Scott92066772011-03-10 08:46:27 -050076 // Auto-login UI
77 private View mAutoLogin;
78 private Button mAutoLoginAccount;
79 private Button mAutoLoginLogin;
80 private ProgressBar mAutoLoginProgress;
81 private TextView mAutoLoginError;
82 private ImageButton mAutoLoginCancel;
83 private DeviceAccountLogin mAutoLoginHandler;
Michael Kolb81b6f832010-12-12 12:44:27 -080084
Michael Kolba2b2ba82010-08-04 17:54:03 -070085 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080086 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070087
Michael Kolb81b6f832010-12-12 12:44:27 -080088 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080089 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080090 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080091 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070092 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080093 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
94 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080095 mFocusDrawable = resources.getDrawable(
96 R.drawable.textfield_active_holo_dark);
97 mUnfocusDrawable = resources.getDrawable(
98 R.drawable.textfield_default_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080099 mInVoiceMode = false;
Michael Kolb3aaef252011-03-09 18:13:56 -0800100 initLayout(activity);
Michael Kolbfe251992010-07-08 15:41:55 -0700101 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400102
Michael Kolb7cdc4902011-02-03 17:54:40 -0800103 @Override
104 void setTitleGravity(int gravity) {
105 if (mUseQuickControls) {
106 FrameLayout.LayoutParams lp =
107 (FrameLayout.LayoutParams) getLayoutParams();
108 lp.gravity = gravity;
109 setLayoutParams(lp);
110 } else {
111 super.setTitleGravity(gravity);
112 }
113 }
114
John Reck1605bef2011-01-10 18:11:18 -0800115 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700116 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700117 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700118
Michael Kolb3f65c382010-08-20 15:31:16 -0700119 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800120 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700121 mAllButton = findViewById(R.id.all_btn);
122 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400123 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800124 mBackButton = (ImageButton) findViewById(R.id.back);
125 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -0800126 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800127 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700128 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -0800129 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700130 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700131 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700132 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -0800133 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700134 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800135 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700136 mBackButton.setOnClickListener(this);
137 mForwardButton.setOnClickListener(this);
138 mStar.setOnClickListener(this);
139 mAllButton.setOnClickListener(this);
140 mStopButton.setOnClickListener(this);
141 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700142 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700143 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800144 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800145 mUrlInput.setUrlInputListener(this);
146 mUrlInput.setContainer(mUrlContainer);
147 mUrlInput.setController(mUiController);
148 mUrlInput.setOnFocusChangeListener(this);
149 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000150 mUrlInput.addQueryTextWatcher(this);
Patrick Scott92066772011-03-10 08:46:27 -0500151 mAutoLogin = findViewById(R.id.autologin);
152 mAutoLoginAccount = (Button) findViewById(R.id.autologin_account);
153 mAutoLoginAccount.setOnClickListener(this);
154 mAutoLoginLogin = (Button) findViewById(R.id.autologin_login);
155 mAutoLoginLogin.setOnClickListener(this);
156 mAutoLoginProgress =
157 (ProgressBar) findViewById(R.id.autologin_progress);
158 mAutoLoginError = (TextView) findViewById(R.id.autologin_error);
159 mAutoLoginCancel =
160 (ImageButton) mAutoLogin.findViewById(R.id.autologin_close);
161 mAutoLoginCancel.setOnClickListener(this);
162
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800163 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800164 }
165
Michael Kolb5a72f182011-01-13 20:35:06 -0800166 void updateNavigationState(Tab tab) {
167 WebView web = tab.getWebView();
168 if (web != null) {
169 mBackButton.setImageResource(web.canGoBack()
170 ? R.drawable.ic_back_holo_dark
171 : R.drawable.ic_back_disabled_holo_dark);
172 mForwardButton.setImageResource(web.canGoForward()
173 ? R.drawable.ic_forward_holo_dark
174 : R.drawable.ic_forward_disabled_holo_dark);
175 }
176 }
177
Patrick Scott92066772011-03-10 08:46:27 -0500178 void updateAutoLogin(Tab tab, boolean animate) {
179 DeviceAccountLogin login = tab.getDeviceAccountLogin();
180 if (login != null) {
181 mAutoLoginHandler = login;
182 mAutoLogin.setVisibility(View.VISIBLE);
183 mAutoLoginAccount.setText(login.getCurrentAccount());
184 mAutoLoginAccount.setEnabled(true);
185 mAutoLoginLogin.setEnabled(true);
186 mAutoLoginProgress.setVisibility(View.GONE);
187 mAutoLoginError.setVisibility(View.GONE);
188 switch (login.getState()) {
189 case DeviceAccountLogin.PROCESSING:
190 mAutoLoginAccount.setEnabled(false);
191 mAutoLoginLogin.setEnabled(false);
192 mAutoLoginProgress.setVisibility(View.VISIBLE);
193 break;
194 case DeviceAccountLogin.FAILED:
195 mAutoLoginProgress.setVisibility(View.GONE);
196 mAutoLoginError.setVisibility(View.VISIBLE);
197 break;
198 case DeviceAccountLogin.INITIAL:
199 break;
200 default:
201 throw new IllegalStateException();
202 }
203 if (animate) {
204 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
205 getContext(), R.anim.autologin_enter));
206 }
207 } else {
208 mAutoLoginHandler = null;
209 if (animate) {
210 hideAutoLogin();
211 } else if (mAutoLogin.getAnimation() == null) {
212 mAutoLogin.setVisibility(View.GONE);
213 }
214 }
215 }
216
Michael Kolb7cdc4902011-02-03 17:54:40 -0800217 private ViewGroup.LayoutParams makeLayoutParams() {
218 if (mUseQuickControls) {
219 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
220 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800221 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800222 return new AbsoluteLayout.LayoutParams(
223 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
224 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800225 }
226 }
227
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800228 @Override
229 public int getEmbeddedHeight() {
Patrick Scott92066772011-03-10 08:46:27 -0500230 int height = mContainer.getHeight();
231 if (mAutoLogin.getVisibility() == View.VISIBLE) {
232 height += mAutoLogin.getHeight();
233 }
234 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800235 }
236
Michael Kolb376b5412010-12-15 11:52:57 -0800237 void setUseQuickControls(boolean useQuickControls) {
238 mUseQuickControls = useQuickControls;
Michael Kolb91902d52011-01-26 17:43:48 -0800239 mUrlInput.setUseQuickControls(mUseQuickControls);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800240 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800241 }
242
243 void setShowProgressOnly(boolean progress) {
244 if (progress) {
245 mContainer.setVisibility(View.GONE);
246 } else {
247 mContainer.setVisibility(View.VISIBLE);
248 }
249 }
250
Michael Kolb31d469b2010-12-09 20:49:54 -0800251 @Override
252 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800253 // if losing focus and not in touch mode, leave as is
254 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
255 setFocusState(hasFocus);
256 mUrlContainer.setBackgroundDrawable(hasFocus
257 ? mFocusDrawable : mUnfocusDrawable);
258 }
259 if (hasFocus) {
260 mUrlInput.forceIme();
261 if (mInVoiceMode) {
262 mUrlInput.forceFilter();
263 }
264 } else if (!mUrlInput.needsUpdate()) {
265 mUrlInput.dismissDropDown();
266 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800267 if (mUseQuickControls) {
268 mUi.hideTitleBar();
269 }
Narayan Kamathc93a2a92011-03-15 11:33:52 +0000270
271 if (mUrlInput.getText().length() == 0) {
272 Tab currentTab = mUiController.getTabControl().getCurrentTab();
273 if (currentTab != null) {
274 mUrlInput.setText(currentTab.getUrl(), false);
275 }
276 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800277 }
278 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700279 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700280
John Reck94b7e042011-02-15 15:02:33 -0800281 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500282 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800283 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500284 }
285
Michael Kolb81b6f832010-12-12 12:44:27 -0800286 /**
287 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800288 * @param clearInput clear the input field
289 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800290 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800291 // editing takes preference of progress
292 mContainer.setVisibility(View.VISIBLE);
293 if (mUseQuickControls) {
294 mProgressView.setVisibility(View.GONE);
295 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800296 if (!mUrlInput.hasFocus()) {
297 mUrlInput.requestFocus();
298 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800299 if (clearInput) {
300 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800301 } else if (mInVoiceMode) {
302 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800303 }
304 }
305
306 boolean isEditingUrl() {
307 return mUrlInput.hasFocus();
308 }
309
Michael Kolb7cdc4902011-02-03 17:54:40 -0800310 void stopEditingUrl() {
311 mUrlInput.clearFocus();
312 }
313
Patrick Scott92066772011-03-10 08:46:27 -0500314 private void hideAutoLogin() {
315 Animation anim = AnimationUtils.loadAnimation(
316 getContext(), R.anim.autologin_exit);
317 anim.setAnimationListener(new AnimationListener() {
318 @Override public void onAnimationEnd(Animation a) {
319 mAutoLogin.setVisibility(View.GONE);
320 }
321 @Override public void onAnimationStart(Animation a) {}
322 @Override public void onAnimationRepeat(Animation a) {}
323 });
324 mAutoLogin.startAnimation(anim);
325 }
326
Michael Kolba2b2ba82010-08-04 17:54:03 -0700327 @Override
328 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800329 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700330 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700331 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700333 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700334 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500335 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700336 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700337 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700338 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800339 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700340 } else if (mStopButton == v) {
341 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700342 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800343 if (!TextUtils.isEmpty(mUrlInput.getText())) {
344 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800345 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700346 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700347 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800348 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800349 } else if (mVoiceSearch == v) {
350 mUiController.startVoiceSearch();
Patrick Scott92066772011-03-10 08:46:27 -0500351 } else if (mAutoLoginCancel == v) {
352 if (mAutoLoginHandler != null) {
353 mAutoLoginHandler.cancel();
354 mAutoLoginHandler = null;
355 }
356 hideAutoLogin();
357 } else if (mAutoLoginLogin == v) {
358 if (mAutoLoginHandler != null) {
359 mAutoLoginAccount.setEnabled(false);
360 mAutoLoginLogin.setEnabled(false);
361 mAutoLoginProgress.setVisibility(View.VISIBLE);
362 mAutoLoginError.setVisibility(View.GONE);
363 mAutoLoginHandler.login(this);
364 }
365 } else if (mAutoLoginAccount == v) {
366 if (mAutoLoginHandler != null) {
367 mAutoLoginHandler.chooseAccount(this);
368 }
Michael Kolbfe251992010-07-08 15:41:55 -0700369 }
370 }
371
Michael Kolba2b2ba82010-08-04 17:54:03 -0700372 @Override
Patrick Scott92066772011-03-10 08:46:27 -0500373 public void setAccount(String account) {
374 mAutoLoginAccount.setText(account);
375 }
376
377 @Override
378 public void loginFailed() {
379 mAutoLoginAccount.setEnabled(true);
380 mAutoLoginLogin.setEnabled(true);
381 mAutoLoginProgress.setVisibility(View.GONE);
382 mAutoLoginError.setVisibility(View.VISIBLE);
383 }
384
385 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700386 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700387
Michael Kolb31d469b2010-12-09 20:49:54 -0800388 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000389 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800390 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800391 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800392 } else {
393 // clear
394 mUrlInput.setText("");
395 }
396 }
397
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800398 private void setFocusState(boolean focus) {
399 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800400 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
401 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700402 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800403 mStar.setVisibility(View.GONE);
404 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800405 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800406 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700407 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700408 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800409 mVoiceSearch.setVisibility(View.GONE);
410 mStar.setVisibility(View.VISIBLE);
411 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800412 if (mUseQuickControls) {
413 mSearchButton.setVisibility(View.GONE);
414 } else {
415 mSearchButton.setVisibility(View.VISIBLE);
416 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800417 mUrlIcon.setImageResource(mInVoiceMode ?
418 R.drawable.ic_search_holo_dark
419 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700420 }
421 }
422
Michael Kolba2b2ba82010-08-04 17:54:03 -0700423 private void stopOrRefresh() {
424 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700425 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700426 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700427 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700428 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400429 }
430
431 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700432 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400433 */
Michael Kolbfe251992010-07-08 15:41:55 -0700434 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700435 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800436 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700437 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800438 if (!blockvisuals) {
439 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
440 mProgressView.setVisibility(View.GONE);
441 mStopButton.setImageDrawable(mReloadDrawable);
442 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700443 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700444 } else {
445 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800446 if (!blockvisuals) {
447 mProgressView.setVisibility(View.VISIBLE);
448 mStopButton.setImageDrawable(mStopDrawable);
449 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700450 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700451 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700452 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
453 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700454 }
Michael Kolbfe251992010-07-08 15:41:55 -0700455 }
456
Michael Kolb60a68f52011-02-24 11:02:52 -0800457 private void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000458 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800459 }
460
461 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800462 SearchEngine searchEngine = BrowserSettings.getInstance()
463 .getSearchEngine();
464 boolean showvoicebutton = voiceSearchEnabled &&
465 (searchEngine != null && searchEngine.supportsVoiceSearch());
466 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800467 View.GONE);
468 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
469 View.VISIBLE);
470 }
471
Michael Kolbfe251992010-07-08 15:41:55 -0700472 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400473 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800474 if (!isEditingUrl()) {
475 mUrlInput.setText(title, false);
476 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700477 }
478
Michael Kolb31d469b2010-12-09 20:49:54 -0800479 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500480
Michael Kolb31d469b2010-12-09 20:49:54 -0800481 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000482 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800483 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800484 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800485 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800486 // clear voice mode when user types
487 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500488 }
489 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800490
Michael Kolbcfa3af52010-12-14 10:36:11 -0800491 // voicesearch
492
493 @Override
494 public void setInVoiceMode(boolean voicemode) {
495 setInVoiceMode(voicemode, null);
496 }
497
498 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
499 mInVoiceMode = voicemode;
500 mUrlInput.setVoiceResults(voiceResults);
Michael Kolb3aaef252011-03-09 18:13:56 -0800501 if (voicemode) {
502 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
503 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800504 }
505
John Reck117f07d2011-01-24 09:39:03 -0800506 @Override
507 void setIncognitoMode(boolean incognito) {
508 mUrlInput.setIncognitoMode(incognito);
509 }
Michael Kolb47171d82011-01-28 10:34:15 -0800510
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800511 @Override
512 public View focusSearch(View focused, int dir) {
513 if (FOCUS_DOWN == dir && hasFocus()) {
514 return getCurrentWebView();
515 }
516 return super.focusSearch(focused, dir);
517 }
518
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000519 void clearCompletions() {
520 mUrlInput.setSuggestedText(null);
521 }
522
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800523 @Override
524 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
525 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
526 // catch back key in order to do slightly more cleanup than usual
527 mUrlInput.clearFocus();
528 return true;
529 }
530 return super.dispatchKeyEventPreIme(evt);
531 }
532
533 private WebView getCurrentWebView() {
534 Tab t = mUi.getActiveTab();
535 if (t != null) {
536 return t.getWebView();
537 } else {
538 return null;
539 }
540 }
541
Narayan Kamath5119edd2011-02-23 15:49:17 +0000542 void registerDropdownChangeListener(DropdownChangeListener d) {
543 mUrlInput.registerDropdownChangeListener(d);
544 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400545}