blob: b95711eae6c32fd76db343baa52249c9fd1927ee [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
Michael Kolb11d19782011-03-20 10:17:40 -070019import com.android.browser.UI.DropdownChangeListener;
John Reck92026732011-02-15 10:12:30 -080020import com.android.browser.UrlInputView.UrlInputListener;
Michael Kolb11d19782011-03-20 10:17:40 -070021import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
John Reck92026732011-02-15 10:12:30 -080022
Michael Kolb46f987e2011-04-05 10:39:10 -070023import android.animation.Animator;
24import android.animation.Animator.AnimatorListener;
25import android.animation.ObjectAnimator;
John Reck92026732011-02-15 10:12:30 -080026import android.app.SearchManager;
Leon Scroggins571b3762010-05-26 10:25:01 -040027import android.content.Context;
John Reck92026732011-02-15 10:12:30 -080028import android.content.Intent;
Leon Scroggins571b3762010-05-26 10:25:01 -040029import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040030import android.graphics.drawable.Drawable;
John Reck92026732011-02-15 10:12:30 -080031import android.os.Bundle;
32import android.speech.RecognizerResultsIntent;
Michael Kolb11d19782011-03-20 10:17:40 -070033import android.text.TextUtils;
34import android.view.ContextThemeWrapper;
Michael Kolb7cdc4902011-02-03 17:54:40 -080035import android.view.Gravity;
Michael Kolb11d19782011-03-20 10:17:40 -070036import android.view.KeyEvent;
37import android.view.LayoutInflater;
John Reck46500332011-06-07 14:36:10 -070038import android.view.Menu;
39import android.view.MenuItem;
Leon Scroggins571b3762010-05-26 10:25:01 -040040import android.view.View;
Michael Kolb11d19782011-03-20 10:17:40 -070041import android.view.View.OnClickListener;
42import android.view.View.OnFocusChangeListener;
Michael Kolb46f987e2011-04-05 10:39:10 -070043import android.view.ViewGroup;
Michael Kolb11d19782011-03-20 10:17:40 -070044import android.view.animation.Animation;
45import android.view.animation.Animation.AnimationListener;
46import android.view.animation.AnimationUtils;
47import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080048import android.widget.AbsoluteLayout;
Michael Kolb11d19782011-03-20 10:17:40 -070049import android.widget.ArrayAdapter;
50import android.widget.Button;
Michael Kolb46f987e2011-04-05 10:39:10 -070051import android.widget.FrameLayout;
Leon Scroggins571b3762010-05-26 10:25:01 -040052import android.widget.ImageView;
John Reck46500332011-06-07 14:36:10 -070053import android.widget.PopupMenu;
54import android.widget.PopupMenu.OnMenuItemClickListener;
Michael Kolb11d19782011-03-20 10:17:40 -070055import android.widget.ProgressBar;
56import android.widget.RelativeLayout;
57import android.widget.Spinner;
58import android.widget.TextView;
59
60import java.util.List;
Leon Scroggins571b3762010-05-26 10:25:01 -040061
62/**
63 * Base class for a title bar used by the browser.
64 */
Michael Kolb11d19782011-03-20 10:17:40 -070065public class TitleBarBase extends RelativeLayout
66 implements OnClickListener, OnFocusChangeListener, UrlInputListener,
John Reck46500332011-06-07 14:36:10 -070067 TextChangeWatcher, DeviceAccountLogin.AutoLoginCallback,
68 OnMenuItemClickListener {
John Reck94b7e042011-02-15 15:02:33 -080069
70 protected static final int PROGRESS_MAX = 100;
71
Leon Scroggins571b3762010-05-26 10:25:01 -040072 // These need to be set by the subclass.
73 protected ImageView mFavicon;
74 protected ImageView mLockIcon;
75
John Reck92026732011-02-15 10:12:30 -080076 protected UiController mUiController;
77 protected BaseUi mBaseUi;
Michael Kolb46f987e2011-04-05 10:39:10 -070078 protected FrameLayout mParent;
79 protected PageProgressView mProgress;
John Reck92026732011-02-15 10:12:30 -080080 protected UrlInputView mUrlInput;
81 protected boolean mInVoiceMode;
Michael Kolb46f987e2011-04-05 10:39:10 -070082 protected View mContainer;
John Reck46500332011-06-07 14:36:10 -070083 private View mUaSwitcher;
Leon Scroggins571b3762010-05-26 10:25:01 -040084
Michael Kolb11d19782011-03-20 10:17:40 -070085 // Auto-login UI
86 protected View mAutoLogin;
87 protected Spinner mAutoLoginAccount;
88 protected Button mAutoLoginLogin;
89 protected ProgressBar mAutoLoginProgress;
90 protected TextView mAutoLoginError;
John Reck12472f62011-04-27 15:32:10 -070091 protected View mAutoLoginCancel;
Michael Kolb11d19782011-03-20 10:17:40 -070092 protected DeviceAccountLogin mAutoLoginHandler;
93 protected ArrayAdapter<String> mAccountsAdapter;
Michael Kolbfdb70242011-03-24 09:41:11 -070094 protected boolean mUseQuickControls;
Michael Kolb11d19782011-03-20 10:17:40 -070095
Michael Kolb46f987e2011-04-05 10:39:10 -070096 //state
97 protected boolean mShowing;
98 protected boolean mInLoad;
99 protected boolean mSkipTitleBarAnimations;
100 private Animator mTitleBarAnimator;
101
102 public TitleBarBase(Context context, UiController controller, BaseUi ui,
103 FrameLayout parent) {
Leon Scroggins571b3762010-05-26 10:25:01 -0400104 super(context, null);
John Reck92026732011-02-15 10:12:30 -0800105 mUiController = controller;
106 mBaseUi = ui;
Michael Kolb46f987e2011-04-05 10:39:10 -0700107 mParent = parent;
Leon Scroggins571b3762010-05-26 10:25:01 -0400108 }
109
Michael Kolb11d19782011-03-20 10:17:40 -0700110 protected void initLayout(Context context, int layoutId) {
111 LayoutInflater factory = LayoutInflater.from(context);
112 factory.inflate(layoutId, this);
Michael Kolb46f987e2011-04-05 10:39:10 -0700113 mContainer = findViewById(R.id.taburlbar);
114 mProgress = (PageProgressView) findViewById(R.id.progress);
Michael Kolb11d19782011-03-20 10:17:40 -0700115 mUrlInput = (UrlInputView) findViewById(R.id.url);
116 mLockIcon = (ImageView) findViewById(R.id.lock);
117 mUrlInput.setUrlInputListener(this);
118 mUrlInput.setController(mUiController);
119 mUrlInput.setOnFocusChangeListener(this);
120 mUrlInput.setSelectAllOnFocus(true);
121 mUrlInput.addQueryTextWatcher(this);
122 mAutoLogin = findViewById(R.id.autologin);
123 mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account);
124 mAutoLoginLogin = (Button) findViewById(R.id.autologin_login);
125 mAutoLoginLogin.setOnClickListener(this);
126 mAutoLoginProgress = (ProgressBar) findViewById(R.id.autologin_progress);
127 mAutoLoginError = (TextView) findViewById(R.id.autologin_error);
John Reck12472f62011-04-27 15:32:10 -0700128 mAutoLoginCancel = mAutoLogin.findViewById(R.id.autologin_close);
Michael Kolb11d19782011-03-20 10:17:40 -0700129 mAutoLoginCancel.setOnClickListener(this);
130 }
131
132 protected void setupUrlInput() {
133 }
134
Michael Kolbfdb70242011-03-24 09:41:11 -0700135 protected void setUseQuickControls(boolean use) {
136 mUseQuickControls = use;
Michael Kolb46f987e2011-04-05 10:39:10 -0700137 setLayoutParams(makeLayoutParams());
Michael Kolbfdb70242011-03-24 09:41:11 -0700138 }
139
Michael Kolb46f987e2011-04-05 10:39:10 -0700140 void setShowProgressOnly(boolean progress) {
141 if (progress && !inAutoLogin()) {
142 mContainer.setVisibility(View.GONE);
143 } else {
144 mContainer.setVisibility(View.VISIBLE);
145 }
146 }
147
148 void setSkipTitleBarAnimations(boolean skip) {
149 mSkipTitleBarAnimations = skip;
150 }
151
152 void show() {
153 if (mUseQuickControls) {
154 mParent.addView(this);
155 } else {
156 if (!mSkipTitleBarAnimations) {
157 cancelTitleBarAnimation(false);
158 int visibleHeight = getVisibleTitleHeight();
159 float startPos = (-getEmbeddedHeight() + visibleHeight);
160 if (getTranslationY() != 0) {
161 startPos = Math.max(startPos, getTranslationY());
162 }
163 mTitleBarAnimator = ObjectAnimator.ofFloat(this,
164 "translationY",
165 startPos, 0);
166 mTitleBarAnimator.start();
167 }
168 mBaseUi.setTitleGravity(Gravity.TOP);
169 }
170 mShowing = true;
171 }
172
173 void hide() {
174 if (mUseQuickControls) {
175 mParent.removeView(this);
176 } else {
177 if (!mSkipTitleBarAnimations) {
178 cancelTitleBarAnimation(false);
179 int visibleHeight = getVisibleTitleHeight();
180 mTitleBarAnimator = ObjectAnimator.ofFloat(this,
181 "translationY", getTranslationY(),
182 (-getEmbeddedHeight() + visibleHeight));
183 mTitleBarAnimator.addListener(mHideTileBarAnimatorListener);
184 mTitleBarAnimator.start();
185 } else {
186 mBaseUi.setTitleGravity(Gravity.NO_GRAVITY);
187 }
188 }
189 mShowing = false;
190 }
191
192 boolean isShowing() {
193 return mShowing;
194 }
195
196 void cancelTitleBarAnimation(boolean reset) {
197 if (mTitleBarAnimator != null) {
198 mTitleBarAnimator.cancel();
199 mTitleBarAnimator = null;
200 }
201 if (reset) {
202 setTranslationY(0);
203 }
204 }
205
206 private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() {
207
208 boolean mWasCanceled;
209 @Override
210 public void onAnimationStart(Animator animation) {
211 mWasCanceled = false;
212 }
213
214 @Override
215 public void onAnimationRepeat(Animator animation) {
216 }
217
218 @Override
219 public void onAnimationEnd(Animator animation) {
220 if (!mWasCanceled) {
221 setTranslationY(0);
222 }
223 mBaseUi.setTitleGravity(Gravity.NO_GRAVITY);
224 }
225
226 @Override
227 public void onAnimationCancel(Animator animation) {
228 mWasCanceled = true;
229 }
230 };
231
232 private int getVisibleTitleHeight() {
233 Tab tab = mBaseUi.getActiveTab();
234 WebView webview = tab != null ? tab.getWebView() : null;
235 return webview != null ? webview.getVisibleTitleHeight() : 0;
236 }
237
238 /**
239 * Update the progress, from 0 to 100.
240 */
241 void setProgress(int newProgress) {
242 if (newProgress >= PROGRESS_MAX) {
243 mProgress.setProgress(PageProgressView.MAX_PROGRESS);
244 mProgress.setVisibility(View.GONE);
245 mInLoad = false;
246 onProgressStopped();
247 // check if needs to be hidden
248 if (!isEditingUrl() && !inAutoLogin()) {
249 hide();
250 if (mUseQuickControls) {
251 setShowProgressOnly(false);
252 }
253 }
254 } else {
255 if (!mInLoad) {
256 mProgress.setVisibility(View.VISIBLE);
257 mInLoad = true;
258 onProgressStarted();
259 }
260 mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS
261 / PROGRESS_MAX);
262 if (!mShowing) {
263 if (mUseQuickControls && !isEditingUrl()) {
264 setShowProgressOnly(true);
265 }
266 show();
267 }
268 }
269 }
270
271 protected void onProgressStarted() {
272 }
273
274 protected void onProgressStopped() {
275 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400276
277 /* package */ void setLock(Drawable d) {
278 assert mLockIcon != null;
279 if (null == d) {
280 mLockIcon.setVisibility(View.GONE);
281 } else {
282 mLockIcon.setImageDrawable(d);
283 mLockIcon.setVisibility(View.VISIBLE);
284 }
285 }
286
287 /* package */ void setFavicon(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700288 mFavicon.setImageDrawable(mBaseUi.getFaviconDrawable(icon));
Leon Scroggins571b3762010-05-26 10:25:01 -0400289 }
290
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800291 public int getEmbeddedHeight() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700292 int height = mContainer.getHeight();
293 if (mAutoLogin.getVisibility() == View.VISIBLE) {
294 height += mAutoLogin.getHeight();
295 }
296 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800297 }
298
Michael Kolb11d19782011-03-20 10:17:40 -0700299 protected void updateAutoLogin(Tab tab, boolean animate) {
300 DeviceAccountLogin login = tab.getDeviceAccountLogin();
301 if (login != null) {
302 mAutoLoginHandler = login;
303 ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
304 android.R.style.Theme_Holo_Light);
305 mAccountsAdapter = new ArrayAdapter<String>(wrapper,
306 android.R.layout.simple_spinner_item, login.getAccountNames());
307 mAccountsAdapter.setDropDownViewResource(
308 android.R.layout.simple_spinner_dropdown_item);
309 mAutoLoginAccount.setAdapter(mAccountsAdapter);
310 mAutoLoginAccount.setSelection(0);
311 mAutoLoginAccount.setEnabled(true);
312 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700313 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700314 mAutoLoginError.setVisibility(View.GONE);
315 switch (login.getState()) {
316 case DeviceAccountLogin.PROCESSING:
317 mAutoLoginAccount.setEnabled(false);
318 mAutoLoginLogin.setEnabled(false);
319 mAutoLoginProgress.setVisibility(View.VISIBLE);
320 break;
321 case DeviceAccountLogin.FAILED:
John Reck12472f62011-04-27 15:32:10 -0700322 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700323 mAutoLoginError.setVisibility(View.VISIBLE);
324 break;
325 case DeviceAccountLogin.INITIAL:
326 break;
327 default:
328 throw new IllegalStateException();
329 }
330 showAutoLogin(animate);
Michael Kolb43909f22011-03-23 13:18:36 -0700331 } else {
332 hideAutoLogin(animate);
Michael Kolb11d19782011-03-20 10:17:40 -0700333 }
334 }
335
336 protected void showAutoLogin(boolean animate) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700337 if (mUseQuickControls) {
338 mBaseUi.showTitleBar();
339 }
Michael Kolb11d19782011-03-20 10:17:40 -0700340 mAutoLogin.setVisibility(View.VISIBLE);
341 if (animate) {
342 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
343 getContext(), R.anim.autologin_enter));
344 }
345 }
346
347 protected void hideAutoLogin(boolean animate) {
348 mAutoLoginHandler = null;
Michael Kolb46f987e2011-04-05 10:39:10 -0700349 if (mUseQuickControls) {
350 mBaseUi.hideTitleBar();
Michael Kolb11d19782011-03-20 10:17:40 -0700351 mAutoLogin.setVisibility(View.GONE);
352 mBaseUi.refreshWebView();
Michael Kolb46f987e2011-04-05 10:39:10 -0700353 } else {
354 if (animate) {
355 Animation anim = AnimationUtils.loadAnimation(getContext(),
356 R.anim.autologin_exit);
357 anim.setAnimationListener(new AnimationListener() {
358 @Override
359 public void onAnimationEnd(Animation a) {
360 mAutoLogin.setVisibility(View.GONE);
361 mBaseUi.refreshWebView();
362 }
363
364 @Override
365 public void onAnimationStart(Animation a) {
366 }
367
368 @Override
369 public void onAnimationRepeat(Animation a) {
370 }
371 });
372 mAutoLogin.startAnimation(anim);
373 } else if (mAutoLogin.getAnimation() == null) {
374 mAutoLogin.setVisibility(View.GONE);
375 mBaseUi.refreshWebView();
376 }
Michael Kolb11d19782011-03-20 10:17:40 -0700377 }
378 }
379
380 @Override
381 public void loginFailed() {
382 mAutoLoginAccount.setEnabled(true);
383 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700384 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700385 mAutoLoginError.setVisibility(View.VISIBLE);
386 }
387
388
389 protected boolean inAutoLogin() {
390 return mAutoLoginHandler != null;
391 }
392
John Reck46500332011-06-07 14:36:10 -0700393 public void setUaSwitcher(View v) {
394 if (mUaSwitcher != null) {
395 mUaSwitcher.setOnClickListener(null);
396 }
397 mUaSwitcher = v;
398 mUaSwitcher.setOnClickListener(this);
399 }
400
Michael Kolb11d19782011-03-20 10:17:40 -0700401 @Override
402 public void onClick(View v) {
403 if (mAutoLoginCancel == v) {
404 if (mAutoLoginHandler != null) {
405 mAutoLoginHandler.cancel();
406 mAutoLoginHandler = null;
407 }
408 hideAutoLogin(true);
409 } else if (mAutoLoginLogin == v) {
410 if (mAutoLoginHandler != null) {
411 mAutoLoginAccount.setEnabled(false);
412 mAutoLoginLogin.setEnabled(false);
413 mAutoLoginProgress.setVisibility(View.VISIBLE);
414 mAutoLoginError.setVisibility(View.GONE);
415 mAutoLoginHandler.login(
416 mAutoLoginAccount.getSelectedItemPosition(), this);
417 }
John Reck46500332011-06-07 14:36:10 -0700418 } else if (mUaSwitcher == v) {
419 BrowserSettings settings = BrowserSettings.getInstance();
420 WebView web = getCurrentWebView();
421 if (web == null) return;
422 boolean desktop = settings.hasDesktopUseragent(web);
423 PopupMenu popup = new PopupMenu(mContext, mUaSwitcher);
424 Menu menu = popup.getMenu();
425 popup.getMenuInflater().inflate(R.menu.ua_switcher, menu);
426 menu.findItem(R.id.ua_mobile_menu_id).setChecked(!desktop);
427 menu.findItem(R.id.ua_desktop_menu_id).setChecked(desktop);
428 popup.setOnMenuItemClickListener(this);
429 popup.show();
Michael Kolb11d19782011-03-20 10:17:40 -0700430 }
431 }
432
433 @Override
John Reck46500332011-06-07 14:36:10 -0700434 public boolean onMenuItemClick(MenuItem item) {
435 BrowserSettings settings = BrowserSettings.getInstance();
436 WebView web = getCurrentWebView();
437 if (web == null) return false;
438 boolean desktop = settings.hasDesktopUseragent(web);
439 switch (item.getItemId()) {
440 case R.id.ua_mobile_menu_id:
441 if (desktop) {
442 settings.toggleDesktopUseragent(web);
443 web.loadUrl(web.getOriginalUrl());
444 }
445 return true;
446 case R.id.ua_desktop_menu_id:
447 if (!desktop) {
448 settings.toggleDesktopUseragent(web);
449 web.loadUrl(web.getOriginalUrl());
450 }
451 return true;
452 }
453 return false;
454 }
455
456 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700457 public void onFocusChange(View view, boolean hasFocus) {
458 // if losing focus and not in touch mode, leave as is
459 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
460 setFocusState(hasFocus);
461 }
462 if (hasFocus) {
463 mUrlInput.forceIme();
464 if (mInVoiceMode) {
465 mUrlInput.forceFilter();
466 }
467 } else if (!mUrlInput.needsUpdate()) {
468 mUrlInput.dismissDropDown();
469 mUrlInput.hideIME();
470 if (mUrlInput.getText().length() == 0) {
471 Tab currentTab = mUiController.getTabControl().getCurrentTab();
472 if (currentTab != null) {
473 mUrlInput.setText(currentTab.getUrl(), false);
474 }
475 }
476 }
477 mUrlInput.clearNeedsUpdate();
478 }
479
480 protected void setFocusState(boolean focus) {
481 if (focus) {
482 updateSearchMode(false);
483 }
484 }
485
486 protected void updateSearchMode(boolean userEdited) {
487 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
488 }
489
490 protected void setSearchMode(boolean voiceSearchEnabled) {}
491
492 boolean isEditingUrl() {
493 return mUrlInput.hasFocus();
494 }
495
496 void stopEditingUrl() {
497 mUrlInput.clearFocus();
498 }
499
500 void setDisplayTitle(String title) {
501 if (!isEditingUrl()) {
502 mUrlInput.setText(title, false);
503 }
504 }
505
506 // UrlInput text watcher
507
508 @Override
509 public void onTextChanged(String newText) {
510 if (mUrlInput.hasFocus()) {
511 // check if input field is empty and adjust voice search state
512 updateSearchMode(true);
513 // clear voice mode when user types
514 setInVoiceMode(false, null);
515 }
516 }
517
518 // voicesearch
519
520 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
521 mInVoiceMode = voicemode;
522 mUrlInput.setVoiceResults(voiceResults);
523 }
524
525 void setIncognitoMode(boolean incognito) {
526 mUrlInput.setIncognitoMode(incognito);
527 }
528
529 void clearCompletions() {
530 mUrlInput.setSuggestedText(null);
531 }
532
John Reck92026732011-02-15 10:12:30 -0800533 // UrlInputListener implementation
534
535 /**
536 * callback from suggestion dropdown
537 * user selected a suggestion
538 */
539 @Override
540 public void onAction(String text, String extra, String source) {
541 mUiController.getCurrentTopWebView().requestFocus();
542 mBaseUi.hideTitleBar();
543 Intent i = new Intent();
544 String action = null;
545 if (UrlInputView.VOICE.equals(source)) {
546 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
547 source = null;
548 } else {
549 action = Intent.ACTION_SEARCH;
550 }
551 i.setAction(action);
552 i.putExtra(SearchManager.QUERY, text);
553 if (extra != null) {
554 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
555 }
556 if (source != null) {
557 Bundle appData = new Bundle();
558 appData.putString(com.android.common.Search.SOURCE, source);
559 i.putExtra(SearchManager.APP_DATA, appData);
560 }
561 mUiController.handleNewIntent(i);
562 setDisplayTitle(text);
563 }
564
565 @Override
566 public void onDismiss() {
567 final Tab currentTab = mBaseUi.getActiveTab();
568 mBaseUi.hideTitleBar();
569 post(new Runnable() {
570 public void run() {
571 clearFocus();
572 if ((currentTab != null) && !mInVoiceMode) {
573 setDisplayTitle(currentTab.getUrl());
574 }
575 }
576 });
577 }
578
579 /**
580 * callback from the suggestion dropdown
581 * copy text to input field and stay in edit mode
582 */
583 @Override
584 public void onCopySuggestion(String text) {
585 mUrlInput.setText(text, true);
586 if (text != null) {
587 mUrlInput.setSelection(text.length());
588 }
589 }
590
John Reck94b7e042011-02-15 15:02:33 -0800591 public void setCurrentUrlIsBookmark(boolean isBookmark) {
592 }
593
Michael Kolb11d19782011-03-20 10:17:40 -0700594 @Override
595 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
596 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
597 // catch back key in order to do slightly more cleanup than usual
598 mUrlInput.clearFocus();
599 return true;
600 }
601 return super.dispatchKeyEventPreIme(evt);
602 }
603
604 protected WebView getCurrentWebView() {
605 Tab t = mBaseUi.getActiveTab();
606 if (t != null) {
607 return t.getWebView();
608 } else {
609 return null;
610 }
611 }
612
613 void registerDropdownChangeListener(DropdownChangeListener d) {
614 mUrlInput.registerDropdownChangeListener(d);
615 }
616
Michael Kolbfdb70242011-03-24 09:41:11 -0700617 /**
618 * called from the Ui when the user wants to edit
619 * @param clearInput clear the input field
620 */
Michael Kolb46f987e2011-04-05 10:39:10 -0700621 void startEditingUrl(boolean clearInput) {
622 // editing takes preference of progress
623 mContainer.setVisibility(View.VISIBLE);
624 if (mUseQuickControls) {
625 mProgress.setVisibility(View.GONE);
626 }
627 if (!mUrlInput.hasFocus()) {
628 mUrlInput.requestFocus();
629 }
630 if (clearInput) {
631 mUrlInput.setText("");
632 } else if (mInVoiceMode) {
633 mUrlInput.showDropDown();
634 }
635 }
636
637 private ViewGroup.LayoutParams makeLayoutParams() {
638 if (mUseQuickControls) {
639 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
640 LayoutParams.WRAP_CONTENT);
641 } else {
642 return new AbsoluteLayout.LayoutParams(
643 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
644 0, 0);
645 }
646 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700647
Leon Scroggins571b3762010-05-26 10:25:01 -0400648}