|
6 | 6 | import android.net.Uri; |
7 | 7 | import android.os.Bundle; |
8 | 8 | import androidx.appcompat.app.AppCompatActivity; |
| 9 | +import androidx.core.view.WindowCompat; |
| 10 | +import androidx.core.view.WindowInsetsCompat; |
| 11 | +import androidx.core.view.WindowInsetsControllerCompat; |
9 | 12 | import androidx.lifecycle.ViewModelProvider; |
10 | 13 | import androidx.navigation.NavController; |
11 | 14 | import androidx.navigation.fragment.NavHostFragment; |
@@ -49,6 +52,10 @@ public static int getBoardHeight() { |
49 | 52 | protected void onCreate(Bundle savedInstanceState) { |
50 | 53 | super.onCreate(savedInstanceState); |
51 | 54 |
|
| 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 | + |
52 | 59 | // Apply fullscreen mode if enabled |
53 | 60 | applyFullscreenMode(); |
54 | 61 |
|
@@ -665,22 +672,83 @@ private void applyLanguageSettings() { |
665 | 672 | private void applyFullscreenMode() { |
666 | 673 | // Check if fullscreen is enabled in preferences |
667 | 674 | boolean fullscreenEnabled = Preferences.fullscreenEnabled; |
668 | | - |
| 675 | + |
669 | 676 | 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 { |
671 | 733 | getWindow().getDecorView().setSystemUiVisibility( |
672 | 734 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
673 | 735 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
674 | 736 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
675 | 737 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
676 | 738 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
677 | 739 | | 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 { |
682 | 748 | 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"); |
684 | 752 | } |
685 | 753 | } |
686 | 754 | } |
0 commit comments