Develop an input method for the Android platform

Source: Internet
Author: User

Objective:
1. Implement new input methods
Objective:
1. Master the android Input Method Framework
Learning gains:
One of the new features of Android 1.5 is the Input Method Framework (IMF), which makes it possible for devices without a keyboard. The IMF is designed to support different IME, including soft keyboard, hand-writing recognizes, and hard keyboard translators. Here, we lock the focus on the soft keyboard.
For general application developers, the new features should ensure that applications can cooperate well with the IMF to provide excellent user experience. The most important thing for an application is to use the new Android: inputtype attribute for each edittext. This attribute actually replaces many existing attributes, including Android: Password, Android: singleline, android: numeric, Android: phonenumber, Android: Capitalize, Android: AutoText, Android: editable. If both are declared, the cupcake device will use the new Android: inputtype attribute and ignore other attributes.
The main API is Android. View. inputmethod. inputmethodmanager, which can be obtained through the context. getsystemservice method. It allows you to interact with the global input method status, such as explicitly hiding or displaying the ime Input Method region.
New features for system developers, it provides an entrance for developing various language input methods. With it, other language input methods can be entered in Android. The following describes how to implement an input method.
To create an input method, you must inherit Android. inputmethodservice. inputmethodservice. This class provides the basic implementation of the input method, including status management, visible control input method, and communication with the current activity. Android provides two input methods and an example. These two input methods are pinyinime and latinime. You can find them in the source packages/inputmethods, for example, softkeyboard, you can find it under platforms/Android-1.5/samples in SDK 1.5. These three input methods provide the best reference for implementing the Android platform's input method.
The packaging method of the input method is the same as that of other applications. In androidmanifest. XML, you must declare the input method as service and attach the appropriate intent filter and related meta data. As follows:
<Service android: Name = ". demoime"
Android: Label = "@ string/ime_name"
Android: Permission = "android. Permission. bind_input_method">
<Intent-filter>
<Action Android: Name = "android. View. inputmethod"/>
</Intent-filter>
<Meta-data Android: Name = "android. View. Im" Android: Resource = "@ XML/method"/>
</Service>
If the input method allows you to adjust the settings, you should also provide a setting activity. At this time, do not forget to add relevant attributes to the XML file of input-method, as shown in the following figure (this file is @ XML/method in meta-data just now ):
<Input-method xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: settingsactivity = "com. Demo. settingsactivity"
Android: isdefault = "@ bool/im_is_default"/>
The input method has two main visible elements: Input view and candiate view. But this is not necessary. You can select the elements you need as needed. The input view is the place where the user inputs text from the keyboard, handwriting, or other methods. When the input method is displayed for the first time, inputmethodservice. oncreateinputview () is called. Candidates view is where the candidate vocabulary set appears. It is optional and can return null when inputmethodservice. oncreatecandidatesview is called.-This is its default behavior.
The input fields of an application can have different input types, including text, numeric values, URLs, email addresses, and search. Therefore, when implementing a new input method, you must be careful about different input types. The input method does not automatically switch between different input types, so you need to support all types in ime. However, it is easy to note that IME is not responsible for verifying the input content-because it is the responsibility of the application.
When inputmethodservice. onstartinputview () is called, an editorinfo object is passed in, which contains details about other attributes of the input type and text field. Editorinfo. inputtype and editorinfo. type_class_mask can be many values, including type_class_number, type_class_datetime, type_class_phone, and type_class_text. For more information, see Android. Text. inputtype.
To send text to an application, you can send a single button event or edit the text near the cursor in the text box of the application. To send a key event, you can simply construct a keyevent object and call inputconnection. sendkeyevent (), or use inputmethodservice. senddownupkeyevents (keyeventcode) to make it easier ). When editing a text box, Android. View. inputmethod. inputconnection has some useful methods, such as gettextbeforecursor.


From: http://topic.csdn.net/u/20101230/09/983c6c34-c9e3-4695-b804-b18ad146b219.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.