am 1bebdcb4: Move RingCharBuffer as a singleton in Util

Merge commit '1bebdcb4e422c0d9e52833dfd3bc0a8b9e07a266' into gingerbread-plus-aosp

* commit '1bebdcb4e422c0d9e52833dfd3bc0a8b9e07a266':
  Move RingCharBuffer as a singleton in Util
main
satok 2010-09-24 00:32:45 -07:00 committed by Android Git Automerger
commit 27bddbe67f
3 changed files with 92 additions and 2 deletions

View File

@ -16,6 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.latin.LatinIMEUtil.RingCharBuffer;
import com.android.inputmethod.voice.FieldContext; import com.android.inputmethod.voice.FieldContext;
import com.android.inputmethod.voice.SettingsUtil; import com.android.inputmethod.voice.SettingsUtil;
import com.android.inputmethod.voice.VoiceInput; import com.android.inputmethod.voice.VoiceInput;
@ -1197,7 +1198,8 @@ public class LatinIME extends InputMethodService
if (primaryCode != KEYCODE_ENTER) { if (primaryCode != KEYCODE_ENTER) {
mJustAddedAutoSpace = false; mJustAddedAutoSpace = false;
} }
LatinImeLogger.logOnInputChar((char)primaryCode, x, y); RingCharBuffer.getInstance().push((char)primaryCode, x, y);
LatinImeLogger.logOnInputChar();
if (isWordSeparator(primaryCode)) { if (isWordSeparator(primaryCode)) {
handleSeparator(primaryCode); handleSeparator(primaryCode);
} else { } else {

View File

@ -80,4 +80,92 @@ public class LatinIMEUtil {
return ((InputMethodManager) context.getSystemService( return ((InputMethodManager) context.getSystemService(
Context.INPUT_METHOD_SERVICE)).getEnabledInputMethodList().size() > 1; Context.INPUT_METHOD_SERVICE)).getEnabledInputMethodList().size() > 1;
} }
/* package */ static class RingCharBuffer {
private static RingCharBuffer sRingCharBuffer = new RingCharBuffer();
private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC';
private static final int INVALID_COORDINATE = -2;
/* package */ static final int BUFSIZE = 20;
private Context mContext;
private boolean mEnabled = false;
private int mEnd = 0;
/* package */ int mLength = 0;
private char[] mCharBuf = new char[BUFSIZE];
private int[] mXBuf = new int[BUFSIZE];
private int[] mYBuf = new int[BUFSIZE];
private RingCharBuffer() {
}
public static RingCharBuffer getInstance() {
return sRingCharBuffer;
}
public static RingCharBuffer init(Context context, boolean enabled) {
sRingCharBuffer.mContext = context;
sRingCharBuffer.mEnabled = enabled;
return sRingCharBuffer;
}
private int normalize(int in) {
int ret = in % BUFSIZE;
return ret < 0 ? ret + BUFSIZE : ret;
}
public void push(char c, int x, int y) {
if (!mEnabled) return;
mCharBuf[mEnd] = c;
mXBuf[mEnd] = x;
mYBuf[mEnd] = y;
mEnd = normalize(mEnd + 1);
if (mLength < BUFSIZE) {
++mLength;
}
}
public char pop() {
if (mLength < 1) {
return PLACEHOLDER_DELIMITER_CHAR;
} else {
mEnd = normalize(mEnd - 1);
--mLength;
return mCharBuf[mEnd];
}
}
public char getLastChar() {
if (mLength < 1) {
return PLACEHOLDER_DELIMITER_CHAR;
} else {
return mCharBuf[normalize(mEnd - 1)];
}
}
public int getPreviousX(char c, int back) {
int index = normalize(mEnd - 2 - back);
if (mLength <= back
|| Character.toLowerCase(c) != Character.toLowerCase(mCharBuf[index])) {
return INVALID_COORDINATE;
} else {
return mXBuf[index];
}
}
public int getPreviousY(char c, int back) {
int index = normalize(mEnd - 2 - back);
if (mLength <= back
|| Character.toLowerCase(c) != Character.toLowerCase(mCharBuf[index])) {
return INVALID_COORDINATE;
} else {
return mYBuf[index];
}
}
public String getLastString() {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < mLength; ++i) {
char c = mCharBuf[normalize(mEnd - 1 - i)];
if (!((LatinIME)mContext).isWordSeparator(c)) {
sb.append(c);
} else {
break;
}
}
return sb.reverse().toString();
}
public void reset() {
mLength = 0;
}
}
} }

View File

@ -50,7 +50,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
public static void logOnDelete() { public static void logOnDelete() {
} }
public static void logOnInputChar(char c, int x, int y) { public static void logOnInputChar() {
} }
public static void logOnException(String metaData, Throwable e) { public static void logOnException(String metaData, Throwable e) {