Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes orientation option cross-platform and conform to latest python-for-android changes, adds android.manifest.orientation. #1548

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ def check_configuration_tokens(self):
adderror('[app] "version.filename" is missing'
', required by "version.regex"')

orientation = get('app', 'orientation', 'landscape')
if orientation not in ('landscape', 'portrait', 'all', 'sensorLandscape'):
adderror('[app] "orientation" have an invalid value')

orientation = self.config.getlist("app", "orientation", ["landscape"])
for o in orientation:
if o not in ("landscape", "portrait", "landscape-reverse", "portrait-reverse"):
adderror(f'[app] "{o}" is not a valid value for "orientation"')
if errors:
self.error('{0} error(s) found in the buildozer.spec'.format(
len(errors)))
Expand Down
7 changes: 6 additions & 1 deletion buildozer/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ requirements = python3,kivy
# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png

# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
# (list) Supported orientations
# Valid options are: landscape, portrait, portrait-reverse or landscape-reverse
orientation = portrait

# (list) List of service to declare
Expand Down Expand Up @@ -242,6 +243,10 @@ fullscreen = 0
# (str) launchMode to set for the main activity
#android.manifest.launch_mode = standard

# (str) screenOrientation to set for the main activity.
# Valid values can be found at https://developer.android.com/guide/topics/manifest/activity-element
#android.manifest.orientation = fullSensor

# (list) Android additional libraries to copy into libs/armeabi
#android.add_libs_armeabi = libs/android/*.so
#android.add_libs_armeabi_v7a = libs/android-v7/*.so
Expand Down
13 changes: 9 additions & 4 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,9 @@ def build_package(self):

if config.getdefault('app', 'p4a.bootstrap', 'sdl2') != 'service_only':
# add orientation
orientation = config.getdefault('app', 'orientation', 'landscape')
if orientation == 'all':
orientation = 'sensor'
build_cmd += [("--orientation", orientation)]
orientation = config.getlist('app', 'orientation', ['landscape'])
for orient in orientation:
build_cmd += [("--orientation", orient)]

# fullscreen ?
fullscreen = config.getbooldefault('app', 'fullscreen', True)
Expand Down Expand Up @@ -1292,6 +1291,12 @@ def build_package(self):
if launch_mode:
build_cmd += [("--activity-launch-mode", launch_mode)]

# screenOrientation
manifest_orientation = config.getdefault(
'app', 'android.manifest.orientation', '')
if manifest_orientation:
build_cmd += [("--manifest-orientation", manifest_orientation)]

# numeric version
numeric_version = config.getdefault('app', 'android.numeric_version')
if numeric_version:
Expand Down
7 changes: 4 additions & 3 deletions docs/source/specifications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ Section [app]
The icon of your application. It must be a PNG of 512x512 size to be able to
cover all the various platform requirements.

- `orientation`: String, orientation of the application.
- `orientation`: List, supported orientations of the application.

Indicate the orientation that your application supports. Defaults to
`landscape`, but can be changed to `portrait` or `all`.
Indicate the orientations that your application supports.
Valid values are: `portrait`, `landscape`, `portrait-reverse`, `landscape-reverse`.
Defaults to `[landscape]`.

- `fullscreen`: Boolean, fullscreen mode.

Expand Down
52 changes: 52 additions & 0 deletions tests/targets/test_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,55 @@ def test_install_platform_p4a_clone_default(self):
assert mock.call(
["git", "clone", "-b", "master", "--single-branch", "https://github.com/kivy/python-for-android.git", "python-for-android"],
cwd=mock.ANY) in m_cmd.call_args_list

def test_orientation(self):
target_android = init_target(self.temp_dir, {
"orientation": "portrait,portrait-reverse"
})
buildozer = target_android.buildozer
m_execute_build_package = call_build_package(target_android)
assert m_execute_build_package.call_args_list == [
mock.call(
[
("--name", "My Application"),
("--version", "0.1"),
("--package", "org.test.myapp"),
("--minsdk", "21"),
("--ndk-api", "21"),
("--private", "{buildozer_dir}/android/app".format(buildozer_dir=buildozer.buildozer_dir)),
("--android-entrypoint", "org.kivy.android.PythonActivity"),
("--android-apptheme", "@android:style/Theme.NoTitleBar"),
("--orientation", "portrait"),
("--orientation", "portrait-reverse"),
("--window",),
('--enable-androidx',),
("debug",),
]
)
]

def test_manifest_orientation(self):
target_android = init_target(self.temp_dir, {
"android.manifest.orientation": "fullSensor"
})
buildozer = target_android.buildozer
m_execute_build_package = call_build_package(target_android)
assert m_execute_build_package.call_args_list == [
mock.call(
[
("--name", "My Application"),
("--version", "0.1"),
("--package", "org.test.myapp"),
("--minsdk", "21"),
("--ndk-api", "21"),
("--private", "{buildozer_dir}/android/app".format(buildozer_dir=buildozer.buildozer_dir)),
("--android-entrypoint", "org.kivy.android.PythonActivity"),
("--android-apptheme", "@android:style/Theme.NoTitleBar"),
("--orientation", "portrait"),
("--window",),
('--enable-androidx',),
("--manifest-orientation", "fullSensor"),
("debug",),
]
)
]