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