OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.graphics.Paint; | 9 import android.graphics.Paint; |
10 import android.graphics.Point; | 10 import android.graphics.Point; |
11 import android.graphics.Rect; | 11 import android.graphics.Rect; |
12 import android.graphics.drawable.Drawable; | 12 import android.graphics.drawable.Drawable; |
13 import android.util.Log; | 13 import android.util.Log; |
14 import android.view.LayoutInflater; | 14 import android.view.LayoutInflater; |
15 import android.view.View; | 15 import android.view.View; |
16 import android.view.WindowManager; | 16 import android.view.WindowManager; |
17 import android.widget.AdapterView; | 17 import android.widget.AdapterView; |
18 import android.widget.ListAdapter; | 18 import android.widget.ListAdapter; |
19 import android.widget.ListPopupWindow; | 19 import android.widget.ListPopupWindow; |
20 import android.widget.TextView; | 20 import android.widget.TextView; |
21 | 21 |
22 import java.util.ArrayList; | 22 import java.util.ArrayList; |
23 | 23 |
24 import org.chromium.content.app.AppResource; | 24 import org.chromium.chrome.R; |
25 import org.chromium.content.browser.ContainerViewDelegate; | 25 import org.chromium.content.browser.ContainerViewDelegate; |
26 import org.chromium.ui.gfx.NativeWindow; | 26 import org.chromium.ui.gfx.NativeWindow; |
27 | 27 |
28 /** | 28 /** |
29 * The Autofill suggestion popup that lists relevant suggestions. | 29 * The Autofill suggestion popup that lists relevant suggestions. |
30 */ | 30 */ |
31 public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem
ClickListener { | 31 public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem
ClickListener { |
32 | 32 |
33 private static final int TEXT_PADDING_DP = 30; | 33 private static final int TEXT_PADDING_DP = 30; |
34 | 34 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 /** | 163 /** |
164 * Get desired popup window width by calculating the maximum text length fro
m Autofill data. | 164 * Get desired popup window width by calculating the maximum text length fro
m Autofill data. |
165 * @param data Autofill suggestion data. | 165 * @param data Autofill suggestion data. |
166 * @return The popup window width. | 166 * @return The popup window width. |
167 */ | 167 */ |
168 private int getDesiredWidth(AutofillSuggestion[] data) { | 168 private int getDesiredWidth(AutofillSuggestion[] data) { |
169 if (mNameViewPaint == null || mLabelViewPaint == null) { | 169 if (mNameViewPaint == null || mLabelViewPaint == null) { |
170 LayoutInflater inflater = | 170 LayoutInflater inflater = |
171 (LayoutInflater) mNativeWindow.getContext().getSystemService
( | 171 (LayoutInflater) mNativeWindow.getContext().getSystemService
( |
172 Context.LAYOUT_INFLATER_SERVICE); | 172 Context.LAYOUT_INFLATER_SERVICE); |
173 View layout = inflater.inflate(AppResource.LAYOUT_AUTOFILL_TEXT, nul
l); | 173 View layout = inflater.inflate(R.layout.autofill_text, null); |
174 TextView nameView = (TextView) layout.findViewById(AppResource.ID_AU
TOFILL_NAME); | 174 TextView nameView = (TextView) layout.findViewById(R.id.autofill_nam
e); |
175 mNameViewPaint = nameView.getPaint(); | 175 mNameViewPaint = nameView.getPaint(); |
176 TextView labelView = (TextView) layout.findViewById(AppResource.ID_A
UTOFILL_LABEL); | 176 TextView labelView = (TextView) layout.findViewById(R.id.autofill_la
bel); |
177 mLabelViewPaint = labelView.getPaint(); | 177 mLabelViewPaint = labelView.getPaint(); |
178 } | 178 } |
179 | 179 |
180 int maxTextWidth = 0; | 180 int maxTextWidth = 0; |
181 Rect bounds = new Rect(); | 181 Rect bounds = new Rect(); |
182 for (int i = 0; i < data.length; ++i) { | 182 for (int i = 0; i < data.length; ++i) { |
183 bounds.setEmpty(); | 183 bounds.setEmpty(); |
184 String name = data[i].mName; | 184 String name = data[i].mName; |
185 int width = 0; | 185 int width = 0; |
186 mNameViewPaint.getTextBounds(name, 0, name.length(), bounds); | 186 mNameViewPaint.getTextBounds(name, 0, name.length(), bounds); |
(...skipping 28 matching lines...) Expand all Loading... |
215 ListAdapter adapter = (ListAdapter) parent.getAdapter(); | 215 ListAdapter adapter = (ListAdapter) parent.getAdapter(); |
216 AutofillSuggestion data = (AutofillSuggestion) adapter.getItem(posit
ion); | 216 AutofillSuggestion data = (AutofillSuggestion) adapter.getItem(posit
ion); |
217 mAutofillCallback.suggestionSelected(position, data.mName, data.mUni
queId); | 217 mAutofillCallback.suggestionSelected(position, data.mName, data.mUni
queId); |
218 } catch (ClassCastException e) { | 218 } catch (ClassCastException e) { |
219 Log.w("AutofillWindow", "error in onItemClick", e); | 219 Log.w("AutofillWindow", "error in onItemClick", e); |
220 assert false; | 220 assert false; |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 } | 224 } |
OLD | NEW |