Files
android_development/samples/MultiClientInputMethod/src/com/example/android/multiclientinputmethod/SoftInputWindowManager.java
Yohei Yukawa eb0868906c Add a sample multi-client IME
This CL adds a sample multi-client IME.  Ahthough there are still many
limitations and missing features in this sample IME, this CL
demonstrates how a multi-client IME can be implemented.

Fix: 115784148
Test: prebuilts/checkstyle/checkstyle.py -f \
      development/samples/MultiClientInputMethod/
Test: Manually verified as follows:
  1. make -j MultiClientInputMethod
  2. adb install -r $OUT/system/priv-app/MultiClientInputMethod/MultiClientInputMethod.apk
  3. adb root
  4. adb shell setprop persist.debug.multi_client_ime \
       com.example.android.multiclientinputmethod/.MultiClientInputMethod
  5. adb reboot
  6. Try multiple text input scenario
Change-Id: Ide43e16448fa00355a2c08bc45ae94d98553da50
2018-11-12 15:09:07 -08:00

62 lines
2.2 KiB
Java

/*
* Copyright (C) 2018 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.example.android.multiclientinputmethod;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.inputmethodservice.MultiClientInputMethodServiceDelegate;
import android.os.IBinder;
import android.util.SparseArray;
import android.view.Display;
final class SoftInputWindowManager {
private final Context mContext;
private final MultiClientInputMethodServiceDelegate mDelegate;
private final SparseArray<SoftInputWindow> mSoftInputWindows = new SparseArray<>();
SoftInputWindowManager(Context context, MultiClientInputMethodServiceDelegate delegate) {
mContext = context;
mDelegate = delegate;
}
SoftInputWindow getOrCreateSoftInputWindow(int displayId) {
final SoftInputWindow existingWindow = mSoftInputWindows.get(displayId);
if (existingWindow != null) {
return existingWindow;
}
final Display display =
mContext.getSystemService(DisplayManager.class).getDisplay(displayId);
if (display == null) {
return null;
}
final IBinder windowToken = mDelegate.createInputMethodWindowToken(displayId);
if (windowToken == null) {
return null;
}
final Context displayContext = mContext.createDisplayContext(display);
final SoftInputWindow newWindow = new SoftInputWindow(displayContext, windowToken);
mSoftInputWindows.put(displayId, newWindow);
return newWindow;
}
SoftInputWindow getSoftInputWindow(int displayId) {
return mSoftInputWindows.get(displayId);
}
}