blob: 9fcc7b7828b2d6012fcbd3d3260c71e607735470 [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;
John Reckf94df7e2011-03-14 16:28:56 -070029import android.view.ContextThemeWrapper;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080030import 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;
John Reckf94df7e2011-03-14 16:28:56 -070036import android.view.animation.Animation;
37import android.view.animation.Animation.AnimationListener;
38import android.view.animation.AnimationUtils;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080039import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080040import android.widget.AbsoluteLayout;
John Reckf94df7e2011-03-14 16:28:56 -070041import android.widget.ArrayAdapter;
Patrick Scott92066772011-03-10 08:46:27 -050042import android.widget.Button;
Michael Kolb7cdc4902011-02-03 17:54:40 -080043import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080044import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040045import android.widget.ImageView;
Patrick Scott92066772011-03-10 08:46:27 -050046import android.widget.ProgressBar;
John Reckf94df7e2011-03-14 16:28:56 -070047import android.widget.Spinner;
Patrick Scott92066772011-03-10 08:46:27 -050048import android.widget.TextView;
Leon Scroggins571b3762010-05-26 10:25:01 -040049
Michael Kolbcfa3af52010-12-14 10:36:11 -080050import java.util.List;
51
Leon Scroggins571b3762010-05-26 10:25:01 -040052/**
Michael Kolbfe251992010-07-08 15:41:55 -070053 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040054 */
Michael Kolbfe251992010-07-08 15:41:55 -070055public class TitleBarXLarge extends TitleBarBase
Patrick Scott92066772011-03-10 08:46:27 -050056 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher,
57 DeviceAccountLogin.AutoLoginCallback {
Leon Scroggins571b3762010-05-26 10:25:01 -040058
Michael Kolb66706532010-12-12 19:50:22 -080059 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070060
Michael Kolba2b2ba82010-08-04 17:54:03 -070061 private Drawable mStopDrawable;
62 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070063
Michael Kolb3f65c382010-08-20 15:31:16 -070064 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080065 private ImageButton mBackButton;
66 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080067 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080068 private ImageView mUrlIcon;
69 private ImageView mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080070 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070071 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070072 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070073 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070074 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080075 private ImageView mVoiceSearch;
Michael Kolbc7485ae2010-09-03 10:10:58 -070076 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080077 private Drawable mFocusDrawable;
78 private Drawable mUnfocusDrawable;
Patrick Scott92066772011-03-10 08:46:27 -050079 // Auto-login UI
80 private View mAutoLogin;
John Reckf94df7e2011-03-14 16:28:56 -070081 private Spinner mAutoLoginAccount;
Patrick Scott92066772011-03-10 08:46:27 -050082 private Button mAutoLoginLogin;
83 private ProgressBar mAutoLoginProgress;
84 private TextView mAutoLoginError;
85 private ImageButton mAutoLoginCancel;
86 private DeviceAccountLogin mAutoLoginHandler;
John Reckf94df7e2011-03-14 16:28:56 -070087 private ArrayAdapter<String> mAccountsAdapter;
Michael Kolb81b6f832010-12-12 12:44:27 -080088
Michael Kolba2b2ba82010-08-04 17:54:03 -070089 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080090 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070091
Michael Kolb81b6f832010-12-12 12:44:27 -080092 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080093 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080094 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080095 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070096 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080097 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
98 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080099 mFocusDrawable = resources.getDrawable(
100 R.drawable.textfield_active_holo_dark);
101 mUnfocusDrawable = resources.getDrawable(
102 R.drawable.textfield_default_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800103 mInVoiceMode = false;
Michael Kolb3aaef252011-03-09 18:13:56 -0800104 initLayout(activity);
Michael Kolbfe251992010-07-08 15:41:55 -0700105 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400106
John Reck1605bef2011-01-10 18:11:18 -0800107 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700108 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700109 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700110
Michael Kolb3f65c382010-08-20 15:31:16 -0700111 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800112 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700113 mAllButton = findViewById(R.id.all_btn);
114 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400115 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800116 mBackButton = (ImageButton) findViewById(R.id.back);
117 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -0800118 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800119 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700120 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -0800121 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700122 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700123 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700124 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -0800125 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700126 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800127 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700128 mBackButton.setOnClickListener(this);
129 mForwardButton.setOnClickListener(this);
130 mStar.setOnClickListener(this);
131 mAllButton.setOnClickListener(this);
132 mStopButton.setOnClickListener(this);
133 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700134 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700135 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800136 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800137 mUrlInput.setUrlInputListener(this);
138 mUrlInput.setContainer(mUrlContainer);
139 mUrlInput.setController(mUiController);
140 mUrlInput.setOnFocusChangeListener(this);
141 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000142 mUrlInput.addQueryTextWatcher(this);
Patrick Scott92066772011-03-10 08:46:27 -0500143 mAutoLogin = findViewById(R.id.autologin);
John Reckf94df7e2011-03-14 16:28:56 -0700144 mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account);
Patrick Scott92066772011-03-10 08:46:27 -0500145 mAutoLoginLogin = (Button) findViewById(R.id.autologin_login);
146 mAutoLoginLogin.setOnClickListener(this);
147 mAutoLoginProgress =
148 (ProgressBar) findViewById(R.id.autologin_progress);
149 mAutoLoginError = (TextView) findViewById(R.id.autologin_error);
150 mAutoLoginCancel =
151 (ImageButton) mAutoLogin.findViewById(R.id.autologin_close);
152 mAutoLoginCancel.setOnClickListener(this);
153
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800154 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800155 }
156
Michael Kolb5a72f182011-01-13 20:35:06 -0800157 void updateNavigationState(Tab tab) {
158 WebView web = tab.getWebView();
159 if (web != null) {
160 mBackButton.setImageResource(web.canGoBack()
161 ? R.drawable.ic_back_holo_dark
162 : R.drawable.ic_back_disabled_holo_dark);
163 mForwardButton.setImageResource(web.canGoForward()
164 ? R.drawable.ic_forward_holo_dark
165 : R.drawable.ic_forward_disabled_holo_dark);
166 }
167 }
168
Patrick Scott92066772011-03-10 08:46:27 -0500169 void updateAutoLogin(Tab tab, boolean animate) {
170 DeviceAccountLogin login = tab.getDeviceAccountLogin();
171 if (login != null) {
172 mAutoLoginHandler = login;
173 mAutoLogin.setVisibility(View.VISIBLE);
John Reckf94df7e2011-03-14 16:28:56 -0700174 ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
175 android.R.style.Theme_Holo_Light);
176 mAccountsAdapter = new ArrayAdapter<String>(wrapper,
177 android.R.layout.simple_spinner_item, login.getAccountNames());
178 mAccountsAdapter.setDropDownViewResource(
179 android.R.layout.simple_spinner_dropdown_item);
180 mAutoLoginAccount.setAdapter(mAccountsAdapter);
181 mAutoLoginAccount.setSelection(0);
Patrick Scott92066772011-03-10 08:46:27 -0500182 mAutoLoginAccount.setEnabled(true);
183 mAutoLoginLogin.setEnabled(true);
184 mAutoLoginProgress.setVisibility(View.GONE);
185 mAutoLoginError.setVisibility(View.GONE);
186 switch (login.getState()) {
187 case DeviceAccountLogin.PROCESSING:
188 mAutoLoginAccount.setEnabled(false);
189 mAutoLoginLogin.setEnabled(false);
190 mAutoLoginProgress.setVisibility(View.VISIBLE);
191 break;
192 case DeviceAccountLogin.FAILED:
193 mAutoLoginProgress.setVisibility(View.GONE);
194 mAutoLoginError.setVisibility(View.VISIBLE);
195 break;
196 case DeviceAccountLogin.INITIAL:
197 break;
198 default:
199 throw new IllegalStateException();
200 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700201 if (mUseQuickControls) {
202 mUi.showTitleBar();
203 } else {
204 if (animate) {
205 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
206 getContext(), R.anim.autologin_enter));
207 }
Patrick Scott92066772011-03-10 08:46:27 -0500208 }
209 } else {
210 mAutoLoginHandler = null;
Michael Kolb8a4c3822011-03-15 14:52:05 -0700211 if (mUseQuickControls) {
212 mUi.hideTitleBar();
Patrick Scott92066772011-03-10 08:46:27 -0500213 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700214 mUi.refreshWebView();
Michael Kolb8a4c3822011-03-15 14:52:05 -0700215 } else {
216 if (animate) {
217 hideAutoLogin();
218 } else if (mAutoLogin.getAnimation() == null) {
219 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700220 mUi.refreshWebView();
Michael Kolb8a4c3822011-03-15 14:52:05 -0700221 }
Patrick Scott92066772011-03-10 08:46:27 -0500222 }
223 }
224 }
225
Michael Kolb8a4c3822011-03-15 14:52:05 -0700226 boolean inAutoLogin() {
227 return mAutoLoginHandler != null;
228 }
229
Michael Kolb7cdc4902011-02-03 17:54:40 -0800230 private ViewGroup.LayoutParams makeLayoutParams() {
231 if (mUseQuickControls) {
232 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
233 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800234 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800235 return new AbsoluteLayout.LayoutParams(
236 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
237 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800238 }
239 }
240
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800241 @Override
242 public int getEmbeddedHeight() {
Patrick Scott92066772011-03-10 08:46:27 -0500243 int height = mContainer.getHeight();
244 if (mAutoLogin.getVisibility() == View.VISIBLE) {
245 height += mAutoLogin.getHeight();
246 }
247 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800248 }
249
Michael Kolb376b5412010-12-15 11:52:57 -0800250 void setUseQuickControls(boolean useQuickControls) {
251 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800252 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800253 }
254
255 void setShowProgressOnly(boolean progress) {
Michael Kolb8a4c3822011-03-15 14:52:05 -0700256 if (progress && !inAutoLogin()) {
Michael Kolb376b5412010-12-15 11:52:57 -0800257 mContainer.setVisibility(View.GONE);
258 } else {
259 mContainer.setVisibility(View.VISIBLE);
260 }
261 }
262
Michael Kolb31d469b2010-12-09 20:49:54 -0800263 @Override
264 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800265 // if losing focus and not in touch mode, leave as is
266 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
267 setFocusState(hasFocus);
268 mUrlContainer.setBackgroundDrawable(hasFocus
269 ? mFocusDrawable : mUnfocusDrawable);
270 }
271 if (hasFocus) {
272 mUrlInput.forceIme();
273 if (mInVoiceMode) {
274 mUrlInput.forceFilter();
275 }
276 } else if (!mUrlInput.needsUpdate()) {
277 mUrlInput.dismissDropDown();
278 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800279 if (mUseQuickControls) {
280 mUi.hideTitleBar();
281 }
Narayan Kamathc93a2a92011-03-15 11:33:52 +0000282
283 if (mUrlInput.getText().length() == 0) {
284 Tab currentTab = mUiController.getTabControl().getCurrentTab();
285 if (currentTab != null) {
286 mUrlInput.setText(currentTab.getUrl(), false);
287 }
288 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800289 }
290 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700291 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700292
John Reck94b7e042011-02-15 15:02:33 -0800293 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500294 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800295 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500296 }
297
Michael Kolb81b6f832010-12-12 12:44:27 -0800298 /**
299 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800300 * @param clearInput clear the input field
301 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800302 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800303 // editing takes preference of progress
304 mContainer.setVisibility(View.VISIBLE);
305 if (mUseQuickControls) {
306 mProgressView.setVisibility(View.GONE);
307 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800308 if (!mUrlInput.hasFocus()) {
309 mUrlInput.requestFocus();
310 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800311 if (clearInput) {
312 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800313 } else if (mInVoiceMode) {
314 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800315 }
316 }
317
318 boolean isEditingUrl() {
319 return mUrlInput.hasFocus();
320 }
321
Michael Kolb7cdc4902011-02-03 17:54:40 -0800322 void stopEditingUrl() {
323 mUrlInput.clearFocus();
324 }
325
Patrick Scott92066772011-03-10 08:46:27 -0500326 private void hideAutoLogin() {
327 Animation anim = AnimationUtils.loadAnimation(
328 getContext(), R.anim.autologin_exit);
329 anim.setAnimationListener(new AnimationListener() {
330 @Override public void onAnimationEnd(Animation a) {
331 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700332 mUi.refreshWebView();
Patrick Scott92066772011-03-10 08:46:27 -0500333 }
334 @Override public void onAnimationStart(Animation a) {}
335 @Override public void onAnimationRepeat(Animation a) {}
336 });
337 mAutoLogin.startAnimation(anim);
338 }
339
Michael Kolba2b2ba82010-08-04 17:54:03 -0700340 @Override
341 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800342 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700343 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700344 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700345 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700346 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700347 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500348 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700349 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700350 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700351 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800352 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700353 } else if (mStopButton == v) {
354 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700355 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800356 if (!TextUtils.isEmpty(mUrlInput.getText())) {
357 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800358 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700359 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700360 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800361 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800362 } else if (mVoiceSearch == v) {
363 mUiController.startVoiceSearch();
Patrick Scott92066772011-03-10 08:46:27 -0500364 } else if (mAutoLoginCancel == v) {
365 if (mAutoLoginHandler != null) {
366 mAutoLoginHandler.cancel();
367 mAutoLoginHandler = null;
368 }
369 hideAutoLogin();
370 } else if (mAutoLoginLogin == v) {
371 if (mAutoLoginHandler != null) {
372 mAutoLoginAccount.setEnabled(false);
373 mAutoLoginLogin.setEnabled(false);
374 mAutoLoginProgress.setVisibility(View.VISIBLE);
375 mAutoLoginError.setVisibility(View.GONE);
John Reckf94df7e2011-03-14 16:28:56 -0700376 mAutoLoginHandler.login(
377 mAutoLoginAccount.getSelectedItemPosition(), this);
Patrick Scott92066772011-03-10 08:46:27 -0500378 }
Michael Kolbfe251992010-07-08 15:41:55 -0700379 }
380 }
381
Michael Kolba2b2ba82010-08-04 17:54:03 -0700382 @Override
Patrick Scott92066772011-03-10 08:46:27 -0500383 public void loginFailed() {
384 mAutoLoginAccount.setEnabled(true);
385 mAutoLoginLogin.setEnabled(true);
386 mAutoLoginProgress.setVisibility(View.GONE);
387 mAutoLoginError.setVisibility(View.VISIBLE);
388 }
389
390 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700391 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700392
Michael Kolb31d469b2010-12-09 20:49:54 -0800393 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000394 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800395 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800396 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800397 } else {
398 // clear
399 mUrlInput.setText("");
400 }
401 }
402
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800403 private void setFocusState(boolean focus) {
404 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800405 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
406 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700407 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800408 mStar.setVisibility(View.GONE);
409 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800410 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800411 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700412 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700413 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800414 mVoiceSearch.setVisibility(View.GONE);
415 mStar.setVisibility(View.VISIBLE);
416 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800417 if (mUseQuickControls) {
418 mSearchButton.setVisibility(View.GONE);
419 } else {
420 mSearchButton.setVisibility(View.VISIBLE);
421 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800422 mUrlIcon.setImageResource(mInVoiceMode ?
423 R.drawable.ic_search_holo_dark
424 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700425 }
426 }
427
Michael Kolba2b2ba82010-08-04 17:54:03 -0700428 private void stopOrRefresh() {
429 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700430 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700431 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700432 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700433 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400434 }
435
436 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700437 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400438 */
Michael Kolbfe251992010-07-08 15:41:55 -0700439 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700440 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800441 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700442 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800443 if (!blockvisuals) {
444 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
445 mProgressView.setVisibility(View.GONE);
446 mStopButton.setImageDrawable(mReloadDrawable);
447 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700448 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700449 } else {
450 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800451 if (!blockvisuals) {
452 mProgressView.setVisibility(View.VISIBLE);
453 mStopButton.setImageDrawable(mStopDrawable);
454 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700455 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700456 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700457 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
458 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700459 }
Michael Kolbfe251992010-07-08 15:41:55 -0700460 }
461
Michael Kolb60a68f52011-02-24 11:02:52 -0800462 private void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000463 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800464 }
465
466 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800467 SearchEngine searchEngine = BrowserSettings.getInstance()
468 .getSearchEngine();
469 boolean showvoicebutton = voiceSearchEnabled &&
470 (searchEngine != null && searchEngine.supportsVoiceSearch());
471 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800472 View.GONE);
473 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
474 View.VISIBLE);
475 }
476
Michael Kolbfe251992010-07-08 15:41:55 -0700477 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400478 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800479 if (!isEditingUrl()) {
480 mUrlInput.setText(title, false);
481 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700482 }
483
Michael Kolb31d469b2010-12-09 20:49:54 -0800484 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500485
Michael Kolb31d469b2010-12-09 20:49:54 -0800486 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000487 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800488 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800489 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800490 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800491 // clear voice mode when user types
492 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500493 }
494 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800495
Michael Kolbcfa3af52010-12-14 10:36:11 -0800496 // voicesearch
497
498 @Override
499 public void setInVoiceMode(boolean voicemode) {
500 setInVoiceMode(voicemode, null);
501 }
502
503 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
504 mInVoiceMode = voicemode;
505 mUrlInput.setVoiceResults(voiceResults);
Michael Kolb3aaef252011-03-09 18:13:56 -0800506 if (voicemode) {
507 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
508 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800509 }
510
John Reck117f07d2011-01-24 09:39:03 -0800511 @Override
512 void setIncognitoMode(boolean incognito) {
513 mUrlInput.setIncognitoMode(incognito);
514 }
Michael Kolb47171d82011-01-28 10:34:15 -0800515
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800516 @Override
517 public View focusSearch(View focused, int dir) {
518 if (FOCUS_DOWN == dir && hasFocus()) {
519 return getCurrentWebView();
520 }
521 return super.focusSearch(focused, dir);
522 }
523
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000524 void clearCompletions() {
525 mUrlInput.setSuggestedText(null);
526 }
527
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800528 @Override
529 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
530 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
531 // catch back key in order to do slightly more cleanup than usual
532 mUrlInput.clearFocus();
533 return true;
534 }
535 return super.dispatchKeyEventPreIme(evt);
536 }
537
538 private WebView getCurrentWebView() {
539 Tab t = mUi.getActiveTab();
540 if (t != null) {
541 return t.getWebView();
542 } else {
543 return null;
544 }
545 }
546
Narayan Kamath5119edd2011-02-23 15:49:17 +0000547 void registerDropdownChangeListener(DropdownChangeListener d) {
548 mUrlInput.registerDropdownChangeListener(d);
549 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400550}