2010-12-02 09:46:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard;
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
public class KeyboardShiftState {
|
|
|
|
private static final String TAG = "KeyboardShiftState";
|
2010-11-13 08:16:34 +00:00
|
|
|
private static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE;
|
|
|
|
|
|
|
|
private static final int NORMAL = 0;
|
|
|
|
private static final int MANUAL_SHIFTED = 1;
|
2011-01-18 09:12:44 +00:00
|
|
|
private static final int MANUAL_SHIFTED_FROM_AUTO = 2;
|
2010-11-13 08:16:34 +00:00
|
|
|
private static final int AUTO_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
|
|
|
|
|
|
|
private int mState = NORMAL;
|
|
|
|
|
|
|
|
public boolean setShifted(boolean newShiftState) {
|
|
|
|
final int oldState = mState;
|
|
|
|
if (newShiftState) {
|
2011-01-18 09:12:44 +00:00
|
|
|
switch (oldState) {
|
|
|
|
case NORMAL:
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = MANUAL_SHIFTED;
|
2011-01-18 09:12:44 +00:00
|
|
|
break;
|
|
|
|
case AUTO_SHIFTED:
|
|
|
|
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:
|
|
|
|
case AUTO_SHIFTED:
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = NORMAL;
|
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
|
|
|
return mState != oldState;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setShiftLocked(boolean newShiftLockState) {
|
|
|
|
final int oldState = mState;
|
|
|
|
if (newShiftLockState) {
|
2011-01-18 09:12:44 +00:00
|
|
|
switch (oldState) {
|
|
|
|
case NORMAL:
|
|
|
|
case MANUAL_SHIFTED:
|
|
|
|
case MANUAL_SHIFTED_FROM_AUTO:
|
|
|
|
case AUTO_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 {
|
2011-01-18 09:12:44 +00:00
|
|
|
switch (oldState) {
|
|
|
|
case SHIFT_LOCKED:
|
|
|
|
case SHIFT_LOCK_SHIFTED:
|
2010-11-13 08:16:34 +00:00
|
|
|
mState = NORMAL;
|
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, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState)
|
|
|
|
+ " > " + this);
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setAutomaticTemporaryUpperCase() {
|
|
|
|
final int oldState = mState;
|
|
|
|
mState = AUTO_SHIFTED;
|
|
|
|
if (DEBUG)
|
|
|
|
Log.d(TAG, "setAutomaticTemporaryUpperCase: " + toString(oldState) + " > " + this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShiftedOrShiftLocked() {
|
|
|
|
return mState != NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShiftLocked() {
|
|
|
|
return mState == SHIFT_LOCKED || mState == SHIFT_LOCK_SHIFTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAutomaticTemporaryUpperCase() {
|
|
|
|
return mState == AUTO_SHIFTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isManualTemporaryUpperCase() {
|
2011-01-18 09:12:44 +00:00
|
|
|
return mState == MANUAL_SHIFTED || mState == MANUAL_SHIFTED_FROM_AUTO
|
|
|
|
|| mState == SHIFT_LOCK_SHIFTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isManualTemporaryUpperCaseFromAuto() {
|
|
|
|
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) {
|
|
|
|
case NORMAL: return "NORMAL";
|
|
|
|
case MANUAL_SHIFTED: return "MANUAL_SHIFTED";
|
2011-01-18 09:12:44 +00:00
|
|
|
case MANUAL_SHIFTED_FROM_AUTO: return "MANUAL_SHIFTED_FROM_AUTO";
|
2010-11-13 08:16:34 +00:00
|
|
|
case AUTO_SHIFTED: return "AUTO_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";
|
|
|
|
default: return "UKNOWN";
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|