Plumbing for ProductionFlag.USES_CURSOR_ANCHOR_MONITOR
With this CL, LatinIME starts calling InputMethodService#setCursorAnchorMonitorMode in #onStartInput() when ProductionFlag.USES_CURSOR_ANCHOR_MONITOR flag is explicitly set to true. BUG: 13891796 Change-Id: Ib2fb0c3521b61859d4cc530155ccaaee7ee16cbcmain
parent
a4ac18551f
commit
fab4ce43f8
|
@ -17,11 +17,12 @@
|
|||
package com.android.inputmethod.compat;
|
||||
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class InputMethodServiceCompatUtils {
|
||||
// Note that InputMethodService.enableHardwareAcceleration() has been introduced
|
||||
// Note that {@link InputMethodService#enableHardwareAcceleration} has been introduced
|
||||
// in API level 17 (Build.VERSION_CODES.JELLY_BEAN_MR1).
|
||||
private static final Method METHOD_enableHardwareAcceleration =
|
||||
CompatUtils.getMethod(InputMethodService.class, "enableHardwareAcceleration");
|
||||
|
@ -34,4 +35,30 @@ public final class InputMethodServiceCompatUtils {
|
|||
return (Boolean)CompatUtils.invoke(ims, false /* defaultValue */,
|
||||
METHOD_enableHardwareAcceleration);
|
||||
}
|
||||
|
||||
public static void setCursorAnchorMonitorMode(final InputMethodService ims, final int mode) {
|
||||
if (ProductionFlag.USES_CURSOR_ANCHOR_MONITOR) {
|
||||
ExperimentalAPIUtils.setCursorAnchorMonitorMode(ims, mode);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* For unreleased APIs. ProGuard will strip this class entirely, unless used explicitly.
|
||||
*/
|
||||
private static final class ExperimentalAPIUtils {
|
||||
// Note that {@link InputMethodManager#setCursorAnchorMonitorMode} is not yet available as
|
||||
// an official API as of API level 19 (Build.VERSION_CODES.KITKAT).
|
||||
private static final Method METHOD_setCursorAnchorMonitorMode = CompatUtils.getMethod(
|
||||
InputMethodService.class, "setCursorAnchorMonitorMode", int.class);
|
||||
|
||||
private ExperimentalAPIUtils() {
|
||||
// This utility class is not publicly instantiable.
|
||||
}
|
||||
|
||||
public static void setCursorAnchorMonitorMode(final InputMethodService ims,
|
||||
final int mode) {
|
||||
CompatUtils.invoke(ims, null /* defaultValue */,
|
||||
METHOD_setCursorAnchorMonitorMode, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -366,6 +366,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
if (latinIme != null) {
|
||||
executePendingImsCallback(latinIme, editorInfo, restarting);
|
||||
latinIme.onStartInputInternal(editorInfo, restarting);
|
||||
if (ProductionFlag.USES_CURSOR_ANCHOR_MONITOR) {
|
||||
// Currently we need to call this every time when the IME is attached to
|
||||
// new application.
|
||||
// TODO: Consider if we can do this automatically in the framework.
|
||||
InputMethodServiceCompatUtils.setCursorAnchorMonitorMode(latinIme, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -923,6 +929,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
mSubtypeState.currentSubtypeUsed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCursor(Rect rect) {
|
||||
if (DEBUG) {
|
||||
Log.i(TAG, "onUpdateCursor:" + rect.toShortString());
|
||||
}
|
||||
super.onUpdateCursor(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the user has clicked on the extracted text view,
|
||||
* when running in fullscreen mode. The default implementation hides
|
||||
|
|
Loading…
Reference in New Issue