diff options
Diffstat (limited to 'java/src')
9 files changed, 393 insertions, 103 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index d637ab5f1..f27d79382 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -74,7 +74,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions { private MainKeyboardView mKeyboardView; private LatinIME mLatinIME; private Resources mResources; - private SettingsValues mCurrentSettingsValues; private KeyboardState mState; @@ -136,7 +135,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions { } public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) { - mCurrentSettingsValues = settingsValues; final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( mThemeContext, editorInfo); builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation, @@ -171,20 +169,20 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions { } private void setKeyboard(final Keyboard keyboard) { - final Keyboard oldKeyboard = mKeyboardView.getKeyboard(); - mKeyboardView.setGestureInputEnabled(mCurrentSettingsValues.mGestureInputEnabled); - mKeyboardView.setKeyboard(keyboard); + final MainKeyboardView keyboardView = mKeyboardView; + final Keyboard oldKeyboard = keyboardView.getKeyboard(); + keyboardView.setKeyboard(keyboard); mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding); - mKeyboardView.setKeyPreviewPopupEnabled( + keyboardView.setKeyPreviewPopupEnabled( SettingsValues.isKeyPreviewPopupEnabled(mPrefs, mResources), SettingsValues.getKeyPreviewPopupDismissDelay(mPrefs, mResources)); - mKeyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive); - mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); + keyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive); + keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); final boolean subtypeChanged = (oldKeyboard == null) || !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale); final boolean needsToDisplayLanguage = mSubtypeSwitcher.needsToDisplayLanguage( keyboard.mId.mLocale); - mKeyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage, + keyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage, ImfUtils.hasMultipleEnabledIMEsOrSubtypes(mLatinIME, true)); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index f751fa53c..f1f942ccb 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -35,9 +35,9 @@ import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.RelativeLayout; import android.widget.TextView; +import com.android.inputmethod.keyboard.internal.PreviewPlacerView; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; @@ -97,9 +97,6 @@ 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 GESTURE_DRAWING_WIDTH = 5; - private final static int GESTURE_DRAWING_COLOR = 0xff33b5e5; - // Main keyboard private Keyboard mKeyboard; protected final KeyDrawParams mKeyDrawParams; @@ -109,10 +106,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { protected final KeyPreviewDrawParams mKeyPreviewDrawParams; private boolean mShowKeyPreviewPopup = true; private int mDelayAfterPreview; - private ViewGroup mPreviewPlacer; + private PreviewPlacerView mPreviewPlacer; - /** True if the gesture input is enabled. */ - protected boolean mGestureInputEnabled; + /** True if {@link KeyboardView} should handle gesture events. */ + protected boolean mShouldHandleGesture; // Drawing /** True if the entire keyboard needs to be dimmed. */ @@ -125,14 +122,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { private final HashSet<Key> mInvalidatedKeys = new HashSet<Key>(); /** The region of invalidated keys */ private final Rect mInvalidatedKeysRect = new Rect(); - /** The region of invalidated gestures */ - private final Rect mInvalidatedGesturesRect = new Rect(); /** The keyboard bitmap buffer for faster updates */ private Bitmap mBuffer; /** The canvas for the above mutable keyboard bitmap */ private Canvas mCanvas; private final Paint mPaint = new Paint(); - private final Paint mGesturePaint = new Paint(); private final Paint.FontMetrics mFontMetrics = new Paint.FontMetrics(); // This sparse array caches key label text height in pixel indexed by key label text size. private static final SparseArray<Float> sTextHeightCache = new SparseArray<Float>(); @@ -382,13 +376,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mPaint.setAntiAlias(true); - - // TODO: These paint parameters should be specified via attribute of the view and styleable. - mGesturePaint.setAntiAlias(true); - mGesturePaint.setStyle(Paint.Style.STROKE); - mGesturePaint.setStrokeJoin(Paint.Join.ROUND); - mGesturePaint.setColor(GESTURE_DRAWING_COLOR); - mGesturePaint.setStrokeWidth(GESTURE_DRAWING_WIDTH); } // Read fraction value in TypedArray as float. @@ -443,8 +430,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { return mShowKeyPreviewPopup; } - public void setGestureInputEnabled(boolean gestureInputEnabled) { - mGestureInputEnabled = gestureInputEnabled; + public void setGestureHandlingMode(boolean shouldHandleGesture) { + mShouldHandleGesture = shouldHandleGesture; } @Override @@ -888,26 +875,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mDrawingHandler.dismissKeyPreview(mDelayAfterPreview, tracker); } - private static class PreviewView extends RelativeLayout { - KeyPreviewDrawParams mParams; - Paint mGesturePaint; - - public PreviewView(Context context, KeyPreviewDrawParams params, Paint gesturePaint) { - super(context); - setWillNotDraw(false); - mParams = params; - mGesturePaint = gesturePaint; - } - - @Override - public void onDraw(Canvas canvas) { - super.onDraw(canvas); - canvas.translate(mParams.mCoordinates[0], mParams.mCoordinates[1]); - PointerTracker.drawGestureTrailForAllPointerTrackers(canvas, mGesturePaint); - canvas.translate(-mParams.mCoordinates[0], -mParams.mCoordinates[1]); - } - } - private void addKeyPreview(TextView keyPreview) { if (mPreviewPlacer == null) { createPreviewPlacer(); @@ -917,29 +884,31 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } private void createPreviewPlacer() { - mPreviewPlacer = new PreviewView(getContext(), mKeyPreviewDrawParams, mGesturePaint); + mPreviewPlacer = new PreviewPlacerView(getContext()); + final int[] viewOrigin = new int[2]; + getLocationInWindow(viewOrigin); + mPreviewPlacer.setOrigin(viewOrigin[0], viewOrigin[1]); final ViewGroup windowContentView = (ViewGroup)getRootView().findViewById(android.R.id.content); windowContentView.addView(mPreviewPlacer); } + public void showGesturePreviewText(String gesturePreviewText) { + // TDOD: Add user settings option to control drawing gesture trail. + if (mPreviewPlacer == null) { + createPreviewPlacer(); + } + mPreviewPlacer.setGesturePreviewText(gesturePreviewText); + mPreviewPlacer.invalidate(); + } + @Override public void showGestureTrail(PointerTracker tracker) { + // TDOD: Add user settings option to control drawing gesture trail. if (mPreviewPlacer == null) { createPreviewPlacer(); } - final Rect r = tracker.getBoundingBox(); - if (!r.isEmpty()) { - // Invalidate the rectangular region encompassing the gesture. This is needed because - // past points along the gesture will fade and gradually disappear. - final KeyPreviewDrawParams params = mKeyPreviewDrawParams; - mInvalidatedGesturesRect.set(r); - mInvalidatedGesturesRect.offset(params.mCoordinates[0], params.mCoordinates[1]); - mInvalidatedGesturesRect.inset(-GESTURE_DRAWING_WIDTH, -GESTURE_DRAWING_WIDTH); - mPreviewPlacer.invalidate(mInvalidatedGesturesRect); - } else { - mPreviewPlacer.invalidate(); - } + mPreviewPlacer.invalidatePointer(tracker); } @SuppressWarnings("deprecation") // setBackgroundDrawable is replaced by setBackground in API16 diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 8c234e4e6..110f3c3e3 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -461,7 +461,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key super.setKeyboard(keyboard); mKeyDetector.setKeyboard( keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); - PointerTracker.setKeyDetector(mKeyDetector, mGestureInputEnabled); + PointerTracker.setKeyDetector(mKeyDetector, mShouldHandleGesture); mTouchScreenRegulator.setKeyboard(keyboard); mMoreKeysPanelCache.clear(); @@ -479,6 +479,12 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key AccessibleKeyboardViewProxy.getInstance().setKeyboard(keyboard); } + @Override + public void setGestureHandlingMode(final boolean shouldHandleGesture) { + super.setGestureHandlingMode(shouldHandleGesture); + PointerTracker.setKeyDetector(mKeyDetector, shouldHandleGesture); + } + /** * Returns whether the device has distinct multi-touch panel. * @return true if the device has distinct multi-touch panel. diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 4a5ecf986..67857d111 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard; import android.graphics.Canvas; import android.graphics.Paint; -import android.graphics.Rect; import android.os.SystemClock; import android.util.Log; import android.view.MotionEvent; @@ -42,8 +41,8 @@ public class PointerTracker { private static final boolean DEBUG_LISTENER = false; private static boolean DEBUG_MODE = LatinImeLogger.sDBG; - // TODO: There should be an option to turn on/off the gesture input. - private static boolean sIsGestureEnabled = true; + /** True if {@link PointerTracker}s should handle gesture events. */ + private static boolean sShouldHandleGesture = false; private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec @@ -199,7 +198,7 @@ public class PointerTracker { sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack; setParameters(MainKeyboardView.PointerTrackerParams.DEFAULT); - updateGestureInputEnabledState(null, false /* gestureInputEnabled */); + updateGestureHandlingMode(null, false /* shouldHandleGesture */); } public static void setParameters(MainKeyboardView.PointerTrackerParams params) { @@ -208,14 +207,13 @@ public class PointerTracker { params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance); } - private static void updateGestureInputEnabledState(Keyboard keyboard, - boolean gestureInputEnabled) { - if (!gestureInputEnabled + private static void updateGestureHandlingMode(Keyboard keyboard, boolean shouldHandleGesture) { + if (!shouldHandleGesture || AccessibilityUtils.getInstance().isTouchExplorationEnabled() || (keyboard != null && keyboard.mId.passwordInput())) { - sIsGestureEnabled = false; + sShouldHandleGesture = false; } else { - sIsGestureEnabled = true; + sShouldHandleGesture = true; } } @@ -243,7 +241,7 @@ public class PointerTracker { } } - public static void setKeyDetector(KeyDetector keyDetector, boolean gestureInputEnabledByUser) { + public static void setKeyDetector(KeyDetector keyDetector, boolean shouldHandleGesture) { final int trackersSize = sTrackers.size(); for (int i = 0; i < trackersSize; ++i) { final PointerTracker tracker = sTrackers.get(i); @@ -252,7 +250,7 @@ public class PointerTracker { tracker.mKeyboardLayoutHasBeenChanged = true; } final Keyboard keyboard = keyDetector.getKeyboard(); - updateGestureInputEnabledState(keyboard, gestureInputEnabledByUser); + updateGestureHandlingMode(keyboard, shouldHandleGesture); } public static void dismissAllKeyPreviews() { @@ -297,17 +295,6 @@ public class PointerTracker { sAggregratedPointers.reset(); } - // TODO: To handle multi-touch gestures we may want to move this method to - // {@link PointerTrackerQueue}. - public static void drawGestureTrailForAllPointerTrackers(Canvas canvas, Paint paint) { - final int trackersSize = sTrackers.size(); - for (int i = 0; i < trackersSize; ++i) { - final PointerTracker tracker = sTrackers.get(i); - tracker.mGestureStroke.drawGestureTrail(canvas, paint, tracker.getLastX(), - tracker.getLastY()); - } - } - private PointerTracker(int id, KeyEventHandler handler) { if (handler == null) throw new NullPointerException(); @@ -525,6 +512,12 @@ public class PointerTracker { mDrawingProxy.invalidateKey(key); } + public void drawGestureTrail(Canvas canvas, Paint paint) { + if (mInGesture) { + mGestureStroke.drawGestureTrail(canvas, paint, mLastX, mLastY); + } + } + public int getLastX() { return mLastX; } @@ -536,9 +529,6 @@ public class PointerTracker { public long getDownTime() { return mDownTime; } - public Rect getBoundingBox() { - return mGestureStroke.getBoundingBox(); - } private Key onDownKey(int x, int y, long eventTime) { mDownTime = eventTime; @@ -669,8 +659,8 @@ public class PointerTracker { if (queue != null && queue.size() == 1) { mIsPossibleGesture = false; // A gesture should start only from the letter key. - if (sIsGestureEnabled && mIsAlphabetKeyboard && !mIsShowingMoreKeysPanel && key != null - && Keyboard.isLetterCode(key.mCode)) { + if (sShouldHandleGesture && mIsAlphabetKeyboard && !mIsShowingMoreKeysPanel + && key != null && Keyboard.isLetterCode(key.mCode)) { mIsPossibleGesture = true; // TODO: pointer times should be relative to first down even in entire batch input // instead of resetting to 0 for each new down event. @@ -714,7 +704,7 @@ public class PointerTracker { private void onGestureMoveEvent(PointerTracker tracker, int x, int y, long eventTime, boolean isHistorical, Key key) { final int gestureTime = (int)(eventTime - tracker.getDownTime()); - if (sIsGestureEnabled && mIsPossibleGesture) { + if (sShouldHandleGesture && mIsPossibleGesture) { final GestureStroke stroke = mGestureStroke; stroke.addPoint(x, y, gestureTime, isHistorical); if (!mInGesture && stroke.isStartOfAGesture(gestureTime, sWasInGesture)) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java index c16b70ef0..28d6c1d07 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java @@ -16,7 +16,6 @@ package com.android.inputmethod.keyboard.internal; import android.graphics.Canvas; import android.graphics.Paint; -import android.graphics.Rect; import android.util.FloatMath; import com.android.inputmethod.latin.Constants; @@ -41,7 +40,6 @@ public class GestureStroke { private int mMinGestureLength; private int mMinGestureLengthWhileInGesture; private int mMinGestureSampleLength; - private final Rect mDrawingRect = new Rect(); // TODO: Move some of these to resource. private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 1.0f; @@ -90,7 +88,6 @@ public class GestureStroke { mEventTimes.setLength(0); mXCoordinates.setLength(0); mYCoordinates.setLength(0); - mDrawingRect.setEmpty(); } private void updateLastPoint(final int x, final int y, final int time) { @@ -198,8 +195,4 @@ public class GestureStroke { } } } - - public Rect getBoundingBox() { - return mDrawingRect; - } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java index d732fc061..308e2411e 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java @@ -2098,6 +2098,24 @@ public final class KeyboardTextsSet { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, /* ~34 */ + // TODO: Move these to sr-Latn once we can handle IETF language tag with script name specified. + // BEGIN: More keys definitions for Serbian (Latin) + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // <string name="more_keys_for_s">š,ß,ś</string> + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // <string name="more_keys_for_c">č,ç,ć</string> + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + // <string name="more_keys_for_d">ď</string> + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // <string name="more_keys_for_z">ž,ź,ż</string> + // END: More keys definitions for Serbian (Latin) + // BEGIN: More keys definitions for Serbian (Cyrillic) // U+0437: "з" CYRILLIC SMALL LETTER ZE /* 35 */ "\u0437", // U+045B: "ћ" CYRILLIC SMALL LETTER TSHE @@ -2111,6 +2129,7 @@ public final class KeyboardTextsSet { // U+045D: "ѝ" CYRILLIC SMALL LETTER I WITH GRAVE /* 40 */ "\u045D", /* 41 */ null, + // END: More keys definitions for Serbian (Cyrillic) // U+2018: "‘" LEFT SINGLE QUOTATION MARK // U+2019: "’" RIGHT SINGLE QUOTATION MARK // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK @@ -2169,6 +2188,110 @@ public final class KeyboardTextsSet { /* 24 */ "\u00E6", }; + /* Language sw: Swahili */ + private static final String[] LANGUAGE_sw = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E0,\u00E1,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101", + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E8,\u00E9,\u00EA,\u00EB,\u0113", + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + /* 2 */ "\u00EE,\u00EF,\u00ED,\u012B,\u00EC", + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + /* 3 */ "\u00F4,\u00F6,\u00F2,\u00F3,\u0153,\u00F8,\u014D,\u00F5", + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FB,\u00FC,\u00F9,\u00FA,\u016B", + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + /* 5 */ "\u00DF", + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + /* 6 */ "\u00F1", + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + /* 7 */ "\u00E7", + /* 8~ */ + null, null, null, null, null, null, null, + /* ~14 */ + /* 15 */ "g\'", + }; + + /* Language tl: Tagalog */ + private static final String[] LANGUAGE_tl = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + /* 0 */ "\u00E1,\u00E0,\u00E4,\u00E2,\u00E3,\u00E5,\u0105,\u00E6,\u0101,\u00AA", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u00E8,\u00EB,\u00EA,\u0119,\u0117,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00ED,\u00EF,\u00EC,\u00EE,\u012F,\u012B", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + /* 3 */ "\u00F3,\u00F2,\u00F6,\u00F4,\u00F5,\u00F8,\u0153,\u014D,\u00BA", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u00F9,\u00FB,\u016B", + /* 5 */ null, + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u00F1,\u0144", + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + /* 7 */ "\u00E7,\u0107,\u010D", + }; + /* Language tr: Turkish */ private static final String[] LANGUAGE_tr = { // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX @@ -2477,6 +2600,8 @@ public final class KeyboardTextsSet { "sl", LANGUAGE_sl, /* Slovenian */ "sr", LANGUAGE_sr, /* Serbian */ "sv", LANGUAGE_sv, /* Swedish */ + "sw", LANGUAGE_sw, /* Swahili */ + "tl", LANGUAGE_tl, /* Tagalog */ "tr", LANGUAGE_tr, /* Turkish */ "uk", LANGUAGE_uk, /* Ukrainian */ "vi", LANGUAGE_vi, /* Vietnamese */ diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java new file mode 100644 index 000000000..2a53c59bb --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * 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.internal; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Paint.Align; +import android.text.TextUtils; +import android.util.SparseArray; +import android.widget.RelativeLayout; + +import com.android.inputmethod.keyboard.PointerTracker; +import com.android.inputmethod.latin.R; + +public class PreviewPlacerView extends RelativeLayout { + // TODO: Move these parameters to attributes of {@link KeyboardView}. + private final static int GESTURE_DRAWING_COLOR = 0xff33b5e5; + private static final int GESTURE_PREVIEW_TEXT_COLOR = Color.WHITE; + private static final int GESTURE_PREVIEW_TEXT_SHADING_COLOR = 0xff33b5e5; + private static final int GESTURE_PREVIEW_TEXT_SHADOW_COLOR = 0xff252525; + private static final int GESTURE_PREVIEW_CONNECTOR_COLOR = Color.WHITE; + + private final Paint mGesturePaint; + private final int mGesturePreviewTraileWidth; + private final Paint mTextPaint; + private final int mGesturePreviewTextOffset; + private final int mGesturePreviewTextShadowBorder; + private final int mGesturePreviewTextShadingBorder; + private final int mGesturePreviewTextConnectorWidth; + + private int mXOrigin; + private int mYOrigin; + + private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>(); + + private String mGesturePreviewText; + + public PreviewPlacerView(Context context) { + super(context); + setWillNotDraw(false); + + final Resources res = getResources(); + // TODO: Move these parameters to attributes of {@link KeyboardView}. + mGesturePreviewTraileWidth = res.getDimensionPixelSize( + R.dimen.gesture_preview_trail_width); + final int textSize = res.getDimensionPixelSize(R.dimen.gesture_preview_text_size); + mGesturePreviewTextOffset = res.getDimensionPixelSize( + R.dimen.gesture_preview_text_offset); + mGesturePreviewTextShadowBorder = res.getDimensionPixelOffset( + R.dimen.gesture_preview_text_shadow_border); + mGesturePreviewTextShadingBorder = res.getDimensionPixelOffset( + R.dimen.gesture_preview_text_shading_border); + mGesturePreviewTextConnectorWidth = res.getDimensionPixelOffset( + R.dimen.gesture_preview_text_connector_width); + + mGesturePaint = new Paint(); + mGesturePaint.setAntiAlias(true); + mGesturePaint.setStyle(Paint.Style.STROKE); + mGesturePaint.setStrokeJoin(Paint.Join.ROUND); + mGesturePaint.setColor(GESTURE_DRAWING_COLOR); + mGesturePaint.setStrokeWidth(mGesturePreviewTraileWidth); + + mTextPaint = new Paint(); + mTextPaint.setAntiAlias(true); + mTextPaint.setStrokeJoin(Paint.Join.ROUND); + mTextPaint.setTextAlign(Align.CENTER); + mTextPaint.setTextSize(textSize); + } + + public void setOrigin(int x, int y) { + mXOrigin = x; + mYOrigin = y; + } + + public void invalidatePointer(PointerTracker tracker) { + synchronized (mPointers) { + mPointers.put(tracker.mPointerId, tracker); + // TODO: Should narrow the invalidate region. + invalidate(); + } + } + + @Override + public void onDraw(Canvas canvas) { + super.onDraw(canvas); + // TDOD: Add user settings option to control drawing gesture trail and gesture preview. + synchronized (mPointers) { + canvas.translate(mXOrigin, mYOrigin); + final int trackerCount = mPointers.size(); + boolean floatingPreviewHasDrawn = false; + for (int index = 0; index < trackerCount; index++) { + final PointerTracker tracker = mPointers.valueAt(index); + tracker.drawGestureTrail(canvas, mGesturePaint); + // TODO: Figure out more cleaner way to draw gesture preview text. + if (!floatingPreviewHasDrawn) { + drawGesturePreviewText(canvas, tracker, mGesturePreviewText); + floatingPreviewHasDrawn = true; + } + } + canvas.translate(-mXOrigin, -mYOrigin); + } + } + + public void setGesturePreviewText(String gesturePreviewText) { + mGesturePreviewText = gesturePreviewText; + invalidate(); + } + + private void drawGesturePreviewText(Canvas canvas, PointerTracker tracker, + String gesturePreviewText) { + if (TextUtils.isEmpty(gesturePreviewText)) { + return; + } + + final Paint paint = mTextPaint; + final int lastX = tracker.getLastX(); + final int lastY = tracker.getLastY(); + final int textSize = (int)paint.getTextSize(); + final int canvasWidth = canvas.getWidth(); + + final int halfTextWidth = (int)paint.measureText(gesturePreviewText) / 2 + textSize; + final int textX = Math.min(Math.max(lastX, halfTextWidth), canvasWidth - halfTextWidth); + + int textY = Math.max(-textSize, lastY - mGesturePreviewTextOffset); + if (textY < 0) { + // Paint black text shadow if preview extends above keyboard region. + paint.setStyle(Paint.Style.FILL_AND_STROKE); + paint.setColor(GESTURE_PREVIEW_TEXT_SHADOW_COLOR); + paint.setStrokeWidth(mGesturePreviewTextShadowBorder); + canvas.drawText(gesturePreviewText, textX, textY, paint); + } + + // Paint the vertical line connecting the touch point to the preview text. + paint.setStyle(Paint.Style.STROKE); + paint.setColor(GESTURE_PREVIEW_CONNECTOR_COLOR); + paint.setStrokeWidth(mGesturePreviewTextConnectorWidth); + final int lineTopY = textY - textSize / 4; + canvas.drawLine(lastX, lastY, lastX, lineTopY, paint); + if (lastX != textX) { + // Paint the horizontal line connection the touch point to the preview text. + canvas.drawLine(lastX, lineTopY, textX, lineTopY, paint); + } + + // Paint the shading for the text preview + paint.setStyle(Paint.Style.FILL_AND_STROKE); + paint.setColor(GESTURE_PREVIEW_TEXT_SHADING_COLOR); + paint.setStrokeWidth(mGesturePreviewTextShadingBorder); + canvas.drawText(gesturePreviewText, textX, textY, paint); + + // Paint the text preview + paint.setColor(GESTURE_PREVIEW_TEXT_COLOR); + paint.setStyle(Paint.Style.FILL); + canvas.drawText(gesturePreviewText, textX, textY, paint); + } +} diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d4b59c4cd..9f9d07b3a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -82,7 +82,8 @@ import java.util.Locale; * Input method implementation for Qwerty'ish keyboard. */ public class LatinIME extends InputMethodService implements KeyboardActionListener, - SuggestionStripView.Listener, TargetApplicationGetter.OnTargetApplicationKnownListener { + SuggestionStripView.Listener, TargetApplicationGetter.OnTargetApplicationKnownListener, + Suggest.SuggestInitializationListener { private static final String TAG = LatinIME.class.getSimpleName(); private static final boolean TRACE = false; private static boolean DEBUG; @@ -426,6 +427,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } + @Override + public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable) { + mIsMainDictionaryAvailable = isMainDictionaryAvailable; + updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability(); + } + private void initSuggest() { final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); final String localeStr = subtypeLocale.toString(); @@ -437,7 +444,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else { oldContactsDictionary = null; } - mSuggest = new Suggest(this, subtypeLocale); + mSuggest = new Suggest(this /* Context */, subtypeLocale, + this /* SuggestInitializationListener */); if (mCurrentSettings.mCorrectionEnabled) { mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold); } @@ -673,6 +681,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } switcher.loadKeyboard(editorInfo, mCurrentSettings); + updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability(); if (mSuggestionStripView != null) mSuggestionStripView.clear(); @@ -1334,6 +1343,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mWordComposer.setBatchInputPointers(batchPointers); final SuggestedWords suggestedWords = getSuggestedWords(); showSuggestionStrip(suggestedWords, null); + final String gesturePreviewText = (suggestedWords.size() > 0) + ? suggestedWords.getWord(0) : null; + mKeyboardSwitcher.getKeyboardView().showGesturePreviewText(gesturePreviewText); } @Override @@ -1341,6 +1353,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mWordComposer.setBatchInputPointers(batchPointers); final SuggestedWords suggestedWords = getSuggestedWords(); showSuggestionStrip(suggestedWords, null); + mKeyboardSwitcher.getKeyboardView().showGesturePreviewText(null); if (suggestedWords == null || suggestedWords.size() == 0) { return; } @@ -2044,18 +2057,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onRefreshKeyboard() { // When the device locale is changed in SetupWizard etc., this method may get called via // onConfigurationChanged before SoftInputWindow is shown. + initSuggest(); + loadSettings(); if (mKeyboardSwitcher.getKeyboardView() != null) { // Reload keyboard because the current language has been changed. mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mCurrentSettings); + updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability(); } - initSuggest(); - loadSettings(); // Since we just changed languages, we should re-evaluate suggestions with whatever word // we are currently composing. If we are not composing anything, we may want to display // predictions or punctuation signs (which is done by the updateSuggestionStrip anyway). mHandler.postUpdateSuggestionStrip(); } + private void updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability() { + final MainKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView(); + if (keyboardView != null) { + final boolean shouldHandleGesture = mCurrentSettings.mGestureInputEnabled + && mIsMainDictionaryAvailable; + keyboardView.setGestureHandlingMode(shouldHandleGesture); + } + } + // TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to // {@link KeyboardSwitcher}. Called from KeyboardSwitcher public void hapticAndAudioFeedback(final int primaryCode) { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 598ef1de7..3e3cf76f1 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -42,6 +42,10 @@ public class Suggest { // TODO: rename this to CORRECTION_ON public static final int CORRECTION_FULL = 1; + public interface SuggestInitializationListener { + public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable); + } + private static final boolean DBG = LatinImeLogger.sDBG; private Dictionary mMainDictionary; @@ -55,11 +59,14 @@ public class Suggest { private float mAutoCorrectionThreshold; // Locale used for upper- and title-casing words - final private Locale mLocale; + private final Locale mLocale; + private final SuggestInitializationListener mListener; - public Suggest(final Context context, final Locale locale) { + public Suggest(final Context context, final Locale locale, + final SuggestInitializationListener listener) { initAsynchronously(context, locale); mLocale = locale; + mListener = listener; } /* package for test */ Suggest(final Context context, final File dictionary, @@ -67,6 +74,7 @@ public class Suggest { final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(context, dictionary, startOffset, length /* useFullEditDistance */, false, locale); mLocale = locale; + mListener = null; mMainDictionary = mainDict; addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict); initWhitelistAndAutocorrectAndPool(context, locale); @@ -98,6 +106,9 @@ public class Suggest { public void resetMainDict(final Context context, final Locale locale) { mMainDictionary = null; + if (mListener != null) { + mListener.onUpdateMainDictionaryAvailability(hasMainDictionary()); + } new Thread("InitializeBinaryDictionary") { @Override public void run() { @@ -105,6 +116,9 @@ public class Suggest { DictionaryFactory.createMainDictionaryFromManager(context, locale); addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, newMainDict); mMainDictionary = newMainDict; + if (mListener != null) { + mListener.onUpdateMainDictionaryAvailability(hasMainDictionary()); + } } }.start(); } |