{ "id": "63222", "key": "TIMOB-2590", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "11244", "name": "Release 1.7.0", "archived": true, "released": true, "releaseDate": "2011-06-13" }, { "id": "11245", "name": "Sprint 2011-10", "archived": true, "released": true, "releaseDate": "2011-03-14" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2011-04-17T01:59:32.000+0000", "created": "2011-04-15T03:23:47.000+0000", "priority": { "name": "Trivial", "id": "5" }, "labels": [ "android", "defect", "release-1.7.0", "reported-1.5.1", "reported-1.6.0", "rplist" ], "versions": [], "issuelinks": [], "assignee": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2011-05-17T11:01:25.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "{html}

I've been working on this for hours now.

\n

I have a simple event listener:

\n
\n\nTitanium.Gesture.addEventListener('orientationchange', function(e){\n    var orient = e.orientation;\n    if(orient == 1 || orient == 2) {\n        portWin.height = screenHeight;\n        portWin.width = screenWidth;\n        portWeb.height = screenHeight;\n        portWeb.width = screenWidth;\n        portWeb.evalJS('portRotate(\"port\")');\n    }\n    else {\n        portWin.height = screenWidth;\n        portWin.width = screenHeight;\n        portWeb.height = screenWidth;\n        portWeb.width = screenHeight;\n        portWeb.evalJS('portRotate(\"land\")');\n    }\n});\n
\n

... which works fine on thee iPhone emulator, but I can't get it\nto work at all on my Android phone. I've stripped it down to just\nproducing an alert on the event occuring and still nothing.

\n

I've looked around and saw something about putting the event\nlistener in a separate .js file, but that doesn't work. I've\ninstalled the KitchenSink app to my phone and the orientationchange\nexample works fine. I honestly don't know what I'm doing different\nfor it to not work.

\n

Any suggestions please?

{html}", "attachment": [], "flagged": false, "summary": "Android: OrientationChange doesn't work", "creator": { "name": "stinkypickle", "key": "stinkypickle", "displayName": "StinkyPickle", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "stinkypickle", "key": "stinkypickle", "displayName": "StinkyPickle", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "128898", "author": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "body": "{html}

Several pro clients are experiencing this as well. I can confirm\nthat this is true in the latest builds.

\n

Problem

\n

On Android, Ti.Gesture.addEventListener 'orientationchange'\nnever fires.

\n

Expected Behavior

\n

Whenever the simulator or real device is rotated, this event\nshould fire.

\n

Tested On

\n

All tests done on Titanium Mobile 1.6.0 pulled January 8th,\n2011
\nBROKEN on Android Simulator, 2.2
\nBROKEN on Android Device, Epic 4G 2.2
\nWORKS on iPhone Simulator, 4.2

\n

Sample Code

\n
\n/**\n* This app displays a label with the current orientation. It will work on iPhone and update\n* as you rotate the simulator or device, but it will NOT update on Android; it will display\n* the initial orientation, but will not update for future orientation changes.\n*/\nvar win = Titanium.UI.createWindow({\n    backgroundColor: '#fff'\n});\nwin.orientationModes = [\n    Titanium.UI.PORTRAIT,\n    Titanium.UI.UPSIDE_PORTRAIT,\n    Titanium.UI.LANDSCAPE_LEFT,\n    Titanium.UI.LANDSCAPE_RIGHT\n];\nvar label = Titanium.UI.createLabel({\n    color: '#999',\n    text: 'I am Window 1',\n    font: { fontSize: 20, fontFamily: 'Helvetica Neue' },\n    textAlign: 'center',\n    width: 'auto'\n});\nwin.add(label);\nwin.open();\n\nfunction getOrientation(o) {\n    switch (o) {\n        case Titanium.UI.PORTRAIT:\n            return 'portrait';\n        case Titanium.UI.UPSIDE_PORTRAIT:\n            return 'upside portrait';\n        case Titanium.UI.LANDSCAPE_LEFT:\n            return 'landscape left';\n        case Titanium.UI.LANDSCAPE_RIGHT:\n            return 'landscape right';\n        default:\n            return '';\n    }\n}\n\nlabel.text = getOrientation(Titanium.Gesture.orientation);\nTi.Gesture.addEventListener('orientationchange', function (e) {\n    label.text = getOrientation(e.orientation);\n});\n
\n

Associated Helpdesk Ticket

\n

http://developer.appcelerator.com/helpdesk/view/62991

{html}", "updateAuthor": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "created": "2011-04-15T03:23:47.000+0000", "updated": "2011-04-15T03:23:47.000+0000" }, { "id": "128899", "author": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "body": "{html}

Workaround

\n

The orientationchange event will fire in a heavyweight window\n(an activity). Setting both url: 'child.js' and one of\nnavBarHidden: true, modal: true, or fullscreen:true allows you to\nwork around this limitation in app.js.

\n

For example, your app.js may look like this:

\n
\nvar win = Ti.UI.createWindow({\n  url: 'child.js',\n  navBarHidden: true,\n  backgroundColor: '#fff'\n});\nwin.open();\n
\n

And child.js would contain the following:

\n
\nvar win = Ti.UI.currentWindow;\nwin.orientationModes = [\nTitanium.UI.PORTRAIT,\nTitanium.UI.UPSIDE_PORTRAIT,\nTitanium.UI.LANDSCAPE_LEFT,\nTitanium.UI.LANDSCAPE_RIGHT,\nTitanium.UI.FACE_UP,\nTitanium.UI.FACE_DOWN\n];\nvar label = Titanium.UI.createLabel({\n    color: '#999',\n    text: 'I am Window 1',\n    font: { fontSize: 20, fontFamily: 'Helvetica Neue' },\n    textAlign: 'center',\n    width: 'auto'\n});\nwin.add(label);\n\nfunction getOrientation(o) {\n    switch (o) {\n        case Titanium.UI.PORTRAIT:\n            return 'portrait';\n        case Titanium.UI.UPSIDE_PORTRAIT:\n            return 'upside portrait';\n        case Titanium.UI.LANDSCAPE_LEFT:\n            return 'landscape left';\n        case Titanium.UI.LANDSCAPE_RIGHT:\n            return 'landscape right';\n        case Titanium.UI.FACE_UP:\n            return 'face up';\n        case Titanium.UI.FACE_DOWN:\n            return 'face down';\n        case Titanium.UI.UNKNOWN:\n            return 'unknown';\n        default:\n            return 'constant not recognized';\n    }\n}\n\nlabel.text = getOrientation(Titanium.Gesture.orientation);\nTi.Gesture.addEventListener('orientationchange', function (e) {\n    label.text = getOrientation(e.orientation);\n});\n
\n

This code will work on both iPhone and Android.

{html}", "updateAuthor": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "created": "2011-04-15T03:23:48.000+0000", "updated": "2011-04-15T03:23:48.000+0000" }, { "id": "128900", "author": { "name": "jimwilliams", "key": "jimwilliams", "displayName": "jimwilliams", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

The workaround does work on android, but then has the undesired\nside effect that when pressing the android previous button to go\nback from the child, the app is left at a blank app screen. In the\ncode, I can see that the window associated with child.js closes\n(added an eventListener which fires as expected). So now the app is\nleft with a zombie window in the hierarchy. Pressing previous again\nwill exit out to the home screen (or whatever was previous in the\nwindow list, I assume). But this added zombie window kind of ruins\nthe utility of the workaround.

\n

Is there a way to force the zombie window to close when I\nreceive the close event from the child.js window? I'd like to shoot\nit in the head, as is the customary practice to effectively deal\nwith zombies.

{html}", "updateAuthor": { "name": "jimwilliams", "key": "jimwilliams", "displayName": "jimwilliams", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:49.000+0000", "updated": "2011-04-15T03:23:49.000+0000" }, { "id": "128901", "author": { "name": "markruys", "key": "markruys", "displayName": "Mark Ruys", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

@jimwilliams: Does 'exitOnClose' help you? See \nhttp://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.....

{html}", "updateAuthor": { "name": "markruys", "key": "markruys", "displayName": "Mark Ruys", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:49.000+0000", "updated": "2011-04-15T03:23:49.000+0000" }, { "id": "128902", "author": { "name": "jimwilliams", "key": "jimwilliams", "displayName": "jimwilliams", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

It so totally does the trick.

\n

I am still not up to speed on all the Android-only stuff in\nTitanium these days; up until 1.5.0, I tried to stay away from\nAndroid-specific things to make my life easier when supporting the\niPhone (and that went both ways, of course). But since this code is\na hack to work around Android-specific issues in the first place,\nhaving an Android-specific feature used to tune the\nAndroid-required hack is not so distasteful.

\n

Thanks so much for the pointer.

{html}", "updateAuthor": { "name": "jimwilliams", "key": "jimwilliams", "displayName": "jimwilliams", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:49.000+0000", "updated": "2011-04-15T03:23:49.000+0000" }, { "id": "128903", "author": { "name": "kc", "key": "kc", "displayName": "KC", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

This seems to work if you are creating a new window from an\nexisting window. I tried using the code above and also the example\nfrom the KitchenSink orientation.js by it's self in my app.js and\nit still displays the error described above.

\n

\nhttps://github.com/appcelerator/KitchenSink/blob/master/KitchenSink...

{html}", "updateAuthor": { "name": "kc", "key": "kc", "displayName": "KC", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:50.000+0000", "updated": "2011-04-15T03:23:50.000+0000" }, { "id": "128904", "author": { "name": "aleard", "key": "aleard", "displayName": "Alan Leard", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Related HD ticket: http://developer.appcelerator.com/helpdesk/view/74931

{html}", "updateAuthor": { "name": "aleard", "key": "aleard", "displayName": "Alan Leard", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:50.000+0000", "updated": "2011-04-15T03:23:50.000+0000" }, { "id": "128905", "author": { "name": "mculpepper", "key": "mculpepper", "displayName": "Marshall Culpepper", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

We've pushed a lot of orientation changes / updates recently for\n1.6.0, Can you guys verify if these pushes have fixed your problem,\nand mark as resolved?

{html}", "updateAuthor": { "name": "mculpepper", "key": "mculpepper", "displayName": "Marshall Culpepper", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:51.000+0000", "updated": "2011-04-15T03:23:51.000+0000" }, { "id": "128906", "author": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "body": "{html}

@Marshall: Just verified that my original code sample now works\non my device.

\n

Titanium SDK version: 1.7.0 (03/03/11 10:45 87a2113...)
\nWORKS on Android Device Epic 4G 2.2

{html}", "updateAuthor": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "created": "2011-04-15T03:23:51.000+0000", "updated": "2011-04-15T03:23:51.000+0000" }, { "id": "128907", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Marking resolved per conversation with Dawson.

{html}", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:52.000+0000", "updated": "2011-04-15T03:23:52.000+0000" }, { "id": "132800", "author": { "name": "iotashan", "key": "iotashan", "displayName": "Shannon Hicks", "active": true, "timeZone": "America/Chicago" }, "body": "I just tested this with a 1.7.0 build from 4/25, and it still doesn't work. To reproduce, put this code at the top of an app.js of a brand new project:\n\n{code:JavaScript}\t\tTitanium.Gesture.addEventListener('orientationchange',function(e){\n\t\t\talert('width: '+Titanium.Platform.displayCaps.platformWidth+' height:'+Titanium.Platform.displayCaps.platformHeight);\n\t\t});\n{code}\n\nRan in both the emulator (2.3) and on a Droid X (2.2)", "updateAuthor": { "name": "iotashan", "key": "iotashan", "displayName": "Shannon Hicks", "active": true, "timeZone": "America/Chicago" }, "created": "2011-04-26T15:28:00.000+0000", "updated": "2011-04-26T15:28:00.000+0000" }, { "id": "133801", "author": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "body": "@Shannon the platformWidth and height not accurately reflecting the current orientation would be a separate issue. This issue is about the orientationchange event not firing.\n\n@Don I do have another use case where the orientationchange does not fire. If your app.js opens a tab group, then Ti.Gesture.addEventListener('orientationchange', ...) won't fire. If I had to hazard a guess, the orientation change event is only fired on the front most activity (ie whichever window is active in the tab group), and Ti.Gesture binds itself to the app.js activity. Check out the sample code below...\n\n{code:javascript}\nvar tabGroup = Ti.UI.createTabGroup();\ntabGroup.addTab(Ti.UI.createTab({ title: 'Tab 1', window: Ti.UI.createWindow({ backgroundColor: 'red' }) }));\ntabGroup.addTab(Ti.UI.createTab({ title: 'Tab 2', window: Ti.UI.createWindow({ backgroundColor: 'blue' }) }));\ntabGroup.open();\n\n/* Ti.UI.createWindow({ backgroundColor: 'green' }).open(); */\n\nTi.Gesture.addEventListener('orientationchange', function(e) {\n Ti.UI.createAlertDialog({\n message: e.orientation\n }).show();\n});\n{code}", "updateAuthor": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "created": "2011-05-17T10:09:24.000+0000", "updated": "2011-05-17T10:09:24.000+0000" }, { "id": "133810", "author": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "updateAuthor": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "created": "2011-05-17T11:01:25.000+0000", "updated": "2011-05-17T11:01:25.000+0000" } ], "maxResults": 13, "total": 13, "startAt": 0 } } }