am 12e77de2: Merge "Use private lock object instead of synchronized method"

* commit '12e77de2128d836a53eb6cd3f96b939f71727241':
  Use private lock object instead of synchronized method
main
Tadashi G. Takaoka 2013-04-10 02:38:23 -07:00 committed by Android Git Automerger
commit 1502d97795
1 changed files with 31 additions and 22 deletions

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