|
22 | 22 | import android.util.Base64; |
23 | 23 | import android.view.View; |
24 | 24 | import android.view.Window; |
| 25 | +import android.view.WindowInsetsController; |
25 | 26 | import android.view.inputmethod.InputMethodManager; |
26 | 27 | import android.webkit.WebView; |
27 | 28 | import androidx.core.content.FileProvider; |
@@ -643,74 +644,82 @@ private void removeShortcut(String id, CallbackContext callback) { |
643 | 644 |
|
644 | 645 | private void setUiTheme( |
645 | 646 | final String systemBarColor, |
646 | | - final JSONObject theme, |
| 647 | + final JSONObject schema, |
647 | 648 | final CallbackContext callback |
648 | 649 | ) { |
649 | 650 | this.systemBarColor = Color.parseColor(systemBarColor); |
650 | | - this.theme = new Theme(theme); |
| 651 | + this.theme = new Theme(schema); |
651 | 652 |
|
652 | | - if (Build.VERSION.SDK_INT >= 21) { |
653 | | - final Window window = activity.getWindow(); |
654 | | - // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK |
655 | | - window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
656 | | - window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
657 | | - try { |
658 | | - // Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21 |
| 653 | + final Window window = activity.getWindow(); |
| 654 | + // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK |
| 655 | + window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
| 656 | + window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
| 657 | + try { |
| 658 | + // Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21 |
659 | 659 |
|
660 | | - window |
661 | | - .getClass() |
662 | | - .getMethod("setNavigationBarColor", int.class) |
663 | | - .invoke(window, this.systemBarColor); |
| 660 | + window |
| 661 | + .getClass() |
| 662 | + .getMethod("setNavigationBarColor", int.class) |
| 663 | + .invoke(window, this.systemBarColor); |
664 | 664 |
|
665 | | - window |
666 | | - .getClass() |
667 | | - .getMethod("setStatusBarColor", int.class) |
668 | | - .invoke(window, this.systemBarColor); |
| 665 | + window |
| 666 | + .getClass() |
| 667 | + .getMethod("setStatusBarColor", int.class) |
| 668 | + .invoke(window, this.systemBarColor); |
669 | 669 |
|
| 670 | + if (Build.VERSION.SDK_INT < 30) { |
670 | 671 | setStatusBarStyle(window); |
671 | 672 | setNavigationBarStyle(window); |
672 | | - callback.success("OK"); |
673 | | - } catch (IllegalArgumentException error) { |
674 | | - callback.error(error.toString()); |
675 | | - } catch (Exception error) { |
676 | | - callback.error(error.toString()); |
| 673 | + } else { |
| 674 | + String themeType = theme.getType(); |
| 675 | + WindowInsetsController controller = window.getInsetsController(); |
| 676 | + int appearance = |
| 677 | + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS | |
| 678 | + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS; |
| 679 | + |
| 680 | + if (themeType.equals("light")) { |
| 681 | + controller.setSystemBarsAppearance(appearance, appearance); |
| 682 | + } else { |
| 683 | + controller.setSystemBarsAppearance(0, appearance); |
| 684 | + } |
677 | 685 | } |
| 686 | + callback.success("OK"); |
| 687 | + } catch (IllegalArgumentException error) { |
| 688 | + callback.error(error.toString()); |
| 689 | + } catch (Exception error) { |
| 690 | + callback.error(error.toString()); |
678 | 691 | } |
679 | 692 | } |
680 | 693 |
|
681 | 694 | private void setStatusBarStyle(final Window window) { |
682 | | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
683 | | - View decorView = window.getDecorView(); |
684 | | - int uiOptions = decorView.getSystemUiVisibility(); |
685 | | - String themeType = theme.getType(); |
686 | | - |
687 | | - if (themeType.equals("light")) { |
688 | | - decorView.setSystemUiVisibility( |
689 | | - uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
690 | | - ); |
691 | | - return; |
692 | | - } |
| 695 | + View decorView = window.getDecorView(); |
| 696 | + int uiOptions = decorView.getSystemUiVisibility(); |
| 697 | + String themeType = theme.getType(); |
| 698 | + |
| 699 | + if (themeType.equals("light")) { |
693 | 700 | decorView.setSystemUiVisibility( |
694 | | - uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
| 701 | + uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
695 | 702 | ); |
| 703 | + return; |
696 | 704 | } |
| 705 | + decorView.setSystemUiVisibility( |
| 706 | + uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
| 707 | + ); |
697 | 708 | } |
698 | 709 |
|
699 | 710 | private void setNavigationBarStyle(final Window window) { |
700 | | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
701 | | - View decorView = window.getDecorView(); |
702 | | - int uiOptions = decorView.getSystemUiVisibility(); |
703 | | - String themeType = theme.getType(); |
| 711 | + View decorView = window.getDecorView(); |
| 712 | + int uiOptions = decorView.getSystemUiVisibility(); |
| 713 | + String themeType = theme.getType(); |
704 | 714 |
|
705 | | - // 0x80000000 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
706 | | - // 0x00000010 SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
| 715 | + // 0x80000000 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
| 716 | + // 0x00000010 SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
707 | 717 |
|
708 | | - if (themeType.equals("light")) { |
709 | | - decorView.setSystemUiVisibility(uiOptions | 0x80000000 | 0x00000010); |
710 | | - return; |
711 | | - } |
712 | | - decorView.setSystemUiVisibility(uiOptions | 0x80000000 & ~0x00000010); |
| 718 | + if (themeType.equals("light")) { |
| 719 | + decorView.setSystemUiVisibility(uiOptions | 0x80000000 | 0x00000010); |
| 720 | + return; |
713 | 721 | } |
| 722 | + decorView.setSystemUiVisibility(uiOptions | 0x80000000 & ~0x00000010); |
714 | 723 | } |
715 | 724 |
|
716 | 725 | private void getCordovaIntent(CallbackContext callback) { |
|
0 commit comments