diff options
Diffstat (limited to 'java/src')
15 files changed, 282 insertions, 164 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java index b9b6362fc..0ab84f7b5 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java @@ -36,6 +36,7 @@ import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.latin.CollectionUtils; +import com.android.inputmethod.latin.CoordinateUtils; /** * Exposes a virtual view sub-tree for {@link KeyboardView} and generates @@ -62,7 +63,7 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider private final Rect mTempBoundsInScreen = new Rect(); /** The parent view's cached on-screen location. */ - private final int[] mParentLocation = new int[2]; + private final int[] mParentLocation = CoordinateUtils.newInstance(); /** The virtual view identifier for the focused node. */ private int mAccessibilityFocusedView = UNDEFINED; @@ -180,7 +181,8 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); - mTempBoundsInScreen.offset(mParentLocation[0], mParentLocation[1]); + mTempBoundsInScreen.offset( + CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); final Rect boundsInScreen = mTempBoundsInScreen; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 472f74b12..d7cb5aa92 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -45,6 +45,7 @@ import com.android.inputmethod.keyboard.internal.KeyVisualAttributes; import com.android.inputmethod.keyboard.internal.PreviewPlacerView; import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.CoordinateUtils; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; @@ -134,7 +135,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // Preview placer view private final PreviewPlacerView mPreviewPlacerView; - private final int[] mCoordinates = new int[2]; + private final int[] mCoordinates = CoordinateUtils.newInstance(); // Key preview private static final int PREVIEW_ALPHA = 240; @@ -832,10 +833,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // In transient state. return; } - final int[] viewOrigin = new int[2]; + final int[] viewOrigin = CoordinateUtils.newInstance(); getLocationInWindow(viewOrigin); final DisplayMetrics dm = getResources().getDisplayMetrics(); - if (viewOrigin[1] < dm.heightPixels / 4) { + if (CoordinateUtils.y(viewOrigin) < dm.heightPixels / 4) { // In transient state. return; } @@ -850,7 +851,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { Log.w(TAG, "Cannot find android.R.id.content view to add PreviewPlacerView"); } else { windowContentView.addView(mPreviewPlacerView); - mPreviewPlacerView.setKeyboardViewGeometry(viewOrigin[0], viewOrigin[1], width, height); + mPreviewPlacerView.setKeyboardViewGeometry( + CoordinateUtils.x(viewOrigin), CoordinateUtils.y(viewOrigin), width, height); } } @@ -940,7 +942,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and // the left/right background is used if such background is specified. final int statePosition; - int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 + mCoordinates[0]; + int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 + + CoordinateUtils.x(mCoordinates); if (previewX < 0) { previewX = 0; statePosition = STATE_LEFT; @@ -952,7 +955,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } // The key preview is placed vertically above the top edge of the parent key with an // arbitrary offset. - final int previewY = key.mY - previewHeight + mPreviewOffset + mCoordinates[1]; + final int previewY = key.mY - previewHeight + mPreviewOffset + + CoordinateUtils.y(mCoordinates); if (background != null) { final int hasMoreKeys = (key.mMoreKeys != null) ? STATE_HAS_MOREKEYS : STATE_NORMAL; diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index d5f40ad36..7e9e3ce1a 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -29,6 +29,7 @@ import android.graphics.Paint.Align; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Message; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.util.AttributeSet; import android.util.Log; @@ -156,12 +157,14 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack 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_UPDATE_BATCH_INPUT = 4; private final int mKeyRepeatStartTimeout; private final int mKeyRepeatInterval; private final int mLongPressKeyTimeout; private final int mLongPressShiftKeyTimeout; private final int mIgnoreAltCodeKeyTimeout; + private final int mGestureRecognitionUpdateTime; public KeyTimerHandler(final MainKeyboardView outerInstance, final TypedArray mainKeyboardViewAttr) { @@ -177,6 +180,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack R.styleable.MainKeyboardView_longPressShiftKeyTimeout, 0); mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt( R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0); + mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt( + R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0); } @Override @@ -201,6 +206,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack KeyboardSwitcher.getInstance().onLongPressTimeout(msg.arg1); } break; + case MSG_UPDATE_BATCH_INPUT: + tracker.updateBatchInputByTimer(SystemClock.uptimeMillis()); + startUpdateBatchInputTimer(tracker); + break; } } @@ -349,8 +358,24 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack cancelLongPressTimer(); } + @Override + public void startUpdateBatchInputTimer(final PointerTracker tracker) { + if (mGestureRecognitionUpdateTime <= 0) { + return; + } + removeMessages(MSG_UPDATE_BATCH_INPUT, tracker); + sendMessageDelayed(obtainMessage(MSG_UPDATE_BATCH_INPUT, tracker), + mGestureRecognitionUpdateTime); + } + + @Override + public void cancelAllUpdateBatchInputTimers() { + removeMessages(MSG_UPDATE_BATCH_INPUT); + } + public void cancelAllMessages() { cancelKeyTimers(); + cancelAllUpdateBatchInputTimers(); } } diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java index 9c450e994..a698b0bd8 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java @@ -26,6 +26,7 @@ import android.widget.PopupWindow; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.CoordinateUtils; import com.android.inputmethod.latin.InputPointers; import com.android.inputmethod.latin.R; @@ -34,7 +35,7 @@ import com.android.inputmethod.latin.R; * detecting key presses and touch movements. */ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel { - private final int[] mCoordinates = new int[2]; + private final int[] mCoordinates = CoordinateUtils.newInstance(); private final KeyDetector mKeyDetector; @@ -169,7 +170,7 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys window.setHeight(container.getMeasuredHeight()); parentView.getLocationInWindow(mCoordinates); window.showAtLocation(parentView, Gravity.NO_GRAVITY, - x + mCoordinates[0], y + mCoordinates[1]); + x + CoordinateUtils.x(mCoordinates), y + CoordinateUtils.y(mCoordinates)); mOriginX = x + container.getPaddingLeft(); mOriginY = y + container.getPaddingTop(); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index c8052af6a..296a45faf 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -94,6 +94,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element { public void cancelDoubleTapTimer(); public boolean isInDoubleTapTimeout(); public void cancelKeyTimers(); + public void startUpdateBatchInputTimer(PointerTracker tracker); + public void cancelAllUpdateBatchInputTimers(); public static class Adapter implements TimerProxy { @Override @@ -116,6 +118,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element { public boolean isInDoubleTapTimeout() { return false; } @Override public void cancelKeyTimers() {} + @Override + public void startUpdateBatchInputTimer(PointerTracker tracker) {} + @Override + public void cancelAllUpdateBatchInputTimers() {} } } @@ -705,25 +711,36 @@ public final class PointerTracker implements PointerTrackerQueue.Element { mDrawingProxy.showGesturePreviewTrail(this, isOldestTrackerInQueue(this)); } + public void updateBatchInputByTimer(final long eventTime) { + final int gestureTime = (int)(eventTime - sGestureFirstDownTime); + mGestureStrokeWithPreviewPoints.duplicateLastPointWith(gestureTime); + updateBatchInput(eventTime); + } + private void mayUpdateBatchInput(final long eventTime, final Key key) { if (key != null) { - synchronized (sAggregratedPointers) { - final GestureStroke stroke = mGestureStrokeWithPreviewPoints; - stroke.appendIncrementalBatchPoints(sAggregratedPointers); - final int size = sAggregratedPointers.getPointerSize(); - if (size > sLastRecognitionPointSize - && stroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) { - sLastRecognitionPointSize = size; - sLastRecognitionTime = eventTime; - if (DEBUG_LISTENER) { - Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", - mPointerId, size)); - } - mListener.onUpdateBatchInput(sAggregratedPointers); + updateBatchInput(eventTime); + } + mDrawingProxy.showGesturePreviewTrail(this, isOldestTrackerInQueue(this)); + } + + private void updateBatchInput(final long eventTime) { + synchronized (sAggregratedPointers) { + final GestureStroke stroke = mGestureStrokeWithPreviewPoints; + stroke.appendIncrementalBatchPoints(sAggregratedPointers); + final int size = sAggregratedPointers.getPointerSize(); + if (size > sLastRecognitionPointSize + && stroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) { + sLastRecognitionPointSize = size; + sLastRecognitionTime = eventTime; + if (DEBUG_LISTENER) { + Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId, + size)); } + mTimerProxy.startUpdateBatchInputTimer(this); + mListener.onUpdateBatchInput(sAggregratedPointers); } } - mDrawingProxy.showGesturePreviewTrail(this, isOldestTrackerInQueue(this)); } private void mayEndBatchInput(final long eventTime) { @@ -737,6 +754,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { Log.d(TAG, String.format("[%d] onEndBatchInput : batchPoints=%d", mPointerId, sAggregratedPointers.getPointerSize())); } + mTimerProxy.cancelAllUpdateBatchInputTimers(); mListener.onEndBatchInput(sAggregratedPointers); } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java index 699aaeaef..80562cb2c 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java @@ -19,7 +19,6 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; -import android.graphics.RectF; import android.os.SystemClock; import com.android.inputmethod.latin.Constants; @@ -118,98 +117,7 @@ final class GesturePreviewTrail { / params.mTrailLingerDuration, 0.0f); } - static final class WorkingSet { - // Input - // Previous point (P1) coordinates and trail radius. - public float p1x, p1y; - public float r1; - // Current point (P2) coordinates and trail radius. - public float p2x, p2y; - public float r2; - - // Output - // Closing point of arc at P1. - public float p1ax, p1ay; - // Opening point of arc at P1. - public float p1bx, p1by; - // Opening point of arc at P2. - public float p2ax, p2ay; - // Closing point of arc at P2. - public float p2bx, p2by; - // Start angle of the trail arcs. - public float aa; - // Sweep angle of the trail arc at P1. - public float a1; - public RectF arc1 = new RectF(); - // Sweep angle of the trail arc at P2. - public float a2; - public RectF arc2 = new RectF(); - } - - private static final float RIGHT_ANGLE = (float)(Math.PI / 2.0d); - private static final float RADIAN_TO_DEGREE = (float)(180.0d / Math.PI); - - private static boolean calculatePathPoints(final WorkingSet w) { - final float dx = w.p2x - w.p1x; - final float dy = w.p2y - w.p1y; - // Distance of the points. - final double l = Math.hypot(dx, dy); - if (Double.compare(0.0d, l) == 0) { - return false; - } - // Angle of the line p1-p2 - final float a = (float)Math.atan2(dy, dx); - // Difference of trail cap radius. - final float dr = w.r2 - w.r1; - // Variation of angle at trail cap. - final float ar = (float)Math.asin(dr / l); - // The start angle of trail cap arc at P1. - final float aa = a - (RIGHT_ANGLE + ar); - // The end angle of trail cap arc at P2. - final float ab = a + (RIGHT_ANGLE + ar); - final float cosa = (float)Math.cos(aa); - final float sina = (float)Math.sin(aa); - final float cosb = (float)Math.cos(ab); - final float sinb = (float)Math.sin(ab); - w.p1ax = w.p1x + w.r1 * cosa; - w.p1ay = w.p1y + w.r1 * sina; - w.p1bx = w.p1x + w.r1 * cosb; - w.p1by = w.p1y + w.r1 * sinb; - w.p2ax = w.p2x + w.r2 * cosa; - w.p2ay = w.p2y + w.r2 * sina; - w.p2bx = w.p2x + w.r2 * cosb; - w.p2by = w.p2y + w.r2 * sinb; - w.aa = aa * RADIAN_TO_DEGREE; - final float ar2degree = ar * 2.0f * RADIAN_TO_DEGREE; - w.a1 = -180.0f + ar2degree; - w.a2 = 180.0f + ar2degree; - w.arc1.set(w.p1x, w.p1y, w.p1x, w.p1y); - w.arc1.inset(-w.r1, -w.r1); - w.arc2.set(w.p2x, w.p2y, w.p2x, w.p2y); - w.arc2.inset(-w.r2, -w.r2); - return true; - } - - private static void createPath(final Path path, final WorkingSet w) { - path.rewind(); - // Trail cap at P1. - path.moveTo(w.p1x, w.p1y); - path.arcTo(w.arc1, w.aa, w.a1); - // Trail cap at P2. - path.moveTo(w.p2x, w.p2y); - path.arcTo(w.arc2, w.aa, w.a2); - // Two trapezoids connecting P1 and P2. - path.moveTo(w.p1ax, w.p1ay); - path.lineTo(w.p1x, w.p1y); - path.lineTo(w.p1bx, w.p1by); - path.lineTo(w.p2bx, w.p2by); - path.lineTo(w.p2x, w.p2y); - path.lineTo(w.p2ax, w.p2ay); - path.close(); - } - - private final WorkingSet mWorkingSet = new WorkingSet(); - private final Path mPath = new Path(); + private final RoundedLine mRoundedLine = new RoundedLine(); /** * Draw gesture preview trail @@ -243,36 +151,35 @@ final class GesturePreviewTrail { if (startIndex < trailSize) { paint.setColor(params.mTrailColor); paint.setStyle(Paint.Style.FILL); - final Path path = mPath; - final WorkingSet w = mWorkingSet; - w.p1x = getXCoordValue(xCoords[startIndex]); - w.p1y = yCoords[startIndex]; + final RoundedLine line = mRoundedLine; + int p1x = getXCoordValue(xCoords[startIndex]); + int p1y = yCoords[startIndex]; int lastTime = sinceDown - eventTimes[startIndex]; float maxWidth = getWidth(lastTime, params); - w.r1 = maxWidth / 2.0f; + float r1 = maxWidth / 2.0f; // Initialize bounds rectangle. - outBoundsRect.set((int)w.p1x, (int)w.p1y, (int)w.p1x, (int)w.p1y); + outBoundsRect.set(p1x, p1y, p1x, p1y); for (int i = startIndex + 1; i < trailSize - 1; i++) { final int elapsedTime = sinceDown - eventTimes[i]; - w.p2x = getXCoordValue(xCoords[i]); - w.p2y = yCoords[i]; + final int p2x = getXCoordValue(xCoords[i]); + final int p2y = yCoords[i]; + final float width = getWidth(elapsedTime, params); + final float r2 = width / 2.0f; // Draw trail line only when the current point isn't a down point. if (!isDownEventXCoord(xCoords[i])) { final int alpha = getAlpha(elapsedTime, params); paint.setAlpha(alpha); - final float width = getWidth(elapsedTime, params); - w.r2 = width / 2.0f; - if (calculatePathPoints(w)) { - createPath(path, w); + final Path path = line.makePath(p1x, p1y, r1, p2x, p2y, r2); + if (path != null) { canvas.drawPath(path, paint); - outBoundsRect.union((int)w.p2x, (int)w.p2y); + outBoundsRect.union(p2x, p2y); } // Take union for the bounds. maxWidth = Math.max(maxWidth, width); } - w.p1x = w.p2x; - w.p1y = w.p2y; - w.r1 = w.r2; + p1x = p2x; + p1y = p2y; + r1 = r2; lastTime = elapsedTime; } // Take care of trail line width. diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java index aab14e968..a43e94a75 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java @@ -228,6 +228,17 @@ public class GestureStroke { return isStartOfAGesture; } + public void duplicateLastPointWith(final int time) { + final int lastIndex = mEventTimes.getLength() - 1; + if (lastIndex >= 0) { + final int x = mXCoordinates.get(lastIndex); + final int y = mYCoordinates.get(lastIndex); + // TODO: Have appendMajorPoint() + appendPoint(x, y, time); + updateIncrementalRecognitionSize(x, y, time); + } + } + protected void reset() { mIncrementalRecognitionSize = 0; mLastIncrementalBatchSize = 0; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 804a34b81..25a1c6a00 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -486,6 +486,11 @@ public final class KeyboardState { // After chording input while normal state. setShifted(UNSHIFT); } + // After chording input, automatic shift state may have been changed depending on + // what characters were input. + mShiftKeyState.onRelease(); + mSwitchActions.requestUpdatingShiftState(); + return; } else if (mAlphabetShiftState.isShiftLockShifted() && withSliding) { // In shift locked state, shift has been pressed and slid out to other key. setShiftLocked(true); diff --git a/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java b/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java new file mode 100644 index 000000000..1f5252077 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java @@ -0,0 +1,103 @@ +/* + * 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.graphics.Path; +import android.graphics.RectF; + +public final class RoundedLine { + private final RectF mArc1 = new RectF(); + private final RectF mArc2 = new RectF(); + private final Path mPath = new Path(); + + private static final double RADIAN_TO_DEGREE = 180.0d / Math.PI; + private static final double RIGHT_ANGLE = Math.PI / 2.0d; + + /** + * Make a rounded line path + * + * @param p1x the x-coordinate of the start point. + * @param p1y the y-coordinate of the start point. + * @param r1 the radius at the start point + * @param p2x the x-coordinate of the end point. + * @param p2y the y-coordinate of the end point. + * @param r2 the radius at the end point + * @return the path of rounded line + */ + public Path makePath(final float p1x, final float p1y, final float r1, + final float p2x, final float p2y, final float r2) { + final double dx = p2x - p1x; + final double dy = p2y - p1y; + // Distance of the points. + final double l = Math.hypot(dx, dy); + if (Double.compare(0.0d, l) == 0) { + return null; + } + // Angle of the line p1-p2 + final double a = Math.atan2(dy, dx); + // Difference of trail cap radius. + final double dr = r2 - r1; + // Variation of angle at trail cap. + final double ar = Math.asin(dr / l); + // The start angle of trail cap arc at P1. + final double aa = a - (RIGHT_ANGLE + ar); + // The end angle of trail cap arc at P2. + final double ab = a + (RIGHT_ANGLE + ar); + final float cosa = (float)Math.cos(aa); + final float sina = (float)Math.sin(aa); + final float cosb = (float)Math.cos(ab); + final float sinb = (float)Math.sin(ab); + // Closing point of arc at P1. + final float p1ax = p1x + r1 * cosa; + final float p1ay = p1y + r1 * sina; + // Opening point of arc at P1. + final float p1bx = p1x + r1 * cosb; + final float p1by = p1y + r1 * sinb; + // Opening point of arc at P2. + final float p2ax = p2x + r2 * cosa; + final float p2ay = p2y + r2 * sina; + // Closing point of arc at P2. + final float p2bx = p2x + r2 * cosb; + final float p2by = p2y + r2 * sinb; + // Start angle of the trail arcs. + final float angle = (float)(aa * RADIAN_TO_DEGREE); + final float ar2degree = (float)(ar * 2.0d * RADIAN_TO_DEGREE); + // Sweep angle of the trail arc at P1. + final float a1 = -180.0f + ar2degree; + // Sweep angle of the trail arc at P2. + final float a2 = 180.0f + ar2degree; + mArc1.set(p1x, p1y, p1x, p1y); + mArc1.inset(-r1, -r1); + mArc2.set(p2x, p2y, p2x, p2y); + mArc2.inset(-r2, -r2); + + mPath.rewind(); + // Trail cap at P1. + mPath.moveTo(p1x, p1y); + mPath.arcTo(mArc1, angle, a1); + // Trail cap at P2. + mPath.moveTo(p2x, p2y); + mPath.arcTo(mArc2, angle, a2); + // Two trapezoids connecting P1 and P2. + mPath.moveTo(p1ax, p1ay); + mPath.lineTo(p1x, p1y); + mPath.lineTo(p1bx, p1by); + mPath.lineTo(p2bx, p2by); + mPath.lineTo(p2x, p2y); + mPath.lineTo(p2ax, p2ay); + mPath.close(); + return mPath; + } +} diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java index 96c08b3cd..08f08d24e 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java @@ -386,12 +386,11 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - RichInputMethodManager.init(getActivity()); + mPrefs = getPreferenceManager().getSharedPreferences(); + RichInputMethodManager.init(getActivity(), mPrefs); mRichImm = RichInputMethodManager.getInstance(); addPreferencesFromResource(R.xml.additional_subtype_settings); setHasOptionsMenu(true); - - mPrefs = getPreferenceManager().getSharedPreferences(); } @Override diff --git a/java/src/com/android/inputmethod/latin/CoordinateUtils.java b/java/src/com/android/inputmethod/latin/CoordinateUtils.java new file mode 100644 index 000000000..cd3177299 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/CoordinateUtils.java @@ -0,0 +1,39 @@ +/* + * 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.latin; + +public final class CoordinateUtils { + private static final int INDEX_X = 0; + private static final int INDEX_Y = 1; + private static final int ARRAY_SIZE = INDEX_Y + 1; + + private CoordinateUtils() { + // This utility class is not publicly instantiable. + } + + public static int[] newInstance() { + return new int[ARRAY_SIZE]; + } + + public static int x(final int[] coords) { + return coords[INDEX_X]; + } + + public static int y(final int[] coords) { + return coords[INDEX_Y]; + } +} diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index dc3ad4ff0..0b49659e3 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -403,33 +403,28 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @Override public void onCreate() { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - mPrefs = prefs; - LatinImeLogger.init(this, prefs); + mPrefs = PreferenceManager.getDefaultSharedPreferences(this); + mResources = getResources(); + + LatinImeLogger.init(this, mPrefs); if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.getInstance().init(this, prefs); + ResearchLogger.getInstance().init(this, mPrefs); } - RichInputMethodManager.init(this); + RichInputMethodManager.init(this, mPrefs); + mRichImm = RichInputMethodManager.getInstance(); SubtypeSwitcher.init(this); - KeyboardSwitcher.init(this, prefs); + KeyboardSwitcher.init(this, mPrefs); AccessibilityUtils.init(this); super.onCreate(); - mRichImm = RichInputMethodManager.getInstance(); mHandler.onCreate(); DEBUG = LatinImeLogger.sDBG; - final Resources res = getResources(); - mResources = res; - loadSettings(); - - mRichImm.setAdditionalInputMethodSubtypes(mCurrentSettings.getAdditionalSubtypes()); - initSuggest(); - mDisplayOrientation = res.getConfiguration().orientation; + mDisplayOrientation = mResources.getConfiguration().orientation; // Register to receive ringer mode change and network state change. // Also receive installation and removal of a dictionary pack. diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java index 63dfd3250..af0d61cc7 100644 --- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java +++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java @@ -19,6 +19,7 @@ package com.android.inputmethod.latin; import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE; import android.content.Context; +import android.content.SharedPreferences; import android.os.IBinder; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; @@ -49,19 +50,34 @@ public final class RichInputMethodManager { return sInstance; } - public static void init(final Context context) { - sInstance.initInternal(context); + public static void init(final Context context, final SharedPreferences prefs) { + sInstance.initInternal(context, prefs); + } + + private boolean isInitialized() { + return mImmWrapper != null; } private void checkInitialized() { - if (mImmWrapper == null) { + if (!isInitialized()) { throw new RuntimeException(TAG + " is used before initialization"); } } - private void initInternal(final Context context) { + private void initInternal(final Context context, final SharedPreferences prefs) { + if (isInitialized()) { + return; + } mImmWrapper = new InputMethodManagerCompatWrapper(context); mInputMethodInfoOfThisIme = getInputMethodInfoOfThisIme(context); + + // Initialize additional subtypes. + SubtypeLocale.init(context); + final String prefAdditionalSubtypes = SettingsValues.getPrefAdditionalSubtypes( + prefs, context.getResources()); + final InputMethodSubtype[] additionalSubtypes = + AdditionalSubtype.createAdditionalSubtypesArray(prefAdditionalSubtypes); + setAdditionalInputMethodSubtypes(additionalSubtypes); } public InputMethodManager getInputMethodManager() { diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d6daa0d26..8de64c1c9 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -22,7 +22,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.util.Log; import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.keyboard.internal.KeySpecParser; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; @@ -82,7 +81,6 @@ public final class SettingsValues { private final int mVibrationDurationSettingsRawValue; @SuppressWarnings("unused") // TODO: Use this private final float mKeypressSoundVolumeRawValue; - private final InputMethodSubtype[] mAdditionalSubtypes; public final boolean mGestureInputEnabled; public final boolean mGesturePreviewTrailEnabled; public final boolean mGestureFloatingPreviewTextEnabled; @@ -170,8 +168,6 @@ public final class SettingsValues { mAutoCorrectionThresholdRawValue); mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); - mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( - getPrefAdditionalSubtypes(prefs, res)); final boolean gestureInputEnabledByBuildConfig = res.getBoolean( R.bool.config_gesture_input_enabled_by_build_config); mGestureInputEnabled = gestureInputEnabledByBuildConfig @@ -375,10 +371,6 @@ public final class SettingsValues { return res.getBoolean(R.bool.config_use_fullscreen_mode); } - public InputMethodSubtype[] getAdditionalSubtypes() { - return mAdditionalSubtypes; - } - public static String getPrefAdditionalSubtypes(final SharedPreferences prefs, final Resources res) { final String predefinedPrefSubtypes = AdditionalSubtype.createPrefSubtypes( diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java index 6cdd9e2cd..8cc09f39b 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java @@ -34,6 +34,7 @@ import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.KeyEventHandler; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; +import com.android.inputmethod.latin.CoordinateUtils; import com.android.inputmethod.latin.R; /** @@ -41,7 +42,7 @@ import com.android.inputmethod.latin.R; * key presses and touch movements. */ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { - private final int[] mCoordinates = new int[2]; + private final int[] mCoordinates = CoordinateUtils.newInstance(); final KeyDetector mModalPanelKeyDetector; private final KeyDetector mSlidingPanelKeyDetector; @@ -163,7 +164,7 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP window.setHeight(container.getMeasuredHeight()); parentView.getLocationInWindow(mCoordinates); window.showAtLocation(parentView, Gravity.NO_GRAVITY, - x + mCoordinates[0], y + mCoordinates[1]); + x + CoordinateUtils.x(mCoordinates), y + CoordinateUtils.y(mCoordinates)); mOriginX = x + container.getPaddingLeft(); mOriginY = y + container.getPaddingTop(); |