aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils/EditUtils.java
blob: 455ce4d2524fb7991cfe1f566fb487c047643c33 (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
package cgeo.geocaching.utils;

import android.text.InputType;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

public final class EditUtils {

    private EditUtils() {
        // utility class
    }

    public static void setActionListener(final EditText editText, final Runnable runnable) {
        editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_GO) {
                    runnable.run();
                    return true;
                }

                return false;
            }
        });

        editText.setOnKeyListener(new View.OnKeyListener() {

            @Override
            public boolean onKey(final View v, final int keyCode, final KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    runnable.run();
                    return true;
                }
                return false;
            }
        });

    }

    public static void disableSuggestions(final EditText edit) {
        edit.setInputType(edit.getInputType()
                | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
                | InputType.TYPE_TEXT_VARIATION_FILTER);
    }
}