Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8518] Android: ImageView does not handle width or height set to Ti.UI.FILL correctly

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-12-13T06:32:58.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sRelease 2.1.0, Sprint 2012-12 Core
ComponentsAndroid
Labelscore, module_media, qe-3.2.0, qe-closed-3.2.0, qe-testadded, regression, triage
ReporterOpie Cyrus
AssigneePing Wang
Created2012-04-04T15:05:25.000+0000
Updated2014-06-25T19:12:18.000+0000

Description

This behavior can be seen when running the KS (1.8.2 version) camera test. Setting the width for the image view in the success callback to Ti.UI.FILL will result in the bounds of the bitmap created not being able to be determined. A work around of setting width to win.size.width addresses the symptom but there appears to be a timing issue where the bounds of the bitmap are determined before the Ti.UI.SIZE value is computed resulting in massive bitmaps with no scaling. This can result in memory issues. It is suspected that this is a order of operations issue that needs to be addressed.

Comments

  1. Max Stepanov 2012-05-30

    @Opie, can you attach an example ?
  2. Allen Yeung 2012-06-12

    Test case:
       var win = Titanium.UI.createWindow({backgroundColor:'white'});
       win.open();
       Titanium.Media.showCamera({
       
       	success:function(event)
       	{
       		var cropRect = event.cropRect;
       		var image = event.media;
       
       		Ti.API.debug('Our type was: '+event.mediaType);
       		if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
       		{
       			var imageView = Ti.UI.createImageView({
       				width:Ti.UI.FILL,
       				height:Ti.UI.FILL,
       				image:event.media
       			});
       			win.add(imageView);
       		}
       		else
       		{
       			alert("got the wrong type back ="+event.mediaType);
       		}
       	},
       	cancel:function()
       	{
       	},
       	error:function(error)
       	{
       		// create alert
       		var a = Titanium.UI.createAlertDialog({title:'Camera'});
       
       		// set message
       		if (error.code == Titanium.Media.NO_CAMERA)
       		{
       			a.setMessage('Please run this test on device');
       		}
       		else
       		{
       			a.setMessage('Unexpected error: ' + error.code);
       		}
       
       		// show alert
       		a.show();
       	},
       	saveToPhotoGallery:true,
       	allowEditing:true,
       	mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
       });
       
    1. Launch the app, and take a picture 2. Click "save" Expected Results: You should see the image in the next screen (a newly created image view) Actual results: You see a white screen and you get an out of memory error in the logs. NOTE: You may need to run this on a phone with a high megapixel camera. I am using galaxy s2.
  3. Allen Yeung 2012-06-12

    The problem is that we create a full bitmap that is no scaled when we pass in a value like Ti.UI.FILL. This causes the out of memory exception. We need to handle the Ti.UI.FILL case correctly.
  4. Allen Yeung 2012-06-12

    PR ready: https://github.com/appcelerator/titanium_mobile/pull/2378
  5. Olga Romero 2012-06-23

    Verified fix with Titanium Studio, build: 2.1.0.201206221045 Titanium SDK: 2.1.0.v20120622174154 Device: Nexus S 4.0.4
  6. Neha Chhabra 2012-07-10

    Reopening to update labels.
  7. Lokesh Choudhary 2013-11-25

    I am able to reproduce this issue on sdk 3.2.0.v20131122172908.I don't see the image in the imageView after capturing & saving the image. Reopening. Environment: Appcel Studio : 3.2.0.201311221207 Ti SDK : 3.2.0.v20131122172908 Mac OSX : 10.8.5 Alloy : 1.3.0-alpha6 CLI - 3.2.0-alpha Nexus 5 - android 4.4 Samsung Galaxy S4 running android 4.2.2
  8. Ping Wang 2013-11-26

    Before 3.2.0, the white window is a LW window which is the root activity. So the camera activity is on top of the root activity, and when the root activity is resumed (the camera activity is closed), the camera callback is invoked. On 3.2.0, the white window is a HW window. But since opening a HW window is an async process, the camera activity is still on top of the root activity not the window activity. Therefore the camera callback will not be invoked until the root activity is resumed (the window activity is closed). To test this ticket, we can either add
    <property name="ti.android.useLegacyWindow" type="bool">true</property>
    to tiapp.xml, or modify the test case to
       var win = Titanium.UI.createWindow({
       	backgroundColor : 'white'
       });
       win.open();
       win.addEventListener("open", function() {
       	Titanium.Media.showCamera({
       
       		success : function(event) {
       			var cropRect = event.cropRect;
       			var image = event.media;
       
       			Ti.API.debug('Our type was: ' + event.mediaType);
       			if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
       				var imageView = Ti.UI.createImageView({
       					width : Ti.UI.FILL,
       					height : Ti.UI.FILL,
       					image : event.media
       				});
       				win.add(imageView);
       			} else {
       				alert("got the wrong type back =" + event.mediaType);
       			}
       		},
       		cancel : function() {
       		},
       		error : function(error) {
       
       		},
       		saveToPhotoGallery : true,
       		allowEditing : true,
       		mediaTypes : [Ti.Media.MEDIA_TYPE_VIDEO, Ti.Media.MEDIA_TYPE_PHOTO]
       	});
       }); 
       
  9. Priya Agarwal 2013-12-13

    Tested Environment: Appcelerator Studio: 3.2.0.201312121648 SDK:3.2.0.v20131212122847 alloy: 1.3.0-cr acs: 1.0.10 npm: 1.3.2 titanium: 3.2.0-cr3 titanium-code-processor: 1.1.0-cr2 Xcode:5.0.2 OS: Mac OSX 10.9 Device: Google Nexus7(v4.3),Iphone5s(v7.0.2) ImageView respecting Ti.UI.Fill for both height and width. Closing as working fine.
  10. Priya Agarwal 2013-12-13

    Reopening just add qe closed label
  11. Priya Agarwal 2013-12-13

    Updated label.Hence closing
  12. ankur garha 2014-06-25

    I have tested it again with Ti SDK 3.2.0, Its working when we set width and height both to Ti.UI.FILL. But if we set only width to Ti.UI.FILL then its not working .

JSON Source