Skip to content

Commit e94f2f7

Browse files
committed
first pass for implement an python access to intent ACTION_SEND
1 parent 1e88c08 commit e94f2f7

File tree

4 files changed

+67
-21
lines changed

4 files changed

+67
-21
lines changed

recipes/android/src/android.pyx

Lines changed: 16 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,17 @@ 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*)
204+
def action_send(mimetype, filename=None, subject=None, text=None):
205+
cdef char *j_mimetype = <bytes>mimetype
206+
cdef char *j_filename = NULL
207+
cdef char *j_subject = NULL
208+
cdef char *j_text = NULL
209+
if filename is not None:
210+
j_filename = <bytes>filename
211+
if subject is not None:
212+
j_subject = <bytes>subject
213+
if text is not None:
214+
j_text = <bytes>text
215+
android_action_send(j_mimetype, j_filename, j_subject, j_text)

recipes/android/src/android_jni.c

Lines changed: 40 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,34 @@ void android_activate_input(void) {
217217

218218
(*env)->CallStaticVoidMethod(env, cls, mid);
219219
}
220+
221+
void android_action_send(char *mimeType, char *filename, char *subject, char *text) {
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/Action");
230+
aassert(cls);
231+
mid = (*env)->GetStaticMethodID(env, cls, "send",
232+
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
233+
aassert(mid);
234+
}
235+
236+
jstring j_mimeType = (*env)->NewStringUTF(env, mimeType);
237+
jstring j_filename = NULL;
238+
jstring j_subject = NULL;
239+
jstring j_text = NULL;
240+
if ( filename != NULL )
241+
j_filename = (*env)->NewStringUTF(env, filename);
242+
if ( subject != NULL )
243+
j_subject = (*env)->NewStringUTF(env, subject);
244+
if ( text != NULL )
245+
j_text = (*env)->NewStringUTF(env, text);
246+
247+
(*env)->CallStaticVoidMethod(
248+
env, cls, mid,
249+
j_mimeType, j_filename, j_subject, j_text);
250+
}

src/src/org/renpy/android/Hardware.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
* device's non-screen hardware. (For example, the vibration and
2323
* accelerometer.)
2424
*/
25-
public class Hardware {
26-
25+
public class Hardware {
26+
2727
// The context.
2828
static Context context;
2929
static View view;
30-
30+
3131
/**
3232
* Vibrate for s seconds.
3333
*/
@@ -39,7 +39,7 @@ static void vibrate(double s) {
3939
}
4040

4141
static SensorEvent lastEvent = null;
42-
42+
4343
static class AccelListener implements SensorEventListener {
4444
public void onSensorChanged(SensorEvent ev) {
4545
lastEvent = ev;
@@ -51,7 +51,7 @@ public void onAccuracyChanged(Sensor sensor , int accuracy) {
5151
}
5252

5353
static AccelListener accelListener = new AccelListener();
54-
54+
5555
/**
5656
* Enable or Disable the accelerometer.
5757
*/
@@ -62,16 +62,16 @@ static void accelerometerEnable(boolean enable) {
6262
if (accel == null) {
6363
return;
6464
}
65-
65+
6666
if (enable) {
67-
sm.registerListener(accelListener, accel, SensorManager.SENSOR_DELAY_GAME);
67+
sm.registerListener(accelListener, accel, SensorManager.SENSOR_DELAY_GAME);
6868
} else {
6969
sm.unregisterListener(accelListener, accel);
70-
70+
7171
}
7272
}
73-
74-
73+
74+
7575
static float[] accelerometerReading() {
7676
if (lastEvent != null) {
7777
return lastEvent.values;

src/src/org/renpy/android/PythonActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
5858
super.onCreate(savedInstanceState);
5959

6060
Hardware.context = this;
61+
Action.context = this;
6162

6263
getWindowManager().getDefaultDisplay().getMetrics(Hardware.metrics);
6364

0 commit comments

Comments
 (0)