Merge "Use private lock object instead of synchronized method"
This commit is contained in:
commit
12e77de212
1 changed files with 31 additions and 22 deletions
|
@ -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,14 +1583,17 @@ 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) {
|
||||||
|
synchronized (mLock) {
|
||||||
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
||||||
mLatinIme = latinIme;
|
mLatinIme = latinIme;
|
||||||
mInBatchInput = true;
|
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) {
|
||||||
|
synchronized (mLock) {
|
||||||
if (!mInBatchInput) {
|
if (!mInBatchInput) {
|
||||||
// Batch input has ended or canceled while the message was being delivered.
|
// Batch input has ended or canceled while the message was being delivered.
|
||||||
return;
|
return;
|
||||||
|
@ -1598,6 +1602,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
||||||
suggestedWords, false /* dismissGestureFloatingPreviewText */);
|
suggestedWords, false /* dismissGestureFloatingPreviewText */);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run in the UI thread.
|
// Run in the UI thread.
|
||||||
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
||||||
|
@ -1609,20 +1614,24 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
.sendToTarget();
|
.sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void onCancelBatchInput() {
|
public void onCancelBatchInput() {
|
||||||
|
synchronized (mLock) {
|
||||||
mInBatchInput = false;
|
mInBatchInput = false;
|
||||||
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
||||||
SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */);
|
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) {
|
||||||
|
synchronized (mLock) {
|
||||||
mInBatchInput = false;
|
mInBatchInput = false;
|
||||||
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
|
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
|
||||||
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
||||||
suggestedWords, true /* dismissGestureFloatingPreviewText */);
|
suggestedWords, true /* dismissGestureFloatingPreviewText */);
|
||||||
return suggestedWords;
|
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
|
||||||
// be synchronized.
|
// be synchronized.
|
||||||
|
|
Loading…
Reference in a new issue