Skip to content

Commit 952759b

Browse files
authored
Enable android cutout mode in axmol engine (#3115)
1 parent 9f93925 commit 952759b

File tree

14 files changed

+41
-30
lines changed

14 files changed

+41
-30
lines changed

axmol/platform/android/java/res/.gitignore

Whitespace-only changes.

axmol/platform/android/java/src/dev/axmol/lib/AxmolActivity.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,19 @@ protected void onCreate(final Bundle savedInstanceState) {
151151
return;
152152
}
153153

154+
Window window = this.getWindow();
155+
// Enable rendering into the cutout area
156+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
157+
WindowManager.LayoutParams lp = window.getAttributes();
158+
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
159+
window.setAttributes(lp);
160+
}
161+
154162
this.hideVirtualButton();
155163

164+
// Input mode
165+
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
166+
156167
onLoadNativeLibraries();
157168

158169
sContext = this;
@@ -163,9 +174,6 @@ protected void onCreate(final Bundle savedInstanceState) {
163174
mPlayer = new AxmolPlayer(this);
164175
setContentView(mPlayer);
165176

166-
Window window = this.getWindow();
167-
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
168-
169177
// Audio configuration
170178
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
171179
}

axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public void run() {
143143
public static void init(final AppCompatActivity activity) {
144144
sActivity = activity;
145145
AxmolEngine.sAxmolEngineListener = (AxmolEngineListener)activity;
146+
146147
if (!sInited) {
147148

148149
PackageManager pm = activity.getPackageManager();
@@ -634,8 +635,9 @@ public static boolean isCutoutEnabled() {
634635
public static int[] getSafeInsets() {
635636
final int[] safeInsets = new int[]{0, 0, 0, 0};
636637
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
637-
Window cocosWindow = sActivity.getWindow();
638-
DisplayCutout displayCutout = cocosWindow.getDecorView().getRootWindowInsets().getDisplayCutout();
638+
Window window = sActivity.getWindow();
639+
WindowInsets rootWindowInsets = window.getDecorView().getRootWindowInsets();
640+
DisplayCutout displayCutout = rootWindowInsets != null ? rootWindowInsets.getDisplayCutout() : null;
639641
// Judge whether it is cutouts (aka notch) screen phone by judge cutout equle to null
640642
if (displayCutout != null) {
641643
List<Rect> rects = displayCutout.getBoundingRects();
@@ -661,9 +663,10 @@ public static int[] getSafeInsets() {
661663
public static int[] getDeviceCornerRadii() {
662664
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
663665
final int[] radii = new int[]{0, 0, 0, 0};
664-
Window cocosWindow = sActivity.getWindow();
665-
View view = cocosWindow.getDecorView();
666+
Window window = sActivity.getWindow();
667+
View view = window.getDecorView();
666668
WindowInsets insets = view.getRootWindowInsets();
669+
if (insets == null) return radii;
667670
android.view.RoundedCorner topLeft = insets.getRoundedCorner(android.view.RoundedCorner.POSITION_TOP_LEFT);
668671
android.view.RoundedCorner topRight = insets.getRoundedCorner(android.view.RoundedCorner.POSITION_TOP_RIGHT);
669672
android.view.RoundedCorner bottomLeft = insets.getRoundedCorner(android.view.RoundedCorner.POSITION_BOTTOM_LEFT);

axmol/platform/android/libaxmol-with-controller/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ android {
1414
sourceSets.main {
1515
aidl.srcDir "../java/src"
1616
java.srcDirs = ['../java/src','../ControllerManualAdapter/src']
17+
res.srcDir "../res"
1718
manifest.srcFile "AndroidManifest.xml"
1819
}
1920

axmol/platform/android/libaxmol/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ android {
1919
sourceSets.main {
2020
aidl.srcDir "../java/src"
2121
java.srcDir "../java/src"
22+
res.srcDir "../res"
2223
manifest.srcFile "AndroidManifest.xml"
2324
}
2425

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<resources>
2+
<style name="AxmolTheme.Fullscreen" parent="Theme.AppCompat.Light.NoActionBar">
3+
<item name="android:windowFullscreen">true</item>
4+
<item name="android:windowNoTitle">true</item>
5+
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
6+
</style>
7+
<style name="AxmolTheme.Dark.Fullscreen" parent="AxmolTheme.Fullscreen">
8+
<item name="android:windowBackground">@android:color/black</item>
9+
</style>
10+
<style name="AxmolTheme.Light.Fullscreen" parent="AxmolTheme.Fullscreen">
11+
<item name="android:windowBackground">@android:color/white</item>
12+
</style>
13+
</resources>

templates/common/proj.android/app/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
android:screenOrientation="sensorLandscape"
1919
android:configChanges="orientation|keyboardHidden|screenSize"
2020
android:label="@string/app_name"
21-
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
21+
android:theme="@style/AxmolTheme.Light.Fullscreen"
2222
android:launchMode="singleTask"
2323
android:taskAffinity=""
2424
android:exported="true" >

tests/cpp-tests/proj.android/app/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
android:screenOrientation="fullSensor"
2222
android:configChanges="orientation|keyboardHidden|screenSize"
2323
android:label="@string/app_name"
24-
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
24+
android:theme="@style/AxmolTheme.Light.Fullscreen"
2525
android:launchMode="singleTask"
2626
android:taskAffinity=""
27-
android:exported="true" >
27+
android:exported="true"
28+
android:resizeableActivity="true">
2829
<intent-filter>
2930
<action android:name="android.intent.action.MAIN" />
3031

tests/fairygui-tests/proj.android/app/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
android:screenOrientation="sensorLandscape"
2020
android:configChanges="orientation|keyboardHidden|screenSize"
2121
android:label="@string/app_name"
22-
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
22+
android:theme="@style/AxmolTheme.Light.Fullscreen"
2323
android:launchMode="singleTask"
2424
android:taskAffinity=""
2525
android:exported="true" >

tests/live2d-tests/proj.android/app/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
android:screenOrientation="sensorLandscape"
2121
android:configChanges="orientation|keyboardHidden|screenSize"
2222
android:label="@string/app_name"
23-
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
23+
android:theme="@style/AxmolTheme.Light.Fullscreen"
2424
android:launchMode="singleTask"
2525
android:taskAffinity=""
2626
android:exported="true" >

0 commit comments

Comments
 (0)