Mercurial > dwindows
comparison android/dw.cpp @ 2790:20d39af27aa4
Android: Add a new function for Android dw_file_open() which will open the
URI that dw_file_browse() now saves at the end of the returned path.
This is a hacky method of letting things function on Android... since
Android seems to not let you open files with a pure path. Even if the file
exists it will fail to open, you need to use the ugly Android URIs.
Not sure if I will keep this solution or not, but committing it so Dynamic
Windows Interface Builder will function on Android in the meantime.
dw_file_open() just calls the system open() on non-Android platforms.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 13 Jul 2022 14:57:38 +0000 |
parents | 220d63da2183 |
children | 5c61aba17b69 |
comparison
equal
deleted
inserted
replaced
2789:025b4e3e7e75 | 2790:20d39af27aa4 |
---|---|
1276 jmethodID fileBrowse = env->GetMethodID(clazz, "fileBrowseNew", | 1276 jmethodID fileBrowse = env->GetMethodID(clazz, "fileBrowseNew", |
1277 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;"); | 1277 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;"); |
1278 // Call the method on the object | 1278 // Call the method on the object |
1279 jstring jresult = (jstring)_dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, fileBrowse, jstr, path, jext, flags), _DW_REFERENCE_NONE); | 1279 jstring jresult = (jstring)_dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, fileBrowse, jstr, path, jext, flags), _DW_REFERENCE_NONE); |
1280 if(jresult) | 1280 if(jresult) |
1281 retval = strdup(env->GetStringUTFChars(jresult, nullptr)); | 1281 { |
1282 const char *str = env->GetStringUTFChars(jresult, nullptr); | |
1283 if(str) | |
1284 { | |
1285 size_t len = strlen(str); | |
1286 | |
1287 // Allocate a string with an extra two bytes... so we can | |
1288 // check for the trailing \n in dw_file_open() without a | |
1289 // memory violation. | |
1290 if((retval = (char *)calloc(1, len + 2))) | |
1291 { | |
1292 char *tmp; | |
1293 | |
1294 strncpy(retval, str, len); | |
1295 // If we have a URI encoded, find the double \n and replace the | |
1296 // first \n with NULL so the string still looks like a normal path. | |
1297 tmp = strstr(retval, "\n\n"); | |
1298 if (tmp) | |
1299 *tmp = 0; | |
1300 } | |
1301 } | |
1302 } | |
1303 } | |
1304 return retval; | |
1305 } | |
1306 | |
1307 int API dw_file_open(const char *path, int mode) | |
1308 { | |
1309 JNIEnv *env; | |
1310 int retval = -1; | |
1311 | |
1312 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1313 { | |
1314 // dw_file_browse saves a second string with the URI after the path | |
1315 // So find the end of the string and check for a trailing \n | |
1316 // The URI will be after that if found. | |
1317 const char *uri = strchr(path, 0); | |
1318 jstring jstr = env->NewStringUTF((uri && *(uri+1) == '\n') ? (uri+2) : path); | |
1319 // First get the class that contains the method you need to call | |
1320 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1321 // Get the method that you want to call | |
1322 jmethodID fileOpen = env->GetMethodID(clazz, "fileOpen", | |
1323 "(Ljava/lang/String;I)I"); | |
1324 // Call the method on the object | |
1325 retval = (int)env->CallIntMethod(_dw_obj, fileOpen, jstr, (jint)mode); | |
1326 _dw_jni_check_exception(env); | |
1282 } | 1327 } |
1283 return retval; | 1328 return retval; |
1284 } | 1329 } |
1285 | 1330 |
1286 /* | 1331 /* |
5734 { | 5779 { |
5735 // First get the class that contains the method you need to call | 5780 // First get the class that contains the method you need to call |
5736 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 5781 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
5737 // Get the method that you want to call | 5782 // Get the method that you want to call |
5738 jmethodID windowSetStyle = env->GetMethodID(clazz, "windowSetStyle", | 5783 jmethodID windowSetStyle = env->GetMethodID(clazz, "windowSetStyle", |
5739 "(Landroid/view/View;II)V"); | 5784 "(Ljava/lang/Object;II)V"); |
5740 // Call the method on the object | 5785 // Call the method on the object |
5741 env->CallVoidMethod(_dw_obj, windowSetStyle, handle, (jint)style, (jint)mask); | 5786 env->CallVoidMethod(_dw_obj, windowSetStyle, handle, (jint)style, (jint)mask); |
5742 _dw_jni_check_exception(env); | 5787 _dw_jni_check_exception(env); |
5743 } | 5788 } |
5744 } | 5789 } |