Add delay before prompt

This commit is contained in:
Alexander Sytnyk 2017-06-22 16:16:13 +03:00
parent fcd837321e
commit 27574353c4
3 changed files with 32 additions and 2 deletions

View file

@ -14,7 +14,7 @@
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp">
<AutoCompleteTextView
<net.osmand.plus.mapillary.DelayAutoCompleteTextView
android:id="@+id/auto_complete_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -34,6 +34,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.HelpArticleDialogFragment;
import net.osmand.plus.mapillary.DelayAutoCompleteTextView;
import net.osmand.plus.mapillary.MapillaryAutoCompleteAdapter;
import org.apache.commons.logging.Log;
@ -353,7 +354,7 @@ public class ContextMenuAdapter {
final View autoCompleteTextView = convertView.findViewById(R.id.auto_complete_text_view);
if (autoCompleteTextView != null) {
final AutoCompleteTextView textView = (AutoCompleteTextView) autoCompleteTextView;
final DelayAutoCompleteTextView textView = (DelayAutoCompleteTextView) autoCompleteTextView;
textView.setAdapter(new MapillaryAutoCompleteAdapter(getContext(), R.layout.auto_complete_suggestion, app));
String selectedUsername = app.getSettings().MAPILLARY_FILTER_USERNAME.get();

View file

@ -0,0 +1,29 @@
package net.osmand.plus.mapillary;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
public class DelayAutoCompleteTextView extends android.support.v7.widget.AppCompatAutoCompleteTextView {
private static final int MESSAGE_TEXT_CHANGED = 100;
private static final int DEFAULT_AUTOCOMPLETE_DELAY = 2000;
public DelayAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
DelayAutoCompleteTextView.super.performFiltering((CharSequence) msg.obj, msg.arg1);
}
};
@Override
protected void performFiltering(CharSequence text, int keyCode) {
mHandler.removeMessages(MESSAGE_TEXT_CHANGED);
mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_TEXT_CHANGED, text), DEFAULT_AUTOCOMPLETE_DELAY);
}
}