Skip to content

Commit 145309f

Browse files
committed
Added pyjnius and kivy patches in new recipes
1 parent 05f710c commit 145309f

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
diff --git a/kivy/app.py b/kivy/app.py
2+
index 22d8a3b..3d1d6e8 100644
3+
--- a/kivy/app.py
4+
+++ b/kivy/app.py
5+
@@ -323,6 +323,7 @@ from kivy.resources import resource_find
6+
from kivy.utils import platform as core_platform
7+
from kivy.uix.widget import Widget
8+
from kivy.properties import ObjectProperty, StringProperty
9+
+from kivy.setupconfig import USE_SDL2
10+
11+
12+
platform = core_platform
13+
@@ -1020,7 +1021,7 @@ class App(EventDispatcher):
14+
setting_key = 282 # F1
15+
16+
# android hack, if settings key is pygame K_MENU
17+
- if platform == 'android':
18+
+ if platform == 'android' and not USE_SDL2:
19+
import pygame
20+
setting_key = pygame.K_MENU
21+
22+
diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py
23+
index 90e5f6d..cc5f85a 100755
24+
--- a/kivy/core/window/__init__.py
25+
+++ b/kivy/core/window/__init__.py
26+
@@ -462,6 +462,8 @@ class WindowBase(EventDispatcher):
27+
return 0
28+
29+
def _get_android_kheight(self):
30+
+ if USE_SDL2: # Placeholder until the SDL2 bootstrap supports this
31+
+ return 0
32+
global android
33+
if not android:
34+
import android
35+
diff --git a/kivy/core/window/window_sdl2.py b/kivy/core/window/window_sdl2.py
36+
index 52095b6..ad1446f 100644
37+
--- a/kivy/core/window/window_sdl2.py
38+
+++ b/kivy/core/window/window_sdl2.py
39+
@@ -321,7 +321,7 @@ class WindowSDL(WindowBase):
40+
# We have a conflict of using either the mouse or the finger.
41+
# Right now, we have no mechanism that we could use to know
42+
# which is the preferred one for the application.
43+
- if platform == "ios":
44+
+ if platform in ('ios', 'android'):
45+
SDL2MotionEventProvider.q.appendleft(event)
46+
pass
47+
48+
diff --git a/kivy/metrics.py b/kivy/metrics.py
49+
index 71a7003..76755ae 100644
50+
--- a/kivy/metrics.py
51+
+++ b/kivy/metrics.py
52+
@@ -104,6 +104,7 @@ __all__ = ('Metrics', 'MetricsBase', 'pt', 'inch', 'cm', 'mm', 'dp', 'sp',
53+
from os import environ
54+
from kivy.utils import reify, platform
55+
from kivy.properties import dpi2px
56+
+from kivy.setupconfig import USE_SDL2
57+
58+
59+
def pt(value):
60+
@@ -158,8 +159,13 @@ class MetricsBase(object):
61+
return float(custom_dpi)
62+
63+
if platform == 'android':
64+
- import android
65+
- return android.get_dpi()
66+
+ if USE_SDL2:
67+
+ import jnius
68+
+ Hardware = jnius.autoclass('org.renpy.android.Hardware')
69+
+ return Hardware.getDPI()
70+
+ else:
71+
+ import android
72+
+ return android.get_dpi()
73+
elif platform == 'ios':
74+
import ios
75+
return ios.get_dpi()
76+
@@ -217,8 +223,13 @@ class MetricsBase(object):
77+
78+
if platform == 'android':
79+
from jnius import autoclass
80+
- PythonActivity = autoclass('org.renpy.android.PythonActivity')
81+
- config = PythonActivity.mActivity.getResources().getConfiguration()
82+
+ if USE_SDL2:
83+
+ # This activity name is temporary, it will need to be changed later
84+
+ PythonActivity = autoclass('org.kivy.android.PythonActivity')
85+
+ config = PythonActivity.mActivity.getResources().getConfiguration()
86+
+ else:
87+
+ PythonActivity = autoclass('org.renpy.android.PythonActivity')
88+
+ config = PythonActivity.mActivity.getResources().getConfiguration()
89+
return config.fontScale
90+
91+
return 1.0
92+
diff --git a/setup.py b/setup.py
93+
index 79ba30d..1ccb931 100644
94+
--- a/setup.py
95+
+++ b/setup.py
96+
@@ -366,10 +366,11 @@ if platform not in ('ios', 'android') and (c_options['use_gstreamer']
97+
c_options['use_gstreamer'] = True
98+
99+
100+
-# detect SDL2, only on desktop and iOS
101+
+# detect SDL2, only on desktop and iOS, or android if explicitly enabled
102+
# works if we forced the options or in autodetection
103+
sdl2_flags = {}
104+
-if platform not in ('android',) and c_options['use_sdl2'] in (None, True):
105+
+if c_options['use_sdl2'] or (
106+
+ platform not in ('android',) and c_options['use_sdl2'] is None):
107+
108+
if c_options['use_osx_frameworks'] and platform == 'darwin':
109+
# check the existence of frameworks
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/jnius/jnius_jvm_android.pxi b/jnius/jnius_jvm_android.pxi
2+
index ac89fec..3ca9e0f 100644
3+
--- a/jnius/jnius_jvm_android.pxi
4+
+++ b/jnius/jnius_jvm_android.pxi
5+
@@ -1,5 +1,7 @@
6+
# on android, rely on SDL to get the JNI env
7+
-cdef extern JNIEnv *SDL_ANDROID_GetJNIEnv()
8+
+# cdef extern JNIEnv *SDL_ANDROID_GetJNIEnv()
9+
+cdef extern JNIEnv *SDL_AndroidGetJNIEnv()
10+
11+
cdef JNIEnv *get_platform_jnienv():
12+
- return SDL_ANDROID_GetJNIEnv()
13+
+ return <JNIEnv*>SDL_AndroidGetJNIEnv()
14+
+ # return SDL_ANDROID_GetJNIEnv()
15+
diff --git a/setup.py b/setup.py
16+
index c6beedd..3cc7c4e 100644
17+
--- a/setup.py
18+
+++ b/setup.py
19+
@@ -41,7 +41,7 @@ except ImportError:
20+
21+
if platform == 'android':
22+
# for android, we use SDL...
23+
- libraries = ['sdl', 'log']
24+
+ libraries = ['SDL2', 'log']
25+
library_dirs = ['libs/' + environ['ARCH']]
26+
elif platform == 'darwin':
27+
import subprocess

0 commit comments

Comments
 (0)