From 4e4175f4863b128e9771b9664537faff3d66be86 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 10 Jun 2014 07:08:56 -0700 Subject: [PATCH] add ability to look up by language name. Note: this code is hitting the DB way too often and needs to be optimized! --- .../org/eehouse/android/xw4/DictLangCache.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java index d596a3076..968f47c2e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java @@ -41,6 +41,7 @@ import org.eehouse.android.xw4.jni.CommonPrefs; public class DictLangCache { private static String[] s_langNames; + private static HashMap s_langCodes; private static int s_adaptedLang = -1; private static ArrayAdapter s_langsAdapter; @@ -122,6 +123,17 @@ public class DictLangCache { return result; } + public static boolean haveDict( Context context, String lang, String name ) + { + boolean result = false; + getLangNames( context ); /* inits s_langCodes */ + Integer code = s_langCodes.get( lang ); + if ( null != code ) { + result = haveDict( context, code, name ); + } + return result; + } + public static boolean haveDict( Context context, int code, String name ) { boolean found = false; @@ -353,6 +365,11 @@ public class DictLangCache { if ( null == s_langNames ) { Resources res = context.getResources(); s_langNames = res.getStringArray( R.array.language_names ); + + s_langCodes = new HashMap(); + for ( int ii = 0; ii < s_langNames.length; ++ii ) { + s_langCodes.put( s_langNames[ii], ii ); + } } return s_langNames; }