blob: 5f0200220343967132b06f6ba5212bd0dc0bf49f [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
John Reckf94df7e2011-03-14 16:28:56 -070023import android.accounts.Account;
Michael Kolb8233fac2010-10-26 16:08:53 -070024import android.app.Activity;
Leon Scroggins571b3762010-05-26 10:25:01 -040025import android.content.Context;
26import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070027import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040028import android.graphics.drawable.Drawable;
Michael Kolb1ce78132010-09-23 15:50:53 -070029import android.text.TextUtils;
John Reckf94df7e2011-03-14 16:28:56 -070030import android.view.ContextThemeWrapper;
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;
John Reckf94df7e2011-03-14 16:28:56 -070037import android.view.animation.Animation;
38import android.view.animation.Animation.AnimationListener;
39import android.view.animation.AnimationUtils;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080040import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080041import android.widget.AbsoluteLayout;
John Reckf94df7e2011-03-14 16:28:56 -070042import android.widget.ArrayAdapter;
Patrick Scott92066772011-03-10 08:46:27 -050043import android.widget.Button;
Michael Kolb7cdc4902011-02-03 17:54:40 -080044import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080045import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040046import android.widget.ImageView;
Patrick Scott92066772011-03-10 08:46:27 -050047import android.widget.ProgressBar;
John Reckf94df7e2011-03-14 16:28:56 -070048import android.widget.Spinner;
Patrick Scott92066772011-03-10 08:46:27 -050049import android.widget.TextView;
Leon Scroggins571b3762010-05-26 10:25:01 -040050
Michael Kolbcfa3af52010-12-14 10:36:11 -080051import java.util.List;
52
Leon Scroggins571b3762010-05-26 10:25:01 -040053/**
Michael Kolbfe251992010-07-08 15:41:55 -070054 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040055 */
Michael Kolbfe251992010-07-08 15:41:55 -070056public class TitleBarXLarge extends TitleBarBase
Patrick Scott92066772011-03-10 08:46:27 -050057 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher,
58 DeviceAccountLogin.AutoLoginCallback {
Leon Scroggins571b3762010-05-26 10:25:01 -040059
Michael Kolb66706532010-12-12 19:50:22 -080060 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070061
Michael Kolba2b2ba82010-08-04 17:54:03 -070062 private Drawable mStopDrawable;
63 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070064
Michael Kolb3f65c382010-08-20 15:31:16 -070065 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080066 private ImageButton mBackButton;
67 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080068 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080069 private ImageView mUrlIcon;
70 private ImageView mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080071 private View mUrlContainer;
Michael Kolb513286f2010-09-09 12:55:12 -070072 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070073 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070074 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070075 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080076 private ImageView mVoiceSearch;
Michael Kolbc7485ae2010-09-03 10:10:58 -070077 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080078 private Drawable mFocusDrawable;
79 private Drawable mUnfocusDrawable;
Patrick Scott92066772011-03-10 08:46:27 -050080 // Auto-login UI
81 private View mAutoLogin;
John Reckf94df7e2011-03-14 16:28:56 -070082 private Spinner mAutoLoginAccount;
Patrick Scott92066772011-03-10 08:46:27 -050083 private Button mAutoLoginLogin;
84 private ProgressBar mAutoLoginProgress;
85 private TextView mAutoLoginError;
86 private ImageButton mAutoLoginCancel;
87 private DeviceAccountLogin mAutoLoginHandler;
John Reckf94df7e2011-03-14 16:28:56 -070088 private ArrayAdapter<String> mAccountsAdapter;
Michael Kolb81b6f832010-12-12 12:44:27 -080089
Michael Kolba2b2ba82010-08-04 17:54:03 -070090 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080091 private boolean mUseQuickControls;
Michael Kolbfe251992010-07-08 15:41:55 -070092
Michael Kolb81b6f832010-12-12 12:44:27 -080093 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -080094 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -080095 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -080096 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -070097 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080098 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
99 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800100 mFocusDrawable = resources.getDrawable(
101 R.drawable.textfield_active_holo_dark);
102 mUnfocusDrawable = resources.getDrawable(
103 R.drawable.textfield_default_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800104 mInVoiceMode = false;
Michael Kolb3aaef252011-03-09 18:13:56 -0800105 initLayout(activity);
Michael Kolbfe251992010-07-08 15:41:55 -0700106 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400107
Michael Kolb7cdc4902011-02-03 17:54:40 -0800108 @Override
109 void setTitleGravity(int gravity) {
110 if (mUseQuickControls) {
111 FrameLayout.LayoutParams lp =
112 (FrameLayout.LayoutParams) getLayoutParams();
113 lp.gravity = gravity;
114 setLayoutParams(lp);
115 } else {
116 super.setTitleGravity(gravity);
117 }
118 }
119
John Reck1605bef2011-01-10 18:11:18 -0800120 private void initLayout(Context context) {
Michael Kolbfe251992010-07-08 15:41:55 -0700121 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700122 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700123
Michael Kolb3f65c382010-08-20 15:31:16 -0700124 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800125 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700126 mAllButton = findViewById(R.id.all_btn);
127 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400128 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800129 mBackButton = (ImageButton) findViewById(R.id.back);
130 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -0800131 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800132 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700133 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -0800134 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700135 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700136 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700137 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -0800138 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700139 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb31d469b2010-12-09 20:49:54 -0800140 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700141 mBackButton.setOnClickListener(this);
142 mForwardButton.setOnClickListener(this);
143 mStar.setOnClickListener(this);
144 mAllButton.setOnClickListener(this);
145 mStopButton.setOnClickListener(this);
146 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700147 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700148 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800149 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800150 mUrlInput.setUrlInputListener(this);
151 mUrlInput.setContainer(mUrlContainer);
152 mUrlInput.setController(mUiController);
153 mUrlInput.setOnFocusChangeListener(this);
154 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000155 mUrlInput.addQueryTextWatcher(this);
Patrick Scott92066772011-03-10 08:46:27 -0500156 mAutoLogin = findViewById(R.id.autologin);
John Reckf94df7e2011-03-14 16:28:56 -0700157 mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account);
Patrick Scott92066772011-03-10 08:46:27 -0500158 mAutoLoginLogin = (Button) findViewById(R.id.autologin_login);
159 mAutoLoginLogin.setOnClickListener(this);
160 mAutoLoginProgress =
161 (ProgressBar) findViewById(R.id.autologin_progress);
162 mAutoLoginError = (TextView) findViewById(R.id.autologin_error);
163 mAutoLoginCancel =
164 (ImageButton) mAutoLogin.findViewById(R.id.autologin_close);
165 mAutoLoginCancel.setOnClickListener(this);
166
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800167 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800168 }
169
Michael Kolb5a72f182011-01-13 20:35:06 -0800170 void updateNavigationState(Tab tab) {
171 WebView web = tab.getWebView();
172 if (web != null) {
173 mBackButton.setImageResource(web.canGoBack()
174 ? R.drawable.ic_back_holo_dark
175 : R.drawable.ic_back_disabled_holo_dark);
176 mForwardButton.setImageResource(web.canGoForward()
177 ? R.drawable.ic_forward_holo_dark
178 : R.drawable.ic_forward_disabled_holo_dark);
179 }
180 }
181
Patrick Scott92066772011-03-10 08:46:27 -0500182 void updateAutoLogin(Tab tab, boolean animate) {
183 DeviceAccountLogin login = tab.getDeviceAccountLogin();
184 if (login != null) {
185 mAutoLoginHandler = login;
186 mAutoLogin.setVisibility(View.VISIBLE);
John Reckf94df7e2011-03-14 16:28:56 -0700187 ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
188 android.R.style.Theme_Holo_Light);
189 mAccountsAdapter = new ArrayAdapter<String>(wrapper,
190 android.R.layout.simple_spinner_item, login.getAccountNames());
191 mAccountsAdapter.setDropDownViewResource(
192 android.R.layout.simple_spinner_dropdown_item);
193 mAutoLoginAccount.setAdapter(mAccountsAdapter);
194 mAutoLoginAccount.setSelection(0);
Patrick Scott92066772011-03-10 08:46:27 -0500195 mAutoLoginAccount.setEnabled(true);
196 mAutoLoginLogin.setEnabled(true);
197 mAutoLoginProgress.setVisibility(View.GONE);
198 mAutoLoginError.setVisibility(View.GONE);
199 switch (login.getState()) {
200 case DeviceAccountLogin.PROCESSING:
201 mAutoLoginAccount.setEnabled(false);
202 mAutoLoginLogin.setEnabled(false);
203 mAutoLoginProgress.setVisibility(View.VISIBLE);
204 break;
205 case DeviceAccountLogin.FAILED:
206 mAutoLoginProgress.setVisibility(View.GONE);
207 mAutoLoginError.setVisibility(View.VISIBLE);
208 break;
209 case DeviceAccountLogin.INITIAL:
210 break;
211 default:
212 throw new IllegalStateException();
213 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700214 if (mUseQuickControls) {
215 mUi.showTitleBar();
216 } else {
217 if (animate) {
218 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
219 getContext(), R.anim.autologin_enter));
220 }
Patrick Scott92066772011-03-10 08:46:27 -0500221 }
222 } else {
223 mAutoLoginHandler = null;
Michael Kolb8a4c3822011-03-15 14:52:05 -0700224 if (mUseQuickControls) {
225 mUi.hideTitleBar();
Patrick Scott92066772011-03-10 08:46:27 -0500226 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700227 mUi.refreshWebView();
Michael Kolb8a4c3822011-03-15 14:52:05 -0700228 } else {
229 if (animate) {
230 hideAutoLogin();
231 } else if (mAutoLogin.getAnimation() == null) {
232 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700233 mUi.refreshWebView();
Michael Kolb8a4c3822011-03-15 14:52:05 -0700234 }
Patrick Scott92066772011-03-10 08:46:27 -0500235 }
236 }
237 }
238
Michael Kolb8a4c3822011-03-15 14:52:05 -0700239 boolean inAutoLogin() {
240 return mAutoLoginHandler != null;
241 }
242
Michael Kolb7cdc4902011-02-03 17:54:40 -0800243 private ViewGroup.LayoutParams makeLayoutParams() {
244 if (mUseQuickControls) {
245 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
246 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800247 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800248 return new AbsoluteLayout.LayoutParams(
249 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
250 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800251 }
252 }
253
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800254 @Override
255 public int getEmbeddedHeight() {
Patrick Scott92066772011-03-10 08:46:27 -0500256 int height = mContainer.getHeight();
257 if (mAutoLogin.getVisibility() == View.VISIBLE) {
258 height += mAutoLogin.getHeight();
259 }
260 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800261 }
262
Michael Kolb376b5412010-12-15 11:52:57 -0800263 void setUseQuickControls(boolean useQuickControls) {
264 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800265 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800266 }
267
268 void setShowProgressOnly(boolean progress) {
Michael Kolb8a4c3822011-03-15 14:52:05 -0700269 if (progress && !inAutoLogin()) {
Michael Kolb376b5412010-12-15 11:52:57 -0800270 mContainer.setVisibility(View.GONE);
271 } else {
272 mContainer.setVisibility(View.VISIBLE);
273 }
274 }
275
Michael Kolb31d469b2010-12-09 20:49:54 -0800276 @Override
277 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800278 // if losing focus and not in touch mode, leave as is
279 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
280 setFocusState(hasFocus);
281 mUrlContainer.setBackgroundDrawable(hasFocus
282 ? mFocusDrawable : mUnfocusDrawable);
283 }
284 if (hasFocus) {
285 mUrlInput.forceIme();
286 if (mInVoiceMode) {
287 mUrlInput.forceFilter();
288 }
289 } else if (!mUrlInput.needsUpdate()) {
290 mUrlInput.dismissDropDown();
291 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800292 if (mUseQuickControls) {
293 mUi.hideTitleBar();
294 }
Narayan Kamathc93a2a92011-03-15 11:33:52 +0000295
296 if (mUrlInput.getText().length() == 0) {
297 Tab currentTab = mUiController.getTabControl().getCurrentTab();
298 if (currentTab != null) {
299 mUrlInput.setText(currentTab.getUrl(), false);
300 }
301 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800302 }
303 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700304 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700305
John Reck94b7e042011-02-15 15:02:33 -0800306 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500307 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800308 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500309 }
310
Michael Kolb81b6f832010-12-12 12:44:27 -0800311 /**
312 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800313 * @param clearInput clear the input field
314 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800315 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800316 // editing takes preference of progress
317 mContainer.setVisibility(View.VISIBLE);
318 if (mUseQuickControls) {
319 mProgressView.setVisibility(View.GONE);
320 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800321 if (!mUrlInput.hasFocus()) {
322 mUrlInput.requestFocus();
323 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800324 if (clearInput) {
325 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800326 } else if (mInVoiceMode) {
327 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800328 }
329 }
330
331 boolean isEditingUrl() {
332 return mUrlInput.hasFocus();
333 }
334
Michael Kolb7cdc4902011-02-03 17:54:40 -0800335 void stopEditingUrl() {
336 mUrlInput.clearFocus();
337 }
338
Patrick Scott92066772011-03-10 08:46:27 -0500339 private void hideAutoLogin() {
340 Animation anim = AnimationUtils.loadAnimation(
341 getContext(), R.anim.autologin_exit);
342 anim.setAnimationListener(new AnimationListener() {
343 @Override public void onAnimationEnd(Animation a) {
344 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700345 mUi.refreshWebView();
Patrick Scott92066772011-03-10 08:46:27 -0500346 }
347 @Override public void onAnimationStart(Animation a) {}
348 @Override public void onAnimationRepeat(Animation a) {}
349 });
350 mAutoLogin.startAnimation(anim);
351 }
352
Michael Kolba2b2ba82010-08-04 17:54:03 -0700353 @Override
354 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800355 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700356 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700357 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700358 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700359 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700360 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500361 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700362 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700363 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700364 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800365 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700366 } else if (mStopButton == v) {
367 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700368 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800369 if (!TextUtils.isEmpty(mUrlInput.getText())) {
370 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800371 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700372 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700373 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800374 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800375 } else if (mVoiceSearch == v) {
376 mUiController.startVoiceSearch();
Patrick Scott92066772011-03-10 08:46:27 -0500377 } else if (mAutoLoginCancel == v) {
378 if (mAutoLoginHandler != null) {
379 mAutoLoginHandler.cancel();
380 mAutoLoginHandler = null;
381 }
382 hideAutoLogin();
383 } else if (mAutoLoginLogin == v) {
384 if (mAutoLoginHandler != null) {
385 mAutoLoginAccount.setEnabled(false);
386 mAutoLoginLogin.setEnabled(false);
387 mAutoLoginProgress.setVisibility(View.VISIBLE);
388 mAutoLoginError.setVisibility(View.GONE);
John Reckf94df7e2011-03-14 16:28:56 -0700389 mAutoLoginHandler.login(
390 mAutoLoginAccount.getSelectedItemPosition(), this);
Patrick Scott92066772011-03-10 08:46:27 -0500391 }
Michael Kolbfe251992010-07-08 15:41:55 -0700392 }
393 }
394
Michael Kolba2b2ba82010-08-04 17:54:03 -0700395 @Override
Patrick Scott92066772011-03-10 08:46:27 -0500396 public void loginFailed() {
397 mAutoLoginAccount.setEnabled(true);
398 mAutoLoginLogin.setEnabled(true);
399 mAutoLoginProgress.setVisibility(View.GONE);
400 mAutoLoginError.setVisibility(View.VISIBLE);
401 }
402
403 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700404 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700405
Michael Kolb31d469b2010-12-09 20:49:54 -0800406 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000407 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800408 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800409 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800410 } else {
411 // clear
412 mUrlInput.setText("");
413 }
414 }
415
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800416 private void setFocusState(boolean focus) {
417 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800418 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
419 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700420 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800421 mStar.setVisibility(View.GONE);
422 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800423 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800424 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700425 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700426 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800427 mVoiceSearch.setVisibility(View.GONE);
428 mStar.setVisibility(View.VISIBLE);
429 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800430 if (mUseQuickControls) {
431 mSearchButton.setVisibility(View.GONE);
432 } else {
433 mSearchButton.setVisibility(View.VISIBLE);
434 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800435 mUrlIcon.setImageResource(mInVoiceMode ?
436 R.drawable.ic_search_holo_dark
437 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700438 }
439 }
440
Michael Kolba2b2ba82010-08-04 17:54:03 -0700441 private void stopOrRefresh() {
442 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700443 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700444 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700445 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700446 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400447 }
448
449 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700450 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400451 */
Michael Kolbfe251992010-07-08 15:41:55 -0700452 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700453 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800454 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700455 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800456 if (!blockvisuals) {
457 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
458 mProgressView.setVisibility(View.GONE);
459 mStopButton.setImageDrawable(mReloadDrawable);
460 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700461 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700462 } else {
463 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800464 if (!blockvisuals) {
465 mProgressView.setVisibility(View.VISIBLE);
466 mStopButton.setImageDrawable(mStopDrawable);
467 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700468 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700469 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700470 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
471 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700472 }
Michael Kolbfe251992010-07-08 15:41:55 -0700473 }
474
Michael Kolb60a68f52011-02-24 11:02:52 -0800475 private void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000476 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800477 }
478
479 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800480 SearchEngine searchEngine = BrowserSettings.getInstance()
481 .getSearchEngine();
482 boolean showvoicebutton = voiceSearchEnabled &&
483 (searchEngine != null && searchEngine.supportsVoiceSearch());
484 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800485 View.GONE);
486 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
487 View.VISIBLE);
488 }
489
Michael Kolbfe251992010-07-08 15:41:55 -0700490 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400491 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800492 if (!isEditingUrl()) {
493 mUrlInput.setText(title, false);
494 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700495 }
496
Michael Kolb31d469b2010-12-09 20:49:54 -0800497 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500498
Michael Kolb31d469b2010-12-09 20:49:54 -0800499 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000500 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800501 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800502 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800503 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800504 // clear voice mode when user types
505 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500506 }
507 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800508
Michael Kolbcfa3af52010-12-14 10:36:11 -0800509 // voicesearch
510
511 @Override
512 public void setInVoiceMode(boolean voicemode) {
513 setInVoiceMode(voicemode, null);
514 }
515
516 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
517 mInVoiceMode = voicemode;
518 mUrlInput.setVoiceResults(voiceResults);
Michael Kolb3aaef252011-03-09 18:13:56 -0800519 if (voicemode) {
520 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
521 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800522 }
523
John Reck117f07d2011-01-24 09:39:03 -0800524 @Override
525 void setIncognitoMode(boolean incognito) {
526 mUrlInput.setIncognitoMode(incognito);
527 }
Michael Kolb47171d82011-01-28 10:34:15 -0800528
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800529 @Override
530 public View focusSearch(View focused, int dir) {
531 if (FOCUS_DOWN == dir && hasFocus()) {
532 return getCurrentWebView();
533 }
534 return super.focusSearch(focused, dir);
535 }
536
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000537 void clearCompletions() {
538 mUrlInput.setSuggestedText(null);
539 }
540
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800541 @Override
542 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
543 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
544 // catch back key in order to do slightly more cleanup than usual
545 mUrlInput.clearFocus();
546 return true;
547 }
548 return super.dispatchKeyEventPreIme(evt);
549 }
550
551 private WebView getCurrentWebView() {
552 Tab t = mUi.getActiveTab();
553 if (t != null) {
554 return t.getWebView();
555 } else {
556 return null;
557 }
558 }
559
Narayan Kamath5119edd2011-02-23 15:49:17 +0000560 void registerDropdownChangeListener(DropdownChangeListener d) {
561 mUrlInput.registerDropdownChangeListener(d);
562 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400563}