Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find if screen has rounded corners

I am looking for a way to determine whether Android device has screen with rounded corners and ideally also the radius.

My usecase is a game that consist of a single fullscreen OpenGL view. It renders some UI elements close to the edges and borders to give as much area as possible to the game itself. But when the screen has rounded corners, they would be partially hidden, so they need to be positioned differently.

like image 911
michalsrb Avatar asked Apr 30 '18 16:04

michalsrb


People also ask

Why do rounded corners look better?

Rounded corners are more effective for maps and diagrams because they allow our eyes to easily follow lines “as it suits better to the natural movement of the head and eyes respectively” [5]. Sharp corners throw your eyes off the path of the line so you end up experiencing abrupt pauses when the line changes direction.


2 Answers

Android S Developer Preview adds a RoundedCorner API, via WindowInsets.getRoundedCorner(int position). It provides the center point and radius of each rounded corner.

Ref: https://developer.android.com/about/versions/12/features#rounded_corner_apis

like image 91
rockgecko Avatar answered Oct 15 '22 23:10

rockgecko


Update as of 6th June 2019

Android officially supports display cutouts on devices running Android 9 (API level 28) and higher.

Reference: https://developer.android.com/guide/topics/display-cutout/

Currently (7th May 2018) you can only check if the physical screen is rounded or not (for Android Wear) using [isRounded()][1] method but can not check if screen corners are rounded.

I think there are only a few devices with rounded corners out there. So it's better to just check the name of device and adjust your layout accordingly.

There is one popular Android library to get the market name of an Android device. Check here for more information: https://github.com/jaredrummler/AndroidDeviceNames/

Usage:

String deviceName = DeviceName.getDeviceName();

Hope this workaround will help you temporarily.

Maybe all devices in the future will release with round corner screens (just an assumption).

like image 41
Vikasdeep Singh Avatar answered Oct 15 '22 22:10

Vikasdeep Singh