summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar Abandoned Cart2023-06-12 10:36:06 -0400
committerGravatar Abandoned Cart2023-06-14 16:34:23 -0400
commit2b5dde162ac004c582b20d1c2ad01966e92b2d54 (patch)
tree5a90c030941694a1f8c19f398cd3754f1feaed33 /src/android
parentandroid: Set portrait default control params (diff)
downloadyuzu-2b5dde162ac004c582b20d1c2ad01966e92b2d54.tar.gz
yuzu-2b5dde162ac004c582b20d1c2ad01966e92b2d54.tar.xz
yuzu-2b5dde162ac004c582b20d1c2ad01966e92b2d54.zip
android: Add a separate foldable layout set
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt2
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt380
-rw-r--r--src/android/app/src/main/res/values/integers.xml46
3 files changed, 222 insertions, 206 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
index c65db59f8..c0332a447 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
@@ -332,6 +332,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
332 if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) { 332 if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) {
333 binding.emulationContainer.layoutParams.height = it.bounds.top 333 binding.emulationContainer.layoutParams.height = it.bounds.top
334 // Prevent touch regions from being displayed in the hinge 334 // Prevent touch regions from being displayed in the hinge
335 binding.surfaceInputOverlay.isInFoldableLayout = true
335 binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx 336 binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx
336 binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx) 337 binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)
337 binding.inGameMenu.layoutParams.height = it.bounds.bottom 338 binding.inGameMenu.layoutParams.height = it.bounds.bottom
@@ -344,6 +345,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
344 binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT 345 binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
345 binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT 346 binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
346 binding.overlayContainer.updatePadding(0, 0, 0, 0) 347 binding.overlayContainer.updatePadding(0, 0, 0, 0)
348 binding.surfaceInputOverlay.isInFoldableLayout = false
347 binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT 349 binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
348 updateScreenLayout() 350 updateScreenLayout()
349 } 351 }
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt
index ae5d935d0..f6b29865e 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt
@@ -553,10 +553,7 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
553 553
554 private fun defaultOverlay() { 554 private fun defaultOverlay() {
555 if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) { 555 if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) {
556 if (orientation == portrait) 556 defaultOverlayByLayout(orientation)
557 defaultOverlayPortrait()
558 else
559 defaultOverlayLandscape()
560 } 557 }
561 558
562 resetButtonPlacement() 559 resetButtonPlacement()
@@ -566,265 +563,239 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
566 } 563 }
567 564
568 fun resetButtonPlacement() { 565 fun resetButtonPlacement() {
569 if (orientation == portrait) 566 defaultOverlayByLayout(orientation)
570 defaultOverlayPortrait()
571 else
572 defaultOverlayLandscape()
573 refreshControls() 567 refreshControls()
574 } 568 }
575 569
576 private fun defaultOverlayPortrait() { 570 private val landscapeResources = arrayOf(
577 // Each value represents the position of the button in relation to the screen size without insets. 571 R.integer.SWITCH_BUTTON_A_X,
578 preferences.edit() 572 R.integer.SWITCH_BUTTON_A_Y,
579 .putFloat( 573 R.integer.SWITCH_BUTTON_B_X,
580 ButtonType.BUTTON_A.toString() + "$portrait-X", 574 R.integer.SWITCH_BUTTON_B_Y,
581 resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_X).toFloat() / 1000 575 R.integer.SWITCH_BUTTON_X_X,
582 ) 576 R.integer.SWITCH_BUTTON_X_Y,
583 .putFloat( 577 R.integer.SWITCH_BUTTON_Y_X,
584 ButtonType.BUTTON_A.toString() + "$portrait-Y", 578 R.integer.SWITCH_BUTTON_Y_Y,
585 resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_Y).toFloat() / 1000 579 R.integer.SWITCH_TRIGGER_ZL_X,
586 ) 580 R.integer.SWITCH_TRIGGER_ZL_Y,
587 .putFloat( 581 R.integer.SWITCH_TRIGGER_ZR_X,
588 ButtonType.BUTTON_B.toString() + "$portrait-X", 582 R.integer.SWITCH_TRIGGER_ZR_Y,
589 resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_X).toFloat() / 1000 583 R.integer.SWITCH_BUTTON_DPAD_X,
590 ) 584 R.integer.SWITCH_BUTTON_DPAD_Y,
591 .putFloat( 585 R.integer.SWITCH_TRIGGER_L_X,
592 ButtonType.BUTTON_B.toString() + "$portrait-Y", 586 R.integer.SWITCH_TRIGGER_L_Y,
593 resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_Y).toFloat() / 1000 587 R.integer.SWITCH_TRIGGER_R_X,
594 ) 588 R.integer.SWITCH_TRIGGER_R_Y,
595 .putFloat( 589 R.integer.SWITCH_BUTTON_PLUS_X,
596 ButtonType.BUTTON_X.toString() + "$portrait-X", 590 R.integer.SWITCH_BUTTON_PLUS_Y,
597 resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_X).toFloat() / 1000 591 R.integer.SWITCH_BUTTON_MINUS_X,
598 ) 592 R.integer.SWITCH_BUTTON_MINUS_Y,
599 .putFloat( 593 R.integer.SWITCH_BUTTON_HOME_X,
600 ButtonType.BUTTON_X.toString() + "$portrait-Y", 594 R.integer.SWITCH_BUTTON_HOME_Y,
601 resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_Y).toFloat() / 1000 595 R.integer.SWITCH_BUTTON_CAPTURE_X,
602 ) 596 R.integer.SWITCH_BUTTON_CAPTURE_Y,
603 .putFloat( 597 R.integer.SWITCH_STICK_R_X,
604 ButtonType.BUTTON_Y.toString() + "$portrait-X", 598 R.integer.SWITCH_STICK_R_Y,
605 resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_X).toFloat() / 1000 599 R.integer.SWITCH_STICK_L_X,
606 ) 600 R.integer.SWITCH_STICK_L_Y
607 .putFloat( 601 )
608 ButtonType.BUTTON_Y.toString() + "$portrait-Y", 602
609 resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_Y).toFloat() / 1000 603 private val portraitResources = arrayOf(
610 ) 604 R.integer.SWITCH_BUTTON_A_PORTRAIT_X,
611 .putFloat( 605 R.integer.SWITCH_BUTTON_A_PORTRAIT_Y,
612 ButtonType.TRIGGER_ZL.toString() + "$portrait-X", 606 R.integer.SWITCH_BUTTON_B_PORTRAIT_X,
613 resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_X).toFloat() / 1000 607 R.integer.SWITCH_BUTTON_B_PORTRAIT_Y,
614 ) 608 R.integer.SWITCH_BUTTON_X_PORTRAIT_X,
615 .putFloat( 609 R.integer.SWITCH_BUTTON_X_PORTRAIT_Y,
616 ButtonType.TRIGGER_ZL.toString() + "$portrait-Y", 610 R.integer.SWITCH_BUTTON_Y_PORTRAIT_X,
617 resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_Y).toFloat() / 1000 611 R.integer.SWITCH_BUTTON_Y_PORTRAIT_Y,
618 ) 612 R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_X,
619 .putFloat( 613 R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_Y,
620 ButtonType.TRIGGER_ZR.toString() + "$portrait-X", 614 R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_X,
621 resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_X).toFloat() / 1000 615 R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_Y,
622 ) 616 R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_X,
623 .putFloat( 617 R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_Y,
624 ButtonType.TRIGGER_ZR.toString() + "$portrait-Y", 618 R.integer.SWITCH_TRIGGER_L_PORTRAIT_X,
625 resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_Y).toFloat() / 1000 619 R.integer.SWITCH_TRIGGER_L_PORTRAIT_Y,
626 ) 620 R.integer.SWITCH_TRIGGER_R_PORTRAIT_X,
627 .putFloat( 621 R.integer.SWITCH_TRIGGER_R_PORTRAIT_Y,
628 ButtonType.DPAD_UP.toString() + "$portrait-X", 622 R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_X,
629 resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_X).toFloat() / 1000 623 R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_Y,
630 ) 624 R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_X,
631 .putFloat( 625 R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_Y,
632 ButtonType.DPAD_UP.toString() + "$portrait-Y", 626 R.integer.SWITCH_BUTTON_HOME_PORTRAIT_X,
633 resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_Y).toFloat() / 1000 627 R.integer.SWITCH_BUTTON_HOME_PORTRAIT_Y,
634 ) 628 R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_X,
635 .putFloat( 629 R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_Y,
636 ButtonType.TRIGGER_L.toString() + "$portrait-X", 630 R.integer.SWITCH_STICK_R_PORTRAIT_X,
637 resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_X).toFloat() / 1000 631 R.integer.SWITCH_STICK_R_PORTRAIT_Y,
638 ) 632 R.integer.SWITCH_STICK_L_PORTRAIT_X,
639 .putFloat( 633 R.integer.SWITCH_STICK_L_PORTRAIT_Y
640 ButtonType.TRIGGER_L.toString() + "$portrait-Y", 634 )
641 resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_Y).toFloat() / 1000 635
642 ) 636 private val foldableResources = arrayOf(
643 .putFloat( 637 R.integer.SWITCH_BUTTON_A_FOLDABLE_X,
644 ButtonType.TRIGGER_R.toString() + "$portrait-X", 638 R.integer.SWITCH_BUTTON_A_FOLDABLE_Y,
645 resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_X).toFloat() / 1000 639 R.integer.SWITCH_BUTTON_B_FOLDABLE_X,
646 ) 640 R.integer.SWITCH_BUTTON_B_FOLDABLE_Y,
647 .putFloat( 641 R.integer.SWITCH_BUTTON_X_FOLDABLE_X,
648 ButtonType.TRIGGER_R.toString() + "$portrait-Y", 642 R.integer.SWITCH_BUTTON_X_FOLDABLE_Y,
649 resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_Y).toFloat() / 1000 643 R.integer.SWITCH_BUTTON_Y_FOLDABLE_X,
650 ) 644 R.integer.SWITCH_BUTTON_Y_FOLDABLE_Y,
651 .putFloat( 645 R.integer.SWITCH_TRIGGER_ZL_FOLDABLE_X,
652 ButtonType.BUTTON_PLUS.toString() + "$portrait-X", 646 R.integer.SWITCH_TRIGGER_ZL_FOLDABLE_Y,
653 resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_X).toFloat() / 1000 647 R.integer.SWITCH_TRIGGER_ZR_FOLDABLE_X,
654 ) 648 R.integer.SWITCH_TRIGGER_ZR_FOLDABLE_Y,
655 .putFloat( 649 R.integer.SWITCH_BUTTON_DPAD_FOLDABLE_X,
656 ButtonType.BUTTON_PLUS.toString() + "$portrait-Y", 650 R.integer.SWITCH_BUTTON_DPAD_FOLDABLE_Y,
657 resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_Y).toFloat() / 1000 651 R.integer.SWITCH_TRIGGER_L_FOLDABLE_X,
658 ) 652 R.integer.SWITCH_TRIGGER_L_FOLDABLE_Y,
659 .putFloat( 653 R.integer.SWITCH_TRIGGER_R_FOLDABLE_X,
660 ButtonType.BUTTON_MINUS.toString() + "$portrait-X", 654 R.integer.SWITCH_TRIGGER_R_FOLDABLE_Y,
661 resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_X).toFloat() / 1000 655 R.integer.SWITCH_BUTTON_PLUS_FOLDABLE_X,
662 ) 656 R.integer.SWITCH_BUTTON_PLUS_FOLDABLE_Y,
663 .putFloat( 657 R.integer.SWITCH_BUTTON_MINUS_FOLDABLE_X,
664 ButtonType.BUTTON_MINUS.toString() + "$portrait-Y", 658 R.integer.SWITCH_BUTTON_MINUS_FOLDABLE_Y,
665 resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_Y).toFloat() / 1000 659 R.integer.SWITCH_BUTTON_HOME_FOLDABLE_X,
666 ) 660 R.integer.SWITCH_BUTTON_HOME_FOLDABLE_Y,
667 .putFloat( 661 R.integer.SWITCH_BUTTON_CAPTURE_FOLDABLE_X,
668 ButtonType.BUTTON_HOME.toString() + "$portrait-X", 662 R.integer.SWITCH_BUTTON_CAPTURE_FOLDABLE_Y,
669 resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_X).toFloat() / 1000 663 R.integer.SWITCH_STICK_R_FOLDABLE_X,
670 ) 664 R.integer.SWITCH_STICK_R_FOLDABLE_Y,
671 .putFloat( 665 R.integer.SWITCH_STICK_L_FOLDABLE_X,
672 ButtonType.BUTTON_HOME.toString() + "$portrait-Y", 666 R.integer.SWITCH_STICK_L_FOLDABLE_Y
673 resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_Y).toFloat() / 1000 667 )
674 ) 668
675 .putFloat( 669 private fun getResourceValue(descriptor: String, position: Int) : Float {
676 ButtonType.BUTTON_CAPTURE.toString() + "$portrait-X", 670 return when (descriptor) {
677 resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_X) 671 portrait -> resources.getInteger(portraitResources[position]).toFloat() / 1000
678 .toFloat() / 1000 672 foldable -> resources.getInteger(foldableResources[position]).toFloat() / 1000
679 ) 673 else -> resources.getInteger(landscapeResources[position]).toFloat() / 1000
680 .putFloat( 674 }
681 ButtonType.BUTTON_CAPTURE.toString() + "$portrait-Y",
682 resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_Y)
683 .toFloat() / 1000
684 )
685 .putFloat(
686 ButtonType.STICK_R.toString() + "$portrait-X",
687 resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_X).toFloat() / 1000
688 )
689 .putFloat(
690 ButtonType.STICK_R.toString() + "$portrait-Y",
691 resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_Y).toFloat() / 1000
692 )
693 .putFloat(
694 ButtonType.STICK_L.toString() + "$portrait-X",
695 resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_X).toFloat() / 1000
696 )
697 .putFloat(
698 ButtonType.STICK_L.toString() + "$portrait-Y",
699 resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_Y).toFloat() / 1000
700 )
701 .apply()
702 } 675 }
703 676
704 private fun defaultOverlayLandscape() { 677 private fun defaultOverlayByLayout(descriptor: String) {
705 // Each value represents the position of the button in relation to the screen size without insets. 678 // Each value represents the position of the button in relation to the screen size without insets.
706 preferences.edit() 679 preferences.edit()
707 .putFloat( 680 .putFloat(
708 ButtonType.BUTTON_A.toString() + "-X", 681 ButtonType.BUTTON_A.toString() + "$descriptor-X",
709 resources.getInteger(R.integer.SWITCH_BUTTON_A_X).toFloat() / 1000 682 getResourceValue(descriptor, 0)
710 ) 683 )
711 .putFloat( 684 .putFloat(
712 ButtonType.BUTTON_A.toString() + "-Y", 685 ButtonType.BUTTON_A.toString() + "$descriptor-Y",
713 resources.getInteger(R.integer.SWITCH_BUTTON_A_Y).toFloat() / 1000 686 getResourceValue(descriptor, 1)
714 ) 687 )
715 .putFloat( 688 .putFloat(
716 ButtonType.BUTTON_B.toString() + "-X", 689 ButtonType.BUTTON_B.toString() + "$descriptor-X",
717 resources.getInteger(R.integer.SWITCH_BUTTON_B_X).toFloat() / 1000 690 getResourceValue(descriptor, 2)
718 ) 691 )
719 .putFloat( 692 .putFloat(
720 ButtonType.BUTTON_B.toString() + "-Y", 693 ButtonType.BUTTON_B.toString() + "$descriptor-Y",
721 resources.getInteger(R.integer.SWITCH_BUTTON_B_Y).toFloat() / 1000 694 getResourceValue(descriptor, 3)
722 ) 695 )
723 .putFloat( 696 .putFloat(
724 ButtonType.BUTTON_X.toString() + "-X", 697 ButtonType.BUTTON_X.toString() + "$descriptor-X",
725 resources.getInteger(R.integer.SWITCH_BUTTON_X_X).toFloat() / 1000 698 getResourceValue(descriptor, 4)
726 ) 699 )
727 .putFloat( 700 .putFloat(
728 ButtonType.BUTTON_X.toString() + "-Y", 701 ButtonType.BUTTON_X.toString() + "$descriptor-Y",
729 resources.getInteger(R.integer.SWITCH_BUTTON_X_Y).toFloat() / 1000 702 getResourceValue(descriptor, 5)
730 ) 703 )
731 .putFloat( 704 .putFloat(
732 ButtonType.BUTTON_Y.toString() + "-X", 705 ButtonType.BUTTON_Y.toString() + "$descriptor-X",
733 resources.getInteger(R.integer.SWITCH_BUTTON_Y_X).toFloat() / 1000 706 getResourceValue(descriptor, 6)
734 ) 707 )
735 .putFloat( 708 .putFloat(
736 ButtonType.BUTTON_Y.toString() + "-Y", 709 ButtonType.BUTTON_Y.toString() + "$descriptor-Y",
737 resources.getInteger(R.integer.SWITCH_BUTTON_Y_Y).toFloat() / 1000 710 getResourceValue(descriptor, 7)
738 ) 711 )
739 .putFloat( 712 .putFloat(
740 ButtonType.TRIGGER_ZL.toString() + "-X", 713 ButtonType.TRIGGER_ZL.toString() + "$descriptor-X",
741 resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_X).toFloat() / 1000 714 getResourceValue(descriptor, 8)
742 ) 715 )
743 .putFloat( 716 .putFloat(
744 ButtonType.TRIGGER_ZL.toString() + "-Y", 717 ButtonType.TRIGGER_ZL.toString() + "$descriptor-Y",
745 resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_Y).toFloat() / 1000 718 getResourceValue(descriptor, 9)
746 ) 719 )
747 .putFloat( 720 .putFloat(
748 ButtonType.TRIGGER_ZR.toString() + "-X", 721 ButtonType.TRIGGER_ZR.toString() + "$descriptor-X",
749 resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_X).toFloat() / 1000 722 getResourceValue(descriptor, 10)
750 ) 723 )
751 .putFloat( 724 .putFloat(
752 ButtonType.TRIGGER_ZR.toString() + "-Y", 725 ButtonType.TRIGGER_ZR.toString() + "$descriptor-Y",
753 resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_Y).toFloat() / 1000 726 getResourceValue(descriptor, 11)
754 ) 727 )
755 .putFloat( 728 .putFloat(
756 ButtonType.DPAD_UP.toString() + "-X", 729 ButtonType.DPAD_UP.toString() + "$descriptor-X",
757 resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_X).toFloat() / 1000 730 getResourceValue(descriptor, 12)
758 ) 731 )
759 .putFloat( 732 .putFloat(
760 ButtonType.DPAD_UP.toString() + "-Y", 733 ButtonType.DPAD_UP.toString() + "$descriptor-Y",
761 resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_Y).toFloat() / 1000 734 getResourceValue(descriptor, 13)
762 ) 735 )
763 .putFloat( 736 .putFloat(
764 ButtonType.TRIGGER_L.toString() + "-X", 737 ButtonType.TRIGGER_L.toString() + "$descriptor-X",
765 resources.getInteger(R.integer.SWITCH_TRIGGER_L_X).toFloat() / 1000 738 getResourceValue(descriptor, 14)
766 ) 739 )
767 .putFloat( 740 .putFloat(
768 ButtonType.TRIGGER_L.toString() + "-Y", 741 ButtonType.TRIGGER_L.toString() + "$descriptor-Y",
769 resources.getInteger(R.integer.SWITCH_TRIGGER_L_Y).toFloat() / 1000 742 getResourceValue(descriptor, 15)
770 ) 743 )
771 .putFloat( 744 .putFloat(
772 ButtonType.TRIGGER_R.toString() + "-X", 745 ButtonType.TRIGGER_R.toString() + "$descriptor-X",
773 resources.getInteger(R.integer.SWITCH_TRIGGER_R_X).toFloat() / 1000 746 getResourceValue(descriptor, 16)
774 ) 747 )
775 .putFloat( 748 .putFloat(
776 ButtonType.TRIGGER_R.toString() + "-Y", 749 ButtonType.TRIGGER_R.toString() + "$descriptor-Y",
777 resources.getInteger(R.integer.SWITCH_TRIGGER_R_Y).toFloat() / 1000 750 getResourceValue(descriptor, 17)
778 ) 751 )
779 .putFloat( 752 .putFloat(
780 ButtonType.BUTTON_PLUS.toString() + "-X", 753 ButtonType.BUTTON_PLUS.toString() + "$descriptor-X",
781 resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_X).toFloat() / 1000 754 getResourceValue(descriptor, 18)
782 ) 755 )
783 .putFloat( 756 .putFloat(
784 ButtonType.BUTTON_PLUS.toString() + "-Y", 757 ButtonType.BUTTON_PLUS.toString() + "$descriptor-Y",
785 resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_Y).toFloat() / 1000 758 getResourceValue(descriptor, 19)
786 ) 759 )
787 .putFloat( 760 .putFloat(
788 ButtonType.BUTTON_MINUS.toString() + "-X", 761 ButtonType.BUTTON_MINUS.toString() + "$descriptor-X",
789 resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_X).toFloat() / 1000 762 getResourceValue(descriptor, 20)
790 ) 763 )
791 .putFloat( 764 .putFloat(
792 ButtonType.BUTTON_MINUS.toString() + "-Y", 765 ButtonType.BUTTON_MINUS.toString() + "$descriptor-Y",
793 resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_Y).toFloat() / 1000 766 getResourceValue(descriptor, 21)
794 ) 767 )
795 .putFloat( 768 .putFloat(
796 ButtonType.BUTTON_HOME.toString() + "-X", 769 ButtonType.BUTTON_HOME.toString() + "$descriptor-X",
797 resources.getInteger(R.integer.SWITCH_BUTTON_HOME_X).toFloat() / 1000 770 getResourceValue(descriptor, 22)
798 ) 771 )
799 .putFloat( 772 .putFloat(
800 ButtonType.BUTTON_HOME.toString() + "-Y", 773 ButtonType.BUTTON_HOME.toString() + "$descriptor-Y",
801 resources.getInteger(R.integer.SWITCH_BUTTON_HOME_Y).toFloat() / 1000 774 getResourceValue(descriptor, 23)
802 ) 775 )
803 .putFloat( 776 .putFloat(
804 ButtonType.BUTTON_CAPTURE.toString() + "-X", 777 ButtonType.BUTTON_CAPTURE.toString() + "$descriptor-X",
805 resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_X) 778 getResourceValue(descriptor, 24)
806 .toFloat() / 1000
807 ) 779 )
808 .putFloat( 780 .putFloat(
809 ButtonType.BUTTON_CAPTURE.toString() + "-Y", 781 ButtonType.BUTTON_CAPTURE.toString() + "$descriptor-Y",
810 resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_Y) 782 getResourceValue(descriptor, 25)
811 .toFloat() / 1000
812 ) 783 )
813 .putFloat( 784 .putFloat(
814 ButtonType.STICK_R.toString() + "-X", 785 ButtonType.STICK_R.toString() + "$descriptor-X",
815 resources.getInteger(R.integer.SWITCH_STICK_R_X).toFloat() / 1000 786 getResourceValue(descriptor, 26)
816 ) 787 )
817 .putFloat( 788 .putFloat(
818 ButtonType.STICK_R.toString() + "-Y", 789 ButtonType.STICK_R.toString() + "$descriptor-Y",
819 resources.getInteger(R.integer.SWITCH_STICK_R_Y).toFloat() / 1000 790 getResourceValue(descriptor, 27)
820 ) 791 )
821 .putFloat( 792 .putFloat(
822 ButtonType.STICK_L.toString() + "-X", 793 ButtonType.STICK_L.toString() + "$descriptor-X",
823 resources.getInteger(R.integer.SWITCH_STICK_L_X).toFloat() / 1000 794 getResourceValue(descriptor, 28)
824 ) 795 )
825 .putFloat( 796 .putFloat(
826 ButtonType.STICK_L.toString() + "-Y", 797 ButtonType.STICK_L.toString() + "$descriptor-Y",
827 resources.getInteger(R.integer.SWITCH_STICK_L_Y).toFloat() / 1000 798 getResourceValue(descriptor, 29)
828 ) 799 )
829 .apply() 800 .apply()
830 } 801 }
@@ -835,18 +806,29 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
835 806
836 override fun onConfigurationChanged(newConfig: Configuration?) { 807 override fun onConfigurationChanged(newConfig: Configuration?) {
837 super.onConfigurationChanged(newConfig) 808 super.onConfigurationChanged(newConfig)
838 orientation = 809 if (!isInFoldableLayout) {
839 if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT) 810 orientation = if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT)
840 portrait 811 portrait
841 else 812 else
842 "" 813 ""
814 }
843 } 815 }
844 816
817 var isInFoldableLayout : Boolean = false
818 set(value) {
819 if (value)
820 orientation = foldable
821 else
822 onConfigurationChanged(resources.configuration)
823 field = value
824 }
825
845 companion object { 826 companion object {
846 private val preferences: SharedPreferences = 827 private val preferences: SharedPreferences =
847 PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) 828 PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
848 829
849 private const val portrait = "-Portrait" 830 private const val portrait = "-Portrait"
831 private const val foldable = "-Foldable"
850 private var orientation = "" 832 private var orientation = ""
851 833
852 /** 834 /**
diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xml
index 326867664..07ddf3470 100644
--- a/src/android/app/src/main/res/values/integers.xml
+++ b/src/android/app/src/main/res/values/integers.xml
@@ -3,15 +3,15 @@
3 <integer name="game_title_lines">2</integer> 3 <integer name="game_title_lines">2</integer>
4 4
5 <!-- Default SWITCH portrait layout --> 5 <!-- Default SWITCH portrait layout -->
6 <integer name="SWITCH_BUTTON_A_PORTRAIT_X">830</integer> 6 <integer name="SWITCH_BUTTON_A_PORTRAIT_X">840</integer>
7 <integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer> 7 <integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer>
8 <integer name="SWITCH_BUTTON_B_PORTRAIT_X">730</integer> 8 <integer name="SWITCH_BUTTON_B_PORTRAIT_X">740</integer>
9 <integer name="SWITCH_BUTTON_B_PORTRAIT_Y">870</integer> 9 <integer name="SWITCH_BUTTON_B_PORTRAIT_Y">860</integer>
10 <integer name="SWITCH_BUTTON_X_PORTRAIT_X">730</integer> 10 <integer name="SWITCH_BUTTON_X_PORTRAIT_X">740</integer>
11 <integer name="SWITCH_BUTTON_X_PORTRAIT_Y">770</integer> 11 <integer name="SWITCH_BUTTON_X_PORTRAIT_Y">780</integer>
12 <integer name="SWITCH_BUTTON_Y_PORTRAIT_X">630</integer> 12 <integer name="SWITCH_BUTTON_Y_PORTRAIT_X">640</integer>
13 <integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer> 13 <integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer>
14 <integer name="SWITCH_STICK_L_PORTRAIT_X">170</integer> 14 <integer name="SWITCH_STICK_L_PORTRAIT_X">180</integer>
15 <integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer> 15 <integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer>
16 <integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer> 16 <integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer>
17 <integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer> 17 <integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer>
@@ -66,4 +66,36 @@
66 <integer name="SWITCH_BUTTON_DPAD_X">260</integer> 66 <integer name="SWITCH_BUTTON_DPAD_X">260</integer>
67 <integer name="SWITCH_BUTTON_DPAD_Y">790</integer> 67 <integer name="SWITCH_BUTTON_DPAD_Y">790</integer>
68 68
69 <!-- Default SWITCH foldable layout -->
70 <integer name="SWITCH_BUTTON_A_FOLDABLE_X">830</integer>
71 <integer name="SWITCH_BUTTON_A_FOLDABLE_Y">420</integer>
72 <integer name="SWITCH_BUTTON_B_FOLDABLE_X">730</integer>
73 <integer name="SWITCH_BUTTON_B_FOLDABLE_Y">470</integer>
74 <integer name="SWITCH_BUTTON_X_FOLDABLE_X">730</integer>
75 <integer name="SWITCH_BUTTON_X_FOLDABLE_Y">370</integer>
76 <integer name="SWITCH_BUTTON_Y_FOLDABLE_X">630</integer>
77 <integer name="SWITCH_BUTTON_Y_FOLDABLE_Y">420</integer>
78 <integer name="SWITCH_STICK_L_FOLDABLE_X">170</integer>
79 <integer name="SWITCH_STICK_L_FOLDABLE_Y">240</integer>
80 <integer name="SWITCH_STICK_R_FOLDABLE_X">820</integer>
81 <integer name="SWITCH_STICK_R_FOLDABLE_Y">240</integer>
82 <integer name="SWITCH_TRIGGER_L_FOLDABLE_X">140</integer>
83 <integer name="SWITCH_TRIGGER_L_FOLDABLE_Y">100</integer>
84 <integer name="SWITCH_TRIGGER_R_FOLDABLE_X">860</integer>
85 <integer name="SWITCH_TRIGGER_R_FOLDABLE_Y">100</integer>
86 <integer name="SWITCH_TRIGGER_ZL_FOLDABLE_X">140</integer>
87 <integer name="SWITCH_TRIGGER_ZL_FOLDABLE_Y">40</integer>
88 <integer name="SWITCH_TRIGGER_ZR_FOLDABLE_X">860</integer>
89 <integer name="SWITCH_TRIGGER_ZR_FOLDABLE_Y">40</integer>
90 <integer name="SWITCH_BUTTON_MINUS_FOLDABLE_X">440</integer>
91 <integer name="SWITCH_BUTTON_MINUS_FOLDABLE_Y">550</integer>
92 <integer name="SWITCH_BUTTON_PLUS_FOLDABLE_X">560</integer>
93 <integer name="SWITCH_BUTTON_PLUS_FOLDABLE_Y">550</integer>
94 <integer name="SWITCH_BUTTON_HOME_FOLDABLE_X">600</integer>
95 <integer name="SWITCH_BUTTON_HOME_FOLDABLE_Y">550</integer>
96 <integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_X">400</integer>
97 <integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_Y">550</integer>
98 <integer name="SWITCH_BUTTON_DPAD_FOLDABLE_X">240</integer>
99 <integer name="SWITCH_BUTTON_DPAD_FOLDABLE_Y">420</integer>
100
69</resources> 101</resources>