Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [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 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 21 | import android.database.DataSetObserver; |
| 22 | import android.graphics.Rect; |
John Reck | dcda1d5 | 2010-11-29 10:05:54 -0800 | [diff] [blame] | 23 | import android.text.TextUtils; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
John Reck | b77bdc4 | 2011-01-24 13:24:48 -0800 | [diff] [blame] | 25 | import android.util.Patterns; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 26 | import android.view.KeyEvent; |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 27 | import android.view.MotionEvent; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 28 | import android.view.View; |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 29 | import android.view.inputmethod.EditorInfo; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 30 | import android.view.inputmethod.InputMethodManager; |
John Reck | 87369ea | 2011-01-23 15:20:38 -0800 | [diff] [blame] | 31 | import android.widget.AdapterView; |
| 32 | import android.widget.AdapterView.OnItemClickListener; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 33 | import android.widget.TextView; |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 34 | import android.widget.TextView.OnEditorActionListener; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 35 | |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 36 | import com.android.browser.SuggestionsAdapter.CompletionListener; |
| 37 | import com.android.browser.SuggestionsAdapter.SuggestItem; |
| 38 | import com.android.browser.UI.DropdownChangeListener; |
| 39 | import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; |
| 40 | import com.android.browser.autocomplete.SuggestiveAutoCompleteTextView; |
| 41 | import com.android.browser.search.SearchEngine; |
| 42 | import com.android.browser.search.SearchEngineInfo; |
| 43 | import com.android.browser.search.SearchEngines; |
| 44 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 45 | import java.util.List; |
| 46 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 47 | /** |
| 48 | * url/search input view |
| 49 | * handling suggestions |
| 50 | */ |
Narayan Kamath | 80aad8d | 2011-02-23 12:01:13 +0000 | [diff] [blame] | 51 | public class UrlInputView extends SuggestiveAutoCompleteTextView |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 52 | implements OnEditorActionListener, |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 53 | CompletionListener, OnItemClickListener, TextChangeWatcher { |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 54 | |
| 55 | static final String TYPED = "browser-type"; |
| 56 | static final String SUGGESTED = "browser-suggest"; |
Michael Kolb | bd2dd64 | 2011-01-13 13:01:30 -0800 | [diff] [blame] | 57 | static final String VOICE = "voice-search"; |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 58 | |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 59 | static interface StateListener { |
| 60 | static final int STATE_NORMAL = 0; |
| 61 | static final int STATE_HIGHLIGHTED = 1; |
| 62 | static final int STATE_EDITED = 2; |
| 63 | |
| 64 | public void onStateChanged(int state); |
| 65 | } |
| 66 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 67 | private UrlInputListener mListener; |
| 68 | private InputMethodManager mInputManager; |
| 69 | private SuggestionsAdapter mAdapter; |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 70 | private View mContainer; |
| 71 | private boolean mLandscape; |
John Reck | b77bdc4 | 2011-01-24 13:24:48 -0800 | [diff] [blame] | 72 | private boolean mIncognitoMode; |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 73 | private boolean mNeedsUpdate; |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 74 | private DropdownChangeListener mDropdownListener; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 75 | |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 76 | private int mState; |
| 77 | private StateListener mStateListener; |
| 78 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 79 | public UrlInputView(Context context, AttributeSet attrs, int defStyle) { |
| 80 | super(context, attrs, defStyle); |
| 81 | init(context); |
| 82 | } |
| 83 | |
| 84 | public UrlInputView(Context context, AttributeSet attrs) { |
| 85 | super(context, attrs); |
| 86 | init(context); |
| 87 | } |
| 88 | |
| 89 | public UrlInputView(Context context) { |
| 90 | super(context); |
| 91 | init(context); |
| 92 | } |
| 93 | |
| 94 | private void init(Context ctx) { |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 95 | mInputManager = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 96 | setOnEditorActionListener(this); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 97 | mAdapter = new SuggestionsAdapter(ctx, this); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 98 | setAdapter(mAdapter); |
Michael Kolb | ba99c5d | 2010-11-29 14:57:41 -0800 | [diff] [blame] | 99 | setSelectAllOnFocus(true); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 100 | onConfigurationChanged(ctx.getResources().getConfiguration()); |
John Reck | 35defff | 2010-11-11 14:06:45 -0800 | [diff] [blame] | 101 | setThreshold(1); |
John Reck | 87369ea | 2011-01-23 15:20:38 -0800 | [diff] [blame] | 102 | setOnItemClickListener(this); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 103 | mNeedsUpdate = false; |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 104 | mDropdownListener = null; |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 105 | addQueryTextWatcher(this); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 106 | |
| 107 | mAdapter.registerDataSetObserver(new DataSetObserver() { |
| 108 | @Override |
| 109 | public void onChanged() { |
| 110 | if (!isPopupShowing()) { |
| 111 | return; |
| 112 | } |
| 113 | dispatchChange(); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void onInvalidated() { |
| 118 | dispatchChange(); |
| 119 | } |
| 120 | }); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 121 | mState = StateListener.STATE_NORMAL; |
| 122 | } |
| 123 | |
| 124 | protected void onFocusChanged(boolean focused, int direction, Rect prevRect) { |
| 125 | super.onFocusChanged(focused, direction, prevRect); |
| 126 | if (focused) { |
| 127 | if (hasSelection()) { |
| 128 | changeState(StateListener.STATE_HIGHLIGHTED); |
| 129 | } else { |
| 130 | changeState(StateListener.STATE_EDITED); |
| 131 | } |
| 132 | } else { |
| 133 | // reset the selection state |
| 134 | changeState(StateListener.STATE_NORMAL); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public boolean onTouchEvent(MotionEvent evt) { |
| 140 | boolean hasSelection = hasSelection(); |
| 141 | boolean res = super.onTouchEvent(evt); |
| 142 | if ((MotionEvent.ACTION_DOWN == evt.getActionMasked()) |
| 143 | && hasSelection) { |
| 144 | changeState(StateListener.STATE_EDITED); |
| 145 | } |
| 146 | return res; |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * check if focus change requires a title bar update |
| 151 | */ |
| 152 | boolean needsUpdate() { |
| 153 | return mNeedsUpdate; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * clear the focus change needs title bar update flag |
| 158 | */ |
| 159 | void clearNeedsUpdate() { |
| 160 | mNeedsUpdate = false; |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Michael Kolb | ba99c5d | 2010-11-29 14:57:41 -0800 | [diff] [blame] | 163 | void setController(UiController controller) { |
| 164 | UrlSelectionActionMode urlSelectionMode |
| 165 | = new UrlSelectionActionMode(controller); |
| 166 | setCustomSelectionActionModeCallback(urlSelectionMode); |
| 167 | } |
| 168 | |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 169 | void setContainer(View container) { |
| 170 | mContainer = container; |
| 171 | } |
| 172 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 173 | public void setUrlInputListener(UrlInputListener listener) { |
| 174 | mListener = listener; |
| 175 | } |
| 176 | |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 177 | public void setStateListener(StateListener listener) { |
| 178 | mStateListener = listener; |
| 179 | // update listener |
| 180 | changeState(mState); |
| 181 | } |
| 182 | |
| 183 | private void changeState(int newState) { |
| 184 | mState = newState; |
| 185 | if (mStateListener != null) { |
| 186 | mStateListener.onStateChanged(mState); |
| 187 | } |
| 188 | } |
| 189 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 190 | void setVoiceResults(List<String> voiceResults) { |
| 191 | mAdapter.setVoiceResults(voiceResults); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 194 | @Override |
| 195 | protected void onConfigurationChanged(Configuration config) { |
John Reck | 35defff | 2010-11-11 14:06:45 -0800 | [diff] [blame] | 196 | super.onConfigurationChanged(config); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 197 | mLandscape = (config.orientation & |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 198 | Configuration.ORIENTATION_LANDSCAPE) != 0; |
John Reck | 35defff | 2010-11-11 14:06:45 -0800 | [diff] [blame] | 199 | mAdapter.setLandscapeMode(mLandscape); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 200 | if (isPopupShowing() && (getVisibility() == View.VISIBLE)) { |
John Reck | 35defff | 2010-11-11 14:06:45 -0800 | [diff] [blame] | 201 | setupDropDown(); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 202 | performFiltering(getUserText(), 0); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public void showDropDown() { |
John Reck | 35defff | 2010-11-11 14:06:45 -0800 | [diff] [blame] | 208 | setupDropDown(); |
| 209 | super.showDropDown(); |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void dismissDropDown() { |
| 214 | super.dismissDropDown(); |
| 215 | mAdapter.clearCache(); |
| 216 | } |
| 217 | |
| 218 | private void setupDropDown() { |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 219 | int width = mContainer != null ? mContainer.getWidth() : getWidth(); |
Michael Kolb | c5998c2 | 2010-10-10 16:04:35 -0700 | [diff] [blame] | 220 | if (width != getDropDownWidth()) { |
| 221 | setDropDownWidth(width); |
| 222 | } |
| 223 | if (getLeft() != -getDropDownHorizontalOffset()) { |
| 224 | setDropDownHorizontalOffset(-getLeft()); |
| 225 | } |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Override |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 229 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 230 | if (BrowserSettings.getInstance().useInstantSearch() && |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 231 | (actionId == EditorInfo.IME_ACTION_NEXT)) { |
| 232 | // When instant is turned on AND the user chooses to complete |
| 233 | // using the tab key, then use the completion rather than the |
| 234 | // text that the user has typed. |
| 235 | finishInput(getText().toString(), null, TYPED); |
| 236 | } else { |
| 237 | finishInput(getUserText(), null, TYPED); |
| 238 | } |
| 239 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 240 | return true; |
| 241 | } |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 242 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 243 | void forceFilter() { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 244 | performForcedFiltering(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 245 | showDropDown(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 248 | void forceIme() { |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 249 | mInputManager.focusIn(this); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 250 | mInputManager.showSoftInput(this, 0); |
| 251 | } |
| 252 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 253 | void hideIME() { |
| 254 | mInputManager.hideSoftInputFromWindow(getWindowToken(), 0); |
| 255 | } |
| 256 | |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 257 | private void finishInput(String url, String extra, String source) { |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 258 | mNeedsUpdate = true; |
| 259 | dismissDropDown(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 260 | mInputManager.hideSoftInputFromWindow(getWindowToken(), 0); |
John Reck | dcda1d5 | 2010-11-29 10:05:54 -0800 | [diff] [blame] | 261 | if (TextUtils.isEmpty(url)) { |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 262 | mListener.onDismiss(); |
| 263 | } else { |
John Reck | b77bdc4 | 2011-01-24 13:24:48 -0800 | [diff] [blame] | 264 | if (mIncognitoMode && isSearch(url)) { |
| 265 | // To prevent logging, intercept this request |
| 266 | // TODO: This is a quick hack, refactor this |
| 267 | SearchEngine searchEngine = BrowserSettings.getInstance() |
| 268 | .getSearchEngine(); |
| 269 | if (searchEngine == null) return; |
| 270 | SearchEngineInfo engineInfo = SearchEngines |
| 271 | .getSearchEngineInfo(mContext, searchEngine.getName()); |
| 272 | if (engineInfo == null) return; |
| 273 | url = engineInfo.getSearchUriForQuery(url); |
| 274 | // mLister.onAction can take it from here without logging |
| 275 | } |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 276 | mListener.onAction(url, extra, source); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 277 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 278 | } |
| 279 | |
John Reck | b77bdc4 | 2011-01-24 13:24:48 -0800 | [diff] [blame] | 280 | boolean isSearch(String inUrl) { |
| 281 | String url = UrlUtils.fixUrl(inUrl).trim(); |
| 282 | if (TextUtils.isEmpty(url)) return false; |
| 283 | |
| 284 | if (Patterns.WEB_URL.matcher(url).matches() |
| 285 | || UrlUtils.ACCEPTED_URI_SCHEMA.matcher(url).matches()) { |
| 286 | return false; |
| 287 | } |
| 288 | return true; |
| 289 | } |
| 290 | |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 291 | // Completion Listener |
| 292 | |
| 293 | @Override |
| 294 | public void onSearch(String search) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 295 | mListener.onCopySuggestion(search); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | @Override |
Michael Kolb | bd2dd64 | 2011-01-13 13:01:30 -0800 | [diff] [blame] | 299 | public void onSelect(String url, int type, String extra) { |
| 300 | finishInput(url, extra, (type == SuggestionsAdapter.TYPE_VOICE_SEARCH) |
| 301 | ? VOICE : SUGGESTED); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 304 | @Override |
John Reck | 87369ea | 2011-01-23 15:20:38 -0800 | [diff] [blame] | 305 | public void onItemClick( |
| 306 | AdapterView<?> parent, View view, int position, long id) { |
| 307 | SuggestItem item = mAdapter.getItem(position); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 308 | onSelect(SuggestionsAdapter.getSuggestionUrl(item), item.type, item.extra); |
John Reck | 87369ea | 2011-01-23 15:20:38 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 311 | interface UrlInputListener { |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 312 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 313 | public void onDismiss(); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 314 | |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 315 | public void onAction(String text, String extra, String source); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 316 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 317 | public void onCopySuggestion(String text); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 318 | |
| 319 | } |
| 320 | |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 321 | public void setIncognitoMode(boolean incognito) { |
John Reck | b77bdc4 | 2011-01-24 13:24:48 -0800 | [diff] [blame] | 322 | mIncognitoMode = incognito; |
| 323 | mAdapter.setIncognitoMode(mIncognitoMode); |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 326 | @Override |
| 327 | public boolean onKeyDown(int keyCode, KeyEvent evt) { |
| 328 | if (keyCode == KeyEvent.KEYCODE_ESCAPE && !isInTouchMode()) { |
| 329 | finishInput(null, null, null); |
| 330 | return true; |
| 331 | } |
| 332 | return super.onKeyDown(keyCode, evt); |
| 333 | } |
| 334 | |
Narayan Kamath | 80aad8d | 2011-02-23 12:01:13 +0000 | [diff] [blame] | 335 | public SuggestionsAdapter getAdapter() { |
| 336 | return mAdapter; |
| 337 | } |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 338 | |
| 339 | private void dispatchChange() { |
| 340 | final Rect popupRect = new Rect(); |
| 341 | getPopupDrawableRect(popupRect); |
| 342 | |
| 343 | if (mDropdownListener != null) { |
| 344 | mDropdownListener.onNewDropdownDimensions(popupRect.height()); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void registerDropdownChangeListener(DropdownChangeListener d) { |
| 349 | mDropdownListener = d; |
| 350 | } |
Michael Kolb | 74e60c2 | 2011-04-30 16:43:47 -0700 | [diff] [blame] | 351 | |
| 352 | /* |
| 353 | * no-op to prevent scrolling of webview when embedded titlebar |
| 354 | * gets edited |
| 355 | */ |
| 356 | @Override |
| 357 | public boolean requestRectangleOnScreen(Rect rect, boolean immediate) { |
| 358 | return false; |
| 359 | } |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 360 | |
| 361 | @Override |
| 362 | public void onTextChanged(String newText) { |
| 363 | if (StateListener.STATE_HIGHLIGHTED == mState) { |
| 364 | changeState(StateListener.STATE_EDITED); |
| 365 | } |
| 366 | } |
| 367 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 368 | } |