Merge "Use private lock object instead of synchronized method"

This commit is contained in:
Tadashi G. Takaoka 2013-04-10 09:35:11 +00:00 committed by Android (Google) Code Review
commit 12e77de212

View file

@ -1551,7 +1551,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private static final class BatchInputUpdater implements Handler.Callback { private static final class BatchInputUpdater implements Handler.Callback {
private final Handler mHandler; private final Handler mHandler;
private LatinIME mLatinIme; private LatinIME mLatinIme;
private boolean mInBatchInput; // synchronized using "this". private final Object mLock = new Object();
private boolean mInBatchInput; // synchronized using {@link #mLock}.
private BatchInputUpdater() { private BatchInputUpdater() {
final HandlerThread handlerThread = new HandlerThread( final HandlerThread handlerThread = new HandlerThread(
@ -1582,21 +1583,25 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
} }
// Run in the UI thread. // Run in the UI thread.
public synchronized void onStartBatchInput(final LatinIME latinIme) { public void onStartBatchInput(final LatinIME latinIme) {
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP); synchronized (mLock) {
mLatinIme = latinIme; mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
mInBatchInput = true; mLatinIme = latinIme;
mInBatchInput = true;
}
} }
// Run in the Handler thread. // Run in the Handler thread.
private synchronized void updateBatchInput(final InputPointers batchPointers) { private void updateBatchInput(final InputPointers batchPointers) {
if (!mInBatchInput) { synchronized (mLock) {
// Batch input has ended or canceled while the message was being delivered. if (!mInBatchInput) {
return; // Batch input has ended or canceled while the message was being delivered.
return;
}
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
suggestedWords, false /* dismissGestureFloatingPreviewText */);
} }
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
suggestedWords, false /* dismissGestureFloatingPreviewText */);
} }
// Run in the UI thread. // Run in the UI thread.
@ -1609,19 +1614,23 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
.sendToTarget(); .sendToTarget();
} }
public synchronized void onCancelBatchInput() { public void onCancelBatchInput() {
mInBatchInput = false; synchronized (mLock) {
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip( mInBatchInput = false;
SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */); mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */);
}
} }
// Run in the UI thread. // Run in the UI thread.
public synchronized SuggestedWords onEndBatchInput(final InputPointers batchPointers) { public SuggestedWords onEndBatchInput(final InputPointers batchPointers) {
mInBatchInput = false; synchronized (mLock) {
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers); mInBatchInput = false;
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip( final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
suggestedWords, true /* dismissGestureFloatingPreviewText */); mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
return suggestedWords; suggestedWords, true /* dismissGestureFloatingPreviewText */);
return suggestedWords;
}
} }
// {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to // {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to