blob: 284fe124eaba357d26e6ebfc6040c9937af6e636 [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
Michael Kolbfe251992010-07-08 15:41:55 -070076 protected Drawable mGenericFavicon;
John Reck92026732011-02-15 10:12:30 -080077 protected UiController mUiController;
78 protected BaseUi mBaseUi;
Michael Kolb46f987e2011-04-05 10:39:10 -070079 protected FrameLayout mParent;
80 protected PageProgressView mProgress;
John Reck92026732011-02-15 10:12:30 -080081 protected UrlInputView mUrlInput;
82 protected boolean mInVoiceMode;
Michael Kolb46f987e2011-04-05 10:39:10 -070083 protected View mContainer;
84
Leon Scroggins571b3762010-05-26 10:25:01 -040085
Michael Kolb11d19782011-03-20 10:17:40 -070086 // Auto-login UI
87 protected View mAutoLogin;
88 protected Spinner mAutoLoginAccount;
89 protected Button mAutoLoginLogin;
90 protected ProgressBar mAutoLoginProgress;
91 protected TextView mAutoLoginError;
John Reck12472f62011-04-27 15:32:10 -070092 protected View mAutoLoginCancel;
Michael Kolb11d19782011-03-20 10:17:40 -070093 protected DeviceAccountLogin mAutoLoginHandler;
94 protected ArrayAdapter<String> mAccountsAdapter;
Michael Kolbfdb70242011-03-24 09:41:11 -070095 protected boolean mUseQuickControls;
Michael Kolb11d19782011-03-20 10:17:40 -070096
Michael Kolb46f987e2011-04-05 10:39:10 -070097 //state
98 protected boolean mShowing;
99 protected boolean mInLoad;
100 protected boolean mSkipTitleBarAnimations;
101 private Animator mTitleBarAnimator;
102
103 public TitleBarBase(Context context, UiController controller, BaseUi ui,
104 FrameLayout parent) {
Leon Scroggins571b3762010-05-26 10:25:01 -0400105 super(context, null);
John Reck92026732011-02-15 10:12:30 -0800106 mUiController = controller;
107 mBaseUi = ui;
Michael Kolb46f987e2011-04-05 10:39:10 -0700108 mParent = parent;
Leon Scroggins571b3762010-05-26 10:25:01 -0400109 mGenericFavicon = context.getResources().getDrawable(
110 R.drawable.app_web_browser_sm);
111 }
112
Michael Kolb11d19782011-03-20 10:17:40 -0700113 protected void initLayout(Context context, int layoutId) {
114 LayoutInflater factory = LayoutInflater.from(context);
115 factory.inflate(layoutId, this);
Michael Kolb46f987e2011-04-05 10:39:10 -0700116 mContainer = findViewById(R.id.taburlbar);
117 mProgress = (PageProgressView) findViewById(R.id.progress);
Michael Kolb11d19782011-03-20 10:17:40 -0700118 mUrlInput = (UrlInputView) findViewById(R.id.url);
119 mLockIcon = (ImageView) findViewById(R.id.lock);
120 mUrlInput.setUrlInputListener(this);
121 mUrlInput.setController(mUiController);
122 mUrlInput.setOnFocusChangeListener(this);
123 mUrlInput.setSelectAllOnFocus(true);
124 mUrlInput.addQueryTextWatcher(this);
125 mAutoLogin = findViewById(R.id.autologin);
126 mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account);
127 mAutoLoginLogin = (Button) findViewById(R.id.autologin_login);
128 mAutoLoginLogin.setOnClickListener(this);
129 mAutoLoginProgress = (ProgressBar) findViewById(R.id.autologin_progress);
130 mAutoLoginError = (TextView) findViewById(R.id.autologin_error);
John Reck12472f62011-04-27 15:32:10 -0700131 mAutoLoginCancel = mAutoLogin.findViewById(R.id.autologin_close);
Michael Kolb11d19782011-03-20 10:17:40 -0700132 mAutoLoginCancel.setOnClickListener(this);
133 }
134
135 protected void setupUrlInput() {
136 }
137
Michael Kolbfdb70242011-03-24 09:41:11 -0700138 protected void setUseQuickControls(boolean use) {
139 mUseQuickControls = use;
Michael Kolb46f987e2011-04-05 10:39:10 -0700140 setLayoutParams(makeLayoutParams());
Michael Kolbfdb70242011-03-24 09:41:11 -0700141 }
142
Michael Kolb46f987e2011-04-05 10:39:10 -0700143 void setShowProgressOnly(boolean progress) {
144 if (progress && !inAutoLogin()) {
145 mContainer.setVisibility(View.GONE);
146 } else {
147 mContainer.setVisibility(View.VISIBLE);
148 }
149 }
150
151 void setSkipTitleBarAnimations(boolean skip) {
152 mSkipTitleBarAnimations = skip;
153 }
154
Michael Kolbeb049822011-04-07 14:09:28 -0700155 void setTitleGravity(int gravity) {
156 int newTop = 0;
Michael Kolbd463a722011-04-08 10:17:49 -0700157 int newLeft = 0;
158 View parent = (View) getParent();
159 if (parent != null) {
160 newLeft = parent.getScrollX();
161 }
Michael Kolbeb049822011-04-07 14:09:28 -0700162 if (gravity != Gravity.NO_GRAVITY) {
Michael Kolbeb049822011-04-07 14:09:28 -0700163 if (parent != null) {
164 if (gravity == Gravity.TOP) {
165 newTop = parent.getScrollY();
166 }
167 }
168 }
169 AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams)
170 getLayoutParams();
171 if (lp != null) {
Michael Kolbd463a722011-04-08 10:17:49 -0700172 lp.x = newLeft;
Michael Kolbeb049822011-04-07 14:09:28 -0700173 lp.y = newTop;
174 setLayoutParams(lp);
175 }
176 }
177
Michael Kolb46f987e2011-04-05 10:39:10 -0700178 void show() {
179 if (mUseQuickControls) {
180 mParent.addView(this);
181 } else {
182 if (!mSkipTitleBarAnimations) {
183 cancelTitleBarAnimation(false);
184 int visibleHeight = getVisibleTitleHeight();
185 float startPos = (-getEmbeddedHeight() + visibleHeight);
186 if (getTranslationY() != 0) {
187 startPos = Math.max(startPos, getTranslationY());
188 }
189 mTitleBarAnimator = ObjectAnimator.ofFloat(this,
190 "translationY",
191 startPos, 0);
192 mTitleBarAnimator.start();
193 }
194 mBaseUi.setTitleGravity(Gravity.TOP);
195 }
196 mShowing = true;
197 }
198
199 void hide() {
200 if (mUseQuickControls) {
201 mParent.removeView(this);
202 } else {
203 if (!mSkipTitleBarAnimations) {
204 cancelTitleBarAnimation(false);
205 int visibleHeight = getVisibleTitleHeight();
206 mTitleBarAnimator = ObjectAnimator.ofFloat(this,
207 "translationY", getTranslationY(),
208 (-getEmbeddedHeight() + visibleHeight));
209 mTitleBarAnimator.addListener(mHideTileBarAnimatorListener);
210 mTitleBarAnimator.start();
211 } else {
212 mBaseUi.setTitleGravity(Gravity.NO_GRAVITY);
213 }
214 }
215 mShowing = false;
216 }
217
218 boolean isShowing() {
219 return mShowing;
220 }
221
222 void cancelTitleBarAnimation(boolean reset) {
223 if (mTitleBarAnimator != null) {
224 mTitleBarAnimator.cancel();
225 mTitleBarAnimator = null;
226 }
227 if (reset) {
228 setTranslationY(0);
229 }
230 }
231
232 private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() {
233
234 boolean mWasCanceled;
235 @Override
236 public void onAnimationStart(Animator animation) {
237 mWasCanceled = false;
238 }
239
240 @Override
241 public void onAnimationRepeat(Animator animation) {
242 }
243
244 @Override
245 public void onAnimationEnd(Animator animation) {
246 if (!mWasCanceled) {
247 setTranslationY(0);
248 }
249 mBaseUi.setTitleGravity(Gravity.NO_GRAVITY);
250 }
251
252 @Override
253 public void onAnimationCancel(Animator animation) {
254 mWasCanceled = true;
255 }
256 };
257
258 private int getVisibleTitleHeight() {
259 Tab tab = mBaseUi.getActiveTab();
260 WebView webview = tab != null ? tab.getWebView() : null;
261 return webview != null ? webview.getVisibleTitleHeight() : 0;
262 }
263
264 /**
265 * Update the progress, from 0 to 100.
266 */
267 void setProgress(int newProgress) {
268 if (newProgress >= PROGRESS_MAX) {
269 mProgress.setProgress(PageProgressView.MAX_PROGRESS);
270 mProgress.setVisibility(View.GONE);
271 mInLoad = false;
272 onProgressStopped();
273 // check if needs to be hidden
274 if (!isEditingUrl() && !inAutoLogin()) {
275 hide();
276 if (mUseQuickControls) {
277 setShowProgressOnly(false);
278 }
279 }
280 } else {
281 if (!mInLoad) {
282 mProgress.setVisibility(View.VISIBLE);
283 mInLoad = true;
284 onProgressStarted();
285 }
286 mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS
287 / PROGRESS_MAX);
288 if (!mShowing) {
289 if (mUseQuickControls && !isEditingUrl()) {
290 setShowProgressOnly(true);
291 }
292 show();
293 }
294 }
295 }
296
297 protected void onProgressStarted() {
298 }
299
300 protected void onProgressStopped() {
301 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400302
303 /* package */ void setLock(Drawable d) {
304 assert mLockIcon != null;
305 if (null == d) {
306 mLockIcon.setVisibility(View.GONE);
307 } else {
308 mLockIcon.setImageDrawable(d);
309 mLockIcon.setVisibility(View.VISIBLE);
310 }
311 }
312
313 /* package */ void setFavicon(Bitmap icon) {
314 assert mFavicon != null;
315 Drawable[] array = new Drawable[3];
316 array[0] = new PaintDrawable(Color.BLACK);
317 PaintDrawable p = new PaintDrawable(Color.WHITE);
318 array[1] = p;
319 if (icon == null) {
320 array[2] = mGenericFavicon;
321 } else {
322 array[2] = new BitmapDrawable(icon);
323 }
324 LayerDrawable d = new LayerDrawable(array);
325 d.setLayerInset(1, 1, 1, 1, 1);
326 d.setLayerInset(2, 2, 2, 2, 2);
327 mFavicon.setImageDrawable(d);
328 }
329
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800330 public int getEmbeddedHeight() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700331 int height = mContainer.getHeight();
332 if (mAutoLogin.getVisibility() == View.VISIBLE) {
333 height += mAutoLogin.getHeight();
334 }
335 return height;
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800336 }
337
Michael Kolb11d19782011-03-20 10:17:40 -0700338 protected void updateAutoLogin(Tab tab, boolean animate) {
339 DeviceAccountLogin login = tab.getDeviceAccountLogin();
340 if (login != null) {
341 mAutoLoginHandler = login;
342 ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
343 android.R.style.Theme_Holo_Light);
344 mAccountsAdapter = new ArrayAdapter<String>(wrapper,
345 android.R.layout.simple_spinner_item, login.getAccountNames());
346 mAccountsAdapter.setDropDownViewResource(
347 android.R.layout.simple_spinner_dropdown_item);
348 mAutoLoginAccount.setAdapter(mAccountsAdapter);
349 mAutoLoginAccount.setSelection(0);
350 mAutoLoginAccount.setEnabled(true);
351 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700352 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700353 mAutoLoginError.setVisibility(View.GONE);
354 switch (login.getState()) {
355 case DeviceAccountLogin.PROCESSING:
356 mAutoLoginAccount.setEnabled(false);
357 mAutoLoginLogin.setEnabled(false);
358 mAutoLoginProgress.setVisibility(View.VISIBLE);
359 break;
360 case DeviceAccountLogin.FAILED:
John Reck12472f62011-04-27 15:32:10 -0700361 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700362 mAutoLoginError.setVisibility(View.VISIBLE);
363 break;
364 case DeviceAccountLogin.INITIAL:
365 break;
366 default:
367 throw new IllegalStateException();
368 }
369 showAutoLogin(animate);
Michael Kolb43909f22011-03-23 13:18:36 -0700370 } else {
371 hideAutoLogin(animate);
Michael Kolb11d19782011-03-20 10:17:40 -0700372 }
373 }
374
375 protected void showAutoLogin(boolean animate) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700376 if (mUseQuickControls) {
377 mBaseUi.showTitleBar();
378 }
Michael Kolb11d19782011-03-20 10:17:40 -0700379 mAutoLogin.setVisibility(View.VISIBLE);
380 if (animate) {
381 mAutoLogin.startAnimation(AnimationUtils.loadAnimation(
382 getContext(), R.anim.autologin_enter));
383 }
384 }
385
386 protected void hideAutoLogin(boolean animate) {
387 mAutoLoginHandler = null;
Michael Kolb46f987e2011-04-05 10:39:10 -0700388 if (mUseQuickControls) {
389 mBaseUi.hideTitleBar();
Michael Kolb11d19782011-03-20 10:17:40 -0700390 mAutoLogin.setVisibility(View.GONE);
391 mBaseUi.refreshWebView();
Michael Kolb46f987e2011-04-05 10:39:10 -0700392 } else {
393 if (animate) {
394 Animation anim = AnimationUtils.loadAnimation(getContext(),
395 R.anim.autologin_exit);
396 anim.setAnimationListener(new AnimationListener() {
397 @Override
398 public void onAnimationEnd(Animation a) {
399 mAutoLogin.setVisibility(View.GONE);
400 mBaseUi.refreshWebView();
401 }
402
403 @Override
404 public void onAnimationStart(Animation a) {
405 }
406
407 @Override
408 public void onAnimationRepeat(Animation a) {
409 }
410 });
411 mAutoLogin.startAnimation(anim);
412 } else if (mAutoLogin.getAnimation() == null) {
413 mAutoLogin.setVisibility(View.GONE);
414 mBaseUi.refreshWebView();
415 }
Michael Kolb11d19782011-03-20 10:17:40 -0700416 }
417 }
418
419 @Override
420 public void loginFailed() {
421 mAutoLoginAccount.setEnabled(true);
422 mAutoLoginLogin.setEnabled(true);
John Reck12472f62011-04-27 15:32:10 -0700423 mAutoLoginProgress.setVisibility(View.INVISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -0700424 mAutoLoginError.setVisibility(View.VISIBLE);
425 }
426
427
428 protected boolean inAutoLogin() {
429 return mAutoLoginHandler != null;
430 }
431
432 @Override
433 public void onClick(View v) {
434 if (mAutoLoginCancel == v) {
435 if (mAutoLoginHandler != null) {
436 mAutoLoginHandler.cancel();
437 mAutoLoginHandler = null;
438 }
439 hideAutoLogin(true);
440 } else if (mAutoLoginLogin == v) {
441 if (mAutoLoginHandler != null) {
442 mAutoLoginAccount.setEnabled(false);
443 mAutoLoginLogin.setEnabled(false);
444 mAutoLoginProgress.setVisibility(View.VISIBLE);
445 mAutoLoginError.setVisibility(View.GONE);
446 mAutoLoginHandler.login(
447 mAutoLoginAccount.getSelectedItemPosition(), this);
448 }
449 }
450 }
451
452 @Override
453 public void onFocusChange(View view, boolean hasFocus) {
454 // if losing focus and not in touch mode, leave as is
455 if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
456 setFocusState(hasFocus);
457 }
458 if (hasFocus) {
459 mUrlInput.forceIme();
460 if (mInVoiceMode) {
461 mUrlInput.forceFilter();
462 }
463 } else if (!mUrlInput.needsUpdate()) {
464 mUrlInput.dismissDropDown();
465 mUrlInput.hideIME();
466 if (mUrlInput.getText().length() == 0) {
467 Tab currentTab = mUiController.getTabControl().getCurrentTab();
468 if (currentTab != null) {
469 mUrlInput.setText(currentTab.getUrl(), false);
470 }
471 }
472 }
473 mUrlInput.clearNeedsUpdate();
474 }
475
476 protected void setFocusState(boolean focus) {
477 if (focus) {
478 updateSearchMode(false);
479 }
480 }
481
482 protected void updateSearchMode(boolean userEdited) {
483 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
484 }
485
486 protected void setSearchMode(boolean voiceSearchEnabled) {}
487
488 boolean isEditingUrl() {
489 return mUrlInput.hasFocus();
490 }
491
492 void stopEditingUrl() {
493 mUrlInput.clearFocus();
494 }
495
496 void setDisplayTitle(String title) {
497 if (!isEditingUrl()) {
498 mUrlInput.setText(title, false);
499 }
500 }
501
502 // UrlInput text watcher
503
504 @Override
505 public void onTextChanged(String newText) {
506 if (mUrlInput.hasFocus()) {
507 // check if input field is empty and adjust voice search state
508 updateSearchMode(true);
509 // clear voice mode when user types
510 setInVoiceMode(false, null);
511 }
512 }
513
514 // voicesearch
515
516 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
517 mInVoiceMode = voicemode;
518 mUrlInput.setVoiceResults(voiceResults);
519 }
520
521 void setIncognitoMode(boolean incognito) {
522 mUrlInput.setIncognitoMode(incognito);
523 }
524
525 void clearCompletions() {
526 mUrlInput.setSuggestedText(null);
527 }
528
John Reck92026732011-02-15 10:12:30 -0800529 // UrlInputListener implementation
530
531 /**
532 * callback from suggestion dropdown
533 * user selected a suggestion
534 */
535 @Override
536 public void onAction(String text, String extra, String source) {
537 mUiController.getCurrentTopWebView().requestFocus();
538 mBaseUi.hideTitleBar();
539 Intent i = new Intent();
540 String action = null;
541 if (UrlInputView.VOICE.equals(source)) {
542 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
543 source = null;
544 } else {
545 action = Intent.ACTION_SEARCH;
546 }
547 i.setAction(action);
548 i.putExtra(SearchManager.QUERY, text);
549 if (extra != null) {
550 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
551 }
552 if (source != null) {
553 Bundle appData = new Bundle();
554 appData.putString(com.android.common.Search.SOURCE, source);
555 i.putExtra(SearchManager.APP_DATA, appData);
556 }
557 mUiController.handleNewIntent(i);
558 setDisplayTitle(text);
559 }
560
561 @Override
562 public void onDismiss() {
563 final Tab currentTab = mBaseUi.getActiveTab();
564 mBaseUi.hideTitleBar();
565 post(new Runnable() {
566 public void run() {
567 clearFocus();
568 if ((currentTab != null) && !mInVoiceMode) {
569 setDisplayTitle(currentTab.getUrl());
570 }
571 }
572 });
573 }
574
575 /**
576 * callback from the suggestion dropdown
577 * copy text to input field and stay in edit mode
578 */
579 @Override
580 public void onCopySuggestion(String text) {
581 mUrlInput.setText(text, true);
582 if (text != null) {
583 mUrlInput.setSelection(text.length());
584 }
585 }
586
John Reck94b7e042011-02-15 15:02:33 -0800587 public void setCurrentUrlIsBookmark(boolean isBookmark) {
588 }
589
Michael Kolb11d19782011-03-20 10:17:40 -0700590 @Override
591 public boolean dispatchKeyEventPreIme(KeyEvent evt) {
592 if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
593 // catch back key in order to do slightly more cleanup than usual
594 mUrlInput.clearFocus();
595 return true;
596 }
597 return super.dispatchKeyEventPreIme(evt);
598 }
599
600 protected WebView getCurrentWebView() {
601 Tab t = mBaseUi.getActiveTab();
602 if (t != null) {
603 return t.getWebView();
604 } else {
605 return null;
606 }
607 }
608
609 void registerDropdownChangeListener(DropdownChangeListener d) {
610 mUrlInput.registerDropdownChangeListener(d);
611 }
612
Michael Kolbfdb70242011-03-24 09:41:11 -0700613 /**
614 * called from the Ui when the user wants to edit
615 * @param clearInput clear the input field
616 */
Michael Kolb46f987e2011-04-05 10:39:10 -0700617 void startEditingUrl(boolean clearInput) {
618 // editing takes preference of progress
619 mContainer.setVisibility(View.VISIBLE);
620 if (mUseQuickControls) {
621 mProgress.setVisibility(View.GONE);
622 }
623 if (!mUrlInput.hasFocus()) {
624 mUrlInput.requestFocus();
625 }
626 if (clearInput) {
627 mUrlInput.setText("");
628 } else if (mInVoiceMode) {
629 mUrlInput.showDropDown();
630 }
631 }
632
633 private ViewGroup.LayoutParams makeLayoutParams() {
634 if (mUseQuickControls) {
635 return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
636 LayoutParams.WRAP_CONTENT);
637 } else {
638 return new AbsoluteLayout.LayoutParams(
639 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
640 0, 0);
641 }
642 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700643
Leon Scroggins571b3762010-05-26 10:25:01 -0400644}