Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19779] Android orientations on orientationchange not providing accurate results in some Android Tablets

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2017-11-06T18:16:59.000+0000
Affected Version/sRelease 5.0.1, Release 5.0.2, Release 5.0.0
Fix Version/sn/a
ComponentsAndroid
Labelsorientations
Reporter Ricardo Ramirez
AssigneeJoshua Quick
Created2015-10-23T20:22:21.000+0000
Updated2017-11-06T18:17:04.000+0000

Description

Issue description

With the new Titanium SDK, SINCE 4.1.0, Android tablets that have their default orientation in landscape are reporting it's orientation as portrait when it is actually landscape and landscape when it is actually portrait. The customer experienced this issue using the Samsung Galaxy Tab 3 model GT-P5210.

Steps to replicate

-Create a new titanium alloy project -Open the app folder -Replace the index.xml file inside views folder, the index.tss file inside styles folder and the index.js file inside controllers -Change orientation in emulator -Build and run -Device Orientation is sometimes detected as portrait when it is actually landscape and landscape when it is actually portrait

Attachments

FileDateSize
index.js2015-10-23T20:22:04.000+00001486
index.tss2015-10-23T20:22:13.000+0000388
index.xml2015-10-23T20:21:57.000+0000140

Comments

  1. Ashraf Abu 2015-11-17

    PR: https://github.com/appcelerator/titanium_mobile/pull/7455
  2. Dawson Toth 2015-11-23

    I'm wondering if this ticket is related? [TIMOB-19878]
  3. Ricardo Ramirez 2015-11-23

    [~dawsontoth] Seems very similar, but on my tests and according to the customer shared info, the event was triggered but it was sending wrong info and not every time, I was not able to reproduce it (even in Gennymotion) but i had 2 customers with this issue if you see at the Github PR, the engineering team reproduced and solved the issue. I just have one question [~msamah], this PR was inserted on the now released SDK 5.1.0.GA or this solution still in review ?
  4. Ricardo Ramirez 2015-11-24

    [~cng] [~msamah] In which version is or will be the fix ?
  5. Ashraf Abu 2015-11-25

    [~rramirez] This is in master branch for 5.2.0 release.
  6. Ricardo Ramirez 2015-11-25

    Thanks !
  7. Lokesh Choudhary 2016-01-21

    Verified the fix. orientationchange now returns accurate orientation on tablets. Closing. Environment: Appc Studio : 4.5.0.201601131150 Ti SDK : 5.2.0.v20160114021251 Ti CLI : 5.0.5 Alloy : 1.7.26 MAC Yosemite : 10.10.5 Appc NPM : 4.2.3-1 Appc CLI : 5.2.0-231 Node: v0.12.27 Samsung Galaxy Tab SM-600 - Android 4.3
  8. Louis Quaintance 2016-03-16

    Unfortunately this still isn't fixed perfectly Create an app and add following Ti.Gesture.addEventListener('orientationchange', function(){ console.log("orientationchange fired"); }); Deploy to an Android tablet Now hold the device in portrait and position horizontally flat, mid air Now tilt device one corner of the device up slightly and rotate round towards it being in a landscape position Note how the console.log("orientationchange fired") has not been executed even though the screen has orientated
  9. Ashraf Abu 2016-03-16

    What device are you using and which Android version is it running?
  10. Louis Quaintance 2016-03-16

    Nexus 10 ( Android 4.4.2 ) and Nexus 9 ( Android 6.0 )
  11. Ashraf Abu 2016-03-16

    You are using Titanium SDK 5.2.0.GA?
  12. Louis Quaintance 2016-03-16

    Yes 5.2.0.GA
  13. Sharif AbuDarda 2016-03-21

    Hello, I have tested the issue on Galaxy tab 4 (Android 4.4.2) with SDK 5.2.0.GA. I could not reproduce this issue. I followed the below instructions: 1.Deploy to an Android tablet 2.Hold the device in portrait and position then horizontally flat in mid air 3.Now, tilt device one corner up slightly and rotate around towards it being in a landscape position. 4.See for orientationchange event in console log. Following these steps, when the device changes the orientation the app detects it and fired the change event perfectly. Now, when I tried with SDK 5.1.0.GA I see that the fired event provides the wrong mode in console for 2-3 times. After that, it starts providing the right mode.
        function doClick(e) {
        	Ti.API.info('Hello World!');
        }
        
        Ti.Gesture.addEventListener('orientationchange', function(event) {
        	Ti.API.info('Gesture Orientation: ', event.orientation);
        	Ti.API.info('Landscape: ', Ti.Gesture.isLandscape());
        	Ti.API.info('Portrait: ', Ti.Gesture.isPortrait());
        	console.log("orientationchange fired");
        });
        
        $.index.open();
        
  14. Ashraf Abu 2016-03-31

    Unable to reproduce. If there are instructions or more details on how to reproduce, please comment. I'll resolve this as unable to reproduce if there isn't more movement on this in a few days.
  15. Peter Lancaster 2016-03-31

    Looking at this - could the issue be related to how sensitive the device accelerometer is, and in turn how much information it reports back for the SDK to determine a correct value to report? For example - when @Louis and I typically see this issue - a device is rotated slowly, placed on a table carefully, or in the process of some other 'slower' action. Essentially - undertaking user actions that would trigger a device's accelerometer to report back more refined values.
  16. Ashraf Abu 2016-04-01

    That's an interesting hypothesis. Does it work correctly if you turned it at a normal speed? And what's considered a slower action?
  17. Peter Lancaster 2016-04-01

    Typically, a 'quick' movement (e.g. a sharp or 'normal speed' turn from portrait to landscape) would see the UI update correctly in a majority of cases. But a slower movement (e.g. a gradual turn and tilt - in the same kind of manner you would if you were playing a gravity / physics based game such as Labyrinth - or if you were carefully placing a device face up, onto a table) would trigger the error more frequently. Our theory was that once in the device accelerometer (or logic) gets into this state, it reports back in the same manner, until another 'sharp' action breaks the process (perhaps the flow inside here: https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/gesture/src/java/ti/modules/titanium/gesture/GestureModule.java - might have some link to that?).
  18. Louis Quaintance 2016-04-04

    Please try this code index.xml: index.js: function setValues(){ if(Ti.Gesture.isPortrait()){ $.myWindow.backgroundColor = "red"; $.text.text = "I AM IN PORTRAIT"; } else { $.myWindow.backgroundColor = "black"; $.text.text = "I AM IN LANDSCAPE"; } } Ti.Gesture.addEventListener("orientationchange", setValues); $.myWindow.open(); setValues();
  19. Ashraf Abu 2016-04-05

    [~louis.quaintance] Thanks for that code. Able to reproduce the bug with what you have provided.
  20. Paresh Thakor 2016-04-06

    I am also having orientation issue with Nexus 10 device. I put alerts in orientation handing code. The alert shows wrong code for orientations sometimes. It displays portrait code for landscape orientations and landscape codes for portrait orientations. I have used Titanium SDK: 5.2.2.GA Appcelerator Studio: 4.5.0 Project Type: Alloy. {quote}Orientaiton code block:{quote} { function handleOrientationchange(e) { alert('Latest Orientation: ' + e.orientation); if (e.orientation != prevOrientation && OrientationFlag == false && e.orientation >= 1 && e.orientation <= 4) { OrientationFlag = true; if (e.orientation == Titanium.UI.UPSIDE_PORTRAIT || e.orientation == Titanium.UI.PORTRAIT) { ... } else if (e.orientation == Titanium.UI.LANDSCAPE_RIGHT || e.orientation == Titanium.UI.LANDSCAPE_LEFT) { ... } prevOrientation = e.orientation; OrientationFlag = false; } } Ti.Gesture.addEventListener("orientationchange", handleOrientationchange); }
  21. Ashraf Abu 2016-04-07

    [~mobihunterz] May I know which version of Android is being used as well?
  22. Arjan 2016-05-15

    I am also experiencing this issue. Happens also Nexus 7 and 9 simulator, SDK 5.2.2.GA.
  23. Ashraf Abu 2016-05-20

    [~arif] Just want to know more background on this, what's the use case you are using this for?
  24. Arjan 2016-05-20

    Hi Ashraf, we're using it to change the UI layout for landscape vs portrait. When the user switches to landscape, we show another layout / extra columns. I've made a screencast of the issue, you can watch it here: https://streamable.com/a9qk I also made a testproject, you can download it here: https://file.io/eZ7EQ1 As you can see, the first time the device changes orientation, there's no output in the console, so it doesn't seem to detect the change. The second change, it detects the change, but wrong; landscape is detected as portrait from then on and the other way around. This is the issue with every tablet in the simulator, but I also happens on real Nexus devices.
  25. Ashraf Abu 2016-05-20

    Thanks for the screencast. That looks like a bad bug. Will need to get this investigated.
  26. Ashraf Abu 2016-05-20

    I've put the ticket in Triage for now.
  27. Arjan 2016-05-20

    great, thanks!
  28. Ashraf Abu 2016-06-07

    [~mobihunterz] I'm using
          
        Ti.Gesture.addEventListener('orientationchange', function(e){
            switch(e.orientation) {
            case Ti.UI.LANDSCAPE_RIGHT:
                Ti.API.info("LANDSCAPE_RIGHT");
                Ti.UI.createNotification({
                    message:"LANDSCAPE_RIGHT",
                    duration: Ti.UI.NOTIFICATION_DURATION_SHORT
                }).show();
                break;
            case Ti.UI.LANDSCAPE_LEFT:
                Ti.API.info("LANDSCAPE_LEFT");
                Ti.UI.createNotification({
                    message:"LANDSCAPE_LEFT",
                    duration: Ti.UI.NOTIFICATION_DURATION_SHORT
                }).show();
                break;
            case Ti.UI.UPSIDE_PORTRAIT:
                Ti.API.info("UPSIDE_PORTRAIT");
                Ti.UI.createNotification({
                    message:"UPSIDE_PORTRAIT",
                    duration: Ti.UI.NOTIFICATION_DURATION_SHORT
                }).show();
                break;
            case Ti.UI.PORTRAIT:
                Ti.API.info("PORTRAIT");
                Ti.UI.createNotification({
                    message:"PORTRAIT",
                    duration: Ti.UI.NOTIFICATION_DURATION_SHORT
                }).show();
                break;
            default:
                Ti.API.info("Unknown!!");
            } 
             Ti.API.info("Portrait:"+e.source.isPortrait());
             Ti.API.info("Landscape:"+e.source.isLandscape());
        });
        
    And having a hard time reproducing your error.
  29. Arjan 2016-08-26

    I am still having this issue with SDK 5.4.0.GA, on multiple simulators and different Android versions. And it doesn't happen on tablets only! A clean window with orientation listener won't detect the first orientation change. The second time it detects the change, but wrong. Screencast:https://streamable.com/r1r9 Project: http://content3.skoften.net/temp/testje.zip Running on OSX. Studio 4.7.0.201607250649. EDIT: I just tested it on 2 real devices (S6 and S6 Edge) and it works. Maybe it's an simulator-issue? Using Genymotion.
  30. Douglas Alves 2016-12-01

    Using e.source.orientation solved it for me. if(e.source.orientation == Titanium.UI.LANDSCAPE_RIGHT || e.source.orientation == Titanium.UI.LANDSCAPE_LEFT){ //Do Something }else if(e.source.orientation == Titanium.UI.PORTRAIT || e.source.orientation == Titanium.UI.UPSIDE_PORTRAIT){ //Do Something }
  31. Joshua Quick 2017-11-06

    [TIMOB-24537] resolves this. It'll introduces a breaking change where Ti.Gesture provides device orientation instead of app window orientation, like how it works on iOS and Windows Phone.

JSON Source