Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 19 | import com.android.browser.UI.DropdownChangeListener; |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 20 | import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 21 | import com.android.browser.search.SearchEngine; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 22 | |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 23 | import android.accounts.Account; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 24 | import android.app.Activity; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.res.Resources; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 27 | import android.graphics.Bitmap; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 29 | import android.text.TextUtils; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 30 | import android.view.ContextThemeWrapper; |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 31 | import android.view.KeyEvent; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 32 | import android.view.LayoutInflater; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 33 | import android.view.View; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 34 | import android.view.View.OnClickListener; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 35 | import android.view.View.OnFocusChangeListener; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 36 | import android.view.ViewGroup; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 37 | import android.view.animation.Animation; |
| 38 | import android.view.animation.Animation.AnimationListener; |
| 39 | import android.view.animation.AnimationUtils; |
Michael Kolb | b6bc32c | 2010-12-10 11:51:54 -0800 | [diff] [blame] | 40 | import android.webkit.WebView; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 41 | import android.widget.AbsoluteLayout; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 42 | import android.widget.ArrayAdapter; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 43 | import android.widget.Button; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 44 | import android.widget.FrameLayout; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 45 | import android.widget.ImageButton; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 46 | import android.widget.ImageView; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 47 | import android.widget.ProgressBar; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 48 | import android.widget.Spinner; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 49 | import android.widget.TextView; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 50 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 51 | import java.util.List; |
| 52 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 53 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 54 | * tabbed title bar for xlarge screen browser |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 55 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 56 | public class TitleBarXLarge extends TitleBarBase |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 57 | implements OnClickListener, OnFocusChangeListener, TextChangeWatcher, |
| 58 | DeviceAccountLogin.AutoLoginCallback { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 59 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 60 | private XLargeUi mUi; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 61 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 62 | private Drawable mStopDrawable; |
| 63 | private Drawable mReloadDrawable; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 64 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 65 | private View mContainer; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 66 | private ImageButton mBackButton; |
| 67 | private ImageButton mForwardButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 68 | private ImageView mStar; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 69 | private ImageView mUrlIcon; |
| 70 | private ImageView mSearchButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 71 | private View mUrlContainer; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 72 | private View mGoButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 73 | private ImageView mStopButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 74 | private View mAllButton; |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 75 | private View mClearButton; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 76 | private ImageView mVoiceSearch; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 77 | private PageProgressView mProgressView; |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 78 | private Drawable mFocusDrawable; |
| 79 | private Drawable mUnfocusDrawable; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 80 | // Auto-login UI |
| 81 | private View mAutoLogin; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 82 | private Spinner mAutoLoginAccount; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 83 | private Button mAutoLoginLogin; |
| 84 | private ProgressBar mAutoLoginProgress; |
| 85 | private TextView mAutoLoginError; |
| 86 | private ImageButton mAutoLoginCancel; |
| 87 | private DeviceAccountLogin mAutoLoginHandler; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 88 | private ArrayAdapter<String> mAccountsAdapter; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 89 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 90 | private boolean mInLoad; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 91 | private boolean mUseQuickControls; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 92 | |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 93 | public TitleBarXLarge(Activity activity, UiController controller, |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 94 | XLargeUi ui) { |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 95 | super(activity, controller, ui); |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 96 | mUi = ui; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 97 | Resources resources = activity.getResources(); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 98 | mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark); |
| 99 | mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 100 | mFocusDrawable = resources.getDrawable( |
| 101 | R.drawable.textfield_active_holo_dark); |
| 102 | mUnfocusDrawable = resources.getDrawable( |
| 103 | R.drawable.textfield_default_holo_dark); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 104 | mInVoiceMode = false; |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 105 | initLayout(activity); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 106 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 107 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 108 | @Override |
| 109 | void setTitleGravity(int gravity) { |
| 110 | if (mUseQuickControls) { |
| 111 | FrameLayout.LayoutParams lp = |
| 112 | (FrameLayout.LayoutParams) getLayoutParams(); |
| 113 | lp.gravity = gravity; |
| 114 | setLayoutParams(lp); |
| 115 | } else { |
| 116 | super.setTitleGravity(gravity); |
| 117 | } |
| 118 | } |
| 119 | |
John Reck | 1605bef | 2011-01-10 18:11:18 -0800 | [diff] [blame] | 120 | private void initLayout(Context context) { |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 121 | LayoutInflater factory = LayoutInflater.from(context); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 122 | factory.inflate(R.layout.url_bar, this); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 123 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 124 | mContainer = findViewById(R.id.taburlbar); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 125 | mUrlInput = (UrlInputView) findViewById(R.id.url_focused); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 126 | mAllButton = findViewById(R.id.all_btn); |
| 127 | // TODO: Change enabled states based on whether you can go |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 128 | // back/forward. Probably should be done inside onPageStarted. |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 129 | mBackButton = (ImageButton) findViewById(R.id.back); |
| 130 | mForwardButton = (ImageButton) findViewById(R.id.forward); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 131 | mUrlIcon = (ImageView) findViewById(R.id.url_icon); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 132 | mStar = (ImageView) findViewById(R.id.star); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 133 | mStopButton = (ImageView) findViewById(R.id.stop); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 134 | mSearchButton = (ImageView) findViewById(R.id.search); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 135 | mLockIcon = (ImageView) findViewById(R.id.lock); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 136 | mGoButton = findViewById(R.id.go); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 137 | mClearButton = findViewById(R.id.clear); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 138 | mVoiceSearch = (ImageView) findViewById(R.id.voicesearch); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 139 | mProgressView = (PageProgressView) findViewById(R.id.progress); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 140 | mUrlContainer = findViewById(R.id.urlbar_focused); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 141 | mBackButton.setOnClickListener(this); |
| 142 | mForwardButton.setOnClickListener(this); |
| 143 | mStar.setOnClickListener(this); |
| 144 | mAllButton.setOnClickListener(this); |
| 145 | mStopButton.setOnClickListener(this); |
| 146 | mSearchButton.setOnClickListener(this); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 147 | mGoButton.setOnClickListener(this); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 148 | mClearButton.setOnClickListener(this); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 149 | mVoiceSearch.setOnClickListener(this); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 150 | mUrlInput.setUrlInputListener(this); |
| 151 | mUrlInput.setContainer(mUrlContainer); |
| 152 | mUrlInput.setController(mUiController); |
| 153 | mUrlInput.setOnFocusChangeListener(this); |
| 154 | mUrlInput.setSelectAllOnFocus(true); |
Narayan Kamath | 80aad8d | 2011-02-23 12:01:13 +0000 | [diff] [blame] | 155 | mUrlInput.addQueryTextWatcher(this); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 156 | mAutoLogin = findViewById(R.id.autologin); |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 157 | mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 158 | mAutoLoginLogin = (Button) findViewById(R.id.autologin_login); |
| 159 | mAutoLoginLogin.setOnClickListener(this); |
| 160 | mAutoLoginProgress = |
| 161 | (ProgressBar) findViewById(R.id.autologin_progress); |
| 162 | mAutoLoginError = (TextView) findViewById(R.id.autologin_error); |
| 163 | mAutoLoginCancel = |
| 164 | (ImageButton) mAutoLogin.findViewById(R.id.autologin_close); |
| 165 | mAutoLoginCancel.setOnClickListener(this); |
| 166 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 167 | setFocusState(false); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 170 | void updateNavigationState(Tab tab) { |
| 171 | WebView web = tab.getWebView(); |
| 172 | if (web != null) { |
| 173 | mBackButton.setImageResource(web.canGoBack() |
| 174 | ? R.drawable.ic_back_holo_dark |
| 175 | : R.drawable.ic_back_disabled_holo_dark); |
| 176 | mForwardButton.setImageResource(web.canGoForward() |
| 177 | ? R.drawable.ic_forward_holo_dark |
| 178 | : R.drawable.ic_forward_disabled_holo_dark); |
| 179 | } |
| 180 | } |
| 181 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 182 | void updateAutoLogin(Tab tab, boolean animate) { |
| 183 | DeviceAccountLogin login = tab.getDeviceAccountLogin(); |
| 184 | if (login != null) { |
| 185 | mAutoLoginHandler = login; |
| 186 | mAutoLogin.setVisibility(View.VISIBLE); |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 187 | ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, |
| 188 | android.R.style.Theme_Holo_Light); |
| 189 | mAccountsAdapter = new ArrayAdapter<String>(wrapper, |
| 190 | android.R.layout.simple_spinner_item, login.getAccountNames()); |
| 191 | mAccountsAdapter.setDropDownViewResource( |
| 192 | android.R.layout.simple_spinner_dropdown_item); |
| 193 | mAutoLoginAccount.setAdapter(mAccountsAdapter); |
| 194 | mAutoLoginAccount.setSelection(0); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 195 | mAutoLoginAccount.setEnabled(true); |
| 196 | mAutoLoginLogin.setEnabled(true); |
| 197 | mAutoLoginProgress.setVisibility(View.GONE); |
| 198 | mAutoLoginError.setVisibility(View.GONE); |
| 199 | switch (login.getState()) { |
| 200 | case DeviceAccountLogin.PROCESSING: |
| 201 | mAutoLoginAccount.setEnabled(false); |
| 202 | mAutoLoginLogin.setEnabled(false); |
| 203 | mAutoLoginProgress.setVisibility(View.VISIBLE); |
| 204 | break; |
| 205 | case DeviceAccountLogin.FAILED: |
| 206 | mAutoLoginProgress.setVisibility(View.GONE); |
| 207 | mAutoLoginError.setVisibility(View.VISIBLE); |
| 208 | break; |
| 209 | case DeviceAccountLogin.INITIAL: |
| 210 | break; |
| 211 | default: |
| 212 | throw new IllegalStateException(); |
| 213 | } |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 214 | if (mUseQuickControls) { |
| 215 | mUi.showTitleBar(); |
| 216 | } else { |
| 217 | if (animate) { |
| 218 | mAutoLogin.startAnimation(AnimationUtils.loadAnimation( |
| 219 | getContext(), R.anim.autologin_enter)); |
| 220 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 221 | } |
| 222 | } else { |
| 223 | mAutoLoginHandler = null; |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 224 | if (mUseQuickControls) { |
| 225 | mUi.hideTitleBar(); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 226 | mAutoLogin.setVisibility(View.GONE); |
Michael Kolb | 2ba24b9 | 2011-03-17 10:59:10 -0700 | [diff] [blame^] | 227 | mUi.refreshWebView(); |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 228 | } else { |
| 229 | if (animate) { |
| 230 | hideAutoLogin(); |
| 231 | } else if (mAutoLogin.getAnimation() == null) { |
| 232 | mAutoLogin.setVisibility(View.GONE); |
Michael Kolb | 2ba24b9 | 2011-03-17 10:59:10 -0700 | [diff] [blame^] | 233 | mUi.refreshWebView(); |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 234 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 239 | boolean inAutoLogin() { |
| 240 | return mAutoLoginHandler != null; |
| 241 | } |
| 242 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 243 | private ViewGroup.LayoutParams makeLayoutParams() { |
| 244 | if (mUseQuickControls) { |
| 245 | return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 246 | LayoutParams.WRAP_CONTENT); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 247 | } else { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 248 | return new AbsoluteLayout.LayoutParams( |
| 249 | LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, |
| 250 | 0, 0); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 254 | @Override |
| 255 | public int getEmbeddedHeight() { |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 256 | int height = mContainer.getHeight(); |
| 257 | if (mAutoLogin.getVisibility() == View.VISIBLE) { |
| 258 | height += mAutoLogin.getHeight(); |
| 259 | } |
| 260 | return height; |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 263 | void setUseQuickControls(boolean useQuickControls) { |
| 264 | mUseQuickControls = useQuickControls; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 265 | setLayoutParams(makeLayoutParams()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void setShowProgressOnly(boolean progress) { |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 269 | if (progress && !inAutoLogin()) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 270 | mContainer.setVisibility(View.GONE); |
| 271 | } else { |
| 272 | mContainer.setVisibility(View.VISIBLE); |
| 273 | } |
| 274 | } |
| 275 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 276 | @Override |
| 277 | public void onFocusChange(View view, boolean hasFocus) { |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 278 | // if losing focus and not in touch mode, leave as is |
| 279 | if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) { |
| 280 | setFocusState(hasFocus); |
| 281 | mUrlContainer.setBackgroundDrawable(hasFocus |
| 282 | ? mFocusDrawable : mUnfocusDrawable); |
| 283 | } |
| 284 | if (hasFocus) { |
| 285 | mUrlInput.forceIme(); |
| 286 | if (mInVoiceMode) { |
| 287 | mUrlInput.forceFilter(); |
| 288 | } |
| 289 | } else if (!mUrlInput.needsUpdate()) { |
| 290 | mUrlInput.dismissDropDown(); |
| 291 | mUrlInput.hideIME(); |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 292 | if (mUseQuickControls) { |
| 293 | mUi.hideTitleBar(); |
| 294 | } |
Narayan Kamath | c93a2a9 | 2011-03-15 11:33:52 +0000 | [diff] [blame] | 295 | |
| 296 | if (mUrlInput.getText().length() == 0) { |
| 297 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 298 | if (currentTab != null) { |
| 299 | mUrlInput.setText(currentTab.getUrl(), false); |
| 300 | } |
| 301 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 302 | } |
| 303 | mUrlInput.clearNeedsUpdate(); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 304 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 305 | |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 306 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 307 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 308 | mStar.setActivated(isBookmark); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 309 | } |
| 310 | |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 311 | /** |
| 312 | * called from the Ui when the user wants to edit |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 313 | * @param clearInput clear the input field |
| 314 | */ |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 315 | void startEditingUrl(boolean clearInput) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 316 | // editing takes preference of progress |
| 317 | mContainer.setVisibility(View.VISIBLE); |
| 318 | if (mUseQuickControls) { |
| 319 | mProgressView.setVisibility(View.GONE); |
| 320 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 321 | if (!mUrlInput.hasFocus()) { |
| 322 | mUrlInput.requestFocus(); |
| 323 | } |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 324 | if (clearInput) { |
| 325 | mUrlInput.setText(""); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 326 | } else if (mInVoiceMode) { |
| 327 | mUrlInput.showDropDown(); |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
| 331 | boolean isEditingUrl() { |
| 332 | return mUrlInput.hasFocus(); |
| 333 | } |
| 334 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 335 | void stopEditingUrl() { |
| 336 | mUrlInput.clearFocus(); |
| 337 | } |
| 338 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 339 | private void hideAutoLogin() { |
| 340 | Animation anim = AnimationUtils.loadAnimation( |
| 341 | getContext(), R.anim.autologin_exit); |
| 342 | anim.setAnimationListener(new AnimationListener() { |
| 343 | @Override public void onAnimationEnd(Animation a) { |
| 344 | mAutoLogin.setVisibility(View.GONE); |
Michael Kolb | 2ba24b9 | 2011-03-17 10:59:10 -0700 | [diff] [blame^] | 345 | mUi.refreshWebView(); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 346 | } |
| 347 | @Override public void onAnimationStart(Animation a) {} |
| 348 | @Override public void onAnimationRepeat(Animation a) {} |
| 349 | }); |
| 350 | mAutoLogin.startAnimation(anim); |
| 351 | } |
| 352 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 353 | @Override |
| 354 | public void onClick(View v) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 355 | if (mBackButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 356 | mUiController.getCurrentTopWebView().goBack(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 357 | } else if (mForwardButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 358 | mUiController.getCurrentTopWebView().goForward(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 359 | } else if (mStar == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 360 | mUiController.bookmarkCurrentPage( |
Leon Scroggins | bdff8a7 | 2011-02-11 15:49:04 -0500 | [diff] [blame] | 361 | AddBookmarkPage.DEFAULT_FOLDER_ID, true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 362 | } else if (mAllButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 363 | mUiController.bookmarksOrHistoryPicker(false); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 364 | } else if (mSearchButton == v) { |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 365 | mUi.editUrl(true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 366 | } else if (mStopButton == v) { |
| 367 | stopOrRefresh(); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 368 | } else if (mGoButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 369 | if (!TextUtils.isEmpty(mUrlInput.getText())) { |
| 370 | onAction(mUrlInput.getText().toString(), null, |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 371 | UrlInputView.TYPED); |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 372 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 373 | } else if (mClearButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 374 | clearOrClose(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 375 | } else if (mVoiceSearch == v) { |
| 376 | mUiController.startVoiceSearch(); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 377 | } else if (mAutoLoginCancel == v) { |
| 378 | if (mAutoLoginHandler != null) { |
| 379 | mAutoLoginHandler.cancel(); |
| 380 | mAutoLoginHandler = null; |
| 381 | } |
| 382 | hideAutoLogin(); |
| 383 | } else if (mAutoLoginLogin == v) { |
| 384 | if (mAutoLoginHandler != null) { |
| 385 | mAutoLoginAccount.setEnabled(false); |
| 386 | mAutoLoginLogin.setEnabled(false); |
| 387 | mAutoLoginProgress.setVisibility(View.VISIBLE); |
| 388 | mAutoLoginError.setVisibility(View.GONE); |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 389 | mAutoLoginHandler.login( |
| 390 | mAutoLoginAccount.getSelectedItemPosition(), this); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 391 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 395 | @Override |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 396 | public void loginFailed() { |
| 397 | mAutoLoginAccount.setEnabled(true); |
| 398 | mAutoLoginLogin.setEnabled(true); |
| 399 | mAutoLoginProgress.setVisibility(View.GONE); |
| 400 | mAutoLoginError.setVisibility(View.VISIBLE); |
| 401 | } |
| 402 | |
| 403 | @Override |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 404 | void setFavicon(Bitmap icon) { } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 405 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 406 | private void clearOrClose() { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 407 | if (TextUtils.isEmpty(mUrlInput.getUserText())) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 408 | // close |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 409 | mUrlInput.clearFocus(); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 410 | } else { |
| 411 | // clear |
| 412 | mUrlInput.setText(""); |
| 413 | } |
| 414 | } |
| 415 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 416 | private void setFocusState(boolean focus) { |
| 417 | if (focus) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 418 | mUrlInput.setDropDownWidth(mUrlContainer.getWidth()); |
| 419 | mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft()); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 420 | mSearchButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 421 | mStar.setVisibility(View.GONE); |
| 422 | mClearButton.setVisibility(View.VISIBLE); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 423 | mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark); |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 424 | updateSearchMode(false); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 425 | } else { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 426 | mGoButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 427 | mVoiceSearch.setVisibility(View.GONE); |
| 428 | mStar.setVisibility(View.VISIBLE); |
| 429 | mClearButton.setVisibility(View.GONE); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 430 | if (mUseQuickControls) { |
| 431 | mSearchButton.setVisibility(View.GONE); |
| 432 | } else { |
| 433 | mSearchButton.setVisibility(View.VISIBLE); |
| 434 | } |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 435 | mUrlIcon.setImageResource(mInVoiceMode ? |
| 436 | R.drawable.ic_search_holo_dark |
| 437 | : R.drawable.ic_web_holo_dark); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 441 | private void stopOrRefresh() { |
| 442 | if (mInLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 443 | mUiController.stopLoading(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 444 | } else { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 445 | mUiController.getCurrentTopWebView().reload(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 446 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 450 | * Update the progress, from 0 to 100. |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 451 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 452 | @Override |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 453 | void setProgress(int newProgress) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 454 | boolean blockvisuals = mUseQuickControls && isEditingUrl(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 455 | if (newProgress >= PROGRESS_MAX) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 456 | if (!blockvisuals) { |
| 457 | mProgressView.setProgress(PageProgressView.MAX_PROGRESS); |
| 458 | mProgressView.setVisibility(View.GONE); |
| 459 | mStopButton.setImageDrawable(mReloadDrawable); |
| 460 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 461 | mInLoad = false; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 462 | } else { |
| 463 | if (!mInLoad) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 464 | if (!blockvisuals) { |
| 465 | mProgressView.setVisibility(View.VISIBLE); |
| 466 | mStopButton.setImageDrawable(mStopDrawable); |
| 467 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 468 | mInLoad = true; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 469 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 470 | mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS |
| 471 | / PROGRESS_MAX); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 472 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 475 | private void updateSearchMode(boolean userEdited) { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 476 | setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText())); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | private void setSearchMode(boolean voiceSearchEnabled) { |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 480 | SearchEngine searchEngine = BrowserSettings.getInstance() |
| 481 | .getSearchEngine(); |
| 482 | boolean showvoicebutton = voiceSearchEnabled && |
| 483 | (searchEngine != null && searchEngine.supportsVoiceSearch()); |
| 484 | mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE : |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 485 | View.GONE); |
| 486 | mGoButton.setVisibility(voiceSearchEnabled ? View.GONE : |
| 487 | View.VISIBLE); |
| 488 | } |
| 489 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 490 | @Override |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 491 | /* package */ void setDisplayTitle(String title) { |
John Reck | 4851f9e | 2010-12-22 16:40:36 -0800 | [diff] [blame] | 492 | if (!isEditingUrl()) { |
| 493 | mUrlInput.setText(title, false); |
| 494 | } |
Michael Kolb | 7b20ddd | 2010-10-14 15:03:28 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 497 | // UrlInput text watcher |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 498 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 499 | @Override |
Narayan Kamath | 80aad8d | 2011-02-23 12:01:13 +0000 | [diff] [blame] | 500 | public void onTextChanged(String newText) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 501 | if (mUrlInput.hasFocus()) { |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 502 | // check if input field is empty and adjust voice search state |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 503 | updateSearchMode(true); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 504 | // clear voice mode when user types |
| 505 | setInVoiceMode(false, null); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 506 | } |
| 507 | } |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 508 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 509 | // voicesearch |
| 510 | |
| 511 | @Override |
| 512 | public void setInVoiceMode(boolean voicemode) { |
| 513 | setInVoiceMode(voicemode, null); |
| 514 | } |
| 515 | |
| 516 | public void setInVoiceMode(boolean voicemode, List<String> voiceResults) { |
| 517 | mInVoiceMode = voicemode; |
| 518 | mUrlInput.setVoiceResults(voiceResults); |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 519 | if (voicemode) { |
| 520 | mUrlIcon.setImageDrawable(mSearchButton.getDrawable()); |
| 521 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 522 | } |
| 523 | |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 524 | @Override |
| 525 | void setIncognitoMode(boolean incognito) { |
| 526 | mUrlInput.setIncognitoMode(incognito); |
| 527 | } |
Michael Kolb | 47171d8 | 2011-01-28 10:34:15 -0800 | [diff] [blame] | 528 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 529 | @Override |
| 530 | public View focusSearch(View focused, int dir) { |
| 531 | if (FOCUS_DOWN == dir && hasFocus()) { |
| 532 | return getCurrentWebView(); |
| 533 | } |
| 534 | return super.focusSearch(focused, dir); |
| 535 | } |
| 536 | |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 537 | void clearCompletions() { |
| 538 | mUrlInput.setSuggestedText(null); |
| 539 | } |
| 540 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 541 | @Override |
| 542 | public boolean dispatchKeyEventPreIme(KeyEvent evt) { |
| 543 | if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 544 | // catch back key in order to do slightly more cleanup than usual |
| 545 | mUrlInput.clearFocus(); |
| 546 | return true; |
| 547 | } |
| 548 | return super.dispatchKeyEventPreIme(evt); |
| 549 | } |
| 550 | |
| 551 | private WebView getCurrentWebView() { |
| 552 | Tab t = mUi.getActiveTab(); |
| 553 | if (t != null) { |
| 554 | return t.getWebView(); |
| 555 | } else { |
| 556 | return null; |
| 557 | } |
| 558 | } |
| 559 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 560 | void registerDropdownChangeListener(DropdownChangeListener d) { |
| 561 | mUrlInput.registerDropdownChangeListener(d); |
| 562 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 563 | } |