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

Unified Diff: platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/OptionAdapter.java

Issue 2047233003: Provide filter when there are many options (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: NoLog Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/OptionAdapter.java
diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/OptionAdapter.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/OptionAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..4fefb54d8dc73f515fad4e22627c25aa29759584
--- /dev/null
+++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/OptionAdapter.java
@@ -0,0 +1,64 @@
+package org.skia.viewer;
+
+import android.content.Context;
+import android.widget.ArrayAdapter;
+import android.widget.Filter;
+import android.widget.Spinner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class OptionAdapter extends ArrayAdapter<String> {
+ private String mCurrentOption;
+ private List<String> mOptions;
+ private Filter mFilter = null;
+ private Spinner mSpinner;
+
+ public OptionAdapter(Context context, int resource, List<String> options, Spinner spinner) {
+ super(context, resource);
+ addAll(options);
+ mOptions = options;
+ mSpinner = spinner;
+ }
+
+ public void setCurrentOption(String currentOption) {
+ this.mCurrentOption = currentOption;
+ }
+
+ private class OptionFilter extends Filter {
+
+ @Override
+ protected FilterResults performFiltering(CharSequence constraint) {
+ final String pattern = constraint.toString().toLowerCase();
+ ArrayList<String> filteredOptions = new ArrayList<>();
+ for(String option : mOptions) {
+ if (option.equals(mCurrentOption)
+ || option.toLowerCase().indexOf(pattern) > -1) {
+ filteredOptions.add(option);
+ }
+ }
+ FilterResults results = new FilterResults();
+ results.values = filteredOptions;
+ results.count = filteredOptions.size();
+ return results;
+ }
+
+ @Override
+ protected void publishResults(CharSequence constraint, FilterResults results) {
+ clear();
+ List<String> filteredOptions = (List<String>) results.values;
+ addAll(filteredOptions);
+ // We set the selection to the current option to avoid unwanted option selection change
+ mSpinner.setSelection(filteredOptions.indexOf(mCurrentOption));
+ notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ public Filter getFilter() {
+ if (mFilter == null) {
+ mFilter = new OptionFilter();
+ }
+ return mFilter;
+ }
+}
« no previous file with comments | « no previous file | platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698