diff --git a/xwords4/android/XWords4/archive/R.java b/xwords4/android/XWords4/archive/R.java
index 6540e8536..c36b0b6e4 100644
--- a/xwords4/android/XWords4/archive/R.java
+++ b/xwords4/android/XWords4/archive/R.java
@@ -18,6 +18,8 @@ public final class R {
public static final int force_radio_names=0x7f06000b;
public static final int game_summary_values=0x7f060009;
public static final int language_codes=0x7f060007;
+ /** These two arrays need to be kept in sync
+ */
public static final int language_names=0x7f060006;
/** Keep in sync with LocSearcher SHOW_BYS enum
*/
diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml
index 6d8c73c20..7412ef9f8 100644
--- a/xwords4/android/XWords4/res/values/common_rsrc.xml
+++ b/xwords4/android/XWords4/res/values/common_rsrc.xml
@@ -195,27 +195,28 @@
- 86400
+
- @string/lang_unknown
- - @string/lang_name_english
- - @string/lang_name_french
- - @string/lang_name_german
- - @string/lang_name_turkish
- - @string/lang_name_arabic
- - @string/lang_name_spanish
- - @string/lang_name_swedish
- - @string/lang_name_polish
- - @string/lang_name_danish
- - @string/lang_name_italian
- - @string/lang_name_dutch
- - @string/lang_name_catalan
- - @string/lang_name_portuguese
+ - English
+ - French
+ - German
+ - Turkish
+ - Arabic
+ - Spanish
+ - Swedish
+ - Polish
+ - Danish
+ - Italian
+ - Dutch
+ - Catalan
+ - Portuguese
- - @string/lang_name_russian
+ - Russian
- - @string/lang_name_czech
- - @string/lang_name_greek
- - @string/lang_name_slovak
+ - Czech
+ - Greek
+ - Slovak
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 bae7d9382..7bfe77aec 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java
@@ -24,12 +24,16 @@ import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.widget.ArrayAdapter;
+
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
import junit.framework.Assert;
import org.eehouse.android.xw4.DictUtils.DictAndLoc;
@@ -38,16 +42,77 @@ import org.eehouse.android.xw4.jni.JNIUtilsImpl;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.jni.DictInfo;
import org.eehouse.android.xw4.jni.CommonPrefs;
+import org.eehouse.android.xw4.loc.LocUtils;
public class DictLangCache {
private static String[] s_langNames;
private static HashMap s_langCodes;
private static int s_adaptedLang = -1;
- private static ArrayAdapter s_langsAdapter;
+ private static LangsArrayAdapter s_langsAdapter;
private static ArrayAdapter s_dictsAdapter;
private static String s_last;
private static Handler s_handler;
+
+
+ public static class LangsArrayAdapter extends ArrayAdapter {
+ private Context m_context;
+ private Map m_map;
+
+ public LangsArrayAdapter( Context context, int itemLayout ) {
+ super( context, itemLayout );
+ m_context = context;
+ }
+
+ public void rebuild()
+ {
+ m_map = new HashMap();
+ DictAndLoc[] dals = DictUtils.dictList( m_context );
+ for ( DictAndLoc dal : dals ) {
+ String lang = getLangName( m_context, dal.name );
+ if ( null != lang && 0 != lang.length() ) {
+ if ( ! m_map.containsValue( lang ) ) {
+ String locName = LocUtils.xlateLang( m_context, lang );
+ locName = Utils.capitalize( locName );
+ m_map.put( locName, lang );
+ }
+ }
+ }
+
+ // Now build the array data
+ clear();
+ for ( Iterator iter = m_map.keySet().iterator();
+ iter.hasNext(); ) {
+ String locName = iter.next();
+ add( locName );
+ }
+ if ( null != s_last ) {
+ add( s_last );
+ }
+ sort( KeepLast );
+ }
+
+ public int getPosForLang( String lang )
+ {
+ int result = -1;
+ for ( int ii = 0; ii < getCount(); ++ii ) {
+ String code = getLangAtPosition( ii );
+ if ( code.equals( lang ) ) {
+ result = ii;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public String getLangAtPosition( int position )
+ {
+ String locName = getItem( position );
+ String result = m_map.get( locName );
+ return result;
+ }
+ }
+
private static Comparator KeepLast =
new Comparator() {
public int compare( String str1, String str2 )
@@ -280,8 +345,7 @@ public class DictLangCache {
s_adaptedLang ) );
}
if ( null != s_langsAdapter ) {
- rebuildAdapter( s_langsAdapter,
- DictLangCache.listLangs( context ) );
+ s_langsAdapter.rebuild();
}
}
} );
@@ -345,13 +409,13 @@ public class DictLangCache {
s_handler = new Handler();
}
- public static ArrayAdapter getLangsAdapter( Context context )
+ public static LangsArrayAdapter getLangsAdapter( Context context )
{
if ( null == s_langsAdapter ) {
s_langsAdapter =
- new ArrayAdapter( context,
- android.R.layout.simple_spinner_item );
- rebuildAdapter( s_langsAdapter, listLangs( context ) );
+ new LangsArrayAdapter( context,
+ android.R.layout.simple_spinner_item );
+ s_langsAdapter.rebuild();
}
return s_langsAdapter;
}
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java
index f8d3f1c1b..d2fbea9c8 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java
@@ -111,16 +111,14 @@ public class DictsDelegate extends ListDelegateBase
private static class DictInfo implements Comparable {
public String m_name;
public String m_lang;
- public String m_langLoc;
public int m_nWords;
public long m_nBytes;
public String m_note;
- public DictInfo( String name, String lang, String langLoc, int nWords,
+ public DictInfo( String name, String lang, int nWords,
long nBytes, String note )
{
m_name = name;
m_lang = lang;
- m_langLoc = langLoc;
m_nWords = nWords;
m_nBytes = nBytes;
m_note = note;
@@ -189,8 +187,9 @@ public class DictsDelegate extends ListDelegateBase
int langCode = DictLangCache.getLangLangCode( m_context,
langName );
boolean expanded = ! m_closedLangs.contains( langName );
+ String locLangName = LocUtils.xlateLang( m_context, langName );
String name = getQuantityString( R.plurals.lang_name_fmt, info.m_numDicts,
- langName, info.m_numDicts );
+ locLangName, info.m_numDicts );
result = ListGroup.make( m_context, convertView,
DictsDelegate.this, groupPos, name,
expanded );
@@ -1267,15 +1266,14 @@ public class DictsDelegate extends ListDelegateBase
for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) {
JSONObject langObj = langs.getJSONObject( ii );
String langName = langObj.getString( "lang" );
- String locLangName = LocUtils.xlateLang( m_context, langName );
if ( null != m_filterLang &&
- ! m_filterLang.equals( locLangName ) ) {
+ ! m_filterLang.equals( langName ) ) {
continue;
}
- if ( ! curLangs.contains( locLangName ) ) {
- closedLangs.add( locLangName );
+ if ( ! curLangs.contains( langName ) ) {
+ closedLangs.add( langName );
}
JSONArray dicts = langObj.getJSONArray( "dicts" );
@@ -1293,14 +1291,13 @@ public class DictsDelegate extends ListDelegateBase
if ( 0 == note.length() ) {
note = null;
}
- DictInfo info =
- new DictInfo( name, langName, locLangName,
- nWords, nBytes, note );
+ DictInfo info = new DictInfo( name, langName, nWords,
+ nBytes, note );
if ( !m_quickFetchMode ) {
// Check if we have it and it needs an update
if ( DictLangCache.haveDict( m_activity,
- locLangName, name )){
+ langName, name )){
boolean matches = true;
String curSum = DictLangCache
.getDictMD5Sum( m_activity, name );
@@ -1331,7 +1328,7 @@ public class DictsDelegate extends ListDelegateBase
DictInfo[] asArray = new DictInfo[dictNames.size()];
asArray = dictNames.toArray( asArray );
Arrays.sort( asArray );
- m_remoteInfo.put( locLangName, asArray );
+ m_remoteInfo.put( langName, asArray );
}
}
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java
index 5a08e160a..1ce00ad90 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java
@@ -58,6 +58,7 @@ import org.eehouse.android.xw4.jni.*;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
+import org.eehouse.android.xw4.DictLangCache.LangsArrayAdapter;
public class GameConfigDelegate extends DelegateBase
implements View.OnClickListener
@@ -527,7 +528,7 @@ public class GameConfigDelegate extends DelegateBase
case REQUEST_LANG:
String langName = data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
selLangChanged( langName );
- setSpinnerSelection( m_langSpinner, langName );
+ setLangSpinnerSelection( langName );
break;
default:
Assert.fail();
@@ -868,6 +869,8 @@ public class GameConfigDelegate extends DelegateBase
if ( null == m_langSpinner ) {
m_langSpinner = (Spinner)findViewById( R.id.lang_spinner );
+ final LangsArrayAdapter adapter = DictLangCache.getLangsAdapter( m_activity );
+
OnItemSelectedListener onSel =
new OnItemSelectedListener() {
@Override
@@ -879,7 +882,8 @@ public class GameConfigDelegate extends DelegateBase
if ( chosen.equals( m_browseText ) ) {
DictsDelegate.downloadForResult( m_activity, REQUEST_LANG );
} else {
- selLangChanged( chosen );
+ String langName = adapter.getLangAtPosition( position );
+ selLangChanged( langName );
}
}
@@ -887,7 +891,6 @@ public class GameConfigDelegate extends DelegateBase
public void onNothingSelected(AdapterView> parentView) {}
};
- ArrayAdapter adapter = DictLangCache.getLangsAdapter( m_activity );
String lang = DictLangCache.getLangName( m_activity, m_gi.dictLang );
configSpinnerWDownload( m_langSpinner, adapter, onSel, lang );
}
@@ -909,7 +912,20 @@ public class GameConfigDelegate extends DelegateBase
adapter.setDropDownViewResource( resID );
spinner.setAdapter( adapter );
spinner.setOnItemSelectedListener( onSel );
- setSpinnerSelection( spinner, curSel );
+ if ( m_langSpinner == spinner ) {
+ setLangSpinnerSelection( curSel );
+ } else {
+ setSpinnerSelection( spinner, curSel );
+ }
+ }
+
+ private void setLangSpinnerSelection( String sel )
+ {
+ LangsArrayAdapter adapter = (LangsArrayAdapter)m_langSpinner.getAdapter();
+ int pos = adapter.getPosForLang( sel );
+ if ( 0 <= pos ) {
+ m_langSpinner.setSelection( pos, true );
+ }
}
private void setSpinnerSelection( Spinner spinner, String sel )
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java
index 46348f7f6..95eeeac2c 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java
@@ -1211,6 +1211,7 @@ public class GamesListDelegate extends ListDelegateBase
XWPrefs.setPrefsString( m_activity,
R.string.key_default_language,
lang );
+ name = DictUtils.removeDictExtn( name );
int[] ids = { R.string.key_default_dict,
R.string.key_default_robodict };
for ( int id : ids ) {