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

Language.java « util « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c7521566581ff98d2e509ef3c617ac969fb5945 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;

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()
  {
    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()
  {
    Context context = MwmApplication.get();
    InputMethodManager imm = (InputMethodManager) context
        .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null)
      return getDefaultLocale();

    final InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
    if (ims == null)
      return getDefaultLocale();

    String locale = ims.getLocale();
    if (TextUtils.isEmpty(locale.trim()))
      return getDefaultLocale();

    return locale;
  }

  @NonNull
  public static native String nativeNormalize(@NonNull String locale);
}