Skip to content

Commit 83c072f

Browse files
committed
action_send: add chooser_title parameter + add documentation
1 parent e94f2f7 commit 83c072f

File tree

3 files changed

+73
-33
lines changed

3 files changed

+73
-33
lines changed

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
~~~~~~~~~~~~~

recipes/android/src/android.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,21 @@ def get_buildinfo():
200200
return binfo
201201

202202
# Action send
203-
cdef extern void android_action_send(char*, char*, char*, char*)
204-
def action_send(mimetype, filename=None, subject=None, text=None):
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):
205206
cdef char *j_mimetype = <bytes>mimetype
206207
cdef char *j_filename = NULL
207208
cdef char *j_subject = NULL
208209
cdef char *j_text = NULL
210+
cdef char *j_chooser_title = NULL
209211
if filename is not None:
210212
j_filename = <bytes>filename
211213
if subject is not None:
212214
j_subject = <bytes>subject
213215
if text is not None:
214216
j_text = <bytes>text
215-
android_action_send(j_mimetype, j_filename, j_subject, j_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)

recipes/android/src/android_jni.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void android_activate_input(void) {
218218
(*env)->CallStaticVoidMethod(env, cls, mid);
219219
}
220220

221-
void android_action_send(char *mimeType, char *filename, char *subject, char *text) {
221+
void android_action_send(char *mimeType, char *filename, char *subject, char *text, char *chooser_title) {
222222
static JNIEnv *env = NULL;
223223
static jclass *cls = NULL;
224224
static jmethodID mid = NULL;
@@ -229,22 +229,26 @@ void android_action_send(char *mimeType, char *filename, char *subject, char *te
229229
cls = (*env)->FindClass(env, "org/renpy/android/Action");
230230
aassert(cls);
231231
mid = (*env)->GetStaticMethodID(env, cls, "send",
232-
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
232+
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
233233
aassert(mid);
234234
}
235235

236236
jstring j_mimeType = (*env)->NewStringUTF(env, mimeType);
237237
jstring j_filename = NULL;
238238
jstring j_subject = NULL;
239239
jstring j_text = NULL;
240+
jstring j_chooser_title = NULL;
240241
if ( filename != NULL )
241242
j_filename = (*env)->NewStringUTF(env, filename);
242243
if ( subject != NULL )
243244
j_subject = (*env)->NewStringUTF(env, subject);
244245
if ( text != NULL )
245246
j_text = (*env)->NewStringUTF(env, text);
247+
if ( chooser_title != NULL )
248+
j_chooser_title = (*env)->NewStringUTF(env, text);
246249

247250
(*env)->CallStaticVoidMethod(
248251
env, cls, mid,
249-
j_mimeType, j_filename, j_subject, j_text);
252+
j_mimeType, j_filename, j_subject, j_text,
253+
j_chooser_title);
250254
}

0 commit comments

Comments
 (0)