Mercurial > dwindows
comparison android/dw.cpp @ 2490:62e124eecd82
Android: Implement timers and beep. Some general code cleanup.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 30 Apr 2021 04:56:52 +0000 |
parents | 6c01b0132813 |
children | e2ca6c1a4661 |
comparison
equal
deleted
inserted
replaced
2489:6c01b0132813 | 2490:62e124eecd82 |
---|---|
359 void *params[8] = { NULL }; | 359 void *params[8] = { NULL }; |
360 | 360 |
361 _dw_event_handler(obj1, params, message); | 361 _dw_event_handler(obj1, params, message); |
362 } | 362 } |
363 | 363 |
364 /* Handler for Timer events */ | |
365 JNIEXPORT jint JNICALL | |
366 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { | |
367 int (*timerfunc)(void *) = (int (* API)(void *))sigfunc; | |
368 | |
369 pthread_setspecific(_dw_env_key, env); | |
370 return timerfunc((void *)data); | |
371 } | |
372 | |
364 /* This function adds a signal handler callback into the linked list. | 373 /* This function adds a signal handler callback into the linked list. |
365 */ | 374 */ |
366 void _dw_new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *discfunc, void *data) | 375 void _dw_new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *discfunc, void *data) |
367 { | 376 { |
368 SignalHandler *newsig = (SignalHandler *)malloc(sizeof(SignalHandler)); | 377 SignalHandler *newsig = (SignalHandler *)malloc(sizeof(SignalHandler)); |
3451 * freq: Frequency. | 3460 * freq: Frequency. |
3452 * dur: Duration. | 3461 * dur: Duration. |
3453 */ | 3462 */ |
3454 void API dw_beep(int freq, int dur) | 3463 void API dw_beep(int freq, int dur) |
3455 { | 3464 { |
3465 JNIEnv *env; | |
3466 | |
3467 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
3468 { | |
3469 // First get the class that contains the method you need to call | |
3470 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
3471 // Get the method that you want to call | |
3472 jmethodID doBeep = env->GetMethodID(clazz, "doBeep", "(I)V"); | |
3473 // Call the method on the object | |
3474 env->CallVoidMethod(_dw_obj, doBeep, dur); | |
3475 } | |
3456 } | 3476 } |
3457 | 3477 |
3458 /* Call this after drawing to the screen to make sure | 3478 /* Call this after drawing to the screen to make sure |
3459 * anything you have drawn is visible. | 3479 * anything you have drawn is visible. |
3460 */ | 3480 */ |
3524 * Returns: | 3544 * Returns: |
3525 * Timer ID for use with dw_timer_disconnect(), 0 on error. | 3545 * Timer ID for use with dw_timer_disconnect(), 0 on error. |
3526 */ | 3546 */ |
3527 int API dw_timer_connect(int interval, void *sigfunc, void *data) | 3547 int API dw_timer_connect(int interval, void *sigfunc, void *data) |
3528 { | 3548 { |
3529 return 0; | 3549 JNIEnv *env; |
3550 int retval = 0; | |
3551 | |
3552 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
3553 { | |
3554 // Use a long paramater | |
3555 jlong longinterval = (jlong)interval; | |
3556 // First get the class that contains the method you need to call | |
3557 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
3558 // Get the method that you want to call | |
3559 jmethodID timerConnect = env->GetMethodID(clazz, "timerConnect", | |
3560 "(JJJ)Ljava/util/Timer;"); | |
3561 // Call the method on the object | |
3562 retval = DW_POINTER_TO_INT(env->NewGlobalRef(env->CallObjectMethod(_dw_obj, | |
3563 timerConnect, longinterval, (jlong)sigfunc, (jlong)data))); | |
3564 } | |
3565 return retval; | |
3530 } | 3566 } |
3531 | 3567 |
3532 /* | 3568 /* |
3533 * Removes timer callback. | 3569 * Removes timer callback. |
3534 * Parameters: | 3570 * Parameters: |
3535 * id: Timer ID returned by dw_timer_connect(). | 3571 * id: Timer ID returned by dw_timer_connect(). |
3536 */ | 3572 */ |
3537 void API dw_timer_disconnect(int timerid) | 3573 void API dw_timer_disconnect(int timerid) |
3538 { | 3574 { |
3575 JNIEnv *env; | |
3576 | |
3577 if(timerid && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
3578 { | |
3579 // Use a long paramater | |
3580 jobject timer = (jobject)timerid; | |
3581 // First get the class that contains the method you need to call | |
3582 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
3583 // Get the method that you want to call | |
3584 jmethodID timerDisconnect = env->GetMethodID(clazz, "timerDisconnect", | |
3585 "(Ljava/util/Timer;)V"); | |
3586 // Call the method on the object | |
3587 env->CallVoidMethod(_dw_obj, timerDisconnect, timer); | |
3588 } | |
3539 } | 3589 } |
3540 | 3590 |
3541 /* | 3591 /* |
3542 * Add a callback to a window event. | 3592 * Add a callback to a window event. |
3543 * Parameters: | 3593 * Parameters: |