2010-12-02 09:46:21 +00:00
|
|
|
/*
|
2011-05-20 03:09:57 +00:00
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
2010-12-02 09:46:21 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +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
|
2010-12-02 09:46:21 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-12-02 09:46:21 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2010-12-02 09:46:21 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-22 02:53:02 +00:00
|
|
|
package com.android.inputmethod.keyboard.internal;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class AlphabetShiftState {
|
2012-01-26 09:03:30 +00:00
|
|
|
private static final String TAG = AlphabetShiftState.class.getSimpleName();
|
2011-12-08 13:10:27 +00:00
|
|
|
private static final boolean DEBUG = false;
|
2010-11-13 08:16:34 +00:00
|
|
|
|
2012-01-26 09:03:30 +00:00
|
|
|
private static final int UNSHIFTED = 0;
|
2010-11-13 08:16:34 +00:00
|
|
|
private static final int MANUAL_SHIFTED = 1;
|
2011-01-18 09:12:44 +00:00
|
|
|
private static final int MANUAL_SHIFTED_FROM_AUTO = 2;
|
2012-01-26 09:03:30 +00:00
|
|
|
private static final int AUTOMATIC_SHIFTED = 3;
|
2011-01-18 09:12:44 +00:00
|
|
|
private static final int SHIFT_LOCKED = 4;
|
|
|
|
private static final int SHIFT_LOCK_SHIFTED = 5;
|
2010-11-13 08:16:34 +00:00
|
|
|
|
2012-01-26 09:03:30 +00:00
|
|
|
private int mState = UNSHIFTED;
|
2010-11-13 08:16:34 +00:00
|
|
|
|
2011-12-06 05:42:30 +00:00
|
|
|
public void setShifted(boolean newShiftState) {
|
2010-11-13 08:16:34 +00:00
|
|
|
final int oldState = mState;
|
|
|
|
if (newShiftState) {
|
2011-01-18 09:12:44 +00:00
|
|
|
switch (oldState) {
|
2012-01-26 09:03:30 +00:00
|
|
|
case UNSHIFTED:
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = MANUAL_SHIFTED;
|
2011-01-18 09:12:44 +00:00
|
|
|
break;
|
2012-01-26 09:03:30 +00:00
|
|
|
case AUTOMATIC_SHIFTED:
|
2011-01-18 09:12:44 +00:00
|
|
|
mState = MANUAL_SHIFTED_FROM_AUTO;
|
|
|
|
break;
|
|
|
|
case SHIFT_LOCKED:
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = SHIFT_LOCK_SHIFTED;
|
2011-01-18 09:12:44 +00:00
|
|
|
break;
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-01-18 09:12:44 +00:00
|
|
|
switch (oldState) {
|
|
|
|
case MANUAL_SHIFTED:
|
|
|
|
case MANUAL_SHIFTED_FROM_AUTO:
|
2012-01-26 09:03:30 +00:00
|
|
|
case AUTOMATIC_SHIFTED:
|
|
|
|
mState = UNSHIFTED;
|
2011-01-18 09:12:44 +00:00
|
|
|
break;
|
|
|
|
case SHIFT_LOCK_SHIFTED:
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = SHIFT_LOCKED;
|
2011-01-18 09:12:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
if (DEBUG)
|
2010-11-12 23:49:56 +00:00
|
|
|
Log.d(TAG, "setShifted(" + newShiftState + "): " + toString(oldState) + " > " + this);
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setShiftLocked(boolean newShiftLockState) {
|
|
|
|
final int oldState = mState;
|
|
|
|
if (newShiftLockState) {
|
2011-01-18 09:12:44 +00:00
|
|
|
switch (oldState) {
|
2012-01-26 09:03:30 +00:00
|
|
|
case UNSHIFTED:
|
2011-01-18 09:12:44 +00:00
|
|
|
case MANUAL_SHIFTED:
|
|
|
|
case MANUAL_SHIFTED_FROM_AUTO:
|
2012-01-26 09:03:30 +00:00
|
|
|
case AUTOMATIC_SHIFTED:
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = SHIFT_LOCKED;
|
2011-01-18 09:12:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
} else {
|
2012-01-26 09:03:30 +00:00
|
|
|
mState = UNSHIFTED;
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
if (DEBUG)
|
2010-11-12 23:49:56 +00:00
|
|
|
Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState)
|
|
|
|
+ " > " + this);
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 09:03:30 +00:00
|
|
|
public void setAutomaticShifted() {
|
2010-11-13 08:16:34 +00:00
|
|
|
final int oldState = mState;
|
2012-01-26 09:03:30 +00:00
|
|
|
mState = AUTOMATIC_SHIFTED;
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG)
|
2012-01-26 09:03:30 +00:00
|
|
|
Log.d(TAG, "setAutomaticShifted: " + toString(oldState) + " > " + this);
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShiftedOrShiftLocked() {
|
2012-01-26 09:03:30 +00:00
|
|
|
return mState != UNSHIFTED;
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShiftLocked() {
|
|
|
|
return mState == SHIFT_LOCKED || mState == SHIFT_LOCK_SHIFTED;
|
|
|
|
}
|
|
|
|
|
2011-11-17 00:00:02 +00:00
|
|
|
public boolean isShiftLockShifted() {
|
|
|
|
return mState == SHIFT_LOCK_SHIFTED;
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:03:30 +00:00
|
|
|
public boolean isAutomaticShifted() {
|
|
|
|
return mState == AUTOMATIC_SHIFTED;
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 09:03:30 +00:00
|
|
|
public boolean isManualShifted() {
|
2011-01-18 09:12:44 +00:00
|
|
|
return mState == MANUAL_SHIFTED || mState == MANUAL_SHIFTED_FROM_AUTO
|
|
|
|
|| mState == SHIFT_LOCK_SHIFTED;
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:03:30 +00:00
|
|
|
public boolean isManualShiftedFromAutomaticShifted() {
|
2011-01-18 09:12:44 +00:00
|
|
|
return mState == MANUAL_SHIFTED_FROM_AUTO;
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return toString(mState);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String toString(int state) {
|
|
|
|
switch (state) {
|
2012-01-26 09:03:30 +00:00
|
|
|
case UNSHIFTED: return "UNSHIFTED";
|
2010-11-13 08:16:34 +00:00
|
|
|
case MANUAL_SHIFTED: return "MANUAL_SHIFTED";
|
2011-01-18 09:12:44 +00:00
|
|
|
case MANUAL_SHIFTED_FROM_AUTO: return "MANUAL_SHIFTED_FROM_AUTO";
|
2012-01-26 09:03:30 +00:00
|
|
|
case AUTOMATIC_SHIFTED: return "AUTOMATIC_SHIFTED";
|
2011-01-18 09:12:44 +00:00
|
|
|
case SHIFT_LOCKED: return "SHIFT_LOCKED";
|
2010-11-13 08:16:34 +00:00
|
|
|
case SHIFT_LOCK_SHIFTED: return "SHIFT_LOCK_SHIFTED";
|
2012-01-26 09:03:30 +00:00
|
|
|
default: return "UNKNOWN";
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|