Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AlwaysAutoCompleteTextView.java « android « notes « owncloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 439d6f7e7f6c025903b4fc0290955dbd6cb309b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package it.niedermann.owncloud.notes.android;

import android.content.Context;
import android.support.v7.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.WindowManager;

/**
 * Extension of the {@link AppCompatAutoCompleteTextView}, but this one is always open, i.e. you can see the list of suggestions even the TextView is empty.
 */
public class AlwaysAutoCompleteTextView extends AppCompatAutoCompleteTextView {

	private int myThreshold;

	public AlwaysAutoCompleteTextView(Context context) {
		super(context);
	}

	public AlwaysAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public AlwaysAutoCompleteTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public void setThreshold(int threshold) {
		if (threshold < 0) {
			threshold = 0;
		}
		myThreshold = threshold;
	}

	@Override
	public boolean enoughToFilter() {
		return getText().length() >= myThreshold;
	}

	@Override
	public int getThreshold() {
		return myThreshold;
	}

	public void showFullDropDown() {
		try {
			performFiltering(getText(), 0);
			showDropDown();
		} catch (WindowManager.BadTokenException e) {
			// https://github.com/stefan-niedermann/nextcloud-notes/issues/366
			e.printStackTrace();
			Log.e(AlwaysAutoCompleteTextView.class.getSimpleName(), "Exception", e);
		}
	}
}