182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppypackage com.xtremelabs.robolectric.shadows;
282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport com.xtremelabs.robolectric.internal.Implementation;
482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport com.xtremelabs.robolectric.internal.Implements;
582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.AdapterView;
782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.AdapterView.OnItemClickListener;
882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.AutoCompleteTextView;
982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.Filterable;
1082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.ListAdapter;
1182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
1282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy/**
1382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy * A shadow for AutoCompleteTextView
1482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy */
1582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy@Implements(AutoCompleteTextView.class)
1682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppypublic class ShadowAutoCompleteTextView extends ShadowEditText {
1782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
1882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    private ListAdapter adapter;
1982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    private int threshold = 2;
2082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    private OnItemClickListener onItemClickListener;
2182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
2282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    @Implementation
2382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    public ListAdapter getAdapter() {
2482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        return adapter;
2582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    }
2682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
2782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    @Implementation
2882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
2982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        this.adapter = adapter;
3082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    }
3182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
3282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    @Implementation
3382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    public int getThreshold() {
3482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        return threshold;
3582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    }
3682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
3782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    @Implementation
3882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    public void setThreshold(int threshold) {
3982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        if (threshold <= 0) {
4082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy            threshold = 1;
4182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        }
4282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        this.threshold = threshold;
4382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    }
4482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
4582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    @Implementation
4682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    public AdapterView.OnItemClickListener getOnItemClickListener() {
4782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        return onItemClickListener;
4882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    }
4982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy
5082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    @Implementation
5182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
5282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy        this.onItemClickListener = onItemClickListener;
5382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy    }
549e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy
559e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy    @Implementation
569e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy    public void replaceText(CharSequence text) {
579e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy        setText(text);
589e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy        setSelection(getText().length());
599e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy    }
6082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy}
61