Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java

Issue 2382913004: Move autofill from ui/ to components/ (Closed)
Patch Set: move dimens cleanly Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.ui.autofill;
6
7 import android.annotation.SuppressLint;
8 import android.content.Context;
9 import android.view.View;
10 import android.widget.AdapterView;
11 import android.widget.PopupWindow;
12
13 import org.chromium.ui.DropdownAdapter;
14 import org.chromium.ui.DropdownItem;
15 import org.chromium.ui.DropdownPopupWindow;
16 import org.chromium.ui.R;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.HashSet;
21 import java.util.List;
22
23 /**
24 * The Autofill suggestion popup that lists relevant suggestions.
25 */
26 public class AutofillPopup extends DropdownPopupWindow implements AdapterView.On ItemClickListener,
27 AdapterView.OnItemLongClickListener, PopupWindow.OnDismissListener {
28
29 /**
30 * The constant used to specify a separator in a list of Autofill suggestion s.
31 * Has to be kept in sync with enum in WebAutofillClient.h
32 */
33 private static final int ITEM_ID_SEPARATOR_ENTRY = -3;
34
35 private final Context mContext;
36 private final AutofillDelegate mAutofillDelegate;
37 private List<AutofillSuggestion> mSuggestions;
38
39 /**
40 * Creates an AutofillWindow with specified parameters.
41 * @param context Application context.
42 * @param anchorView View anchored for popup.
43 * @param autofillDelegate An object that handles the calls to the native Au tofillPopupView.
44 */
45 public AutofillPopup(Context context, View anchorView, AutofillDelegate auto fillDelegate) {
46 super(context, anchorView);
47 mContext = context;
48 mAutofillDelegate = autofillDelegate;
49
50 setOnItemClickListener(this);
51 setOnDismissListener(this);
52 disableHideOnOutsideTap();
53 setContentDescriptionForAccessibility(
54 mContext.getString(R.string.autofill_popup_content_description)) ;
55 }
56
57 /**
58 * Filters the Autofill suggestions to the ones that we support and shows th e popup.
59 * @param suggestions Autofill suggestion data.
60 */
61 @SuppressLint("InlinedApi")
62 public void filterAndShow(AutofillSuggestion[] suggestions, boolean isRtl) {
63 mSuggestions = new ArrayList<AutofillSuggestion>(Arrays.asList(suggestio ns));
64 // Remove the AutofillSuggestions with IDs that are not supported by And roid
65 ArrayList<DropdownItem> cleanedData = new ArrayList<DropdownItem>();
66 HashSet<Integer> separators = new HashSet<Integer>();
67 for (int i = 0; i < suggestions.length; i++) {
68 int itemId = suggestions[i].getSuggestionId();
69 if (itemId == ITEM_ID_SEPARATOR_ENTRY) {
70 separators.add(cleanedData.size());
71 } else {
72 cleanedData.add(suggestions[i]);
73 }
74 }
75
76 setAdapter(new DropdownAdapter(mContext, cleanedData, separators));
77 setRtl(isRtl);
78 show();
79 getListView().setOnItemLongClickListener(this);
80 }
81
82 @Override
83 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
84 DropdownAdapter adapter = (DropdownAdapter) parent.getAdapter();
85 int listIndex = mSuggestions.indexOf(adapter.getItem(position));
86 assert listIndex > -1;
87 mAutofillDelegate.suggestionSelected(listIndex);
88 }
89
90 @Override
91 public boolean onItemLongClick(AdapterView<?> parent, View view, int positio n, long id) {
92 DropdownAdapter adapter = (DropdownAdapter) parent.getAdapter();
93 AutofillSuggestion suggestion = (AutofillSuggestion) adapter.getItem(pos ition);
94 if (!suggestion.isDeletable()) return false;
95
96 int listIndex = mSuggestions.indexOf(suggestion);
97 assert listIndex > -1;
98 mAutofillDelegate.deleteSuggestion(listIndex);
99 return true;
100 }
101
102 @Override
103 public void onDismiss() {
104 mAutofillDelegate.dismissed();
105 }
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698