diff options
Diffstat (limited to 'java/src')
7 files changed, 149 insertions, 117 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 296a45faf..c3cf49f3b 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -749,12 +749,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element { if (getActivePointerTrackerCount() == 1) { sInGesture = false; sTimeRecorder.onEndBatchInput(eventTime); + mTimerProxy.cancelAllUpdateBatchInputTimers(); if (!mIsTrackingCanceled) { if (DEBUG_LISTENER) { 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/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/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 0b49659e3..8519ad31d 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1464,7 +1464,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private static final class BatchInputUpdater implements Handler.Callback { private final Handler mHandler; private LatinIME mLatinIme; - private boolean mInBatchInput; // synchornized using "this". + private boolean mInBatchInput; // synchronized using "this". private BatchInputUpdater() { final HandlerThread handlerThread = new HandlerThread( @@ -1496,6 +1496,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Run in the UI thread. public synchronized void onStartBatchInput() { + mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP); mInBatchInput = true; } @@ -1503,7 +1504,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private synchronized void updateBatchInput(final InputPointers batchPointers, final LatinIME latinIme) { if (!mInBatchInput) { - // Batch input has ended while the message was being delivered. + // Batch input has ended or canceled while the message was being delivered. return; } final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked( @@ -1523,7 +1524,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction .sendToTarget(); } - public void onCancelBatchInput(final LatinIME latinIme) { + public synchronized void onCancelBatchInput(final LatinIME latinIme) { mInBatchInput = false; latinIme.mHandler.showGesturePreviewAndSuggestionStrip( SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */); diff --git a/java/src/com/android/inputmethod/research/MainLogBuffer.java b/java/src/com/android/inputmethod/research/MainLogBuffer.java index 745768d35..94dbf3960 100644 --- a/java/src/com/android/inputmethod/research/MainLogBuffer.java +++ b/java/src/com/android/inputmethod/research/MainLogBuffer.java @@ -16,16 +16,22 @@ package com.android.inputmethod.research; +import android.util.Log; + import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Suggest; import java.util.Random; public class MainLogBuffer extends LogBuffer { + private static final String TAG = MainLogBuffer.class.getSimpleName(); + // For privacy reasons, be sure to set to "false" for production code. + private static final boolean DEBUG = false; + // The size of the n-grams logged. E.g. N_GRAM_SIZE = 2 means to sample bigrams. private static final int N_GRAM_SIZE = 2; // The number of words between n-grams to omit from the log. - private static final int DEFAULT_NUMBER_OF_WORDS_BETWEEN_SAMPLES = 18; + private static final int DEFAULT_NUMBER_OF_WORDS_BETWEEN_SAMPLES = DEBUG ? 2 : 18; private final ResearchLog mResearchLog; private Suggest mSuggest; @@ -61,6 +67,9 @@ public class MainLogBuffer extends LogBuffer { mWordsUntilSafeToSample--; } } + if (DEBUG) { + Log.d(TAG, "shiftedIn " + (newLogUnit.hasWord() ? newLogUnit.getWord() : "")); + } } public void resetWordCounter() { diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index 6295abe8c..e9ffcd981 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -60,6 +60,7 @@ import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Dictionary; +import com.android.inputmethod.latin.InputTypeUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputConnection; @@ -687,7 +688,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang /* package for test */ void commitCurrentLogUnit() { if (DEBUG) { - Log.d(TAG, "commitCurrentLogUnit"); + Log.d(TAG, "commitCurrentLogUnit" + (mCurrentLogUnit.hasWord() ? + ": " + mCurrentLogUnit.getWord() : "")); } if (!mCurrentLogUnit.isEmpty()) { if (mMainLogBuffer != null) { @@ -791,8 +793,11 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang public static void latinIME_onStartInputViewInternal(final EditorInfo editorInfo, final SharedPreferences prefs) { final ResearchLogger researchLogger = getInstance(); - researchLogger.start(); if (editorInfo != null) { + final boolean isPassword = InputTypeUtils.isPasswordInputType(editorInfo.inputType) + || InputTypeUtils.isVisiblePasswordInputType(editorInfo.inputType); + getInstance().setIsPasswordView(isPassword); + researchLogger.start(); final Context context = researchLogger.mInputMethodService; try { final PackageInfo packageInfo; @@ -1059,7 +1064,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang keyboard.mOccupiedHeight, keyboard.mKeys }; - getInstance().setIsPasswordView(isPasswordView); getInstance().enqueueEvent(EVENTKEYS_MAINKEYBOARDVIEW_SETKEYBOARD, values); } } diff --git a/java/src/com/android/inputmethod/research/Statistics.java b/java/src/com/android/inputmethod/research/Statistics.java index 98491bd23..2065ab15e 100644 --- a/java/src/com/android/inputmethod/research/Statistics.java +++ b/java/src/com/android/inputmethod/research/Statistics.java @@ -16,9 +16,14 @@ package com.android.inputmethod.research; +import android.util.Log; + import com.android.inputmethod.latin.Constants; public class Statistics { + private static final String TAG = Statistics.class.getSimpleName(); + private static final boolean DEBUG = false; + // Number of characters entered during a typing session int mCharCount; // Number of letter characters entered during a typing session @@ -103,6 +108,9 @@ public class Statistics { } public void recordChar(int codePoint, long time) { + if (DEBUG) { + Log.d(TAG, "recordChar() called"); + } final long delta = time - mLastTapTime; if (codePoint == Constants.CODE_DELETE) { mDeleteKeyCount++; |