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

Commit b5c2092c authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android (Google) Code Review
Browse files

Merge "Notify commitText event to InputMethodManagerService"

parents 3aab4962 d7443c83
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -601,6 +601,10 @@ public class BaseInputConnection implements InputConnection {
        }
        
        beginBatchEdit();
        if (!composing && !TextUtils.isEmpty(text)) {
            // Notify the text is committed by the user to InputMethodManagerService
            mIMM.notifyTextCommitted();
        }

        // delete composing text set previously.
        int a = getComposingSpanStart(content);
+14 −0
Original line number Diff line number Diff line
@@ -1804,6 +1804,20 @@ public final class InputMethodManager {
        }
    }

    /**
     * Notify the current IME commits text
     * @hide
     */
    public void notifyTextCommitted() {
        synchronized (mH) {
            try {
                mService.notifyTextCommitted();
            } catch (RemoteException e) {
                Log.w(TAG, "IME died: " + mCurId, e);
            }
        }
    }

    /**
     * Returns a map of all shortcut input method info and their subtypes.
     */
+65 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.inputmethod;

import android.util.Slog;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;

import java.util.ArrayDeque;

/**
 * InputMethodSubtypeSwitchingController controls the switching behavior of the subtypes.
 */
public class InputMethodSubtypeSwitchingController {
    private static final String TAG = InputMethodSubtypeSwitchingController.class.getSimpleName();
    private static final boolean DEBUG = false;
    private static final int MAX_HISTORY_SIZE = 4;
    private static class SubtypeParams {
        public final InputMethodInfo mImi;
        public final InputMethodSubtype mSubtype;
        public final long mTime;
        public SubtypeParams(InputMethodInfo imi, InputMethodSubtype subtype) {
            mImi = imi;
            mSubtype = subtype;
            mTime = System.currentTimeMillis();
        }
    }

    private final ArrayDeque<SubtypeParams> mTypedSubtypeHistory = new ArrayDeque<SubtypeParams>();

    // TODO: write unit tests for this method and the logic that determines the next subtype
    public void onCommitText(InputMethodInfo imi, InputMethodSubtype subtype) {
        synchronized(mTypedSubtypeHistory) {
            if (subtype == null) {
                Slog.w(TAG, "Invalid InputMethodSubtype: " + imi.getId() + ", " + subtype);
                return;
            }
            if (DEBUG) {
                Slog.d(TAG, "onCommitText: " + imi.getId() + ", " + subtype);
            }
            if (!imi.supportsSwitchingToNextInputMethod()) {
                Slog.w(TAG, imi.getId() + " doesn't support switching to next input method.");
                return;
            }
            if (mTypedSubtypeHistory.size() >= MAX_HISTORY_SIZE) {
                mTypedSubtypeHistory.poll();
            }
            mTypedSubtypeHistory.addFirst(new SubtypeParams(imi, subtype));
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -75,4 +75,5 @@ interface IInputMethodManager {
    boolean setInputMethodEnabled(String id, boolean enabled);
    oneway void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
    int getInputMethodWindowVisibleHeight();
    oneway void notifyTextCommitted();
}
+14 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.server;

import com.android.internal.content.PackageMonitor;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
import com.android.internal.inputmethod.InputMethodUtils;
import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
import com.android.internal.os.HandlerCaller;
@@ -179,6 +180,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>();
    private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans =
            new LruCache<SuggestionSpan, InputMethodInfo>(SECURE_SUGGESTION_SPANS_MAX_SIZE);
    private final InputMethodSubtypeSwitchingController mSwitchingController =
            new InputMethodSubtypeSwitchingController();

    // Used to bring IME service up to visible adjustment while it is being shown.
    final ServiceConnection mVisibleConnection = new ServiceConnection() {
@@ -2242,6 +2245,17 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        return mWindowManagerService.getInputMethodWindowVisibleHeight();
    }

    @Override
    public void notifyTextCommitted() {
        if (DEBUG) {
            Slog.d(TAG, "Got the notification of commitText");
        }
        final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
        if (imi != null) {
            mSwitchingController.onCommitText(imi, mCurrentSubtype);
        }
    }

    private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
        synchronized (mMethodMap) {
            if (token == null) {