Mercurial > dwindows
comparison android/dw.cpp @ 2476:20c9e83cba2a
Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
dw_text_new(), dw_status_text_new(), dw_checkbox_new() and dw_radiobutton_new().
Fix the signatures used in GetMethodID(), Android Studio can apparently do it autoamtically.
Add a LinearLayout to the DWindows activity, use it as the content view so we don't need XML.
dw_dwindow_new() will now return the LinearLayout instead of the Activity object... so the
handle can be used with dw_box_pack*().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 22 Apr 2021 00:04:01 +0000 |
parents | 16d195d46f2a |
children | 3fbf8783122d |
comparison
equal
deleted
inserted
replaced
2475:16d195d46f2a | 2476:20c9e83cba2a |
---|---|
20 #include <errno.h> | 20 #include <errno.h> |
21 #include <fcntl.h> | 21 #include <fcntl.h> |
22 #include <unistd.h> | 22 #include <unistd.h> |
23 #if defined(__ANDROID__) && (__ANDROID_API__+0) < 21 | 23 #if defined(__ANDROID__) && (__ANDROID_API__+0) < 21 |
24 #include <sys/syscall.h> | 24 #include <sys/syscall.h> |
25 #endif | 25 |
26 | |
27 #if defined(__ANDROID__) && (__ANDROID_API__+0) < 21 | |
28 /* Until Android API version 21 NDK does not define getsid wrapper in libc, although there is the corresponding syscall */ | 26 /* Until Android API version 21 NDK does not define getsid wrapper in libc, although there is the corresponding syscall */ |
29 inline pid_t getsid(pid_t pid) | 27 inline pid_t getsid(pid_t pid) |
30 { | 28 { |
31 return static_cast< pid_t >(::syscall(__NR_getsid, pid)); | 29 return static_cast< pid_t >(::syscall(__NR_getsid, pid)); |
32 } | 30 } |
33 #endif | 31 #endif |
34 | 32 |
35 #ifdef __cplusplus | 33 #ifdef __cplusplus |
36 extern "C" { | 34 extern "C" { |
37 #endif | 35 #endif |
36 | |
37 #define DW_CLASS_NAME "org/dbsoft/dwindows/dwtest/DWindows" | |
38 | 38 |
39 static pthread_key_t _dw_env_key; | 39 static pthread_key_t _dw_env_key; |
40 static HEV _dw_main_event; | 40 static HEV _dw_main_event; |
41 static JavaVM *_dw_jvm; | 41 static JavaVM *_dw_jvm; |
42 static jobject _dw_obj; | 42 static jobject _dw_obj; |
170 } | 170 } |
171 return _dw_user_dir; | 171 return _dw_user_dir; |
172 } | 172 } |
173 | 173 |
174 /* | 174 /* |
175 * Returns a pointer to a static buffer which containes the | 175 * Returns a pointer to a static buffer which contains the |
176 * private application data directory. | 176 * private application data directory. |
177 */ | 177 */ |
178 char * API dw_app_dir(void) | 178 char * API dw_app_dir(void) |
179 { | 179 { |
180 static char _dw_exec_dir[MAX_PATH+1] = {0}; | 180 static char _dw_exec_dir[MAX_PATH+1] = {0}; |
181 /* Code to determine the execution directory here, | 181 /* Code to determine the execution directory here, |
182 * some implementations make this variable global | 182 * some implementations make this variable global |
183 * and determin the location in dw_init(). | 183 * and determine the location in dw_init(). |
184 */ | 184 */ |
185 return _dw_exec_dir; | 185 return _dw_exec_dir; |
186 } | 186 } |
187 | 187 |
188 /* | 188 /* |
365 JNIEnv *env; | 365 JNIEnv *env; |
366 | 366 |
367 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 367 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
368 { | 368 { |
369 // First get the class that contains the method you need to call | 369 // First get the class that contains the method you need to call |
370 jclass clazz = env->FindClass("org/dbsoft/dwindows/dwtest/DWindows"); | 370 jclass clazz = env->FindClass(DW_CLASS_NAME); |
371 // Get the method that you want to call | 371 // Get the method that you want to call |
372 jmethodID boxNew = env->GetMethodID(clazz, "boxNew", "(Ljava/lang/String;)V"); | 372 jmethodID boxNew = env->GetMethodID(clazz, "boxNew", "(II)Landroid/widget/LinearLayout;"); |
373 // Call the method on the object | 373 // Call the method on the object |
374 jobject result = env->CallObjectMethod(_dw_obj, boxNew, type, pad); | 374 jobject result = env->CallObjectMethod(_dw_obj, boxNew, type, pad); |
375 return result; | 375 return result; |
376 } | 376 } |
377 return 0; | 377 return 0; |
436 JNIEnv *env; | 436 JNIEnv *env; |
437 | 437 |
438 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 438 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
439 { | 439 { |
440 // First get the class that contains the method you need to call | 440 // First get the class that contains the method you need to call |
441 jclass clazz = env->FindClass("org/dbsoft/dwindows/dwtest/DWindows"); | 441 jclass clazz = env->FindClass(DW_CLASS_NAME); |
442 // Get the method that you want to call | 442 // Get the method that you want to call |
443 jmethodID boxPack = env->GetMethodID(clazz, "boxPack", "(Ljava/lang/String;)V"); | 443 jmethodID boxPack = env->GetMethodID(clazz, "boxPack", "(Landroid/widget/LinearLayout;Landroid/view/View;IIIIII)V"); |
444 // Call the method on the object | 444 // Call the method on the object |
445 env->CallVoidMethod(_dw_obj, boxPack, box, item, index, width, height, hsize, vsize, pad); | 445 env->CallVoidMethod(_dw_obj, boxPack, box, item, index, width, height, hsize, vsize, pad); |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
531 * Returns: | 531 * Returns: |
532 * A handle to a button window or NULL on failure. | 532 * A handle to a button window or NULL on failure. |
533 */ | 533 */ |
534 HWND API dw_button_new(const char *text, ULONG cid) | 534 HWND API dw_button_new(const char *text, ULONG cid) |
535 { | 535 { |
536 return 0; | 536 JNIEnv *env; |
537 } | 537 |
538 | 538 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
539 { | |
540 // Construct a String | |
541 jstring jstr = env->NewStringUTF(text); | |
542 // First get the class that contains the method you need to call | |
543 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
544 // Get the method that you want to call | |
545 jmethodID buttonNew = env->GetMethodID(clazz, "buttonNew", | |
546 "(Ljava/lang/String;I)Landroid/widget/Button;"); | |
547 // Call the method on the object | |
548 jobject result = env->CallObjectMethod(_dw_obj, buttonNew, jstr, (int)cid); | |
549 return result; | |
550 } | |
551 return 0; | |
552 } | |
553 | |
554 HWND _dw_entryfield_new(const char *text, ULONG cid, int password) | |
555 { | |
556 JNIEnv *env; | |
557 | |
558 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
559 { | |
560 // Construct a String | |
561 jstring jstr = env->NewStringUTF(text); | |
562 // First get the class that contains the method you need to call | |
563 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
564 // Get the method that you want to call | |
565 jmethodID entryfieldNew = env->GetMethodID(clazz, "entryfieldNew", | |
566 "(Ljava/lang/String;II)Landroid/widget/EditText;"); | |
567 // Call the method on the object | |
568 jobject result = env->CallObjectMethod(_dw_obj, entryfieldNew, jstr, (int)cid, password); | |
569 return result; | |
570 } | |
571 return 0; | |
572 } | |
539 /* | 573 /* |
540 * Create a new Entryfield window (widget) to be packed. | 574 * Create a new Entryfield window (widget) to be packed. |
541 * Parameters: | 575 * Parameters: |
542 * text: The default text to be in the entryfield widget. | 576 * text: The default text to be in the entryfield widget. |
543 * id: An ID to be used with dw_window_from_id() or 0L. | 577 * id: An ID to be used with dw_window_from_id() or 0L. |
544 * Returns: | 578 * Returns: |
545 * A handle to an entryfield window or NULL on failure. | 579 * A handle to an entryfield window or NULL on failure. |
546 */ | 580 */ |
547 HWND API dw_entryfield_new(const char *text, ULONG cid) | 581 HWND API dw_entryfield_new(const char *text, ULONG cid) |
548 { | 582 { |
549 return 0; | 583 return _dw_entryfield_new(text, cid, FALSE); |
550 } | 584 } |
551 | 585 |
552 /* | 586 /* |
553 * Create a new Entryfield (password) window (widget) to be packed. | 587 * Create a new Entryfield (password) window (widget) to be packed. |
554 * Parameters: | 588 * Parameters: |
557 * Returns: | 591 * Returns: |
558 * A handle to an entryfield password window or NULL on failure. | 592 * A handle to an entryfield password window or NULL on failure. |
559 */ | 593 */ |
560 HWND API dw_entryfield_password_new(const char *text, ULONG cid) | 594 HWND API dw_entryfield_password_new(const char *text, ULONG cid) |
561 { | 595 { |
562 return 0; | 596 return _dw_entryfield_new(text, cid, TRUE); |
563 } | 597 } |
564 | 598 |
565 /* | 599 /* |
566 * Sets the entryfield character limit. | 600 * Sets the entryfield character limit. |
567 * Parameters: | 601 * Parameters: |
671 * Returns: | 705 * Returns: |
672 * A handle to a radio button window or NULL on failure. | 706 * A handle to a radio button window or NULL on failure. |
673 */ | 707 */ |
674 HWND API dw_radiobutton_new(const char *text, ULONG cid) | 708 HWND API dw_radiobutton_new(const char *text, ULONG cid) |
675 { | 709 { |
710 JNIEnv *env; | |
711 | |
712 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
713 { | |
714 // Construct a String | |
715 jstring jstr = env->NewStringUTF(text); | |
716 // First get the class that contains the method you need to call | |
717 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
718 // Get the method that you want to call | |
719 jmethodID radioButtonNew = env->GetMethodID(clazz, "radioButtonNew", | |
720 "(Ljava/lang/String;I)Landroid/widget/RadioButton;"); | |
721 // Call the method on the object | |
722 jobject result = env->CallObjectMethod(_dw_obj, radioButtonNew, jstr, (int)cid); | |
723 return result; | |
724 } | |
676 return 0; | 725 return 0; |
677 } | 726 } |
678 | 727 |
679 /* | 728 /* |
680 * Create a new slider window (widget) to be packed. | 729 * Create a new slider window (widget) to be packed. |
788 * Returns: | 837 * Returns: |
789 * A handle to a checkbox window or NULL on failure. | 838 * A handle to a checkbox window or NULL on failure. |
790 */ | 839 */ |
791 HWND API dw_checkbox_new(const char *text, ULONG cid) | 840 HWND API dw_checkbox_new(const char *text, ULONG cid) |
792 { | 841 { |
842 JNIEnv *env; | |
843 | |
844 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
845 { | |
846 // Construct a String | |
847 jstring jstr = env->NewStringUTF(text); | |
848 // First get the class that contains the method you need to call | |
849 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
850 // Get the method that you want to call | |
851 jmethodID checkboxNew = env->GetMethodID(clazz, "checkboxNew", | |
852 "(Ljava/lang/String;I)Landroid/widget/CheckBox;"); | |
853 // Call the method on the object | |
854 jobject result = env->CallObjectMethod(_dw_obj, checkboxNew, jstr, (int)cid); | |
855 return result; | |
856 } | |
793 return 0; | 857 return 0; |
794 } | 858 } |
795 | 859 |
796 /* | 860 /* |
797 * Returns the state of the checkbox. | 861 * Returns the state of the checkbox. |
1127 */ | 1191 */ |
1128 void API dw_mle_thaw(HWND handle) | 1192 void API dw_mle_thaw(HWND handle) |
1129 { | 1193 { |
1130 } | 1194 } |
1131 | 1195 |
1196 HWND _dw_text_new(const char *text, ULONG cid, int status) | |
1197 { | |
1198 JNIEnv *env; | |
1199 | |
1200 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1201 { | |
1202 // Construct a String | |
1203 jstring jstr = env->NewStringUTF(text); | |
1204 // First get the class that contains the method you need to call | |
1205 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
1206 // Get the method that you want to call | |
1207 jmethodID textNew = env->GetMethodID(clazz, "textNew", | |
1208 "(Ljava/lang/String;II)Landroid/widget/TextView;"); | |
1209 // Call the method on the object | |
1210 jobject result = env->CallObjectMethod(_dw_obj, textNew, jstr, (int)cid, status); | |
1211 return result; | |
1212 } | |
1213 return 0; | |
1214 } | |
1215 | |
1132 /* | 1216 /* |
1133 * Create a new status text window (widget) to be packed. | 1217 * Create a new status text window (widget) to be packed. |
1134 * Parameters: | 1218 * Parameters: |
1135 * text: The text to be display by the static text widget. | 1219 * text: The text to be display by the static text widget. |
1136 * id: An ID to be used with dw_window_from_id() or 0L. | 1220 * id: An ID to be used with dw_window_from_id() or 0L. |
1137 * Returns: | 1221 * Returns: |
1138 * A handle to a status text window or NULL on failure. | 1222 * A handle to a status text window or NULL on failure. |
1139 */ | 1223 */ |
1140 HWND API dw_status_text_new(const char *text, ULONG cid) | 1224 HWND API dw_status_text_new(const char *text, ULONG cid) |
1141 { | 1225 { |
1142 return 0; | 1226 return _dw_text_new(text, cid, TRUE); |
1143 } | 1227 } |
1144 | 1228 |
1145 /* | 1229 /* |
1146 * Create a new static text window (widget) to be packed. | 1230 * Create a new static text window (widget) to be packed. |
1147 * Parameters: | 1231 * Parameters: |
1150 * Returns: | 1234 * Returns: |
1151 * A handle to a text window or NULL on failure. | 1235 * A handle to a text window or NULL on failure. |
1152 */ | 1236 */ |
1153 HWND API dw_text_new(const char *text, ULONG cid) | 1237 HWND API dw_text_new(const char *text, ULONG cid) |
1154 { | 1238 { |
1155 return 0; | 1239 return _dw_text_new(text, cid, FALSE); |
1156 } | 1240 } |
1157 | 1241 |
1158 /* | 1242 /* |
1159 * Creates a rendering context widget (window) to be packed. | 1243 * Creates a rendering context widget (window) to be packed. |
1160 * Parameters: | 1244 * Parameters: |
2414 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 2498 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
2415 { | 2499 { |
2416 // Construct a String | 2500 // Construct a String |
2417 jstring jstr = env->NewStringUTF(title); | 2501 jstring jstr = env->NewStringUTF(title); |
2418 // First get the class that contains the method you need to call | 2502 // First get the class that contains the method you need to call |
2419 jclass clazz = env->FindClass("org/dbsoft/dwindows/dwtest/DWindows"); | 2503 jclass clazz = env->FindClass(DW_CLASS_NAME); |
2420 // Get the method that you want to call | 2504 // Get the method that you want to call |
2421 jmethodID windowNew = env->GetMethodID(clazz, "windowNew", "(Ljava/lang/String;)V"); | 2505 jmethodID windowNew = env->GetMethodID(clazz, "windowNew", |
2506 "(Ljava/lang/String;I)Landroid/widget/LinearLayout;"); | |
2422 // Call the method on the object | 2507 // Call the method on the object |
2423 jobject result = env->CallObjectMethod(_dw_obj, windowNew, jstr); | 2508 jobject result = env->CallObjectMethod(_dw_obj, windowNew, jstr, (int)flStyle); |
2424 return result; | 2509 return result; |
2425 } | 2510 } |
2426 return 0; | 2511 return 0; |
2427 } | 2512 } |
2428 | 2513 |