Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19597] Android: Add previewRect (height, width) to camera callback

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-02-02T08:22:18.000+0000
Affected Version/sRelease 4.1.1
Fix Version/sRelease 5.2.0
ComponentsAndroid
Labelsandroid, camera, module_media, qe-manualtest, qe-testadded
ReporterMichael Gangolf
AssigneeSrikanth Sombhatla
Created2015-09-17T16:32:42.000+0000
Updated2016-02-04T02:00:56.000+0000

Description

Comments

  1. Michael Gangolf 2015-09-17

    PR: https://github.com/appcelerator/titanium_mobile/pull/7201
  2. Srikanth Sombhatla 2015-11-06

    With this PR, user can get the preview size and can use it to size the captured image accordingly.
  3. Lokesh Choudhary 2016-01-21

    Reopening as no previewRect is seen in the logs but only cropRect:
       [INFO] :   [SAMSUNG-SGH-I747] # SUCCESS : {"height":2448,"width":3264,"cropRect":{"height":2448,"y":0,"width":3264,"x":0},"code":0,"media":{"file":{"hidden":false,"nativePath":"file:///data/data/com.app.testme/app_appdata/tia1453413346146.jpg","writable":true,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data/data/com.app.testme/app_appdata","writable":true,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data/data/com.app.testme","writable":true,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data/data","writable":false,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data","writable":false,"executable":false,"parent":{"hidden":false,"nativePath":"file:///","writable":false,"executable":false,"parent":null,"readonly":true,"directoryListing":["sdcard","persist","storage","efs","config","cache","acct","vendor","d","etc","data_3","data_2","data_1","mnt_1","tombstones","firmware","mnt","ueventd.rc","ueventd.qcom.rc","system","sys","sepolicy_version","sepolicy","seapp_contexts","sbin","publiccert.pem","property_contexts","proc","initlogo.rle","init.usb.rc","init.trace.rc","init.target.rc","init.selinux_restore_set.sh","init.selinux_restore.sh","init.selinux_bootanim_stopped.sh","init.ril.sh","init.ril.rc","init.rc","init.qcom.usb.sh","init.qcom.usb.rc","init.qcom.syspart_fixup.sh","init.qcom.sh","init.qcom.rc","init.qcom.early_boot.sh","init.qcom.class_core.sh","init.environ.rc","init.container.rc","init.carrier.rc","init","fstab.qcom","file_contexts","default.prop","data","root","dev"],"size":0,"apiName":"Ti.Proxy","name":"","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":[],"size":4096,"apiName":"Ti.Proxy","name":"data","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":[],"size":12288,"apiName":"Ti.Proxy","name":"data","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":["lib","cache","databases","shared_prefs","app_appdata"],"size":4096,"apiName":"Ti.Proxy","name":"com.app.testme","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":[".tilicense","tia1453412750901.jpg","tia1453413346146.jpg"],"size":4096,"apiName":"Ti.Proxy","name":"app_appdata","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":[],"size":1795672,"apiName":"Ti.Proxy","name":"tia1453413346146.jpg","symbolicLink":false,"bubbleParent":true},"nativePath":"file:///data/data/com.app.testme/app_appdata/tia1453413346146.jpg","height":2448,"length":1795672,"width":3264,"mimeType":"image/jpeg","apiName":"Ti.Blob","text":null,"type":1,"bubbleParent":true},"success":true,"mediaType":"public.image","y":0,"x":0}
       
    Environment: Appc Studio : 4.5.0.201601210853 Ti SDK : 5.2.0.v20160114021251 Ti CLI : 5.0.6 Alloy : 1.7.33 MAC Yosemite : 10.10.5 Appc NPM : 4.2.3-1 Appc CLI : 5.2.0-231 Node: v0.12.27 Nexus 6P - Android 6.0 Galaxy S3 - Android 4.4.2
  4. Srikanth Sombhatla 2016-01-28

    [~lchoudhary] Looks like the PR is intended when showCamera is used with overlay and takePicture is called. -[~michael] please provide a complete working app.js. -
  5. Srikanth Sombhatla 2016-01-28

    [~lchoudhary] You can use this app.js
           var self = Ti.UI.createWindow();
           var cameraOverlay = Titanium.UI.createView({
           	backgroundColor: '#FF00FFAA'
           });
         
           var cameraOverlayButton = Titanium.UI.createImageView({
               bottom: 100,
               image: '/appcelerator_small.png',
           });
           cameraOverlay.add(cameraOverlayButton);
         
           cameraOverlay.addEventListener('click', function(e){
           	Ti.API.info("taking pic");
               Ti.Media.takePicture();
           });
         
           self.addEventListener("postlayout", postlayoutHandler);
           function postlayoutHandler(e) {
               self.removeEventListener("postlayout", postlayoutHandler);
               Titanium.Media.showCamera({
                   overlay: cameraOverlay,
                   showControls: false,
                   success: function(e) {
                         Ti.API.info('# SUCCESS : '+ JSON.stringify(e));
                   },
                   cancel: function(e) {
                         Ti.API.info('# CANCEL : '+e.error);
                      
                   },
                   error: function(e) {
                         Ti.API.info('# ERROR : '+ e.code +' : '+ e.error);
                      
                   },
                   mediaTypes:Ti.Media.MEDIA_TYPE_PHOTO,
               });
           }
           self.open();
       
    Also there is a dependency on TIMOB-19769 which will crash when camera overlay is used.
  6. Michael Gangolf 2016-01-28

    Thanks for the example! It only works when takePicture() is called (so not with the basic camera controls). The other callback should be here https://github.com/ashcoding/titanium_mobile/blob/da0ba48a38b07142e53a99ca1af7023ee727af5f/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L952 but I need to see how I get the getOptimalPreviewSize() value there
  7. Srikanth Sombhatla 2016-02-01

    [~michael] previewRect makes sense when used with overlay, because native camera control is not used when a overlay is provided in showCamera. -In such case the previewRect should be {-1, -1} as with cropRect.- The same should be updated in docs. Can you update the PR accordingly ? -It can be updated here https://github.com/ashcoding/titanium_mobile/blob/da0ba48a38b07142e53a99ca1af7023ee727af5f/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L917-
  8. Michael Gangolf 2016-02-01

    Sure I'll do that! Thanks for the hint. Will update the PR in the next days
  9. Michael Gangolf 2016-02-01

    output of showCamera without camera overlay will not have previewRect
       Titanium.Media.showCamera({
               success: function(e) {
                   Ti.API.info('# SUCCESS : ' + JSON.stringify(e));
               },
               mediaTypes: Ti.Media.MEDIA_TYPE_PHOTO
           });
       
       {
         "y": 0,
         "x": 0,
         "height": 3264,
         "width": 1836,
         "media": {
           "file": {...},
           "nativePath": "file:///data/data/com.miga.test/app_appdata/tia1453756826134.jpg",
           "height": 3264,
           "length": 1857467,
           "width": 1836,
           "mimeType": "image/jpeg",
           "apiName": "Ti.Blob",
           "text": null,
           "type": 1,
           "bubbleParent": true
         },
         "mediaType": "public.image",
         "code": 0,
         "cropRect": {
           "height": 3264,
           "width": 1836,
           "y": 0,
           "x": 0
         },
         "success": true
       }
       
    PR: https://github.com/appcelerator/titanium_mobile/pull/7660
  10. Srikanth Sombhatla 2016-02-02

    Updates to documentation 5_2_X PR: https://github.com/appcelerator/titanium_mobile/pull/7665 master PR: https://github.com/appcelerator/titanium_mobile/pull/7666
  11. Ashraf Abu 2016-02-02

    5_2_X (7665) and Master (7666) PR for documentation merged.
  12. Michael Gangolf 2016-02-02

    Should I leave it like it is now (undefined if its not used). Or should I create a correct PR with -1?
  13. Srikanth Sombhatla 2016-02-02

    [~michael] You can leave it like that. We just added the documentation changes. Thanks for the effort!
  14. Srikanth Sombhatla 2016-02-03

    [~lchoudhary] Sorry for the confusion. We made that behaviour inline with other properties such that it is undefined when not present. To recap previewRect is present when camera overlay is used. Other cases it is undefined.
  15. Lokesh Choudhary 2016-02-04

    Verified the addition of previewRect(height,width). We see previewRect in the logs only when camera overlay is used. Closing. Environment: Appc Studio : 4.5.0.201601262138 Ti SDK : 5.2.0.v20160203093451 Ti CLI : 5.0.6 Alloy : 1.7.33 MAC Yosemite : 10.10.5 Appc NPM : 4.2.3-2 Appc CLI : 5.2.0-242 Node: 4.2.2 Nexus 6P - Android 6.0

JSON Source