blob: e2c3432c014b27b31813a73c447a89c7cbc3ad5f [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;
John Reck5d43ce82011-06-21 17:16:51 -0700212 mUrlInput.setEnabled(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700213 }
214
215 @Override
216 public void onAnimationRepeat(Animator animation) {
217 }
218
219 @Override
220 public void onAnimationEnd(Animator animation) {
221 if (!mWasCanceled) {
222 setTranslationY(0);
223 }
224 mBaseUi.setTitleGravity(Gravity.NO_GRAVITY);
John Reck5d43ce82011-06-21 17:16:51 -0700225 mUrlInput.setEnabled(true);
Michael Kolb46f987e2011-04-05 10:39:10 -0700226 }
227
228 @Override
229 public void onAnimationCancel(Animator animation) {
230 mWasCanceled = true;
231 }
232 };
233
234 private int getVisibleTitleHeight() {
235 Tab tab = mBaseUi.getActiveTab();
236 WebView webview = tab != null ? tab.getWebView() : null;
237 return webview != null ? webview.getVisibleTitleHeight() : 0;
238 }
239
240 /**
241 * Update the progress, from 0 to 100.
242 */
243 void setProgress(int newProgress) {
244 if (newProgress >= PROGRESS_MAX) {
245 mProgress.setProgress(PageProgressView.MAX_PROGRESS);
246 mProgress.setVisibility(View.GONE);
247 mInLoad = false;
248 onProgressStopped();
249 // check if needs to be hidden
250 if (!isEditingUrl() && !inAutoLogin()) {
251 hide();
252 if (mUseQuickControls) {
253 setShowProgressOnly(false);
254 }
255 }
256 } else {
257 if (!mInLoad) {
258 mProgress.setVisibility(View.VISIBLE);
259 mInLoad = true;
260 onProgressStarted();
261 }
262 mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS
263 / PROGRESS_MAX);
264 if (!mShowing) {
265 if (mUseQuickControls && !isEditingUrl()) {
266 setShowProgressOnly(true);
267 }
268 show();
269 }
270 }
271 }
272
273 protected void onProgressStarted() {
274 }
275
276 protected void onProgressStopped() {
277 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400278
279 /* package */ void setLock(Drawable d) {
280 assert mLockIcon != null;
281 if (null == d) {
282 mLockIcon.setVisibility(View.GONE);
283 } else {
284 mLockIcon.setImageDrawable(d);
285 mLockIcon.setVisibility(View.VISIBLE);
286 }
287 }
288
289 /* package */ void setFavicon(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700290 mFavicon.setImageDrawable(mBaseUi.getFaviconDrawable(icon));
Leon Scroggins571b3762010-05-26 10:25:01 -0400291 }
292
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800293 public int getEmbeddedHeight() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700294 int height = mContainer.getHeight();
295 if (mAutoLogin.getVisibility() == View.VISIBLE) {
296 height += mAutoLogin.getHeight();
297 }
298 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800299 }
300
Michael Kolb11d19782011-03-20 10:17:40 -0700301 protected void updateAutoLogin(Tab tab, boolean animate) {
302 DeviceAccountLogin login = tab.getDeviceAccountLogin();
303 if (login != null) {
304 mAutoLoginHandler = login;
305 ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
306 android.R.style.Theme_Holo_Light);
307 mAccountsAdapter = new ArrayAdapter<String>(wrapper,
308 android.R.layout.simple_spinner_item, login.getAccountNames());
309 mAccountsAdapter.setDropDownViewResource(
310 android.R.layout.simple_spinner_dropdown_item);
311 mAutoLoginAccount.setAdapter(mAccountsAdapter);
312 mAutoLoginAccount.setSelection(0);
313 mAutoLoginAccount.setEnabled(true);
314 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700315 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700316 mAutoLoginError.setVisibility(View.GONE);
317 switch (login.getState()) {
318 case DeviceAccountLogin.PROCESSING:
319 mAutoLoginAccount.setEnabled(false);
320 mAutoLoginLogin.setEnabled(false);
321 mAutoLoginProgress.setVisibility(View.VISIBLE);
322 break;
323 case DeviceAccountLogin.FAILED:
John Reck12472f62011-04-27 15:32:10 -0700324 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700325 mAutoLoginError.setVisibility(View.VISIBLE);
326 break;
327 case DeviceAccountLogin.INITIAL:
328 break;
329 default:
330 throw new IllegalStateException();
331 }
332 showAutoLogin(animate);
Michael Kolb43909f22011-03-23 13:18:36 -0700333 } else {
334 hideAutoLogin(animate);
Michael Kolb11d19782011-03-20 10:17:40 -0700335 }
336 }
337
338 protected void showAutoLogin(boolean animate) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700339 if (mUseQuickControls) {
340 mBaseUi.showTitleBar();
341 }
Michael Kolb11d19782011-03-20 10:17:40 -0700342 mAutoLogin.setVisibility(View.VISIBLE);
343 if (animate) {
344 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
345 getContext(), R.anim.autologin_enter));
346 }
347 }
348
349 protected void hideAutoLogin(boolean animate) {
350 mAutoLoginHandler = null;
Michael Kolb46f987e2011-04-05 10:39:10 -0700351 if (mUseQuickControls) {
352 mBaseUi.hideTitleBar();
Michael Kolb11d19782011-03-20 10:17:40 -0700353 mAutoLogin.setVisibility(View.GONE);
354 mBaseUi.refreshWebView();
Michael Kolb46f987e2011-04-05 10:39:10 -0700355 } else {
356 if (animate) {
357 Animation anim = AnimationUtils.loadAnimation(getContext(),
358 R.anim.autologin_exit);
359 anim.setAnimationListener(new AnimationListener() {
360 @Override
361 public void onAnimationEnd(Animation a) {
362 mAutoLogin.setVisibility(View.GONE);
363 mBaseUi.refreshWebView();
364 }
365
366 @Override
367 public void onAnimationStart(Animation a) {
368 }
369
370 @Override
371 public void onAnimationRepeat(Animation a) {
372 }
373 });
374 mAutoLogin.startAnimation(anim);
375 } else if (mAutoLogin.getAnimation() == null) {
376 mAutoLogin.setVisibility(View.GONE);
377 mBaseUi.refreshWebView();
378 }
Michael Kolb11d19782011-03-20 10:17:40 -0700379 }
380 }
381
382 @Override
383 public void loginFailed() {
384 mAutoLoginAccount.setEnabled(true);
385 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700386 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700387 mAutoLoginError.setVisibility(View.VISIBLE);
388 }
389
390
391 protected boolean inAutoLogin() {
392 return mAutoLoginHandler != null;
393 }
394
John Reck46500332011-06-07 14:36:10 -0700395 public void setUaSwitcher(View v) {
396 if (mUaSwitcher != null) {
397 mUaSwitcher.setOnClickListener(null);
398 }
399 mUaSwitcher = v;
400 mUaSwitcher.setOnClickListener(this);
401 }
402
Michael Kolb11d19782011-03-20 10:17:40 -0700403 @Override
404 public void onClick(View v) {
405 if (mAutoLoginCancel == v) {
406 if (mAutoLoginHandler != null) {
407 mAutoLoginHandler.cancel();
408 mAutoLoginHandler = null;
409 }
410 hideAutoLogin(true);
411 } else if (mAutoLoginLogin == v) {
412 if (mAutoLoginHandler != null) {
413 mAutoLoginAccount.setEnabled(false);
414 mAutoLoginLogin.setEnabled(false);
415 mAutoLoginProgress.setVisibility(View.VISIBLE);
416 mAutoLoginError.setVisibility(View.GONE);
417 mAutoLoginHandler.login(
418 mAutoLoginAccount.getSelectedItemPosition(), this);
419 }
John Reck46500332011-06-07 14:36:10 -0700420 } else if (mUaSwitcher == v) {
421 BrowserSettings settings = BrowserSettings.getInstance();
422 WebView web = getCurrentWebView();
423 if (web == null) return;
424 boolean desktop = settings.hasDesktopUseragent(web);
425 PopupMenu popup = new PopupMenu(mContext, mUaSwitcher);
426 Menu menu = popup.getMenu();
427 popup.getMenuInflater().inflate(R.menu.ua_switcher, menu);
428 menu.findItem(R.id.ua_mobile_menu_id).setChecked(!desktop);
429 menu.findItem(R.id.ua_desktop_menu_id).setChecked(desktop);
430 popup.setOnMenuItemClickListener(this);
431 popup.show();
Michael Kolb11d19782011-03-20 10:17:40 -0700432 }
433 }
434
435 @Override
John Reck46500332011-06-07 14:36:10 -0700436 public boolean onMenuItemClick(MenuItem item) {
437 BrowserSettings settings = BrowserSettings.getInstance();
438 WebView web = getCurrentWebView();
439 if (web == null) return false;
440 boolean desktop = settings.hasDesktopUseragent(web);
441 switch (item.getItemId()) {
442 case R.id.ua_mobile_menu_id:
443 if (desktop) {
444 settings.toggleDesktopUseragent(web);
445 web.loadUrl(web.getOriginalUrl());
446 }
447 return true;
448 case R.id.ua_desktop_menu_id:
449 if (!desktop) {
450 settings.toggleDesktopUseragent(web);
451 web.loadUrl(web.getOriginalUrl());
452 }
453 return true;
454 }
455 return false;
456 }
457
458 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700459 public void onFocusChange(View view, boolean hasFocus) {
460 // if losing focus and not in touch mode, leave as is
461 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
462 setFocusState(hasFocus);
463 }
464 if (hasFocus) {
465 mUrlInput.forceIme();
466 if (mInVoiceMode) {
467 mUrlInput.forceFilter();
468 }
469 } else if (!mUrlInput.needsUpdate()) {
470 mUrlInput.dismissDropDown();
471 mUrlInput.hideIME();
472 if (mUrlInput.getText().length() == 0) {
473 Tab currentTab = mUiController.getTabControl().getCurrentTab();
474 if (currentTab != null) {
475 mUrlInput.setText(currentTab.getUrl(), false);
476 }
477 }
478 }
479 mUrlInput.clearNeedsUpdate();
480 }
481
482 protected void setFocusState(boolean focus) {
483 if (focus) {
484 updateSearchMode(false);
485 }
486 }
487
488 protected void updateSearchMode(boolean userEdited) {
489 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
490 }
491
492 protected void setSearchMode(boolean voiceSearchEnabled) {}
493
494 boolean isEditingUrl() {
495 return mUrlInput.hasFocus();
496 }
497
498 void stopEditingUrl() {
499 mUrlInput.clearFocus();
500 }
501
502 void setDisplayTitle(String title) {
503 if (!isEditingUrl()) {
504 mUrlInput.setText(title, false);
505 }
506 }
507
508 // UrlInput text watcher
509
510 @Override
511 public void onTextChanged(String newText) {
512 if (mUrlInput.hasFocus()) {
513 // check if input field is empty and adjust voice search state
514 updateSearchMode(true);
515 // clear voice mode when user types
516 setInVoiceMode(false, null);
517 }
518 }
519
520 // voicesearch
521
522 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
523 mInVoiceMode = voicemode;
524 mUrlInput.setVoiceResults(voiceResults);
525 }
526
527 void setIncognitoMode(boolean incognito) {
528 mUrlInput.setIncognitoMode(incognito);
529 }
530
531 void clearCompletions() {
532 mUrlInput.setSuggestedText(null);
533 }
534
John Reck92026732011-02-15 10:12:30 -0800535 // UrlInputListener implementation
536
537 /**
538 * callback from suggestion dropdown
539 * user selected a suggestion
540 */
541 @Override
542 public void onAction(String text, String extra, String source) {
543 mUiController.getCurrentTopWebView().requestFocus();
544 mBaseUi.hideTitleBar();
545 Intent i = new Intent();
546 String action = null;
547 if (UrlInputView.VOICE.equals(source)) {
548 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
549 source = null;
550 } else {
551 action = Intent.ACTION_SEARCH;
552 }
553 i.setAction(action);
554 i.putExtra(SearchManager.QUERY, text);
555 if (extra != null) {
556 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
557 }
558 if (source != null) {
559 Bundle appData = new Bundle();
560 appData.putString(com.android.common.Search.SOURCE, source);
561 i.putExtra(SearchManager.APP_DATA, appData);
562 }
563 mUiController.handleNewIntent(i);
564 setDisplayTitle(text);
565 }
566
567 @Override
568 public void onDismiss() {
569 final Tab currentTab = mBaseUi.getActiveTab();
570 mBaseUi.hideTitleBar();
571 post(new Runnable() {
572 public void run() {
573 clearFocus();
574 if ((currentTab != null) && !mInVoiceMode) {
575 setDisplayTitle(currentTab.getUrl());
576 }
577 }
578 });
579 }
580
581 /**
582 * callback from the suggestion dropdown
583 * copy text to input field and stay in edit mode
584 */
585 @Override
586 public void onCopySuggestion(String text) {
587 mUrlInput.setText(text, true);
588 if (text != null) {
589 mUrlInput.setSelection(text.length());
590 }
591 }
592
John Reck94b7e042011-02-15 15:02:33 -0800593 public void setCurrentUrlIsBookmark(boolean isBookmark) {
594 }
595
Michael Kolb11d19782011-03-20 10:17:40 -0700596 @Override
597 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
598 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
599 // catch back key in order to do slightly more cleanup than usual
600 mUrlInput.clearFocus();
601 return true;
602 }
603 return super.dispatchKeyEventPreIme(evt);
604 }
605
606 protected WebView getCurrentWebView() {
607 Tab t = mBaseUi.getActiveTab();
608 if (t != null) {
609 return t.getWebView();
610 } else {
611 return null;
612 }
613 }
614
615 void registerDropdownChangeListener(DropdownChangeListener d) {
616 mUrlInput.registerDropdownChangeListener(d);
617 }
618
Michael Kolbfdb70242011-03-24 09:41:11 -0700619 /**
620 * called from the Ui when the user wants to edit
621 * @param clearInput clear the input field
622 */
Michael Kolb46f987e2011-04-05 10:39:10 -0700623 void startEditingUrl(boolean clearInput) {
624 // editing takes preference of progress
625 mContainer.setVisibility(View.VISIBLE);
626 if (mUseQuickControls) {
627 mProgress.setVisibility(View.GONE);
628 }
629 if (!mUrlInput.hasFocus()) {
630 mUrlInput.requestFocus();
631 }
632 if (clearInput) {
633 mUrlInput.setText("");
634 } else if (mInVoiceMode) {
635 mUrlInput.showDropDown();
636 }
637 }
638
639 private ViewGroup.LayoutParams makeLayoutParams() {
640 if (mUseQuickControls) {
641 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
642 LayoutParams.WRAP_CONTENT);
643 } else {
644 return new AbsoluteLayout.LayoutParams(
645 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
646 0, 0);
647 }
648 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700649
Leon Scroggins571b3762010-05-26 10:25:01 -0400650}