forked from organicmaps/organicmaps-tmp
[android] Better string's conversion interface.
This commit is contained in:
parent
3a37ee0b99
commit
f2e87171b3
5 changed files with 33 additions and 24 deletions
|
@ -63,9 +63,8 @@ namespace jni
|
|||
}
|
||||
*/
|
||||
|
||||
string ToNativeString(jstring str)
|
||||
string ToNativeString(JNIEnv * env, jstring str)
|
||||
{
|
||||
JNIEnv * env = GetEnv();
|
||||
string result;
|
||||
char const * utfBuffer = env->GetStringUTFChars(str, 0);
|
||||
if (utfBuffer)
|
||||
|
@ -76,9 +75,9 @@ namespace jni
|
|||
return result;
|
||||
}
|
||||
|
||||
jstring ToJavaString(string const & s)
|
||||
jstring ToJavaString(JNIEnv * env, char const * s)
|
||||
{
|
||||
return GetEnv()->NewStringUTF(s.c_str());
|
||||
return env->NewStringUTF(s);
|
||||
}
|
||||
|
||||
JNIEnv * GetEnv()
|
||||
|
@ -131,10 +130,9 @@ namespace jni
|
|||
|
||||
jstring jErrorMsg = (jstring) env->CallObjectMethod(e, mid);
|
||||
|
||||
return ToNativeString(jErrorMsg);
|
||||
return ToNativeString(env, jErrorMsg);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace jni
|
||||
|
|
|
@ -17,11 +17,21 @@ namespace jni
|
|||
//jobject CreateJavaObject(JNIEnv * env, char const * klass, char const * sig, ...);
|
||||
//@}
|
||||
|
||||
string ToNativeString(jstring str);
|
||||
jstring ToJavaString(string const & s);
|
||||
JNIEnv * GetEnv();
|
||||
JavaVM * GetJVM();
|
||||
|
||||
string ToNativeString(JNIEnv * env, jstring str);
|
||||
inline string ToNativeString(jstring str)
|
||||
{
|
||||
return ToNativeString(GetEnv(), str);
|
||||
}
|
||||
|
||||
jstring ToJavaString(JNIEnv * env, char const * s);
|
||||
inline jstring ToJavaString(JNIEnv * env, string const & s)
|
||||
{
|
||||
return ToJavaString(env, s.c_str());
|
||||
}
|
||||
|
||||
string DescribeException();
|
||||
|
||||
shared_ptr<jobject> make_global_ref(jobject obj);
|
||||
|
|
|
@ -75,8 +75,8 @@ extern "C"
|
|||
g_totalBytesToDownload = 0;
|
||||
g_totalDownloadedBytes = 0;
|
||||
|
||||
//g_apkPath = jni::ToNativeString(apkPath);
|
||||
string const path = jni::ToNativeString(sdcardPath);
|
||||
//g_apkPath = jni::ToNativeString(env, apkPath);
|
||||
string const path = jni::ToNativeString(env, sdcardPath);
|
||||
|
||||
Platform & pl = GetPlatform();
|
||||
ReaderStreamBuf buffer(pl.GetReader("external_resources.txt"));
|
||||
|
@ -113,8 +113,7 @@ extern "C"
|
|||
}
|
||||
}
|
||||
|
||||
int res = HasSpaceForFiles(path, g_totalBytesToDownload);
|
||||
|
||||
int const res = HasSpaceForFiles(path, g_totalBytesToDownload);
|
||||
switch (res)
|
||||
{
|
||||
case ERR_STORAGE_DISCONNECTED:
|
||||
|
@ -244,8 +243,8 @@ extern "C"
|
|||
Java_com_mapswithme_maps_DownloadResourcesActivity_moveMaps(JNIEnv * env, jobject thiz,
|
||||
jstring fromPath, jstring toPath)
|
||||
{
|
||||
string from = jni::ToNativeString(fromPath);
|
||||
string to = jni::ToNativeString(toPath);
|
||||
string const from = jni::ToNativeString(env, fromPath);
|
||||
string const to = jni::ToNativeString(env, toPath);
|
||||
|
||||
Platform & pl = GetPlatform();
|
||||
Platform::FilesList files;
|
||||
|
|
|
@ -110,7 +110,8 @@ extern "C"
|
|||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_nativeSetString(JNIEnv * env, jobject thiz, jstring name, jstring value)
|
||||
{
|
||||
g_framework->AddString(jni::ToNativeString(name), jni::ToNativeString(value));
|
||||
g_framework->AddString(jni::ToNativeString(env, name),
|
||||
jni::ToNativeString(env, value));
|
||||
}
|
||||
|
||||
#define SETTINGS_PRO_VERSION_URL_KEY "ProVersionURL"
|
||||
|
@ -130,7 +131,7 @@ extern "C"
|
|||
{
|
||||
string res;
|
||||
Settings::Get(SETTINGS_PRO_VERSION_URL_KEY, res);
|
||||
return jni::ToJavaString(res);
|
||||
return jni::ToJavaString(env, res);
|
||||
}
|
||||
|
||||
void OnProVersionServerReply(downloader::HttpRequest & r, shared_ptr<jobject> obj)
|
||||
|
@ -181,7 +182,7 @@ extern "C"
|
|||
shouldCheck = true; //< value is corrupted or invalid, should re-check
|
||||
else
|
||||
{
|
||||
uint64_t curTime = time(0);
|
||||
uint64_t const curTime = time(0);
|
||||
if (curTime - lastCheckTime > PRO_VERSION_CHECK_INTERVAL)
|
||||
shouldCheck = true; //< last check was too long ago
|
||||
else
|
||||
|
@ -194,7 +195,8 @@ extern "C"
|
|||
if (shouldCheck)
|
||||
{
|
||||
LOG(LDEBUG, ("checking for Pro version"));
|
||||
downloader::HttpRequest::Get(jni::ToNativeString(proVersionServerURL), bind(&OnProVersionServerReply, _1, jni::make_global_ref(thiz)));
|
||||
downloader::HttpRequest::Get(jni::ToNativeString(env, proVersionServerURL),
|
||||
bind(&OnProVersionServerReply, _1, jni::make_global_ref(thiz)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +205,7 @@ extern "C"
|
|||
{
|
||||
string res;
|
||||
Settings::Get(SETTINGS_PRO_VERSION_URL_KEY, res);
|
||||
return jni::ToJavaString(res);
|
||||
return jni::ToJavaString(env, res);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
|
|
@ -85,12 +85,12 @@ namespace android
|
|||
|
||||
m_impl = new PlatformImpl();
|
||||
|
||||
m_resourcesDir = jni::ToNativeString(apkPath);
|
||||
m_writableDir = jni::ToNativeString(storagePath);
|
||||
m_settingsDir = jni::ToNativeString(settingsPath);
|
||||
m_resourcesDir = jni::ToNativeString(env, apkPath);
|
||||
m_writableDir = jni::ToNativeString(env, storagePath);
|
||||
m_settingsDir = jni::ToNativeString(env, settingsPath);
|
||||
|
||||
m_localTmpPath = jni::ToNativeString(tmpPath);
|
||||
m_externalTmpPath = jni::ToNativeString(extTmpPath);
|
||||
m_localTmpPath = jni::ToNativeString(env, tmpPath);
|
||||
m_externalTmpPath = jni::ToNativeString(env, extTmpPath);
|
||||
// By default use external temporary folder
|
||||
m_tmpDir = m_externalTmpPath;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue