Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13998] Android: add setCameraFlashMode feature for custom overlays in Ti.Media

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-03-06T20:36:06.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 05, 2014 Sprint 05 API, Release 3.3.0
ComponentsAndroid
Labelsmodule_media, qe-testadded
ReporterMauro Parra-Miranda
AssigneeBiju pm
Created2013-05-28T00:38:49.000+0000
Updated2014-07-22T22:52:30.000+0000

Description

Problem Description

When users sets a custom overlay in the camera, there is no way to set the flash on or off.

More info

https://developer.appcelerator.com/question/152715/flash-mode-in-camera

Comments

  1. Alex Bernier 2013-08-08

    +1 on this feature request
  2. Biju pm 2013-11-05

    PR: https://github.com/appcelerator/titanium_mobile/pull/4912
  3. Alex Bernier 2014-01-22

    Is this ready to go? Would love to start using it.
  4. Biju pm 2014-02-05

    Test case
       var overlay = Ti.UI.createView();
       var button = Titanium.UI.createButton({
           color : '#fff',
           bottom : 10,
           width : 301,
           height : 57,
           font : {
               fontSize : 20,
               fontWeight : 'bold',
               fontFamily : 'Helvetica Neue'
           },
           title : 'Take Picture'
       });
         
       button.addEventListener('click', function() {
           Ti.Media.takePicture();
       });
        
       overlay.add(button);
        
       Titanium.Media.showCamera({
        
           overlay : overlay,
           flashMode : true ,
           mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO,
           saveToPhotoGallery : true
       }); 
       
  5. Biju pm 2014-02-05

    New PR : https://github.com/appcelerator/titanium_mobile/pull/5322
  6. Alex Bernier 2014-02-05

    Will we be able to toggle flashMode from the overlay while the camera is open? Use case would be: 1. Camera preview starts 2. The user sees the scene is too dark without flash and wants to turn flash on 3. A button on the camera overlay would allow the user to set flashMode to turn flash on This use case seems to be the inspiration for the [feature request](https://developer.appcelerator.com/question/152715/flash-mode-in-camera). It may, in fact, be possible in your pull request, Biju, but I wanted to clarify. And if it is possible in your pull request, could you add toggle to your test case? Excited for flash control - thank you for your contribution to this ticket!
  7. Biju pm 2014-02-06

    Test Case
       var overlay = Ti.UI.createView();
       
       var button = Titanium.UI.createButton({
           color : '#fff',
           bottom : 10,
           width : 200,
           height : 57,
           font : {
               fontSize : 20,
               fontWeight : 'bold',
               fontFamily : 'Helvetica Neue'
           },
           title : 'Take Picture'
       });
       
       var buttonChange = Titanium.UI.createButton({
           color : '#fff',
           bottom : 90,
           width : 200,
           height : 57,
           font : {
               fontSize : 20,
               fontWeight : 'bold',
               fontFamily : 'Helvetica Neue'
           },
           title : 'change flashmode'
       });
          
         var label = Ti.UI.createLabel({
         color:'blue',
           textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
           text : "FlashMode OFF" ,
         top: 30,
         width: 200, height: 100
       }); 
       buttonChange.addEventListener('click', function() {
         	Ti.Media.flashMode = !Ti.Media.getFlashMode() ;
         	if(Ti.Media.flashMode)
         	{
         	label.text = "FlashMode ON" ;
         	}
         	else
         	{
         	label.text = "FlashMode OFF" ;
         	}
        });
         button.addEventListener('click', function() {
           Ti.Media.takePicture();
       });
        
       overlay.add(button);
       overlay.add(label);
       overlay.add(buttonChange);
          	 Titanium.Media.showCamera({
           overlay : overlay , 
         flashMode : false 
       }); 
       
  8. Alex Bernier 2014-02-06

    Oh awesome! Our users are going to be so excited. Right now they have to take a photo with normal camera then open the app then select photo from gallery. This will save them so much time. Thank you, again.
  9. Shannon Hicks 2014-02-06

    Wait, Ti.Media.flashMode is a boolean? On the (undocumented) iOS side, we use constants. We need to make sure that it's the same for both platforms, please.
  10. Biju pm 2014-02-07

    Test Case
        var overlay = Ti.UI.createView();
         
        var button = Titanium.UI.createButton({
            color : '#fff',
            bottom : 10,
            width : 200,
            height : 57,
            font : {
                fontSize : 20,
                fontWeight : 'bold',
                fontFamily : 'Helvetica Neue'
            },
            title : 'Take Picture'
        });
         
        var buttonChange = Titanium.UI.createButton({
            color : '#fff',
            bottom : 90,
            width : 200,
            height : 57,
            font : {
                fontSize : 20,
                fontWeight : 'bold',
                fontFamily : 'Helvetica Neue'
            },
            title : 'change flashmode'
        });
            
          var label = Ti.UI.createLabel({
          color:'blue',
            textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
            text : "FlashMode OFF" ,
          top: 30,
          width: 200, height: 100
        }); 
        buttonChange.addEventListener('click', function() {
            Ti.Media.cameraFlashMode = !Ti.Media.getCameraFlashMode() ;
            if(Ti.Media.cameraFlashMode)
            {
            label.text = "FlashMode ON" ;
            }
            else
            {
            label.text = "FlashMode OFF" ;
            }
         });
          button.addEventListener('click', function() {
            Ti.Media.takePicture();
        });
          
        overlay.add(button);
        overlay.add(label);
        overlay.add(buttonChange);
             Titanium.Media.showCamera({
            overlay : overlay , 
          flashMode : false 
        }); 
        
  11. Hieu Pham 2014-04-01

    Modify 'flashMode' to 'cameraFlashMode' for parity with iOS: https://github.com/appcelerator/titanium_mobile/pull/5567
  12. Alex Bernier 2014-07-22

    On iOS, Titanium SDK 3.3.0.GA, setting Ti.Media.cameraFlashMode to false seems to set the camera flash to an "auto" mode; the flash still fires if you cover the light sensor with your hand. Is this expected, and if so, will there be functionality in the future to allow flash to be turned off, overriding auto flash mode?
  13. Alex Bernier 2014-07-22

    Whoops, this ticket is for Android...can't edit/delete comments any more?
  14. Alex Bernier 2014-07-22

    Nevermind, I see the constants in the documentation now. I was using the code snippet above which doesn't use the constants so I'm assuming that's why it's using "auto" behavior.

JSON Source