commit fd0b901a9aa6bb6b25d28315167565e185d3b5a2
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun Oct 18 13:50:59 2020 +0100

    Avoid the possible cutouts at the top of the screen.

diff --git a/src/main/java/org/distorted/main/RubikActivity.java b/src/main/java/org/distorted/main/RubikActivity.java
index e34265d7..8584ac76 100644
--- a/src/main/java/org/distorted/main/RubikActivity.java
+++ b/src/main/java/org/distorted/main/RubikActivity.java
@@ -27,6 +27,7 @@ import android.preference.PreferenceManager;
 import androidx.appcompat.app.AppCompatActivity;
 
 import android.util.DisplayMetrics;
+import android.view.DisplayCutout;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.WindowManager;
@@ -106,8 +107,8 @@ public class RubikActivity extends AppCompatActivity
       mIsLocked = false;
 
       hideNavigationBar();
-      huaweiHack();
 
+      // huaweiHack();
       // askForPermissions();
       }
 
@@ -142,6 +143,8 @@ public class RubikActivity extends AppCompatActivity
     @Override
     public void onAttachedToWindow()
       {
+      super.onAttachedToWindow();
+
       final float RATIO = 0.10f;
       float height = getScreenHeightInPixels();
 
@@ -154,6 +157,13 @@ public class RubikActivity extends AppCompatActivity
       ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
       paramsBot.height = (int)(height*RATIO);
       layoutBot.setLayoutParams(paramsBot);
+
+      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
+        {
+        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
+        int inset = cutout!=null ? cutout.getSafeInsetTop() : 0;
+        RubikStatePlay.setSafeInsetTop(inset);
+        }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/states/RubikStatePlay.java b/src/main/java/org/distorted/states/RubikStatePlay.java
index 7efa3c1c..016ea85a 100644
--- a/src/main/java/org/distorted/states/RubikStatePlay.java
+++ b/src/main/java/org/distorted/states/RubikStatePlay.java
@@ -24,7 +24,6 @@ import android.content.SharedPreferences;
 import android.graphics.drawable.BitmapDrawable;
 import android.os.Bundle;
 import android.util.TypedValue;
-import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.Button;
@@ -56,6 +55,8 @@ public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender
   private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about };
   private static final int NUM_BUTTONS = BUTTON_LABELS.length;
 
+  private static int mSafeInsetTop;
+
   private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton, mLockButton;
   private Button mPlayButton;
   private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
@@ -175,7 +176,7 @@ public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender
           View popupView = mObjectPopup.getContentView();
           popupView.setSystemUiVisibility(RubikActivity.FLAGS);
 
-          mObjectPopup.showAsDropDown(view, margin, margin, Gravity.LEFT);
+          mObjectPopup.showAsDropDown(view, margin, margin + mSafeInsetTop);
           mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount);
 
           mObjectPopup.setFocusable(true);
@@ -214,7 +215,7 @@ public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender
         final int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);
         final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN);
 
-        mPlayPopup.showAsDropDown(view, margin, margin, Gravity.RIGHT);
+        mPlayPopup.showAsDropDown(view, margin, margin + mSafeInsetTop);
         mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+2*margin));
 
         mPlayPopup.setFocusable(true);
@@ -251,7 +252,7 @@ public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender
           View popupView = mMenuPopup.getContentView();
           popupView.setSystemUiVisibility(RubikActivity.FLAGS);
 
-          mMenuPopup.showAsDropDown(view, (int)(-width/12), margin, Gravity.CENTER);
+          mMenuPopup.showAsDropDown(view, (int)(-width/12), margin + mSafeInsetTop);
           mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight);
 
           mMenuPopup.setFocusable(true);
@@ -662,6 +663,13 @@ public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void setSafeInsetTop(int top)
+    {
+    mSafeInsetTop = top;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int getLevel()
