Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7b7907f authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Allow IMEs to start/stop receiving onUpdateCursor callback

This CL introduces an API which allows IMEs to start/stop
receiving onUpdateCursor callback upon their request.

BUG: 13388665
Change-Id: I987326872def181dda5d9d701b762f088e0d9c39
parent 10a5ec23
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -12469,6 +12469,7 @@ package android.inputmethodservice {
    method public void setBackDisposition(int);
    method public void setCandidatesView(android.view.View);
    method public void setCandidatesViewShown(boolean);
    method public void setCursorAnchorMonitorMode(int);
    method public void setExtractView(android.view.View);
    method public void setExtractViewShown(boolean);
    method public void setInputView(android.view.View);
@@ -12480,6 +12481,8 @@ package android.inputmethodservice {
    field public static final int BACK_DISPOSITION_DEFAULT = 0; // 0x0
    field public static final int BACK_DISPOSITION_WILL_DISMISS = 2; // 0x2
    field public static final int BACK_DISPOSITION_WILL_NOT_DISMISS = 1; // 0x1
    field public static final int CURSOR_ANCHOR_MONITOR_MODE_CURSOR_RECT = 1; // 0x1
    field public static final int CURSOR_ANCHOR_MONITOR_MODE_NONE = 0; // 0x0
  }
  public class InputMethodService.InputMethodImpl extends android.inputmethodservice.AbstractInputMethodService.AbstractInputMethodImpl {
+17 −0
Original line number Diff line number Diff line
@@ -249,6 +249,16 @@ public class InputMethodService extends AbstractInputMethodService {
     */
    public static final int IME_VISIBLE = 0x2;

    /**
     * The IME does not require cursor/anchor position.
     */
    public static final int CURSOR_ANCHOR_MONITOR_MODE_NONE = 0x0;

    /**
     * The IME expects that {@link #onUpdateCursor(Rect)} is called back.
     */
    public static final int CURSOR_ANCHOR_MONITOR_MODE_CURSOR_RECT = 0x1;

    InputMethodManager mImm;
    
    int mTheme = 0;
@@ -1701,6 +1711,13 @@ public class InputMethodService extends AbstractInputMethodService {
        // Intentionally empty
    }

    /**
     * Update the cursor/anthor monitor mode.
     */
    public void setCursorAnchorMonitorMode(int monitorMode) {
        mImm.setCursorAnchorMonitorMode(mToken, monitorMode);
    }

    /**
     * Close this input method's soft input area, removing it from the display.
     * The input method will continue running, but the user can no longer use
+42 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.internal.view.InputBindResult;

import android.content.Context;
import android.graphics.Rect;
import android.inputmethodservice.InputMethodService;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -41,13 +42,13 @@ import android.util.Pools.Pool;
import android.util.Pools.SimplePool;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.SparseArray;
import android.view.InputChannel;
import android.view.InputEvent;
import android.view.InputEventSender;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewRootImpl;
import android.util.SparseArray;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -334,6 +335,11 @@ public final class InputMethodManager {
    InputChannel mCurChannel;
    ImeInputEventSender mCurSender;

    /**
     * The current cursor/anchor monitor mode.
     */
    int mCursorAnchorMonitorMode = InputMethodService.CURSOR_ANCHOR_MONITOR_MODE_NONE;

    final Pool<PendingEvent> mPendingEventPool = new SimplePool<PendingEvent>(20);
    final SparseArray<PendingEvent> mPendingEvents = new SparseArray<PendingEvent>(20);

@@ -346,6 +352,7 @@ public final class InputMethodManager {
    static final int MSG_SEND_INPUT_EVENT = 5;
    static final int MSG_TIMEOUT_INPUT_EVENT = 6;
    static final int MSG_FLUSH_INPUT_EVENT = 7;
    static final int SET_CURSOR_ANCHOR_MONITOR_MODE = 8;

    class H extends Handler {
        H(Looper looper) {
@@ -476,6 +483,12 @@ public final class InputMethodManager {
                    finishedInputEvent(msg.arg1, false, false);
                    return;
                }
                case SET_CURSOR_ANCHOR_MONITOR_MODE: {
                    synchronized (mH) {
                        mCursorAnchorMonitorMode = msg.arg1;
                    }
                    return;
                }
            }
        }
    }
@@ -540,6 +553,11 @@ public final class InputMethodManager {
        public void setActive(boolean active) {
            mH.sendMessage(mH.obtainMessage(MSG_SET_ACTIVE, active ? 1 : 0, 0));
        }

        @Override
        public void setCursorAnchorMonitorMode(int monitorMode) {
            mH.sendMessage(mH.obtainMessage(SET_CURSOR_ANCHOR_MONITOR_MODE, monitorMode, 0));
        }
    };

    final InputConnection mDummyInputConnection = new BaseInputConnection(this, false);
@@ -1465,8 +1483,29 @@ public final class InputMethodManager {
     * of the input editor's cursor in its window.
     */
    public boolean isWatchingCursor(View view) {
        if (!isActive(view)) {
            return false;
        }
        synchronized (mH) {
            return mCursorAnchorMonitorMode ==
                    InputMethodService.CURSOR_ANCHOR_MONITOR_MODE_CURSOR_RECT;
        }
    }

    /**
     * Set cursor/anchor monitor mode via {@link com.android.server.InputMethodManagerService}.
     * This is an internal method for {@link android.inputmethodservice.InputMethodService} and
     * should never be used from IMEs and applications.
     *
     * @hide
     */
    public void setCursorAnchorMonitorMode(IBinder imeToken, int monitorMode) {
        try {
            mService.setCursorAnchorMonitorMode(imeToken, monitorMode);
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Report the current cursor location in its window.
+1 −0
Original line number Diff line number Diff line
@@ -27,4 +27,5 @@ oneway interface IInputMethodClient {
    void onBindMethod(in InputBindResult res);
    void onUnbindMethod(int sequence);
    void setActive(boolean active);
    void setCursorAnchorMonitorMode(int monitorMode);
}
+1 −0
Original line number Diff line number Diff line
@@ -78,4 +78,5 @@ interface IInputMethodManager {
    void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
    int getInputMethodWindowVisibleHeight();
    oneway void notifyTextCommitted();
    void setCursorAnchorMonitorMode(in IBinder token, int monitorMode);
}
Loading