Detecting Android navigation setting

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
j9v6
Posts: 72
Joined: Tue Aug 06, 2019 9:27 am
Location: U.K.
Contact:

Detecting Android navigation setting

Post by j9v6 » Wed Apr 28, 2021 6:36 pm

Can LiveCode detect if an Android user has set the system navigation style to Gesture mode instead of the standard three key navigation (Back, Home and Overview buttons)? It makes a difference to the amount of screen real estate you have to work with and where things can be placed.

I know it's not on all versions of Android, but the phone I'm developing against running Android version 10 and the version that some of my testers are using too has it. You can find the navigation settings here: Settings > System & Updates > System Navigation. Three choices: Gestures, Three-key navigation or Navigation dock.

If you enable Gestures mode, then the three soft buttons disappear and navigating the phone is handled by sipes up and sideways similar to using an iPhone X upwards.

Thanks, Al.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Detecting Android navigation setting

Post by jacque » Thu Apr 29, 2021 4:11 pm

Does "the working screenrect" give you the right dimensions? I'm a fan of fullscreenmode but if you're scripting the resizing then that should give you the right screen size to work with.

If it doesn't then a bug report is probably in order.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

j9v6
Posts: 72
Joined: Tue Aug 06, 2019 9:27 am
Location: U.K.
Contact:

Re: Detecting Android navigation setting

Post by j9v6 » Fri Apr 30, 2021 8:06 pm

Hi Jacque,

I've been playing with screenRect options and comparing the results of all three on both the Android simulator and real devices. Unless I'm not understanding it correctly the results seem a little screwy to me. As this is all hardware dependent and for the record my phones screen resolution is 1080 x 2340 which evaluates to 360 x 780 pixels

Setting my phone to gesture navigation this is what I get:

"the screenRect" returns 0,0,360,753
"the working screenRect" returns 0,27,360,780
"the effective working screenRect" returns 0,27,360,780

Setting my phone to three-key navigation give me the following results:

"the screenRect" returns 0,0,360,713
"the working screenRect" returns 0,27,360,740
"the effective working screenRect" returns 0,27,360,740

To my mind "the screenRect" should have returned 0,0,360,780 whether the android device is set to gesture navigation or three-key navigation. If that was the case, "the working screenRect" and "the effective working screenRect" values make sense and you have a solid reference point in "the screenRect" to work with.

Any thoughts on this?

Thanks,
Al.

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Detecting Android navigation setting

Post by bwmilby » Sat May 01, 2021 3:24 pm

I think that is just Android. The virtual hardware buttons are not included in the screenrect. Same thing on the Pixel that I use for development. This is also a key difference between iOS and Android. On iOS you can address the full screen (behind the “furniture”) but you can’t on Android.

But, you really don’t need to worry about the screen size - just use the card rect. You position things based on that rect anyway.
Last edited by bwmilby on Sun May 02, 2021 9:51 pm, edited 1 time in total.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

j9v6
Posts: 72
Joined: Tue Aug 06, 2019 9:27 am
Location: U.K.
Contact:

Re: Detecting Android navigation setting

Post by j9v6 » Sun May 02, 2021 10:52 am

Hi Jacque,

I wrote myself a test tool to mark the values from the various screenRects and it’s definitely got some bugs, so I’ve reported it and uploaded a copy of the test code.

In the meantime I have found that the most reliable option is to use “the screenRect” as this always fits within the viewable screen area... although on some Android devices it is a bit shorter than the screen height. It means you get a chunk of unaddressable space at the bottom of the screen in Gesture mode. Until the BIF is fixed it will have to do and I can work with that I guess.

Al.

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Detecting Android navigation setting

Post by bwmilby » Sun May 02, 2021 9:22 pm

Try the following changes to your stack script: comment out the 2 lines where you set the stack size in preOpenStack and add the following handler:

Code: Select all

on resizeStack
   local tRect
   put the rect of this card into tRect
   put item 1 of tRect into gScreenRect1
   put item 2 of tRect into gScreenRect2
   put item 3 of tRect into gScreenRect3
   put item 4 of tRect into gScreenRect4
   put "the rect of this card" into field "lblScreenRect"
   put tRect into field "lblScreenRectValue"
   positionIt
end resizeStack
I think your issue is that you are attempting to use screen coordinates to place controls. Controls are placed based on card coordinates. Also, on mobile devices you generally do not need to manually adjust the rect of the stack.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

j9v6
Posts: 72
Joined: Tue Aug 06, 2019 9:27 am
Location: U.K.
Contact:

Re: Detecting Android navigation setting

Post by j9v6 » Tue May 04, 2021 2:35 pm

Thanks for the suggestions Brian, I'll have a play with the code you've provided.

The specific problem i've found is in positioning a navigation bar at the bottom of an Android screen (or more to the point positioning anything at the bottom of an Android screen) . Because the screenRect values are inconsistent the navigation bar can end up positioned at the bottom correctly (yay!) or behind the soft nav bar or partially off the bottom of the screen. It seems to depend on the version of Android you use and the device brand itself.

The clunky work-around "solution" is to leave a 40px (approx) margin at the bottom of the Android screen to allow for variations in screenRect values which works but also looks awful aesthetically. If the screenRect values were correct then you can put anything you like precisely on the screen which is how I build my apps. (Please don't say geometry manager :roll: :lol: )

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Detecting Android navigation setting

Post by bwmilby » Tue May 04, 2021 2:49 pm

You should not need to be using screenrect at all on mobile. Download SivaSiva to see a LiveCode app that is responsive to the screen size (most of the app).

All objects are place relative to the card, not the screen. The rect that you need to use is the rect of the card.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

Post Reply

Return to “Android Deployment”