Flutter Engine
The Flutter Engine
OptionAdapter.java
Go to the documentation of this file.
1package org.skia.viewer;
2
3import android.content.Context;
4import android.widget.ArrayAdapter;
5import android.widget.Filter;
6import android.widget.Spinner;
7
8import java.util.ArrayList;
9import java.util.List;
10
11public class OptionAdapter extends ArrayAdapter<String> {
12 private String mCurrentOption;
13 private List<String> mOptions;
14 private Filter mFilter = null;
15 private Spinner mSpinner;
16
17 public OptionAdapter(Context context, int resource, List<String> options, Spinner spinner) {
18 super(context, resource);
19 addAll(options);
20 mOptions = options;
21 mSpinner = spinner;
22 }
23
24 public void setCurrentOption(String currentOption) {
25 this.mCurrentOption = currentOption;
26 }
27
28 private class OptionFilter extends Filter {
29
30 @Override
31 protected FilterResults performFiltering(CharSequence constraint) {
32 final String pattern = constraint.toString().toLowerCase();
33 ArrayList<String> filteredOptions = new ArrayList<>();
34 for(String option : mOptions) {
35 if (option.equals(mCurrentOption)
36 || option.toLowerCase().indexOf(pattern) > -1) {
37 filteredOptions.add(option);
38 }
39 }
40 FilterResults results = new FilterResults();
41 results.values = filteredOptions;
42 results.count = filteredOptions.size();
43 return results;
44 }
45
46 @Override
47 protected void publishResults(CharSequence constraint, FilterResults results) {
48 clear();
49 List<String> filteredOptions = (List<String>) results.values;
50 addAll(filteredOptions);
51 // We set the selection to the current option to avoid unwanted option selection change
52 mSpinner.setSelection(filteredOptions.indexOf(mCurrentOption));
53 notifyDataSetChanged();
54 }
55 }
56
57 @Override
58 public Filter getFilter() {
59 if (mFilter == null) {
60 mFilter = new OptionFilter();
61 }
62 return mFilter;
63 }
64}
const char * options
static SkString resource(SkPDFResourceType type, int index)
SkFilterMode
void setCurrentOption(String currentOption)
OptionAdapter(Context context, int resource, List< String > options, Spinner spinner)
GrSamplerState::Filter Filter
Definition: texelsubset.cpp:39