Titanium Mobile
  1. Titanium Mobile
  2. TIMOB-10232

Android: Capturing onKeyPress from the hardware keyboard

    Details

    • Sprint:
      Release 3.0.0

      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.

        Issue Links

          Activity

          Hide
          Ping Wang added a comment -

          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.

          Show
          Ping Wang added a comment - 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.
          Show
          Ping Wang added a comment - PR https://github.com/appcelerator/titanium_mobile/pull/3095
          Show
          Ping Wang added a comment - 3_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/3410
          Hide
          Natalie Huynh added a comment -

          Tested with 3.0.0.v20121121161553 on Droid 1 2.2.3

          Show
          Natalie Huynh added a comment - Tested with 3.0.0.v20121121161553 on Droid 1 2.2.3

            People

            • Assignee:
              Ping Wang
              Reporter:
              Varun Joshi
            • Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development

                  Agile

                    Poker Sessions

                    This issue is currently not assigned to any Poker Session.