@@ -249,8 +249,8 @@ def make_package(args):
249
249
with open (os .path .join (env_vars_tarpath , "p4a_env_vars.txt" ), "w" ) as f :
250
250
if hasattr (args , "window" ):
251
251
f .write ("P4A_IS_WINDOWED=" + str (args .window ) + "\n " )
252
- if hasattr (args , "orientation " ):
253
- f .write ("P4A_ORIENTATION =" + str (args .orientation ) + "\n " )
252
+ if hasattr (args , "sdl_orientation_hint " ):
253
+ f .write ("KIVY_ORIENTATION =" + str (args .sdl_orientation_hint ) + "\n " )
254
254
f .write ("P4A_NUMERIC_VERSION=" + str (args .numeric_version ) + "\n " )
255
255
f .write ("P4A_MINSDK=" + str (args .min_sdk_version ) + "\n " )
256
256
@@ -690,20 +690,54 @@ def _decode_advanced_permission(permission):
690
690
return _permissions
691
691
692
692
693
- def parse_args_and_make_package (args = None ):
694
- global BLACKLIST_PATTERNS , WHITELIST_PATTERNS , PYTHON
693
+ def get_sdl_orientation_hint (orientations ):
694
+ SDL_ORIENTATION_MAP = {
695
+ "landscape" : "LandscapeLeft" ,
696
+ "portrait" : "Portrait" ,
697
+ "portrait-reverse" : "PortraitUpsideDown" ,
698
+ "landscape-reverse" : "LandscapeRight" ,
699
+ }
700
+ return " " .join (
701
+ [SDL_ORIENTATION_MAP [x ] for x in orientations if x in SDL_ORIENTATION_MAP ]
702
+ )
703
+
695
704
705
+ def get_manifest_orientation (orientations , manifest_orientation = None ):
706
+ # If the user has specifically set an orientation to use in the manifest,
707
+ # use that.
708
+ if manifest_orientation is not None :
709
+ return manifest_orientation
710
+
711
+ # If multiple or no orientations are specified, use unspecified in the manifest,
712
+ # as we can only specify one orientation in the manifest.
713
+ if len (orientations ) != 1 :
714
+ return "unspecified"
715
+
716
+ # Convert the orientation to a value that can be used in the manifest.
717
+ # If the specified orientation is not supported, use unspecified.
718
+ MANIFEST_ORIENTATION_MAP = {
719
+ "landscape" : "landscape" ,
720
+ "portrait" : "portrait" ,
721
+ "portrait-reverse" : "reversePortrait" ,
722
+ "landscape-reverse" : "reverseLandscape" ,
723
+ }
724
+ return MANIFEST_ORIENTATION_MAP .get (orientations [0 ], "unspecified" )
725
+
726
+
727
+ def get_dist_ndk_min_api_level ():
696
728
# Get the default minsdk, equal to the NDK API that this dist is built against
697
729
try :
698
730
with open ('dist_info.json' , 'r' ) as fileh :
699
731
info = json .load (fileh )
700
- default_min_api = int (info ['ndk_api' ])
701
- ndk_api = default_min_api
732
+ ndk_api = int (info ['ndk_api' ])
702
733
except (OSError , KeyError , ValueError , TypeError ):
703
734
print ('WARNING: Failed to read ndk_api from dist info, defaulting to 12' )
704
- default_min_api = 12 # The old default before ndk_api was introduced
705
- ndk_api = 12
735
+ ndk_api = 12 # The old default before ndk_api was introduced
736
+ return ndk_api
706
737
738
+
739
+ def create_argument_parser ():
740
+ ndk_api = get_dist_ndk_min_api_level ()
707
741
import argparse
708
742
ap = argparse .ArgumentParser (description = '''\
709
743
Package a Python application for Android (using
@@ -786,19 +820,21 @@ def parse_args_and_make_package(args=None):
786
820
ap .add_argument ('--window' , dest = 'window' , action = 'store_true' ,
787
821
default = False ,
788
822
help = 'Indicate if the application will be windowed' )
823
+ ap .add_argument ('--manifest-orientation' , dest = 'manifest_orientation' ,
824
+ help = ('The orientation that will be set in the '
825
+ 'android:screenOrientation attribute of the activity '
826
+ 'in the AndroidManifest.xml file. If not set, '
827
+ 'the value will be synthesized from the --orientation option.' ))
789
828
ap .add_argument ('--orientation' , dest = 'orientation' ,
790
- default = 'portrait' ,
791
- help = ('The orientation that the game will '
792
- 'display in. '
793
- 'Usually one of "landscape", "portrait", '
794
- '"sensor", or "user" (the same as "sensor" '
795
- 'but obeying the '
796
- 'user\' s Android rotation setting). '
797
- 'The full list of options is given under '
798
- 'android_screenOrientation at '
799
- 'https://developer.android.com/guide/'
800
- 'topics/manifest/'
801
- 'activity-element.html' ))
829
+ action = "append" , default = [],
830
+ choices = ['portrait' , 'landscape' , 'landscape-reverse' , 'portrait-reverse' ],
831
+ help = ('The orientations that the app will display in. '
832
+ 'Since Android ignores android:screenOrientation '
833
+ 'when in multi-window mode (Which is the default on Android 12+), '
834
+ 'this option will also set the window orientation hints '
835
+ 'for apps using the (default) SDL bootstrap.'
836
+ 'If multiple orientations are given, android:screenOrientation '
837
+ 'will be set to "unspecified"' ))
802
838
803
839
ap .add_argument ('--enable-androidx' , dest = 'enable_androidx' ,
804
840
action = 'store_true' ,
@@ -853,9 +889,9 @@ def parse_args_and_make_package(args=None):
853
889
ap .add_argument ('--sdk' , dest = 'sdk_version' , default = - 1 ,
854
890
type = int , help = ('Deprecated argument, does nothing' ))
855
891
ap .add_argument ('--minsdk' , dest = 'min_sdk_version' ,
856
- default = default_min_api , type = int ,
892
+ default = ndk_api , type = int ,
857
893
help = ('Minimum Android SDK version that the app supports. '
858
- 'Defaults to {}.' .format (default_min_api )))
894
+ 'Defaults to {}.' .format (ndk_api )))
859
895
ap .add_argument ('--allow-minsdk-ndkapi-mismatch' , default = False ,
860
896
action = 'store_true' ,
861
897
help = ('Allow the --minsdk argument to be different from '
@@ -918,6 +954,15 @@ def parse_args_and_make_package(args=None):
918
954
ap .add_argument ('--activity-class-name' , dest = 'activity_class_name' , default = DEFAULT_PYTHON_ACTIVITY_JAVA_CLASS ,
919
955
help = 'The full java class name of the main activity' )
920
956
957
+ return ap
958
+
959
+
960
+ def parse_args_and_make_package (args = None ):
961
+ global BLACKLIST_PATTERNS , WHITELIST_PATTERNS , PYTHON
962
+
963
+ ndk_api = get_dist_ndk_min_api_level ()
964
+ ap = create_argument_parser ()
965
+
921
966
# Put together arguments, and add those from .p4a config file:
922
967
if args is None :
923
968
args = sys .argv [1 :]
@@ -964,6 +1009,13 @@ def _read_configuration():
964
1009
965
1010
args .permissions = parse_permissions (args .permissions )
966
1011
1012
+ args .manifest_orientation = get_manifest_orientation (
1013
+ args .orientation , args .manifest_orientation
1014
+ )
1015
+
1016
+ if get_bootstrap_name () == "sdl2" :
1017
+ args .sdl_orientation_hint = get_sdl_orientation_hint (args .orientation )
1018
+
967
1019
if args .res_xmls and isinstance (args .res_xmls [0 ], list ):
968
1020
args .res_xmls = [x for res in args .res_xmls for x in res ]
969
1021
0 commit comments