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.internal; 18 19import android.util.Log; 20 21/* package */ class ModifierKeyState { 22 protected static final String TAG = ModifierKeyState.class.getSimpleName(); 23 protected static final boolean DEBUG = false; 24 25 protected static final int RELEASING = 0; 26 protected static final int PRESSING = 1; 27 protected static final int CHORDING = 2; 28 29 protected final String mName; 30 protected int mState = RELEASING; 31 32 public ModifierKeyState(String name) { 33 mName = name; 34 } 35 36 public void onPress() { 37 final int oldState = mState; 38 mState = PRESSING; 39 if (DEBUG) 40 Log.d(TAG, mName + ".onPress: " + toString(oldState) + " > " + this); 41 } 42 43 public void onRelease() { 44 final int oldState = mState; 45 mState = RELEASING; 46 if (DEBUG) 47 Log.d(TAG, mName + ".onRelease: " + toString(oldState) + " > " + this); 48 } 49 50 public void onOtherKeyPressed() { 51 final int oldState = mState; 52 if (oldState == PRESSING) 53 mState = CHORDING; 54 if (DEBUG) 55 Log.d(TAG, mName + ".onOtherKeyPressed: " + toString(oldState) + " > " + this); 56 } 57 58 public boolean isPressing() { 59 return mState == PRESSING; 60 } 61 62 public boolean isReleasing() { 63 return mState == RELEASING; 64 } 65 66 public boolean isChording() { 67 return mState == CHORDING; 68 } 69 70 @Override 71 public String toString() { 72 return toString(mState); 73 } 74 75 protected String toString(int state) { 76 switch (state) { 77 case RELEASING: return "RELEASING"; 78 case PRESSING: return "PRESSING"; 79 case CHORDING: return "CHORDING"; 80 default: return "UNKNOWN"; 81 } 82 } 83} 84