2010-09-01 16:35:24 +00:00
|
|
|
/*
|
2011-05-20 03:09:57 +00:00
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
2010-09-01 16:35:24 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations under
|
|
|
|
* the License.
|
|
|
|
*/
|
|
|
|
|
2011-06-22 02:53:02 +00:00
|
|
|
package com.android.inputmethod.keyboard.internal;
|
2010-09-01 16:35:24 +00:00
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2011-06-22 02:53:02 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
|
|
|
|
2010-11-16 09:47:39 +00:00
|
|
|
public class ModifierKeyState {
|
2010-11-13 08:16:34 +00:00
|
|
|
protected static final String TAG = "ModifierKeyState";
|
|
|
|
protected static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE;
|
|
|
|
|
2010-11-16 09:47:39 +00:00
|
|
|
protected static final int RELEASING = 0;
|
|
|
|
protected static final int PRESSING = 1;
|
|
|
|
protected static final int MOMENTARY = 2;
|
2010-09-01 16:35:24 +00:00
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
protected final String mName;
|
2010-11-16 09:47:39 +00:00
|
|
|
protected int mState = RELEASING;
|
2010-09-01 16:35:24 +00:00
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public ModifierKeyState(String name) {
|
|
|
|
mName = name;
|
|
|
|
}
|
|
|
|
|
2010-09-01 16:35:24 +00:00
|
|
|
public void onPress() {
|
2010-11-13 08:16:34 +00:00
|
|
|
final int oldState = mState;
|
2010-09-01 16:35:24 +00:00
|
|
|
mState = PRESSING;
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG)
|
|
|
|
Log.d(TAG, mName + ".onPress: " + toString(oldState) + " > " + this);
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onRelease() {
|
2010-11-13 08:16:34 +00:00
|
|
|
final int oldState = mState;
|
2010-09-01 16:35:24 +00:00
|
|
|
mState = RELEASING;
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG)
|
|
|
|
Log.d(TAG, mName + ".onRelease: " + toString(oldState) + " > " + this);
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onOtherKeyPressed() {
|
2010-11-13 08:16:34 +00:00
|
|
|
final int oldState = mState;
|
2010-11-19 21:52:58 +00:00
|
|
|
if (oldState == PRESSING)
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = MOMENTARY;
|
|
|
|
if (DEBUG)
|
|
|
|
Log.d(TAG, mName + ".onOtherKeyPressed: " + toString(oldState) + " > " + this);
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 07:56:15 +00:00
|
|
|
public boolean isPressing() {
|
|
|
|
return mState == PRESSING;
|
|
|
|
}
|
|
|
|
|
2010-11-12 23:49:56 +00:00
|
|
|
public boolean isReleasing() {
|
|
|
|
return mState == RELEASING;
|
|
|
|
}
|
|
|
|
|
2010-09-01 16:35:24 +00:00
|
|
|
public boolean isMomentary() {
|
|
|
|
return mState == MOMENTARY;
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return toString(mState);
|
|
|
|
}
|
|
|
|
|
2010-11-19 21:52:58 +00:00
|
|
|
protected String toString(int state) {
|
2010-11-13 08:16:34 +00:00
|
|
|
switch (state) {
|
|
|
|
case RELEASING: return "RELEASING";
|
|
|
|
case PRESSING: return "PRESSING";
|
|
|
|
case MOMENTARY: return "MOMENTARY";
|
|
|
|
default: return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|