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");
      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 com.android.inputmethod.keyboard;
     18 
     19 import com.android.inputmethod.latin.Constants;
     20 import com.android.inputmethod.latin.InputPointers;
     21 
     22 public interface KeyboardActionListener {
     23     /**
     24      * Called when the user presses a key. This is sent before the {@link #onCodeInput} is called.
     25      * For keys that repeat, this is only called once.
     26      *
     27      * @param primaryCode the unicode of the key being pressed. If the touch is not on a valid key,
     28      *            the value will be zero.
     29      * @param repeatCount how many times the key was repeated. Zero if it is the first press.
     30      * @param isSinglePointer true if pressing has occurred while no other key is being pressed.
     31      */
     32     public void onPressKey(int primaryCode, int repeatCount, boolean isSinglePointer);
     33 
     34     /**
     35      * Called when the user releases a key. This is sent after the {@link #onCodeInput} is called.
     36      * For keys that repeat, this is only called once.
     37      *
     38      * @param primaryCode the code of the key that was released
     39      * @param withSliding true if releasing has occurred because the user slid finger from the key
     40      *             to other key without releasing the finger.
     41      */
     42     public void onReleaseKey(int primaryCode, boolean withSliding);
     43 
     44     /**
     45      * Send a key code to the listener.
     46      *
     47      * @param primaryCode this is the code of the key that was pressed
     48      * @param x x-coordinate pixel of touched event. If {@link #onCodeInput} is not called by
     49      *            {@link PointerTracker} or so, the value should be
     50      *            {@link Constants#NOT_A_COORDINATE}. If it's called on insertion from the
     51      *            suggestion strip, it should be {@link Constants#SUGGESTION_STRIP_COORDINATE}.
     52      * @param y y-coordinate pixel of touched event. If {@link #onCodeInput} is not called by
     53      *            {@link PointerTracker} or so, the value should be
     54      *            {@link Constants#NOT_A_COORDINATE}.If it's called on insertion from the
     55      *            suggestion strip, it should be {@link Constants#SUGGESTION_STRIP_COORDINATE}.
     56      * @param isKeyRepeat true if this is a key repeat, false otherwise
     57      */
     58     // TODO: change this to send an Event object instead
     59     public void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat);
     60 
     61     /**
     62      * Sends a string of characters to the listener.
     63      *
     64      * @param text the string of characters to be registered.
     65      */
     66     public void onTextInput(String text);
     67 
     68     /**
     69      * Called when user started batch input.
     70      */
     71     public void onStartBatchInput();
     72 
     73     /**
     74      * Sends the ongoing batch input points data.
     75      * @param batchPointers the batch input points representing the user input
     76      */
     77     public void onUpdateBatchInput(InputPointers batchPointers);
     78 
     79     /**
     80      * Sends the final batch input points data.
     81      *
     82      * @param batchPointers the batch input points representing the user input
     83      */
     84     public void onEndBatchInput(InputPointers batchPointers);
     85 
     86     public void onCancelBatchInput();
     87 
     88     /**
     89      * Called when user released a finger outside any key.
     90      */
     91     public void onCancelInput();
     92 
     93     /**
     94      * Called when user finished sliding key input.
     95      */
     96     public void onFinishSlidingInput();
     97 
     98     /**
     99      * Send a non-"code input" custom request to the listener.
    100      * @return true if the request has been consumed, false otherwise.
    101      */
    102     public boolean onCustomRequest(int requestCode);
    103 
    104     public static final KeyboardActionListener EMPTY_LISTENER = new Adapter();
    105 
    106     public static class Adapter implements KeyboardActionListener {
    107         @Override
    108         public void onPressKey(int primaryCode, int repeatCount, boolean isSinglePointer) {}
    109         @Override
    110         public void onReleaseKey(int primaryCode, boolean withSliding) {}
    111         @Override
    112         public void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat) {}
    113         @Override
    114         public void onTextInput(String text) {}
    115         @Override
    116         public void onStartBatchInput() {}
    117         @Override
    118         public void onUpdateBatchInput(InputPointers batchPointers) {}
    119         @Override
    120         public void onEndBatchInput(InputPointers batchPointers) {}
    121         @Override
    122         public void onCancelBatchInput() {}
    123         @Override
    124         public void onCancelInput() {}
    125         @Override
    126         public void onFinishSlidingInput() {}
    127         @Override
    128         public boolean onCustomRequest(int requestCode) {
    129             return false;
    130         }
    131     }
    132 }
    133