package com.ubt.jimu.utils; import android.content.Context; import android.os.Build; import android.os.LocaleList; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.ubt.jimu.Channel; import com.ubt.jimu.R; import com.ubt.jimu.base.entities.NSLocale; import com.ubt.jimu.controller.data.widget.JockstickDataConverter; import com.ubtech.utils.XLog; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.CharBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; /* loaded from: classes2.dex */ public class LocaleUtils { public static final Locale[] a = {Locale.US, Locale.SIMPLIFIED_CHINESE, Locale.TRADITIONAL_CHINESE, Locale.FRANCE, new Locale("es"), new Locale("pt"), Locale.GERMANY, Locale.JAPAN, Locale.ITALY, Locale.KOREA, new Locale("ru"), new Locale("pl"), new Locale("tr"), new Locale("da"), LocaleEx.a, LocaleEx.b, LocaleEx.c}; private static final HashMap b = new HashMap<>(20); interface LocaleEx { public static final Locale a = new Locale("in"); public static final Locale b = new Locale("th"); public static final Locale c = new Locale("yue"); } static { b.put("en", "English"); b.put("zh-hans", "China"); b.put("zh-hant", "HokongChinese"); b.put("fr", "French"); b.put("es", "Spanish"); b.put("ar", "Arab"); b.put("de", "German"); b.put("ja", "Japan"); b.put("ko", "Korean"); b.put("pt", "Portugal"); b.put("it", "Italy"); b.put("ru", "Russian"); b.put("pl", "Polski"); b.put("da", "Danish"); b.put("tr", "Turkish"); b.put(JockstickDataConverter.ID, "Indonesian"); b.put("th", "Thai"); } public static String a(Context context) { StringBuffer stringBuffer = new StringBuffer(); InputStream inputStream = null; try { try { InputStream openRawResource = context.getResources().openRawResource(R.raw.diallingcode); InputStreamReader inputStreamReader = new InputStreamReader(openRawResource); CharBuffer allocate = CharBuffer.allocate(51200); if (inputStreamReader.read(allocate) != 0) { allocate.flip(); } List list = (List) new Gson().fromJson(allocate.toString(), new TypeToken>() { // from class: com.ubt.jimu.utils.LocaleUtils.1 }.getType()); if (list != null && list.size() != 0) { Locale e = e(); String country = e.getCountry(); if (!e.getLanguage().equals(Locale.CHINA.getLanguage())) { if (!e.getLanguage().equals(Locale.ENGLISH.getLanguage())) { Iterator it = list.iterator(); while (true) { if (!it.hasNext()) { break; } NSLocale nSLocale = (NSLocale) it.next(); nSLocale.setName(new Locale("", nSLocale.getCode()).getDisplayCountry()); if (!android.text.TextUtils.isEmpty(country) && country.equals(nSLocale.getCode())) { stringBuffer.append(nSLocale.getName()); stringBuffer.append(nSLocale.getDial_code()); break; } } } else { Iterator it2 = list.iterator(); while (true) { if (!it2.hasNext()) { break; } NSLocale nSLocale2 = (NSLocale) it2.next(); if (!android.text.TextUtils.isEmpty(country) && country.equals(nSLocale2.getCode())) { stringBuffer.append(nSLocale2.getName()); stringBuffer.append(nSLocale2.getDial_code()); break; } } } } else { Iterator it3 = list.iterator(); while (true) { if (!it3.hasNext()) { break; } NSLocale nSLocale3 = (NSLocale) it3.next(); nSLocale3.setName(nSLocale3.getChineseName()); if (!android.text.TextUtils.isEmpty(country) && country.equals(nSLocale3.getCode())) { stringBuffer.append(nSLocale3.getName()); stringBuffer.append(nSLocale3.getDial_code()); break; } } } String trim = stringBuffer.toString().trim(); if (openRawResource != null) { try { openRawResource.close(); } catch (Exception e2) { e2.printStackTrace(); } } return trim; } stringBuffer.append("中国+86"); String trim2 = stringBuffer.toString().trim(); if (openRawResource != null) { try { openRawResource.close(); } catch (Exception e3) { e3.printStackTrace(); } } return trim2; } catch (Exception e4) { e4.printStackTrace(); if (0 != 0) { try { inputStream.close(); } catch (Exception e5) { e5.printStackTrace(); } } stringBuffer.append("中国+86"); return stringBuffer.toString().trim(); } } catch (Throwable th) { if (0 != 0) { try { inputStream.close(); } catch (Exception e6) { e6.printStackTrace(); } } throw th; } } public static String b() { Locale e = e(); Locale[] localeArr = a; int length = localeArr.length; boolean z = false; int i = 0; while (true) { if (i >= length) { break; } if (localeArr[i].getLanguage().equals(e.getLanguage())) { z = true; break; } i++; } return !z ? Locale.US.getLanguage() : Locale.CHINA.getLanguage().equals(e.getLanguage()) ? Locale.CHINA.getCountry().equals(e.getCountry()) ? "zh-hans" : "zh-hant" : LocaleEx.c.getLanguage().equals(e.getLanguage()) ? "zh-hant" : LocaleEx.a.getLanguage().equals(e.getLanguage()) ? JockstickDataConverter.ID : e.getLanguage(); } public static String c() { return g() ? "zh-hans" : b(); } public static String d() { Locale e = e(); return (e == null || android.text.TextUtils.isEmpty(e.getCountry())) ? Locale.US.getCountry() : e.getCountry(); } public static Locale e() { return Build.VERSION.SDK_INT >= 24 ? LocaleList.getDefault().get(0) : Locale.getDefault(); } public static boolean f() { return Locale.getDefault().getCountry().equals(Locale.CHINA.getCountry()); } public static boolean g() { return !Channel.GOOGLE_PLAY.getChannelName().equals(PackageHelper.a("CHANNEL_ID")); } public static String a() { String str = b.get(b()); if (android.text.TextUtils.isEmpty(str)) { str = "English"; } XLog.a("lang-test", "full lang %s", str); return str; } }