OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.shell.omnibox; | 5 package org.chromium.chrome.shell.omnibox; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.Rect; | 8 import android.graphics.Rect; |
9 import android.os.Handler; | 9 import android.os.Handler; |
10 import android.text.Editable; | 10 import android.text.Editable; |
11 import android.text.TextUtils; | 11 import android.text.TextUtils; |
12 import android.text.TextWatcher; | 12 import android.text.TextWatcher; |
13 import android.view.View; | 13 import android.view.View; |
14 import android.view.View.OnLayoutChangeListener; | 14 import android.view.View.OnLayoutChangeListener; |
15 import android.widget.AdapterView; | 15 import android.widget.AdapterView; |
16 import android.widget.AdapterView.OnItemClickListener; | 16 import android.widget.AdapterView.OnItemClickListener; |
17 import android.widget.EditText; | |
17 import android.widget.ListPopupWindow; | 18 import android.widget.ListPopupWindow; |
18 import android.widget.PopupWindow.OnDismissListener; | 19 import android.widget.PopupWindow.OnDismissListener; |
19 import android.widget.TextView; | 20 |
20 | 21 |
21 import org.chromium.chrome.browser.omnibox.AutocompleteController; | 22 import org.chromium.chrome.browser.omnibox.AutocompleteController; |
22 import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsR eceivedListener; | 23 import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsR eceivedListener; |
23 import org.chromium.chrome.browser.omnibox.OmniboxSuggestion; | 24 import org.chromium.chrome.browser.omnibox.OmniboxSuggestion; |
24 import org.chromium.chrome.shell.ChromeShellActivity; | 25 import org.chromium.chrome.shell.ChromeShellActivity; |
25 import org.chromium.chrome.shell.ChromeShellToolbar; | 26 import org.chromium.chrome.shell.ChromeShellToolbar; |
26 import org.chromium.chrome.shell.R; | 27 import org.chromium.chrome.shell.R; |
27 | 28 |
28 import java.util.List; | 29 import java.util.List; |
29 | 30 |
30 /** | 31 /** |
31 * Displays suggestions for the text that is entered to the ChromeShell URL fiel d. | 32 * Displays suggestions for the text that is entered to the ChromeShell URL fiel d. |
32 */ | 33 */ |
33 public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch er { | 34 public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch er { |
34 private static final long SUGGESTION_START_DELAY_MS = 30; | 35 private static final long SUGGESTION_START_DELAY_MS = 30; |
35 | 36 |
36 private final Context mContext; | 37 private final Context mContext; |
37 private final TextView mUrlField; | 38 private final EditText mUrlField; |
38 private final ChromeShellToolbar mToolbar; | 39 private final ChromeShellToolbar mToolbar; |
39 private final AutocompleteController mAutocomplete; | 40 private final AutocompleteController mAutocomplete; |
40 | 41 |
41 private boolean mHasStartedNewOmniboxEditSession; | 42 private boolean mHasStartedNewOmniboxEditSession; |
42 private Runnable mRequestSuggestions; | 43 private Runnable mRequestSuggestions; |
43 private ListPopupWindow mSuggestionsPopup; | 44 private ListPopupWindow mSuggestionsPopup; |
44 private SuggestionArrayAdapter mSuggestionArrayAdapter; | 45 private SuggestionArrayAdapter mSuggestionArrayAdapter; |
45 private int mSuggestionsPopupItemsCount; | 46 private int mSuggestionsPopupItemsCount; |
46 | 47 |
47 /** | 48 /** |
48 * Initializes a suggestion popup that will track urlField value and display suggestions based | 49 * Initializes a suggestion popup that will track urlField value and display suggestions based |
49 * on that value. | 50 * on that value. |
50 */ | 51 */ |
51 public SuggestionPopup(Context context, TextView urlField, | 52 public SuggestionPopup(Context context, EditText urlField, |
52 ChromeShellToolbar toolbar) { | 53 ChromeShellToolbar toolbar) { |
53 mContext = context; | 54 mContext = context; |
54 mUrlField = urlField; | 55 mUrlField = urlField; |
55 mToolbar = toolbar; | 56 mToolbar = toolbar; |
56 mAutocomplete = new AutocompleteController(this); | 57 mAutocomplete = new AutocompleteController(this); |
57 OnLayoutChangeListener listener = new OnLayoutChangeListener() { | 58 OnLayoutChangeListener listener = new OnLayoutChangeListener() { |
58 @Override | 59 @Override |
59 public void onLayoutChange(View v, int left, int top, int right, int bottom, | 60 public void onLayoutChange(View v, int left, int top, int right, int bottom, |
60 int oldLeft, int oldTop, int oldRight, int oldBottom) { | 61 int oldLeft, int oldTop, int oldRight, int oldBottom) { |
61 if (mSuggestionsPopup == null || !mSuggestionsPopup.isShowing()) return; | 62 if (mSuggestionsPopup == null || !mSuggestionsPopup.isShowing()) return; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 @Override | 133 @Override |
133 public void onDismiss() { | 134 public void onDismiss() { |
134 mHasStartedNewOmniboxEditSession = false; | 135 mHasStartedNewOmniboxEditSession = false; |
135 mSuggestionArrayAdapter = null; | 136 mSuggestionArrayAdapter = null; |
136 } | 137 } |
137 }); | 138 }); |
138 } | 139 } |
139 mSuggestionsPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED ); | 140 mSuggestionsPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED ); |
140 mSuggestionsPopup.setWidth(mUrlField.getWidth()); | 141 mSuggestionsPopup.setWidth(mUrlField.getWidth()); |
141 mSuggestionArrayAdapter = | 142 mSuggestionArrayAdapter = |
142 new SuggestionArrayAdapter(mContext, R.layout.dropdown_item, sug gestions); | 143 new SuggestionArrayAdapter(mContext, R.layout.dropdown_item, sug gestions, |
144 mUrlField); | |
Bernhard Bauer
2014/09/10 07:53:31
Indent eight spaces w/r/t the preceding line?
ankit
2014/09/10 11:16:55
Done.
| |
143 mSuggestionsPopup.setHeight(getSuggestionPopupHeight()); | 145 mSuggestionsPopup.setHeight(getSuggestionPopupHeight()); |
144 mSuggestionsPopup.setAdapter(mSuggestionArrayAdapter); | 146 mSuggestionsPopup.setAdapter(mSuggestionArrayAdapter); |
145 mSuggestionsPopup.setAnchorView(mUrlField); | 147 mSuggestionsPopup.setAnchorView(mUrlField); |
146 mSuggestionsPopup.setOnItemClickListener(new OnItemClickListener() { | 148 mSuggestionsPopup.setOnItemClickListener(new OnItemClickListener() { |
147 @Override | 149 @Override |
148 public void onItemClick(AdapterView<?> parent, View view, int positi on, long id) { | 150 public void onItemClick(AdapterView<?> parent, View view, int positi on, long id) { |
149 navigateToSuggestion(position); | 151 navigateToSuggestion(position); |
150 } | 152 } |
151 }); | 153 }); |
152 mSuggestionsPopup.show(); | 154 mSuggestionsPopup.show(); |
(...skipping 30 matching lines...) Expand all Loading... | |
183 | 185 |
184 @Override | 186 @Override |
185 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) { | 187 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) { |
186 mRequestSuggestions = null; | 188 mRequestSuggestions = null; |
187 } | 189 } |
188 | 190 |
189 @Override | 191 @Override |
190 public void onTextChanged(CharSequence s, int start, int before, int count) { | 192 public void onTextChanged(CharSequence s, int start, int before, int count) { |
191 } | 193 } |
192 } | 194 } |
OLD | NEW |