11package arc .backend .android ;
22
3+ import android .annotation .*;
34import android .opengl .*;
45import android .opengl .GLSurfaceView .*;
6+ import android .os .*;
57import android .util .*;
68import android .view .*;
79import arc .*;
@@ -45,6 +47,7 @@ public class AndroidGraphics extends Graphics implements Renderer{
4547 protected int fps ;
4648 int width ;
4749 int height ;
50+ int safeInsetLeft , safeInsetTop , safeInsetBottom , safeInsetRight ;
4851 AndroidApplication app ;
4952 GL20 gl20 ;
5053 GL30 gl30 ;
@@ -215,6 +218,7 @@ public void onSurfaceChanged(GL10 gl, int width, int height){
215218 this .width = width ;
216219 this .height = height ;
217220 updatePpi ();
221+ updateSafeAreaInsets ();
218222 gl .glViewport (0 , 0 , this .width , this .height );
219223 if (!created ){
220224 app .mainThread = Thread .currentThread ();
@@ -238,6 +242,7 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config){
238242 setupGL (gl );
239243 logConfig (config );
240244 updatePpi ();
245+ updateSafeAreaInsets ();
241246
242247 Display display = app .getWindowManager ().getDefaultDisplay ();
243248 this .width = display .getWidth ();
@@ -389,6 +394,35 @@ public void onDrawFrame(GL10 gl){
389394 frames ++;
390395 }
391396
397+ @ TargetApi (Build .VERSION_CODES .P )
398+ protected void updateSafeAreaInsets (){
399+
400+ safeInsetLeft = 0 ;
401+ safeInsetTop = 0 ;
402+ safeInsetRight = 0 ;
403+ safeInsetBottom = 0 ;
404+
405+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ){
406+ try {
407+ DisplayCutout displayCutout = app .getWindow ().getDecorView ().getRootWindowInsets ().getDisplayCutout ();
408+ if (displayCutout != null ){
409+ safeInsetRight = displayCutout .getSafeInsetRight ();
410+ safeInsetBottom = displayCutout .getSafeInsetBottom ();
411+ safeInsetTop = displayCutout .getSafeInsetTop ();
412+ safeInsetLeft = displayCutout .getSafeInsetLeft ();
413+ }
414+ } // Some Application implementations (such as Live Wallpapers) do not implement Application#getApplicationWindow()
415+ catch (UnsupportedOperationException e ){
416+ Log .err ("AndroidGraphics" , "Unable to get safe area insets" , e );
417+ }
418+ }
419+ }
420+
421+ @ Override
422+ public int [] getSafeInsets (){
423+ return new int []{safeInsetLeft , safeInsetRight , safeInsetTop , safeInsetBottom };
424+ }
425+
392426 @ Override
393427 public long getFrameId (){
394428 return frameId ;
0 commit comments