Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8546] Android: handle invalid values on width and height gracefully

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-05-30T14:34:58.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sRelease 2.1.0
ComponentsAndroid
Labelscore, module_media, qe-testadded
ReporterOpie Cyrus
AssigneeMax Stepanov
Created2012-04-04T15:48:41.000+0000
Updated2012-07-13T16:28:10.000+0000

Description

when invalid values are set for width and height an exception occurs when trying to convert the values into TiDimension:
			var imageView = Ti.UI.createImageView({
				width:win.width,
				height:win.height,
				image:event.media
			});
			win.add(imageView);
* this would be when win.width is undefined. This test case can be found in the KS camera test. Resulting error:
04-04 16:26:45.345 21220 21220 E TiApplication: (main) [9299,18498] Sending event: exception on thread: main msg:java.lang.ClassCastException: org.appcelerator.kroll.KrollRuntime$1; Titanium 2.1.0,2012/04/04 15:16,161fb52
04-04 16:26:45.345 21220 21220 E TiApplication: java.lang.ClassCastException: org.appcelerator.kroll.KrollRuntime$1
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.util.TiConvert.toTiDimension(TiConvert.java:550)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.util.TiConvert.toTiDimension(TiConvert.java:561)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at ti.modules.titanium.ui.widget.TiUIImageView.processProperties(TiUIImageView.java:806)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:737)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:530)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:522)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:500)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:616)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:307)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:110)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at ti.modules.titanium.ui.ActivityWindowProxy.handleMessage(ActivityWindowProxy.java:93)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:95)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at android.os.Looper.loop(Looper.java:143)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:4701)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at java.lang.reflect.Method.invokeNative(Native Method)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at java.lang.reflect.Method.invoke(Method.java:521)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-04 16:26:45.345 21220 21220 E TiApplication: 	at dalvik.system.NativeStart.main(Native Method)
04-04 16:26:45.353  1401 21298 I MediaScanner: process file: /sdcard/dcim/Camera/tia70621.jpg
04-04 16:26:45.361  1401 21298 D DlnaMediaParser: getJPEGProfileName: 4
04-04 16:26:45.494  1401  1428 D MediaProvider: current image thumbnail number created successfully is:2
04-04 16:26:45.728  1238  1257 D BatteryTempPolicy: updateBatteryTemp temperature = 380, Threshhold = 3
04-04 16:26:45.767 16521 16521 E GlobalUnplugService: plugged = true,mBatteryPlugged=true
We should gracefully handle invalid values when they are set or processed either by throwing exceptions to let the developer know of the problem or defaulting to valid values. Requires parity discussion.

Comments

  1. Max Stepanov 2012-05-30

    Fixed by PR 2030
  2. Olga Romero 2012-06-23

    For QE
       
       var win = Titanium.UI.currentWindow;
       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:win.size.width,
       				height:win.size.height,
       				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]
       });
       
  3. 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

JSON Source