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