2

How can I get the notch cutout type of a device ? EDIT: As my question is not clear to everybody (I though it was): I am looking for a flag or an enum of some sort that contains the cutout type of the device. It could look like: "CutoutType_Corner". I am not sure if such an enum exists, I am pretty sure it does.

You can get the safe edge insets for all the sides to make sure that the notch (if there) is not covering any parts of the UI. (This is only important if you enable the app to also fill the given space to the left and right of the notch by e.g. setting the window flag LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES.)

In the android developer options you can simulate a display-cutout by choosing between:

  • (None)
  • Corner display cutout
  • (Double display cutout)
  • Tall display cutout

These options are just to simulate but they also provide the same information as if the device really had the chosen cutout as far as I can tell, so there should also be a way to find the set type.

Most of the UI in my case (but also in general in many cases) is centered horizontally without really touching the corners of the screen.

I would like to differentiate between the "corner"- and the "tall"-cutout as the corner is not really occupying important parts of the screen in my case. -> If the screen is a corner-cutout, I can neglect the safe edge insets.

As a visual example: The upper screen is from the Samsung Galaxy S10 with a corner cutout, the lower one is the Google Pixel 3 with a tall-cutout:

Cutout types visually.

The "-Example-" is fitting on the corner-cutout screen, while it is covered by the tall cutout.

Thanks!

Marco Zielbauer
  • 576
  • 1
  • 7
  • 18
  • try never render content in the display cutout area with LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER, the window is never allowed to overlap with the cutout area. more details please ask. I hop it'll help you. – Viral Patel Dec 02 '19 at 06:27
  • @ViralPatel Yes that would be an easy fix but not what I want. I want to render into the cutout area if the spaces allows for it. (The cutout area is there to provide more screen - I want to make use of it (thats why its there). – Marco Zielbauer Dec 02 '19 at 11:02
  • So, what you want in notch? example will remove or move in right,left or bottom. – Viral Patel Dec 02 '19 at 11:42
  • On the second example I will set the example to the bottom (as it will not fit to the left or to the right). If there is just a small test (e.g. "-Ex-") it might fit to the left of the notch. – Marco Zielbauer Dec 02 '19 at 13:01
  • In the values-v28 variant of the styles.xml set this. – Viral Patel Dec 02 '19 at 13:06
  • I want to get the current cutout type. Your solution is working (I am using exactly what you are saying) but it is not my question. – Marco Zielbauer Dec 02 '19 at 13:07
  • So what you want exactly? – Viral Patel Dec 03 '19 at 04:37
  • Have you check this https://stackoverflow.com/a/56609043/7666442 – AskNilesh Dec 04 '19 at 05:47
  • @Nilesh Rathod yes I have. Again it feels like a workaround. – Marco Zielbauer Dec 05 '19 at 08:30
  • @MarcoZielbauer Did you find an answer? – HB. Mar 05 '20 at 04:11

1 Answers1

1

When I tried to solve this task the only suitable API I could find is DisplayCutout:

val corners = view.rootWindowInsets?.displayCutout?.boundingRects

boundingRects returns cutout rect for each corner and with heuristics you can understand what type of cutouts do you have.

Bracadabra
  • 3,609
  • 3
  • 26
  • 46
  • I understand how you would do it. It is not very straight forward compared to an enum or flag tho - and there must be one for sure. (Thats why I will not accept your answer right away!) – Marco Zielbauer Nov 25 '19 at 10:28