diff options
Diffstat (limited to 'java/src')
7 files changed, 177 insertions, 53 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 44c6a4966..cdf07ed70 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -41,6 +41,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -225,7 +226,7 @@ public class Keyboard { public int GRID_WIDTH; public int GRID_HEIGHT; - public final ArrayList<Key> mKeys = new ArrayList<Key>(); + public final HashSet<Key> mKeys = new HashSet<Key>(); public final ArrayList<Key> mShiftKeys = new ArrayList<Key>(); public final ArrayList<Key> mAltCodeKeysWhileTyping = new ArrayList<Key>(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 4c65522ec..847174c0a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -95,6 +95,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // The maximum key label width in the proportion to the key width. private static final float MAX_LABEL_RATIO = 0.90f; + private final static int ALPHA_OPAQUE = 255; + // Main keyboard private Keyboard mKeyboard; private final KeyDrawParams mKeyDrawParams; @@ -201,6 +203,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { public int mKeyHintLetterSize; public int mKeyShiftedLetterHintSize; public int mKeyHintLabelSize; + public int mAnimAlpha; public KeyDrawParams(TypedArray a) { mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground); @@ -256,6 +259,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio); mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio); } + + public void brendAlpha(Paint paint) { + final int color = paint.getColor(); + paint.setARGB((paint.getAlpha() * mAnimAlpha) / ALPHA_OPAQUE, + Color.red(color), Color.green(color), Color.blue(color)); + } } /* package */ static class KeyPreviewDrawParams { @@ -343,7 +352,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mPaint.setAntiAlias(true); mPaint.setTextAlign(Align.CENTER); - mPaint.setAlpha(255); } // Read fraction value in TypedArray as float. @@ -492,6 +500,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { final int keyDrawY = key.mY + getPaddingTop(); canvas.translate(keyDrawX, keyDrawY); + params.mAnimAlpha = ALPHA_OPAQUE; if (!key.isSpacer()) { onDrawKeyBackground(key, canvas, params); } @@ -535,6 +544,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // Draw key label. final Drawable icon = key.getIcon(mKeyboard.mIconsSet); + if (icon != null) { + icon.setAlpha(params.mAnimAlpha); + } float positionX = centerX; if (key.mLabel != null) { final String label = key.mLabel; @@ -589,6 +601,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // Make label invisible paint.setColor(Color.TRANSPARENT); } + params.brendAlpha(paint); canvas.drawText(label, 0, label.length(), positionX, baseline, paint); // Turn off drop shadow and reset x-scale. paint.setShadowLayer(0, 0, 0, 0); @@ -633,6 +646,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { hintSize = params.mKeyHintLetterSize; } paint.setColor(hintColor); + params.brendAlpha(paint); paint.setTextSize(hintSize); final float hintX, hintY; if (key.hasHintLabel()) { @@ -701,6 +715,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { paint.setTextSize(params.mKeyHintLetterSize); paint.setColor(params.mKeyHintLabelColor); + params.brendAlpha(paint); paint.setTextAlign(Align.CENTER); final float hintX = keyWidth - params.mKeyHintLetterPadding - getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index e320330a1..97f4d07d9 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -98,6 +98,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke private final Drawable mAutoCorrectionSpacebarLedIcon; private static final int SPACE_LED_LENGTH_PERCENT = 80; + // Stuff to draw altCodeWhileTyping keys. + private ValueAnimator mAltCodeKeyWhileTypingFadeoutAnimator; + private ValueAnimator mAltCodeKeyWhileTypingFadeinAnimator; + private int mAltCodeKeyWhileTypingAnimAlpha; + // More keys keyboard private PopupWindow mMoreKeysWindow; private MoreKeysPanel mMoreKeysPanel; @@ -122,7 +127,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke private static final int MSG_REPEAT_KEY = 1; private static final int MSG_LONGPRESS_KEY = 2; private static final int MSG_DOUBLE_TAP = 3; - private static final int MSG_KEY_TYPED = 4; + private static final int MSG_TYPING_STATE_EXPIRED = 4; private final KeyTimerParams mParams; private boolean mInKeyRepeat; @@ -148,6 +153,18 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke KeyboardSwitcher.getInstance().onLongPressTimeout(msg.arg1); } break; + case MSG_TYPING_STATE_EXPIRED: + final ValueAnimator fadeout = keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator; + if (fadeout != null && fadeout.isStarted()) { + fadeout.cancel(); + } + // TODO: Start the fade in animation with an initial value that is the same as the + // final value when the above fade out animation gets cancelled. + final ValueAnimator fadein = keyboardView.mAltCodeKeyWhileTypingFadeinAnimator; + if (fadein != null && !fadein.isStarted()) { + fadein.start(); + } + break; } } @@ -222,14 +239,30 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } @Override - public void startKeyTypedTimer() { - removeMessages(MSG_KEY_TYPED); - sendMessageDelayed(obtainMessage(MSG_KEY_TYPED), mParams.mIgnoreSpecialKeyTimeout); + public void startTypingStateTimer() { + final boolean isTyping = isTypingState(); + removeMessages(MSG_TYPING_STATE_EXPIRED); + sendMessageDelayed( + obtainMessage(MSG_TYPING_STATE_EXPIRED), mParams.mIgnoreAltCodeKeyTimeout); + final LatinKeyboardView keyboardView = getOuterInstance(); + if (isTyping) { + return; + } + final ValueAnimator fadein = keyboardView.mAltCodeKeyWhileTypingFadeinAnimator; + if (fadein != null && fadein.isStarted()) { + fadein.cancel(); + } + // TODO: Start the fade out animation with an initial value that is the same as the + // final value when the above fade in animation gets cancelled. + final ValueAnimator fadeout = keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator; + if (fadeout != null && !fadeout.isStarted()) { + fadeout.start(); + } } @Override - public boolean isTyping() { - return hasMessages(MSG_KEY_TYPED); + public boolean isTypingState() { + return hasMessages(MSG_TYPING_STATE_EXPIRED); } @Override @@ -288,7 +321,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke public final int mLongPressKeyTimeout; public final int mLongPressShiftKeyTimeout; public final int mLongPressSpaceKeyTimeout; - public final int mIgnoreSpecialKeyTimeout; + public final int mIgnoreAltCodeKeyTimeout; KeyTimerParams() { mKeyRepeatStartTimeout = 0; @@ -296,7 +329,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke mLongPressKeyTimeout = 0; mLongPressShiftKeyTimeout = 0; mLongPressSpaceKeyTimeout = 0; - mIgnoreSpecialKeyTimeout = 0; + mIgnoreAltCodeKeyTimeout = 0; } public KeyTimerParams(TypedArray latinKeyboardViewAttr) { @@ -310,8 +343,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke R.styleable.LatinKeyboardView_longPressShiftKeyTimeout, 0); mLongPressSpaceKeyTimeout = latinKeyboardViewAttr.getInt( R.styleable.LatinKeyboardView_longPressSpaceKeyTimeout, 0); - mIgnoreSpecialKeyTimeout = latinKeyboardViewAttr.getInt( - R.styleable.LatinKeyboardView_ignoreSpecialKeyTimeout, 0); + mIgnoreAltCodeKeyTimeout = latinKeyboardViewAttr.getInt( + R.styleable.LatinKeyboardView_ignoreAltCodeKeyTimeout, 0); } } @@ -342,6 +375,10 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke R.styleable.LatinKeyboardView_spacebarTextShadowColor, 0); final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId( R.styleable.LatinKeyboardView_languageOnSpacebarFadeoutAnimator, 0); + final int altCodeKeyWhileTypingFadeoutAnimatorResId = a.getResourceId( + R.styleable.LatinKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0); + final int altCodeKeyWhileTypingFadeinAnimatorResId = a.getResourceId( + R.styleable.LatinKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0); final KeyTimerParams keyTimerParams = new KeyTimerParams(a); mPointerTrackerParams = new PointerTrackerParams(a); @@ -357,7 +394,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke PointerTracker.setParameters(mPointerTrackerParams); - ValueAnimator animator = loadValueAnimator(context, languageOnSpacebarFadeoutAnimatorResId); + final ValueAnimator animator = loadValueAnimator(languageOnSpacebarFadeoutAnimatorResId); if (animator != null) { animator.addUpdateListener(new AnimatorUpdateListener() { @Override @@ -377,11 +414,47 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke animator.end(); } mLanguageOnSpacebarFadeoutAnimator = animator; + + final ValueAnimator fadeout = loadValueAnimator(altCodeKeyWhileTypingFadeoutAnimatorResId); + if (fadeout != null) { + fadeout.addUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + mAltCodeKeyWhileTypingAnimAlpha = (Integer)animation.getAnimatedValue(); + updateAltCodeKeyWhileTyping(); + } + }); + fadeout.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator a) { + final ValueAnimator valueAnimator = (ValueAnimator)a; + } + }); + } + mAltCodeKeyWhileTypingFadeoutAnimator = fadeout; + + final ValueAnimator fadein = loadValueAnimator(altCodeKeyWhileTypingFadeinAnimatorResId); + if (fadein != null) { + fadein.addUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + mAltCodeKeyWhileTypingAnimAlpha = (Integer)animation.getAnimatedValue(); + updateAltCodeKeyWhileTyping(); + } + }); + fadein.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator a) { + final ValueAnimator valueAnimator = (ValueAnimator)a; + } + }); + } + mAltCodeKeyWhileTypingFadeinAnimator = fadein; } - private static ValueAnimator loadValueAnimator(Context context, int resId) { + private ValueAnimator loadValueAnimator(int resId) { if (resId == 0) return null; - return (ValueAnimator)AnimatorInflater.loadAnimator(context, resId); + return (ValueAnimator)AnimatorInflater.loadAnimator(getContext(), resId); } public void setKeyboardActionListener(KeyboardActionListener listener) { @@ -437,6 +510,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap; mSpacebarTextSize = keyHeight * mSpacebarTextRatio; mSpacebarLocale = keyboard.mId.mLocale; + mSpacebarTextAlpha = ALPHA_OPAQUE; + mAltCodeKeyWhileTypingAnimAlpha = ALPHA_OPAQUE; } /** @@ -797,6 +872,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke invalidateKey(shortcutKey); } + private void updateAltCodeKeyWhileTyping() { + final Keyboard keyboard = getKeyboard(); + if (keyboard == null) return; + for (final Key key : keyboard.mAltCodeKeysWhileTyping) { + invalidateKey(key); + } + } + public void startDisplayLanguageOnSpacebar(boolean subtypeChanged, boolean needsToDisplayLanguage) { final ValueAnimator animator = mLanguageOnSpacebarFadeoutAnimator; @@ -825,6 +908,9 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke @Override protected void onDrawKeyTopVisuals(Key key, Canvas canvas, Paint paint, KeyDrawParams params) { + if (key.altCodeWhileTyping() && key.isEnabled()) { + params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha; + } if (key.mCode == Keyboard.CODE_SPACE) { drawSpacebar(key, canvas, paint); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 607b33bb4..ed889712a 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -68,8 +68,8 @@ public class PointerTracker { } public interface TimerProxy { - public void startKeyTypedTimer(); - public boolean isTyping(); + public void startTypingStateTimer(); + public boolean isTypingState(); public void startKeyRepeatTimer(PointerTracker tracker); public void startLongPressTimer(PointerTracker tracker); public void startLongPressTimer(int code); @@ -81,9 +81,9 @@ public class PointerTracker { public static class Adapter implements TimerProxy { @Override - public void startKeyTypedTimer() {} + public void startTypingStateTimer() {} @Override - public boolean isTyping() { return false; } + public boolean isTypingState() { return false; } @Override public void startKeyRepeatTimer(PointerTracker tracker) {} @Override @@ -251,25 +251,26 @@ public class PointerTracker { // primaryCode is different from {@link Key#mCode}. private void callListenerOnCodeInput(Key key, int primaryCode, int x, int y) { final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier(); - final boolean alterCode = key.altCodeWhileTyping() && mTimerProxy.isTyping(); - final int code = alterCode ? key.mAltCode : primaryCode; + final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState(); + final int code = altersCode ? key.mAltCode : primaryCode; if (DEBUG_LISTENER) { Log.d(TAG, "onCodeInput: " + Keyboard.printableCode(code) + " text=" + key.mOutputText + " x=" + x + " y=" + y - + " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode + + " ignoreModifier=" + ignoreModifierKey + " altersCode=" + altersCode + " enabled=" + key.isEnabled()); } if (ignoreModifierKey) { return; } - if (key.isEnabled()) { + // Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state. + if (key.isEnabled() || altersCode) { if (code == Keyboard.CODE_OUTPUT_TEXT) { mListener.onTextInput(key.mOutputText); } else if (code != Keyboard.CODE_UNSPECIFIED) { mListener.onCodeInput(code, x, y); } if (!key.altCodeWhileTyping() && !key.isModifier()) { - mTimerProxy.startKeyTypedTimer(); + mTimerProxy.startTypingStateTimer(); } } } @@ -322,10 +323,11 @@ public class PointerTracker { private void setReleasedKeyGraphics(Key key) { mDrawingProxy.dismissKeyPreview(this); - if (key == null || !key.isEnabled()) { + if (key == null) { return; } + // Even if the key is disabled, update the key release graphics just in case. updateReleaseKeyGraphics(key); if (key.isShift()) { @@ -351,7 +353,14 @@ public class PointerTracker { } private void setPressedKeyGraphics(Key key) { - if (key == null || !key.isEnabled()) { + if (key == null) { + return; + } + + // Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state. + final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState(); + final boolean needsToUpdateGraphics = key.isEnabled() || altersCode; + if (!needsToUpdateGraphics) { return; } @@ -368,7 +377,7 @@ public class PointerTracker { } } - if (key.altCodeWhileTyping() && mTimerProxy.isTyping()) { + if (key.altCodeWhileTyping() && mTimerProxy.isTypingState()) { final int altCode = key.mAltCode; final Key altKey = mKeyboard.getKey(altCode); if (altKey != null) { diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index e2a48306a..61d75e278 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -124,40 +124,40 @@ public class ProximityInfo { final float[] sweetSpotCenterXs; final float[] sweetSpotCenterYs; final float[] sweetSpotRadii; - final boolean calculateSweetSpotParams; + + for (int i = 0; i < keyCount; ++i) { + final Key key = keys[i]; + keyXCoordinates[i] = key.mX; + keyYCoordinates[i] = key.mY; + keyWidths[i] = key.mWidth; + keyHeights[i] = key.mHeight; + keyCharCodes[i] = key.mCode; + } + if (touchPositionCorrection != null && touchPositionCorrection.isValid()) { sweetSpotCenterXs = new float[keyCount]; sweetSpotCenterYs = new float[keyCount]; sweetSpotRadii = new float[keyCount]; - calculateSweetSpotParams = true; for (int i = 0; i < keyCount; i++) { final Key key = keys[i]; - keyXCoordinates[i] = key.mX; - keyYCoordinates[i] = key.mY; - keyWidths[i] = key.mWidth; - keyHeights[i] = key.mHeight; - keyCharCodes[i] = key.mCode; - if (calculateSweetSpotParams) { - final Rect hitBox = key.mHitBox; - final int row = hitBox.top / mKeyHeight; - if (row < touchPositionCorrection.mRadii.length) { - final float hitBoxCenterX = (hitBox.left + hitBox.right) * 0.5f; - final float hitBoxCenterY = (hitBox.top + hitBox.bottom) * 0.5f; - final float hitBoxWidth = hitBox.right - hitBox.left; - final float hitBoxHeight = hitBox.bottom - hitBox.top; - final float x = touchPositionCorrection.mXs[row]; - final float y = touchPositionCorrection.mYs[row]; - final float radius = touchPositionCorrection.mRadii[row]; - sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth; - sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight; - sweetSpotRadii[i] = radius * (float) Math.sqrt( - hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight); - } + final Rect hitBox = key.mHitBox; + final int row = hitBox.top / mKeyHeight; + if (row < touchPositionCorrection.mRadii.length) { + final float hitBoxCenterX = (hitBox.left + hitBox.right) * 0.5f; + final float hitBoxCenterY = (hitBox.top + hitBox.bottom) * 0.5f; + final float hitBoxWidth = hitBox.right - hitBox.left; + final float hitBoxHeight = hitBox.bottom - hitBox.top; + final float x = touchPositionCorrection.mXs[row]; + final float y = touchPositionCorrection.mYs[row]; + final float radius = touchPositionCorrection.mRadii[row]; + sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth; + sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight; + sweetSpotRadii[i] = radius * (float) Math.sqrt( + hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight); } } } else { sweetSpotCenterXs = sweetSpotCenterYs = sweetSpotRadii = null; - calculateSweetSpotParams = false; } mNativeProximityInfo = setProximityInfoNative(mLocaleStr, MAX_PROXIMITY_CHARS_SIZE, diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 201e0f410..6b231f81c 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -16,9 +16,11 @@ package com.android.inputmethod.latin; +import android.text.TextUtils; import android.view.inputmethod.CompletionInfo; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -71,7 +73,9 @@ public class SuggestedWords { return "SuggestedWords:" + " mTypedWordValid=" + mTypedWordValid + " mHasAutoCorrectionCandidate=" + mHasAutoCorrectionCandidate - + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions; + + " mAllowsToBeAutoCorrected=" + mAllowsToBeAutoCorrected + + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions + + " words=" + Arrays.toString(mSuggestedWordInfoList.toArray()); } public static ArrayList<SuggestedWordInfo> getFromCharSequenceList( @@ -141,5 +145,14 @@ public class SuggestedWords { public boolean isObsoleteSuggestedWord () { return mPreviousSuggestedWord; } + + @Override + public String toString() { + if (TextUtils.isEmpty(mDebugString)) { + return mWord.toString(); + } else { + return mWord.toString() + " (" + mDebugString.toString() + ")"; + } + } } } diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 3324a3793..5f6be6867 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -143,7 +143,7 @@ public class WordComposer { codes = keyDetector.newCodeArray(); keyDetector.getKeyAndNearbyCodes(x, y, codes); keyX = keyDetector.getTouchX(x); - keyY = keyDetector.getTouchX(y); + keyY = keyDetector.getTouchY(y); } add(primaryCode, codes, keyX, keyY); } |