diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2019-03-03 22:19:24 +0300 |
---|---|---|
committer | Andy Scherzinger <info@andy-scherzinger.de> | 2019-03-03 22:19:24 +0300 |
commit | 7a3f2e59f8be75256c98bde597eb979fefb4f255 (patch) | |
tree | fa5ba8490724969b9f6f6ef0b3101aac9982be13 /app/src/main/java/it/niedermann/nextcloud/deck/ui/widget | |
parent | a8bb38bff68a7a34cfac51bae870d5323badf089 (diff) |
implement user search (WiP: result always null)
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/widget')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/DelayedAutoCompleteTextView.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/DelayedAutoCompleteTextView.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/DelayedAutoCompleteTextView.java new file mode 100644 index 000000000..4d68dab8c --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/DelayedAutoCompleteTextView.java @@ -0,0 +1,57 @@ +package it.niedermann.nextcloud.deck.ui.widget; + +import android.content.Context; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.view.View; +import android.widget.ProgressBar; + +/** + * Delayed auto complete text view, based on + * https://makovkastar.github.io/blog/2014/04/12/android-autocompletetextview-with-suggestions-from-a-web-service/ + * by Alex Melnykov + */ +public class DelayedAutoCompleteTextView extends android.support.v7.widget.AppCompatAutoCompleteTextView { + private static final int MESSAGE_TEXT_CHANGED = 100; + private static final int DEFAULT_AUTOCOMPLETE_DELAY = 500; + + private int mAutoCompleteDelay = DEFAULT_AUTOCOMPLETE_DELAY; + private ProgressBar mLoadingIndicator; + + private final Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + DelayedAutoCompleteTextView.super.performFiltering((CharSequence) msg.obj, msg.arg1); + } + }; + + public DelayedAutoCompleteTextView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public void setLoadingIndicator(ProgressBar progressBar) { + mLoadingIndicator = progressBar; + } + + public void setAutoCompleteDelay(int autoCompleteDelay) { + mAutoCompleteDelay = autoCompleteDelay; + } + + @Override + protected void performFiltering(CharSequence text, int keyCode) { + if (mLoadingIndicator != null) { + mLoadingIndicator.setVisibility(View.VISIBLE); + } + mHandler.removeMessages(MESSAGE_TEXT_CHANGED); + mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_TEXT_CHANGED, text), mAutoCompleteDelay); + } + + @Override + public void onFilterComplete(int count) { + if (mLoadingIndicator != null) { + mLoadingIndicator.setVisibility(View.GONE); + } + super.onFilterComplete(count); + } +} |