Smooth Orientation Changes

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Smooth Orientation Changes

Post by dcpbarrington » Mon Aug 04, 2014 11:18 pm

Forum,

I have an Android App that I'm finishing and want to improve the user experience when they change the orientation of the device. Here is how I have it set up to adjust the stack when the screen orientation changes.

Code: Select all

on preOpenStack
   get initializeStackLibraries()
   set the fullScreenMode of this stack to "letterbox" 
end preOpenStack

on orientationChanged
   if environment() is not "mobile" then exit orientationChanged
   
   put mobileDeviceOrientation() into tOrientation
   
      if tOrientation = "portrait" then
         set the width of this stack to 480
         set the height of this stack to 800
      else if tOrientation = "landscape left" OR tOrientation = "landscape right" then
         set the width of this stack to 800
         set the height of this stack to 480
      else if tOrientation = "portrait upside down" then
      else if tOrientation = "face up" or tOrientation = "face down" then
      else
         answer info "Orientation = " & tOrientation
      end if
   
end orientationChanged
The problem is that as the device is moved the screen goes to the wrong size, so the screen looks small with wide dark areas on the sides. See attached images. This is quite annoying to the user.

As far as I can tell the device is telling the program to change orientation pre-maturely and it really as not changed the orientation yet, so the OrientationChanged code is working properly, but not getting the correct effect.

QUESTION
Does anyone have a suggestion on how to de-bounce the screen orientation change, so the orientation is only changed after the user had definitely changed the phone position?
Attachments
VerticalDisplay.png
HorizontalDisplay.png

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Smooth Orientation Changes

Post by Simon » Tue Aug 05, 2014 1:47 am

Hi dcpbarrington,
This might be device dependent. Does the orientation eventually get it right?
I know on my Kindle Fire they've got landscape left and landscape right reversed so that the app is always upside-down.

Hey there's a feature request, orientation override.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Smooth Orientation Changes

Post by dcpbarrington » Tue Aug 05, 2014 2:20 am

Thanks Simon,

The device does eventually get the right orientation after it has been changed for awhile. But it creates this display flicker for the user.

In looking at the mobileDeviceOrientation() output it is saying "landscape-left", but the phone is still in the "portrait" position. So it is a device issue, but I would still want the software to act respond smoothly.

What if I do a wait for 1 second when I get the message and then test the orientation to make sure it has actually changed?

Or should I just ignore the first message and wait for a second to adjust the orientation, but the message is only generated on a Orientation Change, so that may be worse.

Let me know what you think.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Smooth Orientation Changes

Post by Simon » Tue Aug 05, 2014 2:37 am

Do you have acceleratedRendering turned on?
It causes all sorts of havoc for me.
At any rate something is up because normally there isn't a delay (well a short one) but never the small letterbox image you have shown.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Smooth Orientation Changes

Post by Dixie » Tue Aug 05, 2014 11:19 am

from the 'release notes' pdf
The orientationChanged message is sent before any automatic interface rotation takes place thus changes to the orientation lock state and allowed set can be made at this point and still have an effect. If you wish to perform an action after the interface has been rotated, then either do so on
receipt of resizeStack, or by using a send in 0 millisecs message.

So putting the lines of your 'orientationChanged' handler into a 'resizeStack' handler should help... Well, it does for me... I always put the changes I wish to make to the screen on a change of orientation in the 'resizeStack' handler and have a habit of leaving the 'orientationChanged' handler empty...

Code: Select all

on orientationChanged

end orientationChanged

on resizeStack
   if "portrait" is among the words of iphoneDeviceOrientation() then
    --do whatever when rotating here
   end if
   
   if "landscape" is among the words of iphoneDeviceOrientation() then
     --do whatever when rotating here
   end if
end resizeStack

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Smooth Orientation Changes

Post by dcpbarrington » Tue Aug 05, 2014 5:39 pm

Thanks Dixie

If I put the resize code in the resizeStack handler, it never gets called because the stack is not being resized on the orientation change. When I change the device orientation to landscape the display is turned, but is still 480x800 with large BLACK areas on the side like in my attached images.

Maybe I'm doing something wrong, but my application layout is sized for Portrait 480x800. When I turn landscape I change the stack size to 800x480 which make the displayed information wider but less height. I don't move any of the items on the display. I have a scroll area that is much larger then the displayed information.

I have Locked Screen and put in a 100 millisecond delay before I request the mobileDeviceOrientation() and this has improved the experience, but still not as smooth as other apps.

Thanks
Dan

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Smooth Orientation Changes

Post by newtronsols » Tue Aug 05, 2014 11:57 pm

Interesting to try in different versions of LC. I notice that set fullscreenmode and setting the pixelscale has differing affects through LC builds on Android. What didn't work before works and vice versa. It seems to be a constantly moving target - on Android.

I remember once working with a graphics studio and my artwork changed each week. I found that 3 people worked on it - each started from their own last saved version separately. I suspect this is something like LC builds for Android changes.

A case of github forking hell?

Post Reply