[TIMOB-10232] Android: Capturing onKeyPress from the hardware keyboard
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | Medium |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2012-10-10T18:10:34.000+0000 |
| Affected Version/s | Release 2.1.0 |
| Fix Version/s | Release 3.0.0, Release 3.1.0, 2012 Sprint 21 API, 2012 Sprint 21 |
| Components | Android |
| Labels | SupportTeam, api, module_view, qe-testadded |
| Reporter | Varun Joshi |
| Assignee | Ping Wang |
| Created | 2012-07-30T10:46:21.000+0000 |
| Updated | 2013-07-12T10:52:21.000+0000 |
Test case:
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: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();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.PR https://github.com/appcelerator/titanium_mobile/pull/3095
3_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/3410
Tested with 3.0.0.v20121121161553 on Droid 1 2.2.3