“This is the first day of my participation in the First Challenge 2022. For details: First Challenge 2022”

The origin of the story

There is a medical system, similar to the ordering system in restaurants, that uses the APP as the launcher(Android desktop launcher). Such systems generally require that you can’t jump out of the APP, and hide the status bar at the top and the navigation bar at the bottom. After all, the system’s back and home buttons are definitely not accessible to users. At present, there is a problem, 5.1 and later Android system, its built-in input method (i.e., pre-installed input method) does not support Chinese, but users need Chinese input, solution:

  1. Use a third-party input method
  2. Write your own input method

Choose Route 1 and use the third-party input method. According to the third-party input method research, there are a variety of input methods on the market with various functions. There is always a button that can make users who use input methods jump out of the APP. Take Google Pinyin input method as an example, Settings – upper right button – Introduction – terms of service, will be adjusted up the system browser (that is, out of the APP); Settings – dictionary – edit custom phrase, enter the page without the back key to return to APP and so on. Solutions:

  1. Use xposed to intercept the intent request of the input method, prohibit each other to tune up the browser and enter the interface of editing custom phrase.
  2. Choose option 2 and write your own input method

Xposed intercepts the intent for the input method. This article only discusses custom input methods.

Knowledge reserves

Before we start customizing input methods, we need to clarify a few concepts.

1. About the built-in input method of Android system

In the /packages/inputmethods directory of the source code, you can see the built-in inputmethods for ANDROID.

As shown in the figure below, 4.4 has three built-in input methods, namely LatinIME, PinyinIME and OpenWnn.

Since 5.1, there are only LatinIME and OpenWnn, and PinyinIME(Chinese input method) support has been dropped.

  • OpenWnn is an open source input method framework developed by a Japanese company, involving Chinese, Japanese and Korean. So when you open a emulator, you’ll find a Japanese iMe input method with the service name OpenWnn. This is the Japanese input method for OpenWNN.
  • LatinIME virtual keyboard
  • PinyinIMEGoogle pinyin input method

In addition, there is a built-in Leanback IME input method developed by Google for AndroidTV. AndroidTV is completely different.) For details on AndroidTV Input support, see here: onscreen Keyboard, Android Input

2. About AOSP

AOSP related entry

AOSP project library on Github

When viewing the built-in input method in Android, you can see the word AOSP. What is AOSP?

First of all, we need to clarify a concept. What is the AOSP? Android is a Linux-based, open-source, Google-led system designed primarily for touch-screen mobile devices such as smartphones and tablets. It was launched in November 2007 and the first commercial Android device was released in September 2008. It is free and Open Source software, and its Source code is called the Android Open Source Project, or AOSP, as we just mentioned.

In other words, the source code for Android is AOSP. Then Android source code built in those input methods can be called AOSP input methods, such as LatinIME, PinyinIME, OpenWnn.

3. About GMS

This title is a bit far, and the input method has no relationship, pure record. As mentioned above, Android’s source code is AOSP, but what about customized Android operating systems like Google and Huawei and Xiaomi? Well, most Android devices come with pre-installed proprietary software in addition to AOSP, most notably Google Mobile Services (GMS), which includes core applications such as Google Chrome, Digital distribution platform Google Play and related Google Play service development platform.

Strictly speaking, Android=AOSP+GMS. Due to some reasons, GMS cannot be used in China, so all kinds of customized ROMs in China are customized modifications of AOSP plus their own mobile services, such as MIUI and ColorOS.

Solve the problem: create an input method

Input method development has two parts to do, one is to integrate with the input method framework provided by the operating system, and the other is to convert the user’s input string into a list of output candidate words.

public class KeyboardLayout extends LinearLayout { private KeyboardView mKeyboardView; private Keyboard mKeyboard; public KeyboardLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initKeyboard(context, attrs); } private void initKeyboard(Context context, AttributeSet attrs){ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.keyboard); If (a.hasValue(r.tyleable.keyboard_xml)) {// Get the layout of the keyboard from the XML file int Xmlid = A.geresourceId (r.tyleable.keyboard_xml,0); mKeyboard = new Keyboard(context, xmlid); mKeyboardView = (KeyboardView)LayoutInflater.from(context).inflate(R.layout.keyboardview, null); / / set a custom keyboard layout for keyboard view mKeyboardView. SetKeyboard (mKeyboard); mKeyboardView.setEnabled(true); mKeyboardView.setPreviewEnabled(false); addView(mKeyboardView); }}}Copy the code