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      */
     57     public void onCodeInput(int primaryCode, int x, int y);
     58 
     59     /**
     60      * Sends a string of characters to the listener.
     61      *
     62      * @param text the string of characters to be registered.
     63      */
     64     public void onTextInput(String text);
     65 
     66     /**
     67      * Called when user started batch input.
     68      */
     69     public void onStartBatchInput();
     70 
     71     /**
     72      * Sends the ongoing batch input points data.
     73      * @param batchPointers the batch input points representing the user input
     74      */
     75     public void onUpdateBatchInput(InputPointers batchPointers);
     76 
     77     /**
     78      * Sends the final batch input points data.
     79      *
     80      * @param batchPointers the batch input points representing the user input
     81      */
     82     public void onEndBatchInput(InputPointers batchPointers);
     83 
     84     public void onCancelBatchInput();
     85 
     86     /**
     87      * Called when user released a finger outside any key.
     88      */
     89     public void onCancelInput();
     90 
     91     /**
     92      * Called when user finished sliding key input.
     93      */
     94     public void onFinishSlidingInput();
     95 
     96     /**
     97      * Send a non-"code input" custom request to the listener.
     98      * @return true if the request has been consumed, false otherwise.
     99      */
    100     public boolean onCustomRequest(int requestCode);
    101 
    102     public static final KeyboardActionListener EMPTY_LISTENER = new Adapter();
    103 
    104     public static class Adapter implements KeyboardActionListener {
    105         @Override
    106         public void onPressKey(int primaryCode, int repeatCount, boolean isSinglePointer) {}
    107         @Override
    108         public void onReleaseKey(int primaryCode, boolean withSliding) {}
    109         @Override
    110         public void onCodeInput(int primaryCode, int x, int y) {}
    111         @Override
    112         public void onTextInput(String text) {}
    113         @Override
    114         public void onStartBatchInput() {}
    115         @Override
    116         public void onUpdateBatchInput(InputPointers batchPointers) {}
    117         @Override
    118         public void onEndBatchInput(InputPointers batchPointers) {}
    119         @Override
    120         public void onCancelBatchInput() {}
    121         @Override
    122         public void onCancelInput() {}
    123         @Override
    124         public void onFinishSlidingInput() {}
    125         @Override
    126         public boolean onCustomRequest(int requestCode) {
    127             return false;
    128         }
    129     }
    130 }
    131