Android4.0 add a new Android key value

Source: Internet
Author: User

The new key value is added here, not a key value created without credentials, but based on the key values detected in the kernel and then converted to the desired value for Android:

To add a Linux key value of 217, map it to Android's key value browser (which does not exist before this key value) as an example:

1, Android does not have this key value, need to define

/frameworks/base/core/java/android/view/keyevent.java

Define this new key value

public static final int keycode_browser = 210;

We will then see the following comments:

Note:if you add a new keycode This must also add it to:

IsSystem ()

Native/include/android/keycodes.h

Frameworks/base/include/ui/keycodelabels.h

External/webkit/webkit/android/plugins/anpkeycodes.h

Frameworks/base/core/res/res/values/attrs.xml

Emulator?

Last_keycode

Keycode_symbolic_names

//

Also Android currently does not reserve code ranges for vendor-

Specific key codes. If you have a new key codes to the, you

must contribute a patch to the open source project to define

Those new codes. This was intended to maintain a consistent

Set of key code definitions across all Android devices.

The above comment has shown us the steps required to add a key value:

2,/frameworks/base/core/java/android/view/keyevent.java

Public Final Boolean IsSystem () {

Return Native_issystemkey (Mkeycode);

}

/frameworks/base/jni/android_view_keyevent.java

Static Jboolean Native_issystemkey (jnienv* env, Jobject clazz, Jint keycode) {

Return Keyevent::issystemkey (KeyCode);

}

/frameworks/base/libs/ui/input.cpp

BOOL Keyevent::issystemkey (int32_t keycode) {

Switch (keycode) {

......

Case Akeycode_browser:

return true;

}

}

3, Native/include/android/keycodes.h

/*

* Key codes.

*/

enum {

......

Akeycode_calculator = 210,

Akeycode_browser = 211,

}

4, Frameworks/base/include/ui/keycodelabels.h

What is defined here is actually the name of the Linux key and the Android key value in the KL file, which is a mapping table of Linux key to Android key;

such as ATC260X-IRKEYPAD.KL:

......

Key 217 BROWSER//Here BROWSER is the character form of our defined Android key value, 217 is the Linux key value

Well, browser can not be used for no reason, there must be a defined position, this position is KeycodeLabels.h

static const Keycodelabel keycodes[] = {

......

{"CALCULATOR", 210},

{"BROWSER", 211},//The BROWSER here is what we use above, and 211 is the Android key value

{NULL, 0}

}

Load and parse this MAP:ATC260X-IRKEYPAD.KL in EventHub.cpp, then get the Linux key value 217 is a string of key, this string is browser, with the above keycodes array, you can get its corresponding Android The OID key value.

5, External/webkit/webkit/android/plugins/anpkeycodes.h

Enum Anpkeycodes {

......

Kappswitch_anpkeycode = 186,

Kbrowser_anpkeycode = 211,

};

6, Frameworks/base/core/res/res/values/attrs.xml

<attr name= "KeyCode" >

<enum name= "Keycode_calculator" value= "/>"

<enum name= "Keycode_browser" value= "211"/>

</attr>

7,/frameworks/base/core/java/android/view/keyevent.java

Last_keycode is the last keycode, because a new one is added, so you need to change the value of this

Last_keycode = Keycode_browser

private static final

sparsearray<string> keycode_symbolic_names = new sparsearray<string> ();

private static void Populatekeycodesymbolicnames () {

......

Names.append (Keycode_music, "keycode_music");

Names.append (Keycode_calculator, "keycode_calculator");

Names.append (Keycode_browser, "Keycode_browser");

}

After these operations are completed, the key-value mappings for Linux keys to Android are completed. That is, there is one more keycode_browser in Android. Its value is 211.

Android4.0 add a new Android key value

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.