Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10232] Android: Capturing onKeyPress from the hardware keyboard

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-10-10T18:10:34.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 3.0.0, Release 3.1.0, 2012 Sprint 21 API, 2012 Sprint 21
ComponentsAndroid
LabelsSupportTeam, api, module_view, qe-testadded
ReporterVarun Joshi
AssigneePing Wang
Created2012-07-30T10:46:21.000+0000
Updated2013-07-12T10:52:21.000+0000

Description

Requirement

There is a request of a new feature to support the hardware keyboard on Android apart. The only way to capture keystrokes on the device is via a focus event on a textfield or textarea. It has been requested to expose the onKeyPress native Android method (primarily on a view) so the hardware keyboard can be accessed from outside the textfield/textarea.

Comments

  1. Ping Wang 2012-10-02

    Test case:
       var win = Ti.UI.createWindow({
       	backgroundColor : "white"
       });
       
       var v1 = Ti.UI.createView({
       	backgroundColor : "red",
       	top : 0,
       	left: 250,
       	height : 100,
       	width : 100,
       	focusable : true
       });
       
       v1.addEventListener("keypressed", function(e) {
       	Ti.API.info("************** Red view keypressed: keyCode = " + e.keyCode);
       });
       
       v1.addEventListener("click", function(e) {
       	Ti.API.info("************** Red view clicked");
       });
       
       var l1 = Ti.UI.createLabel({
       	top: 0,
       	left: 10,
       	width: 240,
       	text: "Red view: focusable = " + v1.focusable
       });
       
       var b1 = Ti.UI.createButton({
       	top: 0,
       	left: 360,
       	title: "Toggle 'focusable' for Red View"
       });
       
       b1.addEventListener("click", function(){
       	v1.focusable = !v1.focusable;
       	l1.text = "Red view: focusable = " + v1.focusable
       });
       
       
       var v2 = Ti.UI.createView({
       	backgroundColor : "blue",
       	top : 110,
       	left: 250,
       	height : 100,
       	width : 100,
       	focusable : false
       });
       
       v2.addEventListener("keypressed", function(e) {
       	Ti.API.info("************** Blue view keypressed: keyCode = " + e.keyCode);
       });
       
       v2.addEventListener("click", function(e) {
       	Ti.API.info("************** Blue view clicked");
       });
       
       var l2 = Ti.UI.createLabel({
       	top: 110,
       	left: 10,
       	width: 240,
       	text: "Blue view: focusable = " + v2.focusable
       });
       
       var b2 = Ti.UI.createButton({
       	top: 110,
       	left: 360,
       	title: "Toggle 'focusable' for Blue View"
       });
       
       b2.addEventListener("click", function(){
       	v2.focusable = !v2.focusable;
       	l2.text = "Blue view: focusable = " + v2.focusable
       });
       
       
       win.add(l1);
       win.add(l2);
       win.add(b1);
       win.add(b2);
       win.add(v1);
       win.add(v2);
       win.open();
       
    Steps for FR: 1. Run the above test case. 2. Use hardware key to focus the red view. Should see the output in the console, like:
       I/TiAPI   ( 6118):  ************** Red view keypressed: keyCode = 19
       
    3. Click the button "Toggle 'focusable' for Blue View" so that Blue View's focusable is true. (The "keypressed" event can only be fired when focusable=true). 4. Use hardware key to focus the blue view. Should see a similar output in the console.
  2. Ping Wang 2012-10-02

    PR https://github.com/appcelerator/titanium_mobile/pull/3095
  3. Ping Wang 2012-11-12

    3_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/3410
  4. Natalie Huynh 2012-11-26

    Tested with 3.0.0.v20121121161553 on Droid 1 2.2.3

JSON Source