blob: a786fd7dfe29ab5502821ee17dd2f63dbb7355f7 [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 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800270 }
271 mUrlInput.clearNeedsUpdate();
Michael Kolbc7485ae2010-09-03 10:10:58 -0700272 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700273
John Reck94b7e042011-02-15 15:02:33 -0800274 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500275 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800276 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500277 }
278
Michael Kolb81b6f832010-12-12 12:44:27 -0800279 /**
280 * called from the Ui when the user wants to edit
Michael Kolb81b6f832010-12-12 12:44:27 -0800281 * @param clearInput clear the input field
282 */
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800283 void startEditingUrl(boolean clearInput) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800284 // editing takes preference of progress
285 mContainer.setVisibility(View.VISIBLE);
286 if (mUseQuickControls) {
287 mProgressView.setVisibility(View.GONE);
288 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800289 if (!mUrlInput.hasFocus()) {
290 mUrlInput.requestFocus();
291 }
Michael Kolb81b6f832010-12-12 12:44:27 -0800292 if (clearInput) {
293 mUrlInput.setText("");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800294 } else if (mInVoiceMode) {
295 mUrlInput.showDropDown();
Michael Kolb81b6f832010-12-12 12:44:27 -0800296 }
297 }
298
299 boolean isEditingUrl() {
300 return mUrlInput.hasFocus();
301 }
302
Michael Kolb7cdc4902011-02-03 17:54:40 -0800303 void stopEditingUrl() {
304 mUrlInput.clearFocus();
305 }
306
Patrick Scott92066772011-03-10 08:46:27 -0500307 private void hideAutoLogin() {
308 Animation anim = AnimationUtils.loadAnimation(
309 getContext(), R.anim.autologin_exit);
310 anim.setAnimationListener(new AnimationListener() {
311 @Override public void onAnimationEnd(Animation a) {
312 mAutoLogin.setVisibility(View.GONE);
313 }
314 @Override public void onAnimationStart(Animation a) {}
315 @Override public void onAnimationRepeat(Animation a) {}
316 });
317 mAutoLogin.startAnimation(anim);
318 }
319
Michael Kolba2b2ba82010-08-04 17:54:03 -0700320 @Override
321 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800322 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700323 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700324 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700325 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700326 } else if (mStar == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700327 mUiController.bookmarkCurrentPage(
Leon Scrogginsbdff8a72011-02-11 15:49:04 -0500328 AddBookmarkPage.DEFAULT_FOLDER_ID, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700329 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700330 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700331 } else if (mSearchButton == v) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800332 mUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700333 } else if (mStopButton == v) {
334 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700335 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800336 if (!TextUtils.isEmpty(mUrlInput.getText())) {
337 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800338 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700339 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700340 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800341 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800342 } else if (mVoiceSearch == v) {
343 mUiController.startVoiceSearch();
Patrick Scott92066772011-03-10 08:46:27 -0500344 } else if (mAutoLoginCancel == v) {
345 if (mAutoLoginHandler != null) {
346 mAutoLoginHandler.cancel();
347 mAutoLoginHandler = null;
348 }
349 hideAutoLogin();
350 } else if (mAutoLoginLogin == v) {
351 if (mAutoLoginHandler != null) {
352 mAutoLoginAccount.setEnabled(false);
353 mAutoLoginLogin.setEnabled(false);
354 mAutoLoginProgress.setVisibility(View.VISIBLE);
355 mAutoLoginError.setVisibility(View.GONE);
356 mAutoLoginHandler.login(this);
357 }
358 } else if (mAutoLoginAccount == v) {
359 if (mAutoLoginHandler != null) {
360 mAutoLoginHandler.chooseAccount(this);
361 }
Michael Kolbfe251992010-07-08 15:41:55 -0700362 }
363 }
364
Michael Kolba2b2ba82010-08-04 17:54:03 -0700365 @Override
Patrick Scott92066772011-03-10 08:46:27 -0500366 public void setAccount(String account) {
367 mAutoLoginAccount.setText(account);
368 }
369
370 @Override
371 public void loginFailed() {
372 mAutoLoginAccount.setEnabled(true);
373 mAutoLoginLogin.setEnabled(true);
374 mAutoLoginProgress.setVisibility(View.GONE);
375 mAutoLoginError.setVisibility(View.VISIBLE);
376 }
377
378 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700379 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700380
Michael Kolb31d469b2010-12-09 20:49:54 -0800381 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000382 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800383 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800384 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800385 } else {
386 // clear
387 mUrlInput.setText("");
388 }
389 }
390
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800391 private void setFocusState(boolean focus) {
392 if (focus) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800393 mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
394 mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700395 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800396 mStar.setVisibility(View.GONE);
397 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800398 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800399 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700400 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700401 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800402 mVoiceSearch.setVisibility(View.GONE);
403 mStar.setVisibility(View.VISIBLE);
404 mClearButton.setVisibility(View.GONE);
Michael Kolb376b5412010-12-15 11:52:57 -0800405 if (mUseQuickControls) {
406 mSearchButton.setVisibility(View.GONE);
407 } else {
408 mSearchButton.setVisibility(View.VISIBLE);
409 }
Michael Kolbe3524d82011-03-02 14:53:15 -0800410 mUrlIcon.setImageResource(mInVoiceMode ?
411 R.drawable.ic_search_holo_dark
412 : R.drawable.ic_web_holo_dark);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700413 }
414 }
415
Michael Kolba2b2ba82010-08-04 17:54:03 -0700416 private void stopOrRefresh() {
417 if (mInLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700418 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700419 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700420 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700421 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400422 }
423
424 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700425 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400426 */
Michael Kolbfe251992010-07-08 15:41:55 -0700427 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700428 void setProgress(int newProgress) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800429 boolean blockvisuals = mUseQuickControls && isEditingUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700430 if (newProgress >= PROGRESS_MAX) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800431 if (!blockvisuals) {
432 mProgressView.setProgress(PageProgressView.MAX_PROGRESS);
433 mProgressView.setVisibility(View.GONE);
434 mStopButton.setImageDrawable(mReloadDrawable);
435 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700436 mInLoad = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700437 } else {
438 if (!mInLoad) {
Michael Kolbbd018d42010-12-15 15:43:39 -0800439 if (!blockvisuals) {
440 mProgressView.setVisibility(View.VISIBLE);
441 mStopButton.setImageDrawable(mStopDrawable);
442 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700443 mInLoad = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700444 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700445 mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS
446 / PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700447 }
Michael Kolbfe251992010-07-08 15:41:55 -0700448 }
449
Michael Kolb60a68f52011-02-24 11:02:52 -0800450 private void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000451 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800452 }
453
454 private void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800455 SearchEngine searchEngine = BrowserSettings.getInstance()
456 .getSearchEngine();
457 boolean showvoicebutton = voiceSearchEnabled &&
458 (searchEngine != null && searchEngine.supportsVoiceSearch());
459 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800460 View.GONE);
461 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
462 View.VISIBLE);
463 }
464
Michael Kolbfe251992010-07-08 15:41:55 -0700465 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400466 /* package */ void setDisplayTitle(String title) {
John Reck4851f9e2010-12-22 16:40:36 -0800467 if (!isEditingUrl()) {
468 mUrlInput.setText(title, false);
469 }
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700470 }
471
Michael Kolb31d469b2010-12-09 20:49:54 -0800472 // UrlInput text watcher
Leon Scroggins4cd97792010-12-03 15:31:56 -0500473
Michael Kolb31d469b2010-12-09 20:49:54 -0800474 @Override
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000475 public void onTextChanged(String newText) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800476 if (mUrlInput.hasFocus()) {
Michael Kolb81b6f832010-12-12 12:44:27 -0800477 // check if input field is empty and adjust voice search state
Michael Kolb60a68f52011-02-24 11:02:52 -0800478 updateSearchMode(true);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800479 // clear voice mode when user types
480 setInVoiceMode(false, null);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500481 }
482 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800483
Michael Kolbcfa3af52010-12-14 10:36:11 -0800484 // voicesearch
485
486 @Override
487 public void setInVoiceMode(boolean voicemode) {
488 setInVoiceMode(voicemode, null);
489 }
490
491 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
492 mInVoiceMode = voicemode;
493 mUrlInput.setVoiceResults(voiceResults);
Michael Kolb3aaef252011-03-09 18:13:56 -0800494 if (voicemode) {
495 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
496 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800497 }
498
John Reck117f07d2011-01-24 09:39:03 -0800499 @Override
500 void setIncognitoMode(boolean incognito) {
501 mUrlInput.setIncognitoMode(incognito);
502 }
Michael Kolb47171d82011-01-28 10:34:15 -0800503
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800504 @Override
505 public View focusSearch(View focused, int dir) {
506 if (FOCUS_DOWN == dir && hasFocus()) {
507 return getCurrentWebView();
508 }
509 return super.focusSearch(focused, dir);
510 }
511
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000512 void clearCompletions() {
513 mUrlInput.setSuggestedText(null);
514 }
515
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800516 @Override
517 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
518 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
519 // catch back key in order to do slightly more cleanup than usual
520 mUrlInput.clearFocus();
521 return true;
522 }
523 return super.dispatchKeyEventPreIme(evt);
524 }
525
526 private WebView getCurrentWebView() {
527 Tab t = mUi.getActiveTab();
528 if (t != null) {
529 return t.getWebView();
530 } else {
531 return null;
532 }
533 }
534
Narayan Kamath5119edd2011-02-23 15:49:17 +0000535 void registerDropdownChangeListener(DropdownChangeListener d) {
536 mUrlInput.registerDropdownChangeListener(d);
537 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400538}