KeyListener.java revision f013e1afd1e68af5e3b868c26a653bbfb39538f8
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.text.method;
18
19import android.text.Editable;
20import android.view.KeyEvent;
21import android.view.View;
22
23/**
24 * Interface for converting text key events into edit operations on an
25 * Editable class.  Note that for must cases this interface has been
26 * superceded by general soft input methods as defined by
27 * {@link android.view.inputmethod.InputMethod}; it should only be used
28 * for cases where an application has its own on-screen keypad and also wants
29 * to process hard keyboard events to match it.
30 */
31public interface KeyListener {
32    /**
33     * Return the type of text that this key listener is manipulating,
34     * as per {@link android.text.InputType}.  This is used to
35     * determine the mode of the soft keyboard that is shown for the editor.
36     *
37     * <p>If you return
38     * {@link android.text.InputType#TYPE_NULL}
39     * then <em>no</em> soft keyboard will provided.  In other words, you
40     * must be providing your own key pad for on-screen input and the key
41     * listener will be used to handle input from a hard keyboard.
42     *
43     * <p>If you
44     * return any other value, a soft input method will be created when the
45     * user puts focus in the editor, which will provide a keypad and also
46     * consume hard key events.  This means that the key listener will generally
47     * not be used, instead the soft input method will take care of managing
48     * key input as per the content type returned here.
49     */
50    public int getInputType();
51
52    /**
53     * If the key listener wants to handle this key, return true,
54     * otherwise return false and the caller (i.e. the widget host)
55     * will handle the key.
56     */
57    public boolean onKeyDown(View view, Editable text,
58                             int keyCode, KeyEvent event);
59
60    /**
61     * If the key listener wants to handle this key release, return true,
62     * otherwise return false and the caller (i.e. the widget host)
63     * will handle the key.
64     */
65    public boolean onKeyUp(View view, Editable text,
66                           int keyCode, KeyEvent event);
67
68    /**
69     * Remove the given shift states from the edited text.
70     */
71    public void clearMetaKeyState(View view, Editable content, int states);
72}
73