Orientation change
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 474
- Joined: Thu Sep 04, 2008 6:23 am
- Location: Melbourne Australia
Orientation change
Hi,
I have a single stack app which I have built for iOS and Android.
When I,test for iOS and ‘rotate’ the device pertrair,-.landscape, my app rotates too, fills the screen and moves controls as required.
When I installit on one of my iOS devices (iPhone and iPad) it works as expected and handles device rotation correctly.
When I test on the android simulator. And rotate the device the app stays in portrait mode but reduces its size as if the phone suddenly shrank.
So no I have a minature portrait version of my app on a landscape screen with a black region either side.
When I rotate the device again I keep my mini version of the app but in portrait.
I am not aware of any Android specific orientation requirements.
Any suggestions as to why it works fine on iOS but not Android.
I have a single stack app which I have built for iOS and Android.
When I,test for iOS and ‘rotate’ the device pertrair,-.landscape, my app rotates too, fills the screen and moves controls as required.
When I installit on one of my iOS devices (iPhone and iPad) it works as expected and handles device rotation correctly.
When I test on the android simulator. And rotate the device the app stays in portrait mode but reduces its size as if the phone suddenly shrank.
So no I have a minature portrait version of my app on a landscape screen with a black region either side.
When I rotate the device again I keep my mini version of the app but in portrait.
I am not aware of any Android specific orientation requirements.
Any suggestions as to why it works fine on iOS but not Android.
-
- VIP Livecode Opensource Backer
- Posts: 7235
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Orientation change
I'm not sure I'd trust the emulator on this, sometimes a real device behaves differently. That said, can you post your rotation script?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 474
- Joined: Thu Sep 04, 2008 6:23 am
- Location: Melbourne Australia
Re: Orientation change
Here is the code I am using. It is located in the stack script"
rereading this I wonder if setting the fullscreen mode to "letterbox" is the problem?
Code: Select all
on orientationChanged-- need to adjust fields
send "setstack" to me in 0 seconds
end orientationChanged
on setstack
if the environment is "mobile" then
set the lockscreen to true
set the fullscreenmode of this stack to "letterbox"
put mobileOrientation()into torient
put item 3 of screenrect() into sw
put item 4 of screenrect() into sh
if torient contains "portrait" then
--in portrait width is less than heigh
set the width of this stack to min(sw,sh)
set the height of this stack to max(sw,sh)
else
set the width of this stack to max(sw,sh)
set the height of this stack to min(sw,sh)
end if
else
set the width of this stack to 900
set the height of this stack to 600
end if
if the short name of this card = "moment" then
send "fixflds" to card "moment"
end if
if the short name of this card = "info" then
send "fixlocs" to card "info"
end if
end setstack
-
- VIP Livecode Opensource Backer
- Posts: 7235
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Orientation change
FullscreenMode and scripted positioning don't mix very well, usually it's best to choose one or the other. Since you're positioning controls manually, you could probably omit fullscreenMode entirely.
Also change the handler that calls setStack. OrientationChanged is somewhat misleading because it's past-tense, but what it really means is "the user has rotated the device, just warning you that we're about to redraw in a moment." In other words, orientationChanged is sent before the actual dimension change occurs, so if you setStack during orientationChanged, the stack will still be in portrait mode and the screenrect won't have changed yet.
After the orientation notification, the engine then proceeds to redraw the screen in the new orientation and sends a resizeStack message when it does so. That's the time to reset the positioning of the controls if necessary. So I think you'll be okay if you change your current orientationChanged handler into a resizeStack handler. When resizeStack is sent, you're in the new orientation and the screen dimensions will have refreshed. This will work on both iOS and Android. I suspect the original script may have worked on iOS because the device redraws fast enough and you're sending the command "in time" and even though it's a very short amount of time, there was enough delay for the resizing to occur.
Also change the handler that calls setStack. OrientationChanged is somewhat misleading because it's past-tense, but what it really means is "the user has rotated the device, just warning you that we're about to redraw in a moment." In other words, orientationChanged is sent before the actual dimension change occurs, so if you setStack during orientationChanged, the stack will still be in portrait mode and the screenrect won't have changed yet.
After the orientation notification, the engine then proceeds to redraw the screen in the new orientation and sends a resizeStack message when it does so. That's the time to reset the positioning of the controls if necessary. So I think you'll be okay if you change your current orientationChanged handler into a resizeStack handler. When resizeStack is sent, you're in the new orientation and the screen dimensions will have refreshed. This will work on both iOS and Android. I suspect the original script may have worked on iOS because the device redraws fast enough and you're sending the command "in time" and even though it's a very short amount of time, there was enough delay for the resizing to occur.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 474
- Joined: Thu Sep 04, 2008 6:23 am
- Location: Melbourne Australia
Re: Orientation change
thanks for the info @jacque.
I remove the FullScreenMode stuff and rename the orientationchangd handler to resizestack.
The letterboxing no longer occurred but the repositioning of controls failed.
Also in iOS the handler wasn't called either.
I then tried adding an answer dlog to the resizestack handler to see if it was called - it was.
I reinserted the orientation changed handler but increased the send time to 1000 milliseconds
For android this worked. Interestingly I didn't see the dlog from the resizestack handler so I can only assume it wasn't called??
Tried again dropping the send time to 500 milliseconds, still worked
Tested it against iOS and it worked too.
So I now have it working in the simulators. I assume it will work on devices.
I wouldn't have investigated in this fashion without your reply so thank you.
I remove the FullScreenMode stuff and rename the orientationchangd handler to resizestack.
The letterboxing no longer occurred but the repositioning of controls failed.
Also in iOS the handler wasn't called either.
I then tried adding an answer dlog to the resizestack handler to see if it was called - it was.
I reinserted the orientation changed handler but increased the send time to 1000 milliseconds
For android this worked. Interestingly I didn't see the dlog from the resizestack handler so I can only assume it wasn't called??
Tried again dropping the send time to 500 milliseconds, still worked
Tested it against iOS and it worked too.
So I now have it working in the simulators. I assume it will work on devices.
I wouldn't have investigated in this fashion without your reply so thank you.
Re: Orientation change
You should not need to do anything with the size of the stack/card. You should only need to position elements on the card. The engine takes care of adjusting the size of the stack/card when the device rotates (or launches on a device that doesn’t match the development size).
resizeStack is the better place to update UI in my experience. I generally have it call a handler called updateUI.
You also need to manually call the code that updates your UI in the preOpenCard handler if you have a multi card app since it is possible for the metrics to change while on card 1 and then card 2 would never receive a resizeStack message.
resizeStack is the better place to update UI in my experience. I generally have it call a handler called updateUI.
You also need to manually call the code that updates your UI in the preOpenCard handler if you have a multi card app since it is possible for the metrics to change while on card 1 and then card 2 would never receive a resizeStack message.
Brian Milby
Script Tracker https://github.com/bwmilby/scriptTracker
Script Tracker https://github.com/bwmilby/scriptTracker
-
- VIP Livecode Opensource Backer
- Posts: 474
- Joined: Thu Sep 04, 2008 6:23 am
- Location: Melbourne Australia
Re: Orientation change
@Brian, for some reason ResizeStack is not called consistently after the orientationchanged message, so I stopped using it.
You know it really helps if you check your spelling [ResizeStack! not resizstack, doh]
I will get back
You know it really helps if you check your spelling [ResizeStack! not resizstack, doh]
I will get back
-
- VIP Livecode Opensource Backer
- Posts: 474
- Joined: Thu Sep 04, 2008 6:23 am
- Location: Melbourne Australia
Re: Orientation change
ok, all working now.
acting on resizestack, sending message to rearrange controls in 50 miliiseconds.
using mobiledevice orientation to inform width and height.
using those value to adjust control and field positions.
it seems I was undertaking more work than was required.
Thank you @jacque forpointing me in the right direction.
Thank you @bwmilby for getting me to proofread my scripts.
acting on resizestack, sending message to rearrange controls in 50 miliiseconds.
using mobiledevice orientation to inform width and height.
using those value to adjust control and field positions.
it seems I was undertaking more work than was required.
Thank you @jacque forpointing me in the right direction.
Thank you @bwmilby for getting me to proofread my scripts.
-
- VIP Livecode Opensource Backer
- Posts: 29
- Joined: Tue Jun 27, 2006 8:35 pm
- Location: Bellingham, WA USA
- Contact:
Re: Orientation change
I don't usually find that repositioning screen controls for an orientation change requires a "send in time" method... or locking the screen, as long as the repositioning is put inside (or called by) the resizeStack handler. Following a rotation the screen isn't redrawn until the resizeStack handler finishes. When going to a new card I just call resizeStack from the preopenStack handler in order to make sure everything is where it needs to be before the screen is drawn. (I used to write extra code to make sure that I wasn't calling resizestack more than once but LiveCode is so fast in positioning things that I've stopped worrying about this much.
Elementary Software
...now with 20% less chalk dust!
...now with 20% less chalk dust!