Refreshed against 1.1
[webos-internals:adamrmcd-modifications.git] / camera / capture_with_volume_keys.patch
1 Creating a patch which will allow you to snap pictures using the volume keys
2
3 Tested-On: 1.1
4
5 Index: /usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js
6 ===================================================================
7 --- .orig/usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js
8 +++ /usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js
9 @@ -34,7 +34,7 @@ CaptureAssistant = Class.create({
10                         this.sublaunch = false;
11                         this.defaultFilename = null;
12                 }
13 -               
14 +               this.volumeKeySubscription = undefined;
15         },
16  
17         
18 @@ -87,6 +87,17 @@ CaptureAssistant = Class.create({
19                         elemC.style.display = '';
20                 }
21                 
22 +               // listen to volume key events
23 +               this.volumeKeySubscription = new Mojo.Service.Request(
24 +                       'palm://com.palm.keys/audio',
25 +                       {
26 +                               method: 'status',
27 +                               parameters: {'subscribe': true},
28 +                               onFailure: function() { Mojo.Log.error("Could not subscribe to volume key events."); },
29 +                               onSuccess: this.handleVolumeKeys.bind(this)
30 +                       }
31 +               );
32 +
33                 llog("CaptureAssistant::setup() finished");
34         },
35         
36 @@ -173,6 +184,11 @@ CaptureAssistant = Class.create({
37                 }
38                 
39                 this.cameraControl.closeCamera();
40 +
41 +               // Clean up listener for volume keys
42 +               if(this.volumeKeySubscription) {
43 +                       this.volumeKeySubscription.cancel();
44 +               }
45         },
46         
47         handleCommand: function(event){
48 @@ -186,7 +202,14 @@ CaptureAssistant = Class.create({
49                 
50         },
51         
52 -               
53 +       // capture on release of volume keys
54 +       handleVolumeKeys: function(payload) {
55 +               // capture when either volume up or down buttons are released
56 +               if(payload.state === 'up' && (payload.key === 'volume_up' || payload.key === 'volume_down')) {
57 +                       this.cameraControl.capture();
58 +               }
59 +       },
60 +
61         onKeyPress: function(event) {
62                 // Space bar also takes a picture.
63                 if (Mojo.Char.spaceBar == event.originalEvent.keyCode){