blob: e91597f607f659e4e21ee2bc32dd8a16a752ea20 [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 Kolb0c425da2011-05-19 14:35:45 -070023import android.animation.Animator;
24import android.animation.Animator.AnimatorListener;
25import android.animation.AnimatorSet;
26import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070027import android.app.Activity;
Leon Scroggins571b3762010-05-26 10:25:01 -040028import android.content.Context;
Michael Kolb0c425da2011-05-19 14:35:45 -070029import android.content.res.Configuration;
Leon Scroggins571b3762010-05-26 10:25:01 -040030import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070031import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040032import android.graphics.drawable.Drawable;
Michael Kolb1ce78132010-09-23 15:50:53 -070033import android.text.TextUtils;
John Reckf94df7e2011-03-14 16:28:56 -070034import android.view.ContextThemeWrapper;
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080035import android.view.KeyEvent;
Leon Scroggins571b3762010-05-26 10:25:01 -040036import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040037import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070038import android.view.View.OnClickListener;
Michael Kolb31d469b2010-12-09 20:49:54 -080039import android.view.View.OnFocusChangeListener;
Michael Kolb7cdc4902011-02-03 17:54:40 -080040import android.view.ViewGroup;
John Reckf94df7e2011-03-14 16:28:56 -070041import android.view.animation.Animation;
42import android.view.animation.Animation.AnimationListener;
43import android.view.animation.AnimationUtils;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080044import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080045import android.widget.AbsoluteLayout;
John Reckf94df7e2011-03-14 16:28:56 -070046import android.widget.ArrayAdapter;
Patrick Scott92066772011-03-10 08:46:27 -050047import android.widget.Button;
Michael Kolb7cdc4902011-02-03 17:54:40 -080048import android.widget.FrameLayout;
Michael Kolb5a72f182011-01-13 20:35:06 -080049import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040050import android.widget.ImageView;
Patrick Scott92066772011-03-10 08:46:27 -050051import android.widget.ProgressBar;
John Reckf94df7e2011-03-14 16:28:56 -070052import android.widget.Spinner;
Patrick Scott92066772011-03-10 08:46:27 -050053import android.widget.TextView;
Leon Scroggins571b3762010-05-26 10:25:01 -040054
Michael Kolbcfa3af52010-12-14 10:36:11 -080055import java.util.List;
56
Leon Scroggins571b3762010-05-26 10:25:01 -040057/**
Michael Kolbfe251992010-07-08 15:41:55 -070058 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040059 */
Michael Kolbfe251992010-07-08 15:41:55 -070060public class TitleBarXLarge extends TitleBarBase
Patrick Scott92066772011-03-10 08:46:27 -050061 implements OnClickListener, OnFocusChangeListener, TextChangeWatcher,
62 DeviceAccountLogin.AutoLoginCallback {
Leon Scroggins571b3762010-05-26 10:25:01 -040063
Michael Kolb66706532010-12-12 19:50:22 -080064 private XLargeUi mUi;
Michael Kolb8233fac2010-10-26 16:08:53 -070065
Michael Kolba2b2ba82010-08-04 17:54:03 -070066 private Drawable mStopDrawable;
67 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070068
Michael Kolb3f65c382010-08-20 15:31:16 -070069 private View mContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080070 private ImageButton mBackButton;
71 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080072 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080073 private ImageView mUrlIcon;
74 private ImageView mSearchButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080075 private View mUrlContainer;
Michael Kolb0c425da2011-05-19 14:35:45 -070076 private View mNavButtons;
Michael Kolb513286f2010-09-09 12:55:12 -070077 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070078 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070079 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070080 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080081 private ImageView mVoiceSearch;
Michael Kolbc7485ae2010-09-03 10:10:58 -070082 private PageProgressView mProgressView;
Michael Kolbcfa3af52010-12-14 10:36:11 -080083 private Drawable mFocusDrawable;
84 private Drawable mUnfocusDrawable;
Patrick Scott92066772011-03-10 08:46:27 -050085 // Auto-login UI
86 private View mAutoLogin;
John Reckf94df7e2011-03-14 16:28:56 -070087 private Spinner mAutoLoginAccount;
Patrick Scott92066772011-03-10 08:46:27 -050088 private Button mAutoLoginLogin;
89 private ProgressBar mAutoLoginProgress;
90 private TextView mAutoLoginError;
91 private ImageButton mAutoLoginCancel;
92 private DeviceAccountLogin mAutoLoginHandler;
John Reckf94df7e2011-03-14 16:28:56 -070093 private ArrayAdapter<String> mAccountsAdapter;
Michael Kolb81b6f832010-12-12 12:44:27 -080094
Michael Kolba2b2ba82010-08-04 17:54:03 -070095 private boolean mInLoad;
Michael Kolb376b5412010-12-15 11:52:57 -080096 private boolean mUseQuickControls;
Michael Kolb0c425da2011-05-19 14:35:45 -070097 private boolean mHideNavButtons;
Michael Kolbfe251992010-07-08 15:41:55 -070098
Michael Kolb81b6f832010-12-12 12:44:27 -080099 public TitleBarXLarge(Activity activity, UiController controller,
Michael Kolb66706532010-12-12 19:50:22 -0800100 XLargeUi ui) {
John Reck92026732011-02-15 10:12:30 -0800101 super(activity, controller, ui);
Michael Kolb81b6f832010-12-12 12:44:27 -0800102 mUi = ui;
Michael Kolb8233fac2010-10-26 16:08:53 -0700103 Resources resources = activity.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -0800104 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
105 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800106 mFocusDrawable = resources.getDrawable(
107 R.drawable.textfield_active_holo_dark);
108 mUnfocusDrawable = resources.getDrawable(
109 R.drawable.textfield_default_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800110 mInVoiceMode = false;
Michael Kolb3aaef252011-03-09 18:13:56 -0800111 initLayout(activity);
Michael Kolbfe251992010-07-08 15:41:55 -0700112 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400113
John Reck1605bef2011-01-10 18:11:18 -0800114 private void initLayout(Context context) {
Michael Kolb0c425da2011-05-19 14:35:45 -0700115 Resources res = mContext.getResources();
116 mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons);
Michael Kolbfe251992010-07-08 15:41:55 -0700117 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700118 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -0700119
Michael Kolb3f65c382010-08-20 15:31:16 -0700120 mContainer = findViewById(R.id.taburlbar);
Michael Kolb31d469b2010-12-09 20:49:54 -0800121 mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
Michael Kolbfe251992010-07-08 15:41:55 -0700122 mAllButton = findViewById(R.id.all_btn);
123 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -0400124 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -0800125 mBackButton = (ImageButton) findViewById(R.id.back);
126 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -0800127 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800128 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700129 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -0800130 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700131 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolb513286f2010-09-09 12:55:12 -0700132 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700133 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -0800134 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700135 mProgressView = (PageProgressView) findViewById(R.id.progress);
Michael Kolb0c425da2011-05-19 14:35:45 -0700136 mNavButtons = findViewById(R.id.navbuttons);
Michael Kolb31d469b2010-12-09 20:49:54 -0800137 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700138 mBackButton.setOnClickListener(this);
139 mForwardButton.setOnClickListener(this);
140 mStar.setOnClickListener(this);
141 mAllButton.setOnClickListener(this);
142 mStopButton.setOnClickListener(this);
143 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -0700144 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700145 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800146 mVoiceSearch.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -0800147 mUrlInput.setUrlInputListener(this);
148 mUrlInput.setContainer(mUrlContainer);
149 mUrlInput.setController(mUiController);
150 mUrlInput.setOnFocusChangeListener(this);
151 mUrlInput.setSelectAllOnFocus(true);
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000152 mUrlInput.addQueryTextWatcher(this);
Patrick Scott92066772011-03-10 08:46:27 -0500153 mAutoLogin = findViewById(R.id.autologin);
John Reckf94df7e2011-03-14 16:28:56 -0700154 mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account);
Patrick Scott92066772011-03-10 08:46:27 -0500155 mAutoLoginLogin = (Button) findViewById(R.id.autologin_login);
156 mAutoLoginLogin.setOnClickListener(this);
157 mAutoLoginProgress =
158 (ProgressBar) findViewById(R.id.autologin_progress);
159 mAutoLoginError = (TextView) findViewById(R.id.autologin_error);
160 mAutoLoginCancel =
161 (ImageButton) mAutoLogin.findViewById(R.id.autologin_close);
162 mAutoLoginCancel.setOnClickListener(this);
163
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800164 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800165 }
166
Michael Kolb0c425da2011-05-19 14:35:45 -0700167 @Override
168 public void onConfigurationChanged(Configuration config) {
169 super.onConfigurationChanged(config);
170 Resources res = mContext.getResources();
171 mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons);
172 if (mUrlInput.hasFocus()) {
173 if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) {
174 int aw = mNavButtons.getMeasuredWidth();
175 mNavButtons.setVisibility(View.GONE);
176 mNavButtons.setAlpha(0f);
177 mNavButtons.setTranslationX(-aw);
178 } else if (!mHideNavButtons && (mNavButtons.getVisibility() == View.GONE)) {
179 mNavButtons.setVisibility(View.VISIBLE);
180 mNavButtons.setAlpha(1f);
181 mNavButtons.setTranslationX(0);
182 }
183 }
184 }
185
Michael Kolb5a72f182011-01-13 20:35:06 -0800186 void updateNavigationState(Tab tab) {
187 WebView web = tab.getWebView();
188 if (web != null) {
189 mBackButton.setImageResource(web.canGoBack()
190 ? R.drawable.ic_back_holo_dark
191 : R.drawable.ic_back_disabled_holo_dark);
192 mForwardButton.setImageResource(web.canGoForward()
193 ? R.drawable.ic_forward_holo_dark
194 : R.drawable.ic_forward_disabled_holo_dark);
195 }
196 }
197
Patrick Scott92066772011-03-10 08:46:27 -0500198 void updateAutoLogin(Tab tab, boolean animate) {
199 DeviceAccountLogin login = tab.getDeviceAccountLogin();
200 if (login != null) {
201 mAutoLoginHandler = login;
202 mAutoLogin.setVisibility(View.VISIBLE);
John Reckf94df7e2011-03-14 16:28:56 -0700203 ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
204 android.R.style.Theme_Holo_Light);
205 mAccountsAdapter = new ArrayAdapter<String>(wrapper,
206 android.R.layout.simple_spinner_item, login.getAccountNames());
207 mAccountsAdapter.setDropDownViewResource(
208 android.R.layout.simple_spinner_dropdown_item);
209 mAutoLoginAccount.setAdapter(mAccountsAdapter);
210 mAutoLoginAccount.setSelection(0);
Patrick Scott92066772011-03-10 08:46:27 -0500211 mAutoLoginAccount.setEnabled(true);
212 mAutoLoginLogin.setEnabled(true);
213 mAutoLoginProgress.setVisibility(View.GONE);
214 mAutoLoginError.setVisibility(View.GONE);
215 switch (login.getState()) {
216 case DeviceAccountLogin.PROCESSING:
217 mAutoLoginAccount.setEnabled(false);
218 mAutoLoginLogin.setEnabled(false);
219 mAutoLoginProgress.setVisibility(View.VISIBLE);
220 break;
221 case DeviceAccountLogin.FAILED:
222 mAutoLoginProgress.setVisibility(View.GONE);
223 mAutoLoginError.setVisibility(View.VISIBLE);
224 break;
225 case DeviceAccountLogin.INITIAL:
226 break;
227 default:
228 throw new IllegalStateException();
229 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700230 if (mUseQuickControls) {
231 mUi.showTitleBar();
232 } else {
233 if (animate) {
234 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
235 getContext(), R.anim.autologin_enter));
236 }
Patrick Scott92066772011-03-10 08:46:27 -0500237 }
238 } else {
239 mAutoLoginHandler = null;
Michael Kolb8a4c3822011-03-15 14:52:05 -0700240 if (mUseQuickControls) {
241 mUi.hideTitleBar();
Patrick Scott92066772011-03-10 08:46:27 -0500242 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700243 mUi.refreshWebView();
Michael Kolb8a4c3822011-03-15 14:52:05 -0700244 } else {
245 if (animate) {
246 hideAutoLogin();
247 } else if (mAutoLogin.getAnimation() == null) {
248 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700249 mUi.refreshWebView();
Michael Kolb8a4c3822011-03-15 14:52:05 -0700250 }
Patrick Scott92066772011-03-10 08:46:27 -0500251 }
252 }
253 }
254
Michael Kolb8a4c3822011-03-15 14:52:05 -0700255 boolean inAutoLogin() {
256 return mAutoLoginHandler != null;
257 }
258
Michael Kolb7cdc4902011-02-03 17:54:40 -0800259 private ViewGroup.LayoutParams makeLayoutParams() {
260 if (mUseQuickControls) {
261 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
262 LayoutParams.WRAP_CONTENT);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800263 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800264 return new AbsoluteLayout.LayoutParams(
265 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
266 0, 0);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800267 }
268 }
269
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800270 @Override
271 public int getEmbeddedHeight() {
Patrick Scott92066772011-03-10 08:46:27 -0500272 int height = mContainer.getHeight();
273 if (mAutoLogin.getVisibility() == View.VISIBLE) {
274 height += mAutoLogin.getHeight();
275 }
276 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800277 }
278
Michael Kolb376b5412010-12-15 11:52:57 -0800279 void setUseQuickControls(boolean useQuickControls) {
280 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800281 setLayoutParams(makeLayoutParams());
Michael Kolb376b5412010-12-15 11:52:57 -0800282 }
283
284 void setShowProgressOnly(boolean progress) {
Michael Kolb8a4c3822011-03-15 14:52:05 -0700285 if (progress && !inAutoLogin()) {
Michael Kolb376b5412010-12-15 11:52:57 -0800286 mContainer.setVisibility(View.GONE);
287 } else {
288 mContainer.setVisibility(View.VISIBLE);
289 }
290 }
291
Michael Kolb31d469b2010-12-09 20:49:54 -0800292 @Override
293 public void onFocusChange(View view, boolean hasFocus) {
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800294 // if losing focus and not in touch mode, leave as is
295 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
296 setFocusState(hasFocus);
297 mUrlContainer.setBackgroundDrawable(hasFocus
298 ? mFocusDrawable : mUnfocusDrawable);
299 }
300 if (hasFocus) {
301 mUrlInput.forceIme();
302 if (mInVoiceMode) {
303 mUrlInput.forceFilter();
304 }
305 } else if (!mUrlInput.needsUpdate()) {
306 mUrlInput.dismissDropDown();
307 mUrlInput.hideIME();
Michael Kolb2a56eca2011-02-25 09:45:06 -0800308 if (mUseQuickControls) {
309 mUi.hideTitleBar();
310 }
Narayan Kamathc93a2a92011-03-15 11:33:52 +0000311
312 if (mUrlInput.getText().length() == 0) {
313 Tab currentTab = mUiController.getTabControl().getCurrentTab();
314 if (currentTab != null) {
315 mUrlInput.setText(currentTab.getUrl(), false);
316 }
317 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800318 }
319 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700320 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700321
John Reck94b7e042011-02-15 15:02:33 -0800322 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500323 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800324 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500325 }
326
Michael Kolb81b6f832010-12-12 12:44:27 -0800327 /**
328 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800329 * @param clearInput clear the input field
330 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800331 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800332 // editing takes preference of progress
333 mContainer.setVisibility(View.VISIBLE);
334 if (mUseQuickControls) {
335 mProgressView.setVisibility(View.GONE);
336 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800337 if (!mUrlInput.hasFocus()) {
338 mUrlInput.requestFocus();
339 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800340 if (clearInput) {
341 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800342 } else if (mInVoiceMode) {
343 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800344 }
345 }
346
347 boolean isEditingUrl() {
348 return mUrlInput.hasFocus();
349 }
350
Michael Kolb7cdc4902011-02-03 17:54:40 -0800351 void stopEditingUrl() {
352 mUrlInput.clearFocus();
353 }
354
Patrick Scott92066772011-03-10 08:46:27 -0500355 private void hideAutoLogin() {
356 Animation anim = AnimationUtils.loadAnimation(
357 getContext(), R.anim.autologin_exit);
358 anim.setAnimationListener(new AnimationListener() {
359 @Override public void onAnimationEnd(Animation a) {
360 mAutoLogin.setVisibility(View.GONE);
Michael Kolb2ba24b92011-03-17 10:59:10 -0700361 mUi.refreshWebView();
Patrick Scott92066772011-03-10 08:46:27 -0500362 }
363 @Override public void onAnimationStart(Animation a) {}
364 @Override public void onAnimationRepeat(Animation a) {}
365 });
366 mAutoLogin.startAnimation(anim);
367 }
368
Michael Kolba2b2ba82010-08-04 17:54:03 -0700369 @Override
370 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800371 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700372 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700373 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700374 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700375 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700376 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500377 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700378 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700380 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800381 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700382 } else if (mStopButton == v) {
383 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700384 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800385 if (!TextUtils.isEmpty(mUrlInput.getText())) {
386 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800387 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700388 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700389 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800390 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800391 } else if (mVoiceSearch == v) {
392 mUiController.startVoiceSearch();
Patrick Scott92066772011-03-10 08:46:27 -0500393 } else if (mAutoLoginCancel == v) {
394 if (mAutoLoginHandler != null) {
395 mAutoLoginHandler.cancel();
396 mAutoLoginHandler = null;
397 }
398 hideAutoLogin();
399 } else if (mAutoLoginLogin == v) {
400 if (mAutoLoginHandler != null) {
401 mAutoLoginAccount.setEnabled(false);
402 mAutoLoginLogin.setEnabled(false);
403 mAutoLoginProgress.setVisibility(View.VISIBLE);
404 mAutoLoginError.setVisibility(View.GONE);
John Reckf94df7e2011-03-14 16:28:56 -0700405 mAutoLoginHandler.login(
406 mAutoLoginAccount.getSelectedItemPosition(), this);
Patrick Scott92066772011-03-10 08:46:27 -0500407 }
Michael Kolbfe251992010-07-08 15:41:55 -0700408 }
409 }
410
Michael Kolba2b2ba82010-08-04 17:54:03 -0700411 @Override
Patrick Scott92066772011-03-10 08:46:27 -0500412 public void loginFailed() {
413 mAutoLoginAccount.setEnabled(true);
414 mAutoLoginLogin.setEnabled(true);
415 mAutoLoginProgress.setVisibility(View.GONE);
416 mAutoLoginError.setVisibility(View.VISIBLE);
417 }
418
419 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700420 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700421
Michael Kolb31d469b2010-12-09 20:49:54 -0800422 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000423 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800424 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800425 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800426 } else {
427 // clear
428 mUrlInput.setText("");
429 }
430 }
431
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800432 private void setFocusState(boolean focus) {
433 if (focus) {
Michael Kolb0c425da2011-05-19 14:35:45 -0700434 if (mHideNavButtons) {
435 hideNavButtons();
436 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800437 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
438 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700439 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800440 mStar.setVisibility(View.GONE);
441 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800442 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800443 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700444 } else {
Michael Kolb0c425da2011-05-19 14:35:45 -0700445 if (mHideNavButtons) {
446 showNavButtons();
447 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700448 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800449 mVoiceSearch.setVisibility(View.GONE);
450 mStar.setVisibility(View.VISIBLE);
451 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800452 if (mUseQuickControls) {
453 mSearchButton.setVisibility(View.GONE);
454 } else {
455 mSearchButton.setVisibility(View.VISIBLE);
456 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800457 mUrlIcon.setImageResource(mInVoiceMode ?
458 R.drawable.ic_search_holo_dark
459 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700460 }
461 }
462
Michael Kolba2b2ba82010-08-04 17:54:03 -0700463 private void stopOrRefresh() {
464 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700465 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700466 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700468 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400469 }
470
471 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700472 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400473 */
Michael Kolbfe251992010-07-08 15:41:55 -0700474 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700475 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800476 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700477 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800478 if (!blockvisuals) {
479 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
480 mProgressView.setVisibility(View.GONE);
481 mStopButton.setImageDrawable(mReloadDrawable);
482 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700483 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700484 } else {
485 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800486 if (!blockvisuals) {
487 mProgressView.setVisibility(View.VISIBLE);
488 mStopButton.setImageDrawable(mStopDrawable);
489 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700490 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700491 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700492 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
493 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700494 }
Michael Kolbfe251992010-07-08 15:41:55 -0700495 }
496
Michael Kolb60a68f52011-02-24 11:02:52 -0800497 private void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000498 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800499 }
500
501 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800502 SearchEngine searchEngine = BrowserSettings.getInstance()
503 .getSearchEngine();
504 boolean showvoicebutton = voiceSearchEnabled &&
505 (searchEngine != null && searchEngine.supportsVoiceSearch());
506 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800507 View.GONE);
508 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
509 View.VISIBLE);
510 }
511
Michael Kolbfe251992010-07-08 15:41:55 -0700512 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400513 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800514 if (!isEditingUrl()) {
515 mUrlInput.setText(title, false);
516 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700517 }
518
Michael Kolb31d469b2010-12-09 20:49:54 -0800519 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500520
Michael Kolb31d469b2010-12-09 20:49:54 -0800521 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000522 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800523 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800524 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800525 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800526 // clear voice mode when user types
527 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500528 }
529 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800530
Michael Kolbcfa3af52010-12-14 10:36:11 -0800531 // voicesearch
532
533 @Override
534 public void setInVoiceMode(boolean voicemode) {
535 setInVoiceMode(voicemode, null);
536 }
537
538 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
539 mInVoiceMode = voicemode;
540 mUrlInput.setVoiceResults(voiceResults);
Michael Kolb3aaef252011-03-09 18:13:56 -0800541 if (voicemode) {
542 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
543 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800544 }
545
John Reck117f07d2011-01-24 09:39:03 -0800546 @Override
547 void setIncognitoMode(boolean incognito) {
548 mUrlInput.setIncognitoMode(incognito);
549 }
Michael Kolb47171d82011-01-28 10:34:15 -0800550
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800551 @Override
552 public View focusSearch(View focused, int dir) {
553 if (FOCUS_DOWN == dir && hasFocus()) {
554 return getCurrentWebView();
555 }
556 return super.focusSearch(focused, dir);
557 }
558
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000559 void clearCompletions() {
560 mUrlInput.setSuggestedText(null);
561 }
562
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800563 @Override
564 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
565 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
566 // catch back key in order to do slightly more cleanup than usual
567 mUrlInput.clearFocus();
568 return true;
569 }
570 return super.dispatchKeyEventPreIme(evt);
571 }
572
573 private WebView getCurrentWebView() {
574 Tab t = mUi.getActiveTab();
575 if (t != null) {
576 return t.getWebView();
577 } else {
578 return null;
579 }
580 }
581
Narayan Kamath5119edd2011-02-23 15:49:17 +0000582 void registerDropdownChangeListener(DropdownChangeListener d) {
583 mUrlInput.registerDropdownChangeListener(d);
584 }
Michael Kolb0c425da2011-05-19 14:35:45 -0700585
586 private void hideNavButtons() {
587 int awidth = mNavButtons.getMeasuredWidth();
588 Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, "translationX", 0, - awidth);
589 Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", mUrlContainer.getLeft(),
590 mUrlContainer.getPaddingLeft());
591 Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, "alpha", 1f, 0f);
592 AnimatorSet combo = new AnimatorSet();
593 combo.playTogether(anim1, anim2, anim3);
594 combo.addListener(new AnimatorListener() {
595
596 @Override
597 public void onAnimationCancel(Animator animation) {
598 }
599
600 @Override
601 public void onAnimationEnd(Animator animation) {
602 mNavButtons.setVisibility(View.GONE);
603 }
604
605 @Override
606 public void onAnimationRepeat(Animator animation) {
607 }
608
609 @Override
610 public void onAnimationStart(Animator animation) {
611 }
612 });
613 combo.setDuration(150);
614 combo.start();
615 }
616
617 private void showNavButtons() {
618 int awidth = mNavButtons.getMeasuredWidth();
619 Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, "translationX", -awidth, 0);
620 Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", 0, awidth);
621 Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, "alpha", 0f, 1f);
622 AnimatorSet combo = new AnimatorSet();
623 combo.playTogether(anim1, anim2, anim3);
624 mNavButtons.setVisibility(View.VISIBLE);
625 combo.setDuration(150);
626 combo.start();
627 }
628
Leon Scroggins571b3762010-05-26 10:25:01 -0400629}