diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardView.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinKeyboardView.java | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java index 22d39f7aa..6672dd22d 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -16,11 +16,11 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.latin.BaseKeyboard.Key; + import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; -import android.inputmethodservice.Keyboard; -import android.inputmethodservice.Keyboard.Key; import android.os.Handler; import android.os.Message; import android.os.SystemClock; @@ -32,14 +32,15 @@ import java.util.List; public class LatinKeyboardView extends LatinKeyboardBaseView { - static final int KEYCODE_OPTIONS = -100; - static final int KEYCODE_OPTIONS_LONGPRESS = -101; - static final int KEYCODE_VOICE = -102; - static final int KEYCODE_F1 = -103; - static final int KEYCODE_NEXT_LANGUAGE = -104; - static final int KEYCODE_PREV_LANGUAGE = -105; + public static final int KEYCODE_OPTIONS = -100; + public static final int KEYCODE_OPTIONS_LONGPRESS = -101; + public static final int KEYCODE_VOICE = -102; + public static final int KEYCODE_F1 = -103; + public static final int KEYCODE_NEXT_LANGUAGE = -104; + public static final int KEYCODE_PREV_LANGUAGE = -105; + public static final int KEYCODE_CAPSLOCK = -106; - private Keyboard mPhoneKeyboard; + private LatinKeyboard mPhoneKeyboard; /** Whether we've started dropping move events because we found a big jump */ private boolean mDroppingEvents; @@ -61,13 +62,13 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { super(context, attrs, defStyle); } - public void setPhoneKeyboard(Keyboard phoneKeyboard) { + public void setPhoneKeyboard(LatinKeyboard phoneKeyboard) { mPhoneKeyboard = phoneKeyboard; } @Override public void setPreviewEnabled(boolean previewEnabled) { - if (getKeyboard() == mPhoneKeyboard) { + if (getLatinKeyboard() == mPhoneKeyboard) { // Phone keyboard never shows popup preview (except language switch). super.setPreviewEnabled(false); } else { @@ -75,8 +76,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { } } - @Override - public void setKeyboard(Keyboard k) { + public void setLatinKeyboard(LatinKeyboard k) { super.setKeyboard(k); // One-seventh of the keyboard width seems like a reasonable threshold mJumpThresholdSquare = k.getMinWidth() / 7; @@ -86,12 +86,21 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { setKeyboardLocal(k); } + public LatinKeyboard getLatinKeyboard() { + BaseKeyboard keyboard = getKeyboard(); + if (keyboard instanceof LatinKeyboard) { + return (LatinKeyboard)keyboard; + } else { + return null; + } + } + @Override protected boolean onLongPress(Key key) { int primaryCode = key.codes[0]; if (primaryCode == KEYCODE_OPTIONS) { return invokeOnKey(KEYCODE_OPTIONS_LONGPRESS); - } else if (primaryCode == '0' && getKeyboard() == mPhoneKeyboard) { + } else if (primaryCode == '0' && getLatinKeyboard() == mPhoneKeyboard) { // Long pressing on 0 in phone number keypad gives you a '+'. return invokeOnKey('+'); } else { @@ -108,10 +117,9 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { @Override protected CharSequence adjustCase(CharSequence label) { - Keyboard keyboard = getKeyboard(); - if (keyboard.isShifted() - && keyboard instanceof LatinKeyboard - && ((LatinKeyboard) keyboard).isAlphaKeyboard() + LatinKeyboard keyboard = getLatinKeyboard(); + if (keyboard.isAlphaKeyboard() + && keyboard.isShifted() && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { label = label.toString().toUpperCase(); @@ -120,13 +128,10 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { } public boolean setShiftLocked(boolean shiftLocked) { - Keyboard keyboard = getKeyboard(); - if (keyboard instanceof LatinKeyboard) { - ((LatinKeyboard)keyboard).setShiftLocked(shiftLocked); - invalidateAllKeys(); - return true; - } - return false; + LatinKeyboard keyboard = getLatinKeyboard(); + keyboard.setShiftLocked(shiftLocked); + invalidateAllKeys(); + return true; } /** @@ -208,7 +213,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { @Override public boolean onTouchEvent(MotionEvent me) { - LatinKeyboard keyboard = (LatinKeyboard) getKeyboard(); + LatinKeyboard keyboard = getLatinKeyboard(); if (DEBUG_LINE) { mLastX = (int) me.getX(); mLastY = (int) me.getY(); @@ -257,7 +262,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { private int mLastY; private Paint mPaint; - private void setKeyboardLocal(Keyboard k) { + private void setKeyboardLocal(LatinKeyboard k) { if (DEBUG_AUTO_PLAY) { findKeys(); if (mHandler2 == null) { @@ -318,7 +323,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { } private void findKeys() { - List<Key> keys = getKeyboard().getKeys(); + List<Key> keys = getLatinKeyboard().getKeys(); // Get the keys on this keyboard for (int i = 0; i < keys.size(); i++) { int code = keys.get(i).codes[0]; |