# Mobile / Android improvements: safe borders, new UI scaling accounting for auto-rotation nicer, better gestures with TCastleExamineNavigation, modern Android photo services, improved docs

**URL:** https://forum.castle-engine.io/t/mobile-android-improvements-safe-borders-new-ui-scaling-accounting-for-auto-rotation-nicer-better-gestures-with-tcastleexaminenavigation-modern-android-photo-services-improved-docs/1293
**Category:** News
**Created:** [August 2, 2024, 3:31pm UTC](https://forum.castle-engine.io/t/mobile-android-improvements-safe-borders-new-ui-scaling-accounting-for-auto-rotation-nicer-better-gestures-with-tcastleexaminenavigation-modern-android-photo-services-improved-docs/1293 "2024-08-02T15:31:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [August 2, 2024, 3:31pm UTC](https://forum.castle-engine.io/t/mobile-android-improvements-safe-borders-new-ui-scaling-accounting-for-auto-rotation-nicer-better-gestures-with-tcastleexaminenavigation-modern-android-photo-services-improved-docs/1293/1 "2024-08-02T15:31:52Z")

</div>

| [![Android inspector with safe borders](https://forum.castle-engine.io/uploads/default/original/2X/f/fc034fdb69c74cd09ade6b27ba126f9bae070c26.png)](https://castle-engine.io/wp/wp-content/uploads/2024/08/Screenshot_1722611917.png "Android inspector with safe borders") |
| [![Android inspector with safe borders](https://forum.castle-engine.io/uploads/default/original/2X/6/6f15eb5e37ecc77b2536f114c21a35dfbcc0a06a.png)](https://castle-engine.io/wp/wp-content/uploads/2024/08/Screenshot_1722611973.png "Android inspector with safe borders") |
| [![Android with safe borders](https://forum.castle-engine.io/uploads/default/original/2X/3/318b9ae1cc36c3c5c42245bbc041bf6003f0943f.png)](https://castle-engine.io/wp/wp-content/uploads/2024/08/Screenshot_1722612090.png "Android with safe borders") |

Hi all! Today we announce a number of improvements for mobile ([Android](https://castle-engine.io/android), [iOS](https://castle-engine.io/ios)) development. They’ve been done while testing:

- [Recently announced Castle Model Viewer on Android](https://castle-engine.io/castle-model-viewer-mobile), see [news](https://castle-engine.io/wp/2024/07/27/castle-model-viewer-reimagined-for-mobile-available-for-android-now/).

- Updated [Game Services Demo](https://play.google.com/store/apps/details?id=io.castleengine.mobile.game.services) on _Google Play_.

- Updated [Darkest Before the Dawn](https://castle-engine.io/darkest_before_dawn.php). A really old game developed using _Castle Game Engine_. Updated – no ads, use latest engine, released again on Google Play! Historically, this is the first game made for Android using Castle Game Engine, in 2013.

( Missed anything? See [all Castle Game Engine applications on Google Play](https://play.google.com/store/apps/dev?id=8315026166336791468). )

Onward to engine improvements around the mobile:

1. `TCastleContainer.SafeBorder` — new property, working on both iOS and Android, exposing the safe area on screen edges where you should not draw anything important/clickable, because the system itself may draw important/clickable stuff on top of your application there. 

For example the system clock/battery/network state take space on top. The software home/back buttons may be on the bottom. _Notch_ are present on some phones which obscure some part of some edge. See [Android docs for display cutouts](https://developer.android.com/develop/ui/views/layout/display-cutout), [and here](https://android-developers.googleblog.com/2018/07/supporting-display-cutouts-on-edge-to.html) how these displays look like. There are a few terms more-or-less interchangeable for this: _safe area_, _insets_, _display cutouts_ on Android, _status bar/bottom bar_ on iOS.

Usually these are non-zero at top and bottom, but `TCastleContainer.SafeBorder` allows us to expose safe areas on potentially any screen side. Underlying API on Android actually gets all 4 sides. (Current code on iOS only queries for top safe area now, but we can improve it.)

We also exposed `TCastleContainer.OnSafeBorderChanged` to notify about safe area changes. This is important, as applications dynamically switch orientation and/or enter/exit immersive fullscreen modes. So to support `TCastleContainer.SafeBorder` perfectly, make sure to react to `TCastleContainer.OnSafeBorderChanged` events.

Our inspector (F8 on desktop, hold 3 fingers for 1 second on mobile) also shows them, as red bars.

They behave OK with switchable orientations (portrait, landscape), phones and tablets and all supported Android versions, and it doesn’t break our behavior on [fullscreen\_immersive](https://castle-engine.io/project_manifest#_basic_project_information). This was some work to test 🙂

How to actually support them — you need to move / enlarge your UI, to leave an extra space at the respective screen edges. You can move your UI (`TCastleUserInterface.Translation`), you can enlarge it (`TCastleUserInterface.Height`), you can use UI borders (`TCastleUserInterface.Border`), you can use padding available on some controls, you can also just add a solid-colored rectangle just for the sake of these insets. There’s no “automatic” answer, as you see — what to do depends on what UI you display. You can take a look [what Castle Model Viewer for mobile](https://github.com/castle-engine/castle-model-viewer-mobile/blob/master/code/gameviewdisplayscene.pas) does.

2. We have a new UI scaling method `usEncloseReferenceSizeAutoOrientation`. It is very similar to `usEncloseReferenceSize`, but automatically “flips” the reference width/height based on whether the current window sizes indicate portrait or landscape orientation. This means that UI controls have the same physical (real) size as your application orientation changes at runtime (e.g. because you support both portrait and landscape, and user just rotated the device).

3. Gestures done with 2 fingers (on mobile) to zoom (pinch) and move (pan) with `TCastleExamineNavigation` have been quite improved. The code was simplified, the gestures now “kick in” instantly and they switch between pinch / pan dynamically, so you can effectively do both pinch and pan without releasing your fingers. This results in UX that feels much better to user.

4. [photo\_service](https://github.com/castle-engine/castle-engine/blob/master/tools/build-tool/data/android/integrated-services/photo_service/README.adoc) on Android was reimplemented to use modern approach on new Android devices and place the images reliably such that they appear in default _“Photos”_ application.

5. We fixed saving files, when the subdirectory of the target file doesn’t exist. Our [handler for saving to `file:/` protocol now creates directory automatically](https://github.com/castle-engine/castle-engine/commit/c281e332c544bd109e475440f1ece4dfe64a6b3e). 

6. We improved our [Android documentation page](https://castle-engine.io/android) (again — this seems to be most often updated documentation page of our website in 2024, maybe aside from [roadmap](https://castle-engine.io/roadmap) 🙂 ). Simplified, and clearly recommends [Android Studio](https://developer.android.com/studio). We work hard to make the Android process very simple and documented. At this point, installing _Android Studio_ (not only Android command-line tools) is the best approach, IMHO — it has Java version that always works, has GUI-friendly access to emulators, mirroring, accepting licenses…

7. We improved our [Android FAQ about emulator usage](https://castle-engine.io/android_faq#emulator).

8. We improved our [Android services list, to list all services and clearly specify which services are usually added automatically to the project](https://castle-engine.io/android_services).

That’s all, for this news announcement! We have a ton of new stuff, brace yourselves for more news 🙂 If you like this, we appreciate your [support on Patreon](https://www.patreon.com/castleengine), or [other financial support](https://castle-engine.io/donate_other.php) , or [other contributions](https://castle-engine.io/helping.php). Reposting / resharing the news about our engine to interested people / places is in particular always appreciated!
