Skip to content

Commit 63f4269

Browse files
committed
Merge branch 'master' of github.com:kivy/python-for-android
2 parents 46595cf + 5b92831 commit 63f4269

30 files changed

+1754
-4000
lines changed

distribute.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function run_prepare() {
188188
exit -1
189189
fi
190190
if [ ! -d "$ANDROIDNDK" ]; then
191-
echo "ANDROIDNDK=$ANDROIDSDK"
191+
echo "ANDROIDNDK=$ANDROIDNDK"
192192
error "ANDROIDNDK path is invalid, it must be a directory. abort."
193193
exit 1
194194
fi
@@ -486,6 +486,7 @@ function run_distribute() {
486486
try cp -a $SRC_PATH/blacklist.txt .
487487

488488
debug "Copy python distribution"
489+
$BUILD_PATH/python-install/bin/python.host -OO -m compileall $BUILD_PATH/python-install
489490
try cp -a $BUILD_PATH/python-install .
490491

491492
debug "Copy libs"
@@ -515,7 +516,6 @@ function run_distribute() {
515516
try rm -rf distutils/tests
516517
try rm -rf email/test
517518
try rm -rf bsddb/test
518-
try rm -rf distutils
519519
try rm -rf config/libpython*.a
520520
try rm -rf config/python.o
521521
try rm -rf curses

docs/source/android.rst

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Example
1919
How it's working
2020
----------------
2121

22-
The whole Android API is accessible in Java. Their is no native or extensible way to access it from Python. The schema for accessing to their API is::
22+
The whole Android API is accessible in Java. Their is no native or extensible
23+
way to access it from Python. The schema for accessing to their API is::
2324

2425
[1] Cython -> [2] C JNI -> [3] Java
2526

@@ -46,63 +47,93 @@ android
4647

4748
.. function:: check_pause()
4849

49-
This should be called on a regular basis to check to see if Android
50-
expects the game to pause. If it return true, the game should
51-
call :func:`android.wait_for_resume()`, after persisting its state
52-
as necessary.
50+
This should be called on a regular basis to check to see if Android
51+
expects the game to pause. If it return true, the game should call
52+
:func:`android.wait_for_resume()`, after persisting its state as necessary.
5353

5454
.. function:: wait_for_resume()
5555

56-
This function should be called after :func:`android.check_pause()`
57-
returns true. It does not return until Android has resumed from
58-
the pause. While in this function, Android may kill a game
59-
without further notice.
56+
This function should be called after :func:`android.check_pause()` returns
57+
true. It does not return until Android has resumed from the pause. While in
58+
this function, Android may kill a game without further notice.
6059

6160
.. function:: map_key(keycode, keysym)
6261

63-
This maps between an android keycode and a python keysym. The android
64-
keycodes are available as constants in the android module.
62+
This maps between an android keycode and a python keysym. The android
63+
keycodes are available as constants in the android module.
6564

6665
.. function:: vibrate(s)
6766

68-
Causes the phone to vibrate for `s` seconds. This requires that your
69-
application have the VIBRATE permission.
67+
Causes the phone to vibrate for `s` seconds. This requires that your
68+
application have the VIBRATE permission.
7069

7170
.. function:: accelerometer_enable(enable)
7271

73-
Enables (if `enable` is true) or disables the device's accelerometer.
72+
Enables (if `enable` is true) or disables the device's accelerometer.
7473

7574
.. function:: accelerometer_reading()
7675

77-
Returns an (x, y, z) tuple of floats that gives the accelerometer
78-
reading, in meters per second squared. See `this page
79-
<http://developer.android.com/reference/android/hardware/SensorEvent.html>`_
80-
for a description of the coordinate system. The accelerometer must
81-
be enabled before this function is called. If the tuple contains
82-
three zero values, the accelerometer is not enabled, not available,
83-
defective, has not returned a reading, or the device is in
84-
free-fall.
76+
Returns an (x, y, z) tuple of floats that gives the accelerometer reading,
77+
in meters per second squared. See `this page
78+
<http://developer.android.com/reference/android/hardware/SensorEvent.html>`_
79+
for a description of the coordinate system. The accelerometer must be
80+
enabled before this function is called. If the tuple contains three zero
81+
values, the accelerometer is not enabled, not available, defective, has not
82+
returned a reading, or the device is in free-fall.
8583

8684
.. function:: get_dpi()
8785

88-
Returns the screen density in dots per inch.
86+
Returns the screen density in dots per inch.
8987

9088
.. function:: show_keyboard()
9189

92-
Shows the soft keyboard.
90+
Shows the soft keyboard.
9391

9492
.. function:: hide_keyboard()
9593

96-
Hides the soft keyboard.
94+
Hides the soft keyboard.
9795

9896
.. function:: wifi_scanner_enable()
9997

100-
Enables wifi scanning. ACCESS_WIFI_STATE and CHANGE_WIFI_STATE permissions required.
98+
Enables wifi scanning. ACCESS_WIFI_STATE and CHANGE_WIFI_STATE permissions
99+
required.
101100

102101
.. function:: wifi_scan()
103102

104-
Returns tuple of (SSID, BSSID, SignalLevel) for each visible WiFi access point.
103+
Returns tuple of (SSID, BSSID, SignalLevel) for each visible WiFi access
104+
point.
105105

106+
.. function:: action_send(mimetype, filename, subject, text, chooser_title)
107+
108+
Deliver data to someone else. This method is a wrapper around `ACTION_SEND
109+
<http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND>`_
110+
111+
:Parameters:
112+
`mimetype`: str
113+
Must be a valid mimetype, that represent the content to sent.
114+
`filename`: str, default to None
115+
(optional) Name of the file to attach. Must be a absolute path.
116+
`subject`: str, default to None
117+
(optional) Default subject
118+
`text`: str, default to None
119+
(optional) Content to send.
120+
`chooser_title`: str, default to None
121+
(optional) Title of the android chooser window, default to 'Send email...'
122+
123+
Sending a simple hello world text::
124+
125+
android.action_send('text/plain', text='Hello world',
126+
subject='Test from python')
127+
128+
Sharing an image file::
129+
130+
# let's say you've make an image in /sdcard/image.png
131+
android.action_send('image/png', filename='/sdcard/image.png')
132+
133+
Sharing an image with a default text too::
134+
135+
android.action_send('image/png', filename='/sdcard/image.png',
136+
text='Hi,\n\tThis is my awesome image, what do you think about it ?')
106137

107138
android_mixer
108139
~~~~~~~~~~~~~

docs/source/prerequisites.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ After installing them, export both installation path, NDK version and API to use
4949

5050
Also, you must configure you're PATH to add the ``android`` binary::
5151

52-
export PATH=/path/to/android-sdk-linux/tools:$PATH
52+
export PATH=/path/to/android-ndk:/path/to/android-sdk-linux/tools:$PATH
5353

docs/source/recipes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Available modules
22
=================
33

44
List of available modules: jpeg pil png sdl sqlite3 pygame kivy android
5-
libxml2 libxslt lxml ffmpeg openssl chipmunk
5+
libxml2 libxslt lxml ffmpeg openssl chipmunk zope twisted
66

77
The up-to-date list is available at:
88
https://github.com/kivy/python-for-android/tree/master/recipes

recipes/android/src/android.pyx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ cdef extern void android_vibrate(double)
120120

121121
def vibrate(s):
122122
android_vibrate(s)
123-
123+
124124
# Accelerometer support.
125125
cdef extern void android_accelerometer_enable(int)
126126
cdef extern void android_accelerometer_reading(float *)
@@ -133,7 +133,7 @@ def accelerometer_enable(p):
133133
android_accelerometer_enable(p)
134134

135135
accelerometer_enabled = p
136-
136+
137137
def accelerometer_reading():
138138
cdef float rv[3]
139139
android_accelerometer_reading(rv)
@@ -199,3 +199,31 @@ def get_buildinfo():
199199
binfo.VERSION_RELEASE = BUILD_VERSION_RELEASE
200200
return binfo
201201

202+
# Action send
203+
cdef extern void android_action_send(char*, char*, char*, char*, char*)
204+
def action_send(mimetype, filename=None, subject=None, text=None,
205+
chooser_title=None):
206+
cdef char *j_mimetype = <bytes>mimetype
207+
cdef char *j_filename = NULL
208+
cdef char *j_subject = NULL
209+
cdef char *j_text = NULL
210+
cdef char *j_chooser_title = NULL
211+
if filename is not None:
212+
j_filename = <bytes>filename
213+
if subject is not None:
214+
j_subject = <bytes>subject
215+
if text is not None:
216+
j_text = <bytes>text
217+
if chooser_title is not None:
218+
j_chooser_title = <bytes>chooser_title
219+
android_action_send(j_mimetype, j_filename, j_subject, j_text,
220+
j_chooser_title)
221+
222+
cdef extern int android_checkstop()
223+
cdef extern void android_ackstop()
224+
225+
def check_stop():
226+
return android_checkstop()
227+
228+
def ack_stop():
229+
android_ackstop()

recipes/android/src/android_jni.c

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ JNIEnv *SDL_ANDROID_GetJNIEnv(void);
1010
#define PUSH_FRAME { (*env)->PushLocalFrame(env, 16); }
1111
#define POP_FRAME { (*env)->PopLocalFrame(env, NULL); }
1212

13-
void android_vibrate(double seconds) {
13+
void android_vibrate(double seconds) {
1414
static JNIEnv *env = NULL;
1515
static jclass *cls = NULL;
1616
static jmethodID mid = NULL;
@@ -26,10 +26,10 @@ void android_vibrate(double seconds) {
2626

2727
(*env)->CallStaticVoidMethod(
2828
env, cls, mid,
29-
(jdouble) seconds);
29+
(jdouble) seconds);
3030
}
3131

32-
void android_accelerometer_enable(int enable) {
32+
void android_accelerometer_enable(int enable) {
3333
static JNIEnv *env = NULL;
3434
static jclass *cls = NULL;
3535
static jmethodID mid = NULL;
@@ -45,7 +45,7 @@ void android_accelerometer_enable(int enable) {
4545

4646
(*env)->CallStaticVoidMethod(
4747
env, cls, mid,
48-
(jboolean) enable);
48+
(jboolean) enable);
4949
}
5050

5151
void android_wifi_scanner_enable(void){
@@ -94,7 +94,7 @@ void android_accelerometer_reading(float *values) {
9494
static jclass *cls = NULL;
9595
static jmethodID mid = NULL;
9696
jobject jvalues;
97-
97+
9898
if (env == NULL) {
9999
env = SDL_ANDROID_GetJNIEnv();
100100
aassert(env);
@@ -105,18 +105,18 @@ void android_accelerometer_reading(float *values) {
105105
}
106106

107107
PUSH_FRAME;
108-
108+
109109
jvalues = (*env)->CallStaticObjectMethod(env, cls, mid);
110110
(*env)->GetFloatArrayRegion(env, jvalues, 0, 3, values);
111-
112-
POP_FRAME;
111+
112+
POP_FRAME;
113113
}
114114

115115
int android_get_dpi(void) {
116116
static JNIEnv *env = NULL;
117117
static jclass *cls = NULL;
118118
static jmethodID mid = NULL;
119-
119+
120120
if (env == NULL) {
121121
env = SDL_ANDROID_GetJNIEnv();
122122
aassert(env);
@@ -217,3 +217,72 @@ void android_activate_input(void) {
217217

218218
(*env)->CallStaticVoidMethod(env, cls, mid);
219219
}
220+
221+
int android_checkstop(void) {
222+
static JNIEnv *env = NULL;
223+
static jclass *cls = NULL;
224+
static jmethodID mid = NULL;
225+
226+
if (env == NULL) {
227+
env = SDL_ANDROID_GetJNIEnv();
228+
aassert(env);
229+
cls = (*env)->FindClass(env, "org/renpy/android/SDLSurfaceView");
230+
aassert(cls);
231+
mid = (*env)->GetStaticMethodID(env, cls, "checkStop", "()I");
232+
aassert(mid);
233+
}
234+
235+
return (*env)->CallStaticIntMethod(env, cls, mid);
236+
}
237+
238+
void android_ackstop(void) {
239+
static JNIEnv *env = NULL;
240+
static jclass *cls = NULL;
241+
static jmethodID mid = NULL;
242+
243+
if (env == NULL) {
244+
env = SDL_ANDROID_GetJNIEnv();
245+
aassert(env);
246+
cls = (*env)->FindClass(env, "org/renpy/android/SDLSurfaceView");
247+
aassert(cls);
248+
mid = (*env)->GetStaticMethodID(env, cls, "ackStop", "()I");
249+
aassert(mid);
250+
}
251+
252+
(*env)->CallStaticIntMethod(env, cls, mid);
253+
}
254+
255+
void android_action_send(char *mimeType, char *filename, char *subject, char *text, char *chooser_title) {
256+
static JNIEnv *env = NULL;
257+
static jclass *cls = NULL;
258+
static jmethodID mid = NULL;
259+
260+
if (env == NULL) {
261+
env = SDL_ANDROID_GetJNIEnv();
262+
aassert(env);
263+
cls = (*env)->FindClass(env, "org/renpy/android/Action");
264+
aassert(cls);
265+
mid = (*env)->GetStaticMethodID(env, cls, "send",
266+
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
267+
aassert(mid);
268+
}
269+
270+
jstring j_mimeType = (*env)->NewStringUTF(env, mimeType);
271+
jstring j_filename = NULL;
272+
jstring j_subject = NULL;
273+
jstring j_text = NULL;
274+
jstring j_chooser_title = NULL;
275+
if ( filename != NULL )
276+
j_filename = (*env)->NewStringUTF(env, filename);
277+
if ( subject != NULL )
278+
j_subject = (*env)->NewStringUTF(env, subject);
279+
if ( text != NULL )
280+
j_text = (*env)->NewStringUTF(env, text);
281+
if ( chooser_title != NULL )
282+
j_chooser_title = (*env)->NewStringUTF(env, text);
283+
284+
(*env)->CallStaticVoidMethod(
285+
env, cls, mid,
286+
j_mimeType, j_filename, j_subject, j_text,
287+
j_chooser_title);
288+
}

0 commit comments

Comments
 (0)