1package com.xtremelabs.robolectric.shadows;
2
3import com.xtremelabs.robolectric.internal.Implementation;
4import com.xtremelabs.robolectric.internal.Implements;
5
6import android.widget.AdapterView;
7import android.widget.AdapterView.OnItemClickListener;
8import android.widget.AutoCompleteTextView;
9import android.widget.Filterable;
10import android.widget.ListAdapter;
11
12/**
13 * A shadow for AutoCompleteTextView
14 */
15@Implements(AutoCompleteTextView.class)
16public class ShadowAutoCompleteTextView extends ShadowEditText {
17
18    private ListAdapter adapter;
19    private int threshold = 2;
20    private OnItemClickListener onItemClickListener;
21
22    @Implementation
23    public ListAdapter getAdapter() {
24        return adapter;
25    }
26
27    @Implementation
28    public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
29        this.adapter = adapter;
30    }
31
32    @Implementation
33    public int getThreshold() {
34        return threshold;
35    }
36
37    @Implementation
38    public void setThreshold(int threshold) {
39        if (threshold <= 0) {
40            threshold = 1;
41        }
42        this.threshold = threshold;
43    }
44
45    @Implementation
46    public AdapterView.OnItemClickListener getOnItemClickListener() {
47        return onItemClickListener;
48    }
49
50    @Implementation
51    public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
52        this.onItemClickListener = onItemClickListener;
53    }
54
55    @Implementation
56    public void replaceText(CharSequence text) {
57        setText(text);
58        setSelection(getText().length());
59    }
60}
61