Android virtual buttons

Source: Internet
Author: User
Document directory
  • 1.1 underlying virtual buttons

 

Android virtual buttons

Android standard keyboards include home, menu, back, and search, but they must also be industrial. Nexus One is not implemented with a touch screen using common buttons,

The display screen is 800x480, but when the capacitive touch screen is 8xx * 480, the virtual button is changed to a place bigger than 800, simulating the android standard button.

1 Solution

To implement a virtual key, two layers of assistance are required in Android. The underlying layer requires that the virtual key be specified in a location greater than the display, such as the position and size of the virtual key and the key value, to the upper layer.

A file interface. The upper Java layer starts a service to read the key response of this region. This is a general architecture. The specific implementation is as follows:

1.1 underlying virtual buttons

In short, all the information of the virtual key is sent to the upper layer through the Sys File System in the kernel. The path of the Sys File System is agreed, so the code is as follows. The

The Protocol format is a continuous string. Each key has six items separated by a colon, and the keys are separated by a colon. The six items are separated by the following order:

Key type: key value: Key Area Center X coordinate: Key Area Center y coordinate: key area width: key area height

ARCH/ARM/Mach-MSM/board-mahimahi.c

static ssize_t mahimahi_virtual_keys_show(struct kobject *kobj,       struct kobj_attribute *attr, char *buf){if (system_rev > 2) {/* center: x: back: 55, menu: 172, home: 298, search 412, y: 835 */return sprintf(buf,__stringify(EV_KEY) ":" __stringify(KEY_BACK)  ":55:835:90:55"   ":" __stringify(EV_KEY) ":" __stringify(KEY_MENU)   ":172:835:125:55"   ":" __stringify(EV_KEY) ":" __stringify(KEY_HOME)   ":298:835:115:55"   ":" __stringify(EV_KEY) ":" __stringify(KEY_SEARCH) ":412:835:95:55"   "/n");} else {/* center: x: home: 55, menu: 185, back: 305, search 425, y: 835 */return sprintf(buf,__stringify(EV_KEY) ":" __stringify(KEY_HOME)  ":55:835:70:55"   ":" __stringify(EV_KEY) ":" __stringify(KEY_MENU)   ":185:835:100:55"   ":" __stringify(EV_KEY) ":" __stringify(KEY_BACK)   ":305:835:70:55"   ":" __stringify(EV_KEY) ":" __stringify(KEY_SEARCH) ":425:835:70:55"   "/n");}} static struct kobj_attribute mahimahi_virtual_keys_attr = {.attr = {.name = "virtualkeys.synaptics-rmi-touchscreen",.mode = S_IRUGO,},.show = &mahimahi_virtual_keys_show,}; static struct attribute *mahimahi_properties_attrs[] = {&mahimahi_virtual_keys_attr.attr,NULL}; static struct attribute_group mahimahi_properties_attr_group = {.attrs = mahimahi_properties_attrs,}; struct kobject *properties_kobj; properties_kobj = kobject_create_and_add("board_properties", NULL);if (properties_kobj)ret = sysfs_create_group(properties_kobj, &mahimahi_properties_attr_group);if (!properties_kobj || ret)pr_err("failed to create board_properties/n");

In the Android system, the touch screen device sends rawinputevent (original input event), and the key sends the keyevent ). Keyevent is directly sent to the application layer. rawinputevent is converted to motionevent in the Java framework of Android and sent to the application layer.

In Android, the implementation of virtual keys is: in some cases, rawinputevent is converted to keyevent.

The inputdevice. Java file in the frameworks/base/services/Java/COM/Android/Server Directory is responsible for processing the main files of virtual keys.

The processing of virtual keys is relatively simple. You need to configure the content of the virtual keys according to the following files:

  
  
  1. /sys/board_properties/virtualkeys.{devicename} 

In the inputdevice. Java file, use readvirtualkeys to convert messages. Convert rawinputevent to key-related content based on the configuration file.

Virtualkeys. {devicename} is an adaptation file for virtual keys. It must be in the/sys/board _ properties/directory of the target file system.

The format of the virtual key configuration file is as follows:

  
  
  1. 0x1: Scan code: X: Y: W: H: 0x1 :......

For example, you can view the configuration file of a virtual key on the mahimahi platform of MSM as follows:

  
  
  1. # cat /sys/board_properties/virtualkeys.synaptics-rmi-touchscreen  
  2. 0x01:158:55:835:90:55:0x01:139:172:835:125:55:
    0x01:102:298:835:115:55:0x01:217:412:835:95:55 

It can be seen that the virtual buttons of the four areas are defined, and their Y coordinates are the same. It can be seen that the rectangular areas of the four buttons are in a horizontal row. The scanned code for conversion is 158,139,102,217, which corresponds to the back (return), menu (menu), Home (Main Interface), and search buttons.

The configuration file for the virtual buttons of another system is as follows:

  
  
  1. $ cat /sys/board_properties/virtualkeys.qtouch-touchscreen  
  2. 0x01:139:90:936:116:104:0x01:102:252:936:
    116:104:0x01:158:402:936:116:104 

The scanned code for conversion is 139,102,158, which corresponds to menu, home, and Back buttons.

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.