OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.ui.autofill; | 5 package org.chromium.ui.autofill; |
6 | 6 |
7 import android.annotation.SuppressLint; | |
7 import android.content.Context; | 8 import android.content.Context; |
8 import android.view.View; | 9 import android.view.View; |
9 import android.widget.AdapterView; | 10 import android.widget.AdapterView; |
10 | 11 |
12 import org.chromium.base.ApiCompatibilityUtils; | |
11 import org.chromium.ui.DropdownAdapter; | 13 import org.chromium.ui.DropdownAdapter; |
12 import org.chromium.ui.DropdownItem; | 14 import org.chromium.ui.DropdownItem; |
13 import org.chromium.ui.DropdownPopupWindow; | 15 import org.chromium.ui.DropdownPopupWindow; |
14 import org.chromium.ui.base.ViewAndroidDelegate; | 16 import org.chromium.ui.base.ViewAndroidDelegate; |
15 | 17 |
16 import java.util.ArrayList; | 18 import java.util.ArrayList; |
17 import java.util.Arrays; | 19 import java.util.Arrays; |
18 import java.util.HashSet; | 20 import java.util.HashSet; |
19 import java.util.List; | 21 import java.util.List; |
20 | 22 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 mContext = context; | 70 mContext = context; |
69 mAutofillCallback = autofillCallback; | 71 mAutofillCallback = autofillCallback; |
70 | 72 |
71 setOnItemClickListener(this); | 73 setOnItemClickListener(this); |
72 } | 74 } |
73 | 75 |
74 /** | 76 /** |
75 * Filters the Autofill suggestions to the ones that we support and shows th e popup. | 77 * Filters the Autofill suggestions to the ones that we support and shows th e popup. |
76 * @param suggestions Autofill suggestion data. | 78 * @param suggestions Autofill suggestion data. |
77 */ | 79 */ |
80 @SuppressLint("InlinedApi") | |
aurimas (slooooooooow)
2014/08/04 15:19:40
Why do we need to suppress lint here? What is caus
Sungmann Cho
2014/08/04 18:32:16
Because of View.LAYOUT_DIRECTION_[LTR|RTL]. These
aurimas (slooooooooow)
2014/08/05 00:07:20
Right, that means we will not work correctly for p
Sungmann Cho
2014/08/05 00:43:53
View.LAYOUT_DIRECTION_[LTR|RTL] are static final a
| |
78 public void filterAndShow(AutofillSuggestion[] suggestions, boolean isRtl) { | 81 public void filterAndShow(AutofillSuggestion[] suggestions, boolean isRtl) { |
79 mSuggestions = new ArrayList<AutofillSuggestion>(Arrays.asList(suggestio ns)); | 82 mSuggestions = new ArrayList<AutofillSuggestion>(Arrays.asList(suggestio ns)); |
80 // Remove the AutofillSuggestions with IDs that are not supported by And roid | 83 // Remove the AutofillSuggestions with IDs that are not supported by And roid |
81 ArrayList<DropdownItem> cleanedData = new ArrayList<DropdownItem>(); | 84 ArrayList<DropdownItem> cleanedData = new ArrayList<DropdownItem>(); |
82 HashSet<Integer> separators = new HashSet<Integer>(); | 85 HashSet<Integer> separators = new HashSet<Integer>(); |
83 for (int i = 0; i < suggestions.length; i++) { | 86 for (int i = 0; i < suggestions.length; i++) { |
84 int itemId = suggestions[i].mUniqueId; | 87 int itemId = suggestions[i].mUniqueId; |
85 if (itemId > 0 || itemId == ITEM_ID_AUTOCOMPLETE_ENTRY || | 88 if (itemId > 0 || itemId == ITEM_ID_AUTOCOMPLETE_ENTRY || |
86 itemId == ITEM_ID_PASSWORD_ENTRY || itemId == ITEM_ID_DATA_L IST_ENTRY) { | 89 itemId == ITEM_ID_PASSWORD_ENTRY || itemId == ITEM_ID_DATA_L IST_ENTRY) { |
87 cleanedData.add(suggestions[i]); | 90 cleanedData.add(suggestions[i]); |
88 } else if (itemId == ITEM_ID_SEPARATOR_ENTRY) { | 91 } else if (itemId == ITEM_ID_SEPARATOR_ENTRY) { |
89 separators.add(cleanedData.size()); | 92 separators.add(cleanedData.size()); |
90 } | 93 } |
91 } | 94 } |
92 setAdapter(new DropdownAdapter(mContext, cleanedData, separators)); | 95 setAdapter(new DropdownAdapter(mContext, cleanedData, separators)); |
93 show(); | 96 show(); |
94 getListView().setLayoutDirection(isRtl ? View.LAYOUT_DIRECTION_RTL : | 97 ApiCompatibilityUtils.setLayoutDirection(getListView(), |
95 View.LAYOUT_DIRECTION_LTR); | 98 isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); |
96 } | 99 } |
97 | 100 |
98 /** | 101 /** |
99 * Overrides the default dismiss behavior to request the controller to dismi ss the view. | 102 * Overrides the default dismiss behavior to request the controller to dismi ss the view. |
100 */ | 103 */ |
101 @Override | 104 @Override |
102 public void dismiss() { | 105 public void dismiss() { |
103 mAutofillCallback.requestHide(); | 106 mAutofillCallback.requestHide(); |
104 } | 107 } |
105 | 108 |
106 /** | 109 /** |
107 * Hides the popup. | 110 * Hides the popup. |
108 */ | 111 */ |
109 public void hide() { | 112 public void hide() { |
110 super.dismiss(); | 113 super.dismiss(); |
111 } | 114 } |
112 | 115 |
113 @Override | 116 @Override |
114 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | 117 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
115 DropdownAdapter adapter = (DropdownAdapter) parent.getAdapter(); | 118 DropdownAdapter adapter = (DropdownAdapter) parent.getAdapter(); |
116 int listIndex = mSuggestions.indexOf(adapter.getItem(position)); | 119 int listIndex = mSuggestions.indexOf(adapter.getItem(position)); |
117 assert listIndex > -1; | 120 assert listIndex > -1; |
118 mAutofillCallback.suggestionSelected(listIndex); | 121 mAutofillCallback.suggestionSelected(listIndex); |
119 } | 122 } |
120 } | 123 } |
OLD | NEW |