Skip to content

Commit f58c9be

Browse files
committed
implement edge-to-edge display support with modern WindowInsets API ( needed since TargetSdkVersion 35) and fix auto-rotation system settings
1 parent ba704e4 commit f58c9be

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
android:name="roboyard.eclabs.ui.MainFragmentActivity"
1717
android:exported="true"
1818
android:theme="@style/Theme.AppCompat.NoActionBar"
19-
android:screenOrientation="fullSensor">
19+
android:screenOrientation="user">
2020
<intent-filter>
2121
<action android:name="android.intent.action.MAIN" />
2222
<category android:name="android.intent.category.LAUNCHER" />

app/src/main/java/roboyard/eclabs/ui/MainFragmentActivity.java

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import android.net.Uri;
77
import android.os.Bundle;
88
import androidx.appcompat.app.AppCompatActivity;
9+
import androidx.core.view.WindowCompat;
10+
import androidx.core.view.WindowInsetsCompat;
11+
import androidx.core.view.WindowInsetsControllerCompat;
912
import androidx.lifecycle.ViewModelProvider;
1013
import androidx.navigation.NavController;
1114
import androidx.navigation.fragment.NavHostFragment;
@@ -49,6 +52,10 @@ public static int getBoardHeight() {
4952
protected void onCreate(Bundle savedInstanceState) {
5053
super.onCreate(savedInstanceState);
5154

55+
// Enable edge-to-edge display for modern Android versions
56+
// This is safe for all versions as WindowCompat handles compatibility
57+
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
58+
5259
// Apply fullscreen mode if enabled
5360
applyFullscreenMode();
5461

@@ -665,22 +672,83 @@ private void applyLanguageSettings() {
665672
private void applyFullscreenMode() {
666673
// Check if fullscreen is enabled in preferences
667674
boolean fullscreenEnabled = Preferences.fullscreenEnabled;
668-
675+
669676
if (fullscreenEnabled) {
670-
// Apply fullscreen mode by hiding the system UI
677+
// Apply fullscreen mode for edge-to-edge compatibility
678+
applyFullscreenModeForEdgeToEdge();
679+
} else {
680+
// Apply normal mode for edge-to-edge compatibility
681+
applyNormalModeForEdgeToEdge();
682+
}
683+
}
684+
685+
private void applyFullscreenModeForEdgeToEdge() {
686+
try {
687+
// Use modern WindowInsets API for API 30+
688+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
689+
WindowInsetsControllerCompat windowInsetsController =
690+
WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
691+
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
692+
windowInsetsController.setSystemBarsBehavior(
693+
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
694+
} else {
695+
// Fallback for older Android versions
696+
getWindow().getDecorView().setSystemUiVisibility(
697+
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
698+
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
699+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
700+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
701+
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
702+
| View.SYSTEM_UI_FLAG_FULLSCREEN);
703+
}
704+
Timber.d("[FULLSCREEN] Edge-to-edge fullscreen mode enabled");
705+
} catch (Exception e) {
706+
Timber.e(e, "[FULLSCREEN] Error applying edge-to-edge fullscreen mode, falling back to legacy");
707+
// Fallback to legacy fullscreen
708+
applyLegacyFullscreen();
709+
}
710+
}
711+
712+
private void applyNormalModeForEdgeToEdge() {
713+
try {
714+
// Use modern WindowInsets API for API 30+
715+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
716+
WindowInsetsControllerCompat windowInsetsController =
717+
WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
718+
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
719+
} else {
720+
// Fallback for older Android versions
721+
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
722+
}
723+
Timber.d("[FULLSCREEN] Edge-to-edge normal mode - system bars visible");
724+
} catch (Exception e) {
725+
Timber.e(e, "[FULLSCREEN] Error applying edge-to-edge normal mode, falling back to legacy");
726+
// Fallback to legacy normal mode
727+
applyLegacyNormalMode();
728+
}
729+
}
730+
731+
private void applyLegacyFullscreen() {
732+
try {
671733
getWindow().getDecorView().setSystemUiVisibility(
672734
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
673735
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
674736
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
675737
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
676738
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
677739
| View.SYSTEM_UI_FLAG_FULLSCREEN);
678-
679-
Timber.d("[FULLSCREEN] Fullscreen mode enabled");
680-
} else {
681-
// Ensure normal mode with system UI visible
740+
Timber.d("[FULLSCREEN] Legacy fullscreen mode applied");
741+
} catch (Exception e) {
742+
Timber.e(e, "[FULLSCREEN] Error applying legacy fullscreen");
743+
}
744+
}
745+
746+
private void applyLegacyNormalMode() {
747+
try {
682748
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
683-
Timber.d("[FULLSCREEN] Fullscreen mode disabled");
749+
Timber.d("[FULLSCREEN] Legacy normal mode applied");
750+
} catch (Exception e) {
751+
Timber.e(e, "[FULLSCREEN] Error applying legacy normal mode");
684752
}
685753
}
686754
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:fitsSystemWindows="true"
78
tools:context=".MainActivity">
89

910
<androidx.fragment.app.FragmentContainerView

dev/TODO.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,7 @@ check if this all works:
9090

9191
# most important
9292

93-
Der Margin unter dem game grid ist zu klein, die untere Zeile des Games ist verdeckt. der game screen darf niemals verdeckt werden, er muss in der hchsten z-ebene liegen
93+
- Wenn man jetzt den bildschrm dreht, dreht er immer die app ausrichtung (landscape oder protrait) unabhngig von den einstellungen im system.
94+
die app soll aber der systemeinstellung für automatisch drehen gehorchen, also z.b. nicht drehen, wenn dies im system ausgeschaltet ist
95+
96+
Wenn man den fullscreen ausschaltet, ist die app trotzdem noch bildschirmfüllend, das soll aber nicht, es soll dann die obere statuszeile des systems ihren eigenen platz haben, (also das normale verhalten, wie bei den meisten apps sonst auch)

0 commit comments

Comments
 (0)