Home | History | Annotate | Download | only in keyboard
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * 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, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 package com.android.inputmethod.keyboard;
     18 
     19 public interface KeyboardActionListener {
     20 
     21     /**
     22      * Called when the user presses a key. This is sent before the {@link #onCodeInput} is called.
     23      * For keys that repeat, this is only called once.
     24      *
     25      * @param primaryCode the unicode of the key being pressed. If the touch is not on a valid key,
     26      *            the value will be zero.
     27      */
     28     public void onPressKey(int primaryCode);
     29 
     30     /**
     31      * Called when the user releases a key. This is sent after the {@link #onCodeInput} is called.
     32      * For keys that repeat, this is only called once.
     33      *
     34      * @param primaryCode the code of the key that was released
     35      * @param withSliding true if releasing has occurred because the user slid finger from the key
     36      *             to other key without releasing the finger.
     37      */
     38     public void onReleaseKey(int primaryCode, boolean withSliding);
     39 
     40     /**
     41      * Send a key code to the listener.
     42      *
     43      * @param primaryCode this is the code of the key that was pressed
     44      * @param x x-coordinate pixel of touched event. If {@link #onCodeInput} is not called by
     45      *            {@link PointerTracker} or so, the value should be {@link #NOT_A_TOUCH_COORDINATE}.
     46      *            If it's called on insertion from the suggestion strip, it should be
     47      *            {@link #SUGGESTION_STRIP_COORDINATE}.
     48      * @param y y-coordinate pixel of touched event. If {@link #onCodeInput} is not called by
     49      *            {@link PointerTracker} or so, the value should be {@link #NOT_A_TOUCH_COORDINATE}.
     50      *            If it's called on insertion from the suggestion strip, it should be
     51      *            {@link #SUGGESTION_STRIP_COORDINATE}.
     52      */
     53     public void onCodeInput(int primaryCode, int x, int y);
     54 
     55     public static final int NOT_A_TOUCH_COORDINATE = -1;
     56     public static final int SUGGESTION_STRIP_COORDINATE = -2;
     57     public static final int SPELL_CHECKER_COORDINATE = -3;
     58 
     59     /**
     60      * Sends a sequence of characters to the listener.
     61      *
     62      * @param text the sequence of characters to be displayed.
     63      */
     64     public void onTextInput(CharSequence text);
     65 
     66     /**
     67      * Called when user released a finger outside any key.
     68      */
     69     public void onCancelInput();
     70 
     71     /**
     72      * Send a non-"code input" custom request to the listener.
     73      * @return true if the request has been consumed, false otherwise.
     74      */
     75     public boolean onCustomRequest(int requestCode);
     76 
     77     public static class Adapter implements KeyboardActionListener {
     78         @Override
     79         public void onPressKey(int primaryCode) {}
     80         @Override
     81         public void onReleaseKey(int primaryCode, boolean withSliding) {}
     82         @Override
     83         public void onCodeInput(int primaryCode, int x, int y) {}
     84         @Override
     85         public void onTextInput(CharSequence text) {}
     86         @Override
     87         public void onCancelInput() {}
     88         @Override
     89         public boolean onCustomRequest(int requestCode) {
     90             return false;
     91         }
     92     }
     93 }
     94