Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorАлександр Зацепин <az@mapswithme.com>2017-10-24 20:22:33 +0300
committermpimenov <mpimenov@users.noreply.github.com>2017-10-24 20:41:33 +0300
commitd7a899145606858674af00c357e31d85f6171edf (patch)
tree32df6f6eef0c59ad96e9a1feec3e0daa3ac2b31f
parent513be8ca49f141bfa4fe8783ab4448c253173bce (diff)
[android] Returned system locale for ugc, refactored getting locale codebeta-1081
-rw-r--r--android/jni/com/mapswithme/maps/SearchEngine.cpp7
-rw-r--r--android/jni/com/mapswithme/platform/Language.cpp27
-rw-r--r--android/jni/com/mapswithme/platform/Language.hpp8
-rw-r--r--android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java2
-rw-r--r--android/src/com/mapswithme/util/Language.java23
5 files changed, 30 insertions, 37 deletions
diff --git a/android/jni/com/mapswithme/maps/SearchEngine.cpp b/android/jni/com/mapswithme/maps/SearchEngine.cpp
index 32ef619608..ad3d087321 100644
--- a/android/jni/com/mapswithme/maps/SearchEngine.cpp
+++ b/android/jni/com/mapswithme/maps/SearchEngine.cpp
@@ -10,7 +10,6 @@
#include "base/logging.hpp"
#include "../core/jni_helper.hpp"
-#include "../platform/Language.hpp"
#include "../platform/Platform.hpp"
#include <cstdint>
@@ -430,7 +429,7 @@ extern "C"
{
search::EverywhereSearchParams params;
params.m_query = jni::ToNativeString(env, bytes);
- params.m_inputLocale = ReplaceDeprecatedLanguageCode(jni::ToNativeString(env, lang));
+ params.m_inputLocale = jni::ToNativeString(env, lang);
params.m_onResults = bind(&OnResults, _1, _2, timestamp, false, hasPosition, lat, lon);
params.m_hotelsFilter = g_hotelsFilterBuilder.Build(env, hotelsFilter);
@@ -446,7 +445,7 @@ extern "C"
{
search::ViewportSearchParams vparams;
vparams.m_query = jni::ToNativeString(env, bytes);
- vparams.m_inputLocale = ReplaceDeprecatedLanguageCode(jni::ToNativeString(env, lang));
+ vparams.m_inputLocale = jni::ToNativeString(env, lang);
vparams.m_hotelsFilter = g_hotelsFilterBuilder.Build(env, hotelsFilter);
// TODO (@alexzatsepin): set up vparams.m_onCompleted here and use
@@ -471,7 +470,7 @@ extern "C"
{
storage::DownloaderSearchParams params;
params.m_query = jni::ToNativeString(env, bytes);
- params.m_inputLocale = ReplaceDeprecatedLanguageCode(jni::ToNativeString(env, lang));
+ params.m_inputLocale = jni::ToNativeString(env, lang);
params.m_onResults = bind(&OnMapSearchResults, _1, timestamp);
if (g_framework->NativeFramework()->SearchInDownloader(params))
diff --git a/android/jni/com/mapswithme/platform/Language.cpp b/android/jni/com/mapswithme/platform/Language.cpp
index 1c0550062e..a63152ad87 100644
--- a/android/jni/com/mapswithme/platform/Language.cpp
+++ b/android/jni/com/mapswithme/platform/Language.cpp
@@ -1,5 +1,3 @@
-#include "Language.hpp"
-
#include "../core/jni_helper.hpp"
#include "base/assert.hpp"
@@ -8,19 +6,6 @@
#include <string>
-std::string ReplaceDeprecatedLanguageCode(std::string const & lang)
-{
- // in* -> id
- // iw* -> he
-
- if (strings::StartsWith(lang, "in"))
- return "id";
- else if (strings::StartsWith(lang, "iw"))
- return "he";
-
- return lang;
-}
-
/// This function is called from native c++ code
std::string GetAndroidSystemLanguage()
{
@@ -33,16 +18,14 @@ std::string GetAndroidSystemLanguage()
return DEFAULT_LANG;
}
- static jclass const localeClass = jni::GetGlobalClassRef(env, "java/util/Locale");
- static jmethodID const localeGetDefaultId = jni::GetStaticMethodID(env, localeClass, "getDefault", "()Ljava/util/Locale;");
- static jmethodID const localeToStringId = env->GetMethodID(localeClass, "toString", "()Ljava/lang/String;");
+ static jclass const languageClass = jni::GetGlobalClassRef(env, "com/mapswithme/util/Language");
+ static jmethodID const getDefaultLocaleId = jni::GetStaticMethodID(env, languageClass, "getDefaultLocale", "()Ljava/lang/String;");
- jni::TScopedLocalRef localeInstance(env, env->CallStaticObjectMethod(localeClass, localeGetDefaultId));
- jni::TScopedLocalRef langString(env, env->CallObjectMethod(localeInstance.get(), localeToStringId));
+ jni::TScopedLocalRef localeRef(env, env->CallStaticObjectMethod(languageClass, getDefaultLocaleId));
- std::string res = jni::ToNativeString(env, (jstring) langString.get());
+ std::string res = jni::ToNativeString(env, (jstring) localeRef.get());
if (res.empty())
res = DEFAULT_LANG;
- return ReplaceDeprecatedLanguageCode(res);
+ return res;
}
diff --git a/android/jni/com/mapswithme/platform/Language.hpp b/android/jni/com/mapswithme/platform/Language.hpp
deleted file mode 100644
index 0ab49bc313..0000000000
--- a/android/jni/com/mapswithme/platform/Language.hpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-
-#include "../core/jni_helper.hpp"
-
-#include <string>
-
-/// More details about deprecated language codes http://developer.android.com/reference/java/util/Locale.html
-std::string ReplaceDeprecatedLanguageCode(std::string const & language);
diff --git a/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java b/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java
index 381163a3b9..e6a36089fb 100644
--- a/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java
+++ b/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java
@@ -93,7 +93,7 @@ public class UGCEditorFragment extends BaseMwmAuthorizationFragment
UGC.Rating[] ratings = new UGC.Rating[modifiedRatings.size()];
modifiedRatings.toArray(ratings);
UGCUpdate update = new UGCUpdate(ratings, mReviewEditText.getText().toString(),
- System.currentTimeMillis(), Language.getKeyboardLocale());
+ System.currentTimeMillis(), Language.getDefaultLocale());
FeatureId featureId = getArguments().getParcelable(ARG_FEATURE_ID);
if (featureId == null)
throw new AssertionError("Feature ID must be passed to this fragment!");
diff --git a/android/src/com/mapswithme/util/Language.java b/android/src/com/mapswithme/util/Language.java
index 151ae76103..6ee82fbe8e 100644
--- a/android/src/com/mapswithme/util/Language.java
+++ b/android/src/com/mapswithme/util/Language.java
@@ -1,8 +1,11 @@
package com.mapswithme.util;
import android.content.Context;
+import android.support.annotation.NonNull;
+import android.text.TextUtils;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
+
import com.mapswithme.maps.MwmApplication;
import java.util.Locale;
@@ -11,21 +14,37 @@ public class Language
{
// Locale.getLanguage() returns even 3-letter codes, not that we need in the C++ core,
// so we use locale itself, like zh_CN
+ @NonNull
public static String getDefaultLocale()
{
- return Locale.getDefault().toString();
+ String lang = Locale.getDefault().toString();
+ if (TextUtils.isEmpty(lang))
+ return Locale.US.toString();
+
+ // Replace deprecated language codes:
+ // in* -> id
+ // iw* -> he
+ if (lang.startsWith("in"))
+ return "id";
+ if (lang.startsWith("iw"))
+ return "he";
+
+ return lang;
}
// After some testing on Galaxy S4, looks like this method doesn't work on all devices:
// sometime it always returns the same value as getDefaultLocale()
+ @NonNull
public static String getKeyboardLocale()
{
final InputMethodManager imm = (InputMethodManager) MwmApplication.get().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null)
{
final InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
- if (ims != null)
+ if (ims != null && !TextUtils.isEmpty(ims.getLocale()))
+ {
return ims.getLocale();
+ }
}
return getDefaultLocale();