Home | History | Annotate | Download | only in method
      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 
     17 package android.text.method;
     18 
     19 import android.text.Editable;
     20 import android.view.KeyEvent;
     21 import android.view.View;
     22 
     23 /**
     24  * Interface for converting text key events into edit operations on an
     25  * Editable class.  Note that for most 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  * <p></p>
     31  * Key presses on soft input methods are not required to trigger the methods
     32  * in this listener, and are in fact discouraged to do so.  The default
     33  * android keyboard will not trigger these for any key to any application
     34  * targetting Jelly Bean or later, and will only deliver it for some
     35  * key presses to applications targetting Ice Cream Sandwich or earlier.
     36  */
     37 public interface KeyListener {
     38     /**
     39      * Return the type of text that this key listener is manipulating,
     40      * as per {@link android.text.InputType}.  This is used to
     41      * determine the mode of the soft keyboard that is shown for the editor.
     42      *
     43      * <p>If you return
     44      * {@link android.text.InputType#TYPE_NULL}
     45      * then <em>no</em> soft keyboard will provided.  In other words, you
     46      * must be providing your own key pad for on-screen input and the key
     47      * listener will be used to handle input from a hard keyboard.
     48      *
     49      * <p>If you
     50      * return any other value, a soft input method will be created when the
     51      * user puts focus in the editor, which will provide a keypad and also
     52      * consume hard key events.  This means that the key listener will generally
     53      * not be used, instead the soft input method will take care of managing
     54      * key input as per the content type returned here.
     55      */
     56     public int getInputType();
     57 
     58     /**
     59      * If the key listener wants to handle this key, return true,
     60      * otherwise return false and the caller (i.e.&nbsp;the widget host)
     61      * will handle the key.
     62      */
     63     public boolean onKeyDown(View view, Editable text,
     64                              int keyCode, KeyEvent event);
     65 
     66     /**
     67      * If the key listener wants to handle this key release, return true,
     68      * otherwise return false and the caller (i.e.&nbsp;the widget host)
     69      * will handle the key.
     70      */
     71     public boolean onKeyUp(View view, Editable text,
     72                            int keyCode, KeyEvent event);
     73 
     74     /**
     75      * If the key listener wants to other kinds of key events, return true,
     76      * otherwise return false and the caller (i.e.&nbsp;the widget host)
     77      * will handle the key.
     78      */
     79     public boolean onKeyOther(View view, Editable text, KeyEvent event);
     80 
     81     /**
     82      * Remove the given shift states from the edited text.
     83      */
     84     public void clearMetaKeyState(View view, Editable content, int states);
     85 }
     86