blob: 7897b65be7feaacd99cc6c51f409e86b525e59e0 [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;
30import android.graphics.Color;
31import android.graphics.drawable.BitmapDrawable;
32import android.graphics.drawable.Drawable;
33import android.graphics.drawable.LayerDrawable;
34import android.graphics.drawable.PaintDrawable;
John Reck92026732011-02-15 10:12:30 -080035import android.os.Bundle;
36import android.speech.RecognizerResultsIntent;
Michael Kolb11d19782011-03-20 10:17:40 -070037import android.text.TextUtils;
38import android.view.ContextThemeWrapper;
Michael Kolb7cdc4902011-02-03 17:54:40 -080039import android.view.Gravity;
Michael Kolb11d19782011-03-20 10:17:40 -070040import android.view.KeyEvent;
41import android.view.LayoutInflater;
Leon Scroggins571b3762010-05-26 10:25:01 -040042import android.view.View;
Michael Kolb11d19782011-03-20 10:17:40 -070043import android.view.View.OnClickListener;
44import android.view.View.OnFocusChangeListener;
Michael Kolb46f987e2011-04-05 10:39:10 -070045import android.view.ViewGroup;
Michael Kolb11d19782011-03-20 10:17:40 -070046import android.view.animation.Animation;
47import android.view.animation.Animation.AnimationListener;
48import android.view.animation.AnimationUtils;
49import android.webkit.WebView;
Michael Kolb7cdc4902011-02-03 17:54:40 -080050import android.widget.AbsoluteLayout;
Michael Kolb11d19782011-03-20 10:17:40 -070051import android.widget.ArrayAdapter;
52import android.widget.Button;
Michael Kolb46f987e2011-04-05 10:39:10 -070053import android.widget.FrameLayout;
Michael Kolb11d19782011-03-20 10:17:40 -070054import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040055import android.widget.ImageView;
Michael Kolb11d19782011-03-20 10:17:40 -070056import android.widget.ProgressBar;
57import android.widget.RelativeLayout;
58import android.widget.Spinner;
59import android.widget.TextView;
60
61import java.util.List;
Leon Scroggins571b3762010-05-26 10:25:01 -040062
63/**
64 * Base class for a title bar used by the browser.
65 */
Michael Kolb11d19782011-03-20 10:17:40 -070066public class TitleBarBase extends RelativeLayout
67 implements OnClickListener, OnFocusChangeListener, UrlInputListener,
68 TextChangeWatcher, DeviceAccountLogin.AutoLoginCallback {
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;
83
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
Michael Kolbeb049822011-04-07 14:09:28 -0700152 void setTitleGravity(int gravity) {
153 int newTop = 0;
Michael Kolbd463a722011-04-08 10:17:49 -0700154 int newLeft = 0;
155 View parent = (View) getParent();
156 if (parent != null) {
157 newLeft = parent.getScrollX();
158 }
Michael Kolbeb049822011-04-07 14:09:28 -0700159 if (gravity != Gravity.NO_GRAVITY) {
Michael Kolbeb049822011-04-07 14:09:28 -0700160 if (parent != null) {
161 if (gravity == Gravity.TOP) {
162 newTop = parent.getScrollY();
163 }
164 }
165 }
166 AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams)
167 getLayoutParams();
168 if (lp != null) {
Michael Kolbd463a722011-04-08 10:17:49 -0700169 lp.x = newLeft;
Michael Kolbeb049822011-04-07 14:09:28 -0700170 lp.y = newTop;
171 setLayoutParams(lp);
172 }
173 }
174
Michael Kolb46f987e2011-04-05 10:39:10 -0700175 void show() {
176 if (mUseQuickControls) {
177 mParent.addView(this);
178 } else {
179 if (!mSkipTitleBarAnimations) {
180 cancelTitleBarAnimation(false);
181 int visibleHeight = getVisibleTitleHeight();
182 float startPos = (-getEmbeddedHeight() + visibleHeight);
183 if (getTranslationY() != 0) {
184 startPos = Math.max(startPos, getTranslationY());
185 }
186 mTitleBarAnimator = ObjectAnimator.ofFloat(this,
187 "translationY",
188 startPos, 0);
189 mTitleBarAnimator.start();
190 }
191 mBaseUi.setTitleGravity(Gravity.TOP);
192 }
193 mShowing = true;
194 }
195
196 void hide() {
197 if (mUseQuickControls) {
198 mParent.removeView(this);
199 } else {
200 if (!mSkipTitleBarAnimations) {
201 cancelTitleBarAnimation(false);
202 int visibleHeight = getVisibleTitleHeight();
203 mTitleBarAnimator = ObjectAnimator.ofFloat(this,
204 "translationY", getTranslationY(),
205 (-getEmbeddedHeight() + visibleHeight));
206 mTitleBarAnimator.addListener(mHideTileBarAnimatorListener);
207 mTitleBarAnimator.start();
208 } else {
209 mBaseUi.setTitleGravity(Gravity.NO_GRAVITY);
210 }
211 }
212 mShowing = false;
213 }
214
215 boolean isShowing() {
216 return mShowing;
217 }
218
219 void cancelTitleBarAnimation(boolean reset) {
220 if (mTitleBarAnimator != null) {
221 mTitleBarAnimator.cancel();
222 mTitleBarAnimator = null;
223 }
224 if (reset) {
225 setTranslationY(0);
226 }
227 }
228
229 private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() {
230
231 boolean mWasCanceled;
232 @Override
233 public void onAnimationStart(Animator animation) {
234 mWasCanceled = false;
235 }
236
237 @Override
238 public void onAnimationRepeat(Animator animation) {
239 }
240
241 @Override
242 public void onAnimationEnd(Animator animation) {
243 if (!mWasCanceled) {
244 setTranslationY(0);
245 }
246 mBaseUi.setTitleGravity(Gravity.NO_GRAVITY);
247 }
248
249 @Override
250 public void onAnimationCancel(Animator animation) {
251 mWasCanceled = true;
252 }
253 };
254
255 private int getVisibleTitleHeight() {
256 Tab tab = mBaseUi.getActiveTab();
257 WebView webview = tab != null ? tab.getWebView() : null;
258 return webview != null ? webview.getVisibleTitleHeight() : 0;
259 }
260
261 /**
262 * Update the progress, from 0 to 100.
263 */
264 void setProgress(int newProgress) {
265 if (newProgress >= PROGRESS_MAX) {
266 mProgress.setProgress(PageProgressView.MAX_PROGRESS);
267 mProgress.setVisibility(View.GONE);
268 mInLoad = false;
269 onProgressStopped();
270 // check if needs to be hidden
271 if (!isEditingUrl() && !inAutoLogin()) {
272 hide();
273 if (mUseQuickControls) {
274 setShowProgressOnly(false);
275 }
276 }
277 } else {
278 if (!mInLoad) {
279 mProgress.setVisibility(View.VISIBLE);
280 mInLoad = true;
281 onProgressStarted();
282 }
283 mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS
284 / PROGRESS_MAX);
285 if (!mShowing) {
286 if (mUseQuickControls && !isEditingUrl()) {
287 setShowProgressOnly(true);
288 }
289 show();
290 }
291 }
292 }
293
294 protected void onProgressStarted() {
295 }
296
297 protected void onProgressStopped() {
298 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400299
300 /* package */ void setLock(Drawable d) {
301 assert mLockIcon != null;
302 if (null == d) {
303 mLockIcon.setVisibility(View.GONE);
304 } else {
305 mLockIcon.setImageDrawable(d);
306 mLockIcon.setVisibility(View.VISIBLE);
307 }
308 }
309
310 /* package */ void setFavicon(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700311 mFavicon.setImageDrawable(mBaseUi.getFaviconDrawable(icon));
Leon Scroggins571b3762010-05-26 10:25:01 -0400312 }
313
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800314 public int getEmbeddedHeight() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700315 int height = mContainer.getHeight();
316 if (mAutoLogin.getVisibility() == View.VISIBLE) {
317 height += mAutoLogin.getHeight();
318 }
319 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800320 }
321
Michael Kolb11d19782011-03-20 10:17:40 -0700322 protected void updateAutoLogin(Tab tab, boolean animate) {
323 DeviceAccountLogin login = tab.getDeviceAccountLogin();
324 if (login != null) {
325 mAutoLoginHandler = login;
326 ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
327 android.R.style.Theme_Holo_Light);
328 mAccountsAdapter = new ArrayAdapter<String>(wrapper,
329 android.R.layout.simple_spinner_item, login.getAccountNames());
330 mAccountsAdapter.setDropDownViewResource(
331 android.R.layout.simple_spinner_dropdown_item);
332 mAutoLoginAccount.setAdapter(mAccountsAdapter);
333 mAutoLoginAccount.setSelection(0);
334 mAutoLoginAccount.setEnabled(true);
335 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700336 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700337 mAutoLoginError.setVisibility(View.GONE);
338 switch (login.getState()) {
339 case DeviceAccountLogin.PROCESSING:
340 mAutoLoginAccount.setEnabled(false);
341 mAutoLoginLogin.setEnabled(false);
342 mAutoLoginProgress.setVisibility(View.VISIBLE);
343 break;
344 case DeviceAccountLogin.FAILED:
John Reck12472f62011-04-27 15:32:10 -0700345 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700346 mAutoLoginError.setVisibility(View.VISIBLE);
347 break;
348 case DeviceAccountLogin.INITIAL:
349 break;
350 default:
351 throw new IllegalStateException();
352 }
353 showAutoLogin(animate);
Michael Kolb43909f22011-03-23 13:18:36 -0700354 } else {
355 hideAutoLogin(animate);
Michael Kolb11d19782011-03-20 10:17:40 -0700356 }
357 }
358
359 protected void showAutoLogin(boolean animate) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700360 if (mUseQuickControls) {
361 mBaseUi.showTitleBar();
362 }
Michael Kolb11d19782011-03-20 10:17:40 -0700363 mAutoLogin.setVisibility(View.VISIBLE);
364 if (animate) {
365 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
366 getContext(), R.anim.autologin_enter));
367 }
368 }
369
370 protected void hideAutoLogin(boolean animate) {
371 mAutoLoginHandler = null;
Michael Kolb46f987e2011-04-05 10:39:10 -0700372 if (mUseQuickControls) {
373 mBaseUi.hideTitleBar();
Michael Kolb11d19782011-03-20 10:17:40 -0700374 mAutoLogin.setVisibility(View.GONE);
375 mBaseUi.refreshWebView();
Michael Kolb46f987e2011-04-05 10:39:10 -0700376 } else {
377 if (animate) {
378 Animation anim = AnimationUtils.loadAnimation(getContext(),
379 R.anim.autologin_exit);
380 anim.setAnimationListener(new AnimationListener() {
381 @Override
382 public void onAnimationEnd(Animation a) {
383 mAutoLogin.setVisibility(View.GONE);
384 mBaseUi.refreshWebView();
385 }
386
387 @Override
388 public void onAnimationStart(Animation a) {
389 }
390
391 @Override
392 public void onAnimationRepeat(Animation a) {
393 }
394 });
395 mAutoLogin.startAnimation(anim);
396 } else if (mAutoLogin.getAnimation() == null) {
397 mAutoLogin.setVisibility(View.GONE);
398 mBaseUi.refreshWebView();
399 }
Michael Kolb11d19782011-03-20 10:17:40 -0700400 }
401 }
402
403 @Override
404 public void loginFailed() {
405 mAutoLoginAccount.setEnabled(true);
406 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700407 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700408 mAutoLoginError.setVisibility(View.VISIBLE);
409 }
410
411
412 protected boolean inAutoLogin() {
413 return mAutoLoginHandler != null;
414 }
415
416 @Override
417 public void onClick(View v) {
418 if (mAutoLoginCancel == v) {
419 if (mAutoLoginHandler != null) {
420 mAutoLoginHandler.cancel();
421 mAutoLoginHandler = null;
422 }
423 hideAutoLogin(true);
424 } else if (mAutoLoginLogin == v) {
425 if (mAutoLoginHandler != null) {
426 mAutoLoginAccount.setEnabled(false);
427 mAutoLoginLogin.setEnabled(false);
428 mAutoLoginProgress.setVisibility(View.VISIBLE);
429 mAutoLoginError.setVisibility(View.GONE);
430 mAutoLoginHandler.login(
431 mAutoLoginAccount.getSelectedItemPosition(), this);
432 }
433 }
434 }
435
436 @Override
437 public void onFocusChange(View view, boolean hasFocus) {
438 // if losing focus and not in touch mode, leave as is
439 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
440 setFocusState(hasFocus);
441 }
442 if (hasFocus) {
443 mUrlInput.forceIme();
444 if (mInVoiceMode) {
445 mUrlInput.forceFilter();
446 }
447 } else if (!mUrlInput.needsUpdate()) {
448 mUrlInput.dismissDropDown();
449 mUrlInput.hideIME();
450 if (mUrlInput.getText().length() == 0) {
451 Tab currentTab = mUiController.getTabControl().getCurrentTab();
452 if (currentTab != null) {
453 mUrlInput.setText(currentTab.getUrl(), false);
454 }
455 }
456 }
457 mUrlInput.clearNeedsUpdate();
458 }
459
460 protected void setFocusState(boolean focus) {
461 if (focus) {
462 updateSearchMode(false);
463 }
464 }
465
466 protected void updateSearchMode(boolean userEdited) {
467 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
468 }
469
470 protected void setSearchMode(boolean voiceSearchEnabled) {}
471
472 boolean isEditingUrl() {
473 return mUrlInput.hasFocus();
474 }
475
476 void stopEditingUrl() {
477 mUrlInput.clearFocus();
478 }
479
480 void setDisplayTitle(String title) {
481 if (!isEditingUrl()) {
482 mUrlInput.setText(title, false);
483 }
484 }
485
486 // UrlInput text watcher
487
488 @Override
489 public void onTextChanged(String newText) {
490 if (mUrlInput.hasFocus()) {
491 // check if input field is empty and adjust voice search state
492 updateSearchMode(true);
493 // clear voice mode when user types
494 setInVoiceMode(false, null);
495 }
496 }
497
498 // voicesearch
499
500 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
501 mInVoiceMode = voicemode;
502 mUrlInput.setVoiceResults(voiceResults);
503 }
504
505 void setIncognitoMode(boolean incognito) {
506 mUrlInput.setIncognitoMode(incognito);
507 }
508
509 void clearCompletions() {
510 mUrlInput.setSuggestedText(null);
511 }
512
John Reck92026732011-02-15 10:12:30 -0800513 // UrlInputListener implementation
514
515 /**
516 * callback from suggestion dropdown
517 * user selected a suggestion
518 */
519 @Override
520 public void onAction(String text, String extra, String source) {
521 mUiController.getCurrentTopWebView().requestFocus();
522 mBaseUi.hideTitleBar();
523 Intent i = new Intent();
524 String action = null;
525 if (UrlInputView.VOICE.equals(source)) {
526 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
527 source = null;
528 } else {
529 action = Intent.ACTION_SEARCH;
530 }
531 i.setAction(action);
532 i.putExtra(SearchManager.QUERY, text);
533 if (extra != null) {
534 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
535 }
536 if (source != null) {
537 Bundle appData = new Bundle();
538 appData.putString(com.android.common.Search.SOURCE, source);
539 i.putExtra(SearchManager.APP_DATA, appData);
540 }
541 mUiController.handleNewIntent(i);
542 setDisplayTitle(text);
543 }
544
545 @Override
546 public void onDismiss() {
547 final Tab currentTab = mBaseUi.getActiveTab();
548 mBaseUi.hideTitleBar();
549 post(new Runnable() {
550 public void run() {
551 clearFocus();
552 if ((currentTab != null) && !mInVoiceMode) {
553 setDisplayTitle(currentTab.getUrl());
554 }
555 }
556 });
557 }
558
559 /**
560 * callback from the suggestion dropdown
561 * copy text to input field and stay in edit mode
562 */
563 @Override
564 public void onCopySuggestion(String text) {
565 mUrlInput.setText(text, true);
566 if (text != null) {
567 mUrlInput.setSelection(text.length());
568 }
569 }
570
John Reck94b7e042011-02-15 15:02:33 -0800571 public void setCurrentUrlIsBookmark(boolean isBookmark) {
572 }
573
Michael Kolb11d19782011-03-20 10:17:40 -0700574 @Override
575 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
576 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
577 // catch back key in order to do slightly more cleanup than usual
578 mUrlInput.clearFocus();
579 return true;
580 }
581 return super.dispatchKeyEventPreIme(evt);
582 }
583
584 protected WebView getCurrentWebView() {
585 Tab t = mBaseUi.getActiveTab();
586 if (t != null) {
587 return t.getWebView();
588 } else {
589 return null;
590 }
591 }
592
593 void registerDropdownChangeListener(DropdownChangeListener d) {
594 mUrlInput.registerDropdownChangeListener(d);
595 }
596
Michael Kolbfdb70242011-03-24 09:41:11 -0700597 /**
598 * called from the Ui when the user wants to edit
599 * @param clearInput clear the input field
600 */
Michael Kolb46f987e2011-04-05 10:39:10 -0700601 void startEditingUrl(boolean clearInput) {
602 // editing takes preference of progress
603 mContainer.setVisibility(View.VISIBLE);
604 if (mUseQuickControls) {
605 mProgress.setVisibility(View.GONE);
606 }
607 if (!mUrlInput.hasFocus()) {
608 mUrlInput.requestFocus();
609 }
610 if (clearInput) {
611 mUrlInput.setText("");
612 } else if (mInVoiceMode) {
613 mUrlInput.showDropDown();
614 }
615 }
616
617 private ViewGroup.LayoutParams makeLayoutParams() {
618 if (mUseQuickControls) {
619 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
620 LayoutParams.WRAP_CONTENT);
621 } else {
622 return new AbsoluteLayout.LayoutParams(
623 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
624 0, 0);
625 }
626 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700627
Leon Scroggins571b3762010-05-26 10:25:01 -0400628}