move lang strings into cache and add method to get 'em

This commit is contained in:
Andy2 2010-08-26 18:43:59 -07:00
parent ecd0280353
commit 40e266dda0
2 changed files with 17 additions and 8 deletions

View file

@ -21,6 +21,7 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import java.util.HashMap; import java.util.HashMap;
import org.eehouse.android.xw4.jni.JNIUtilsImpl; import org.eehouse.android.xw4.jni.JNIUtilsImpl;
@ -28,6 +29,17 @@ import org.eehouse.android.xw4.jni.XwJNI;
public class DictLangCache { public class DictLangCache {
private static HashMap<String,Integer> s_nameToLang; private static HashMap<String,Integer> s_nameToLang;
private static String[] s_langNames;
public static String getLangName( Context context, String name )
{
int code = getLangCode( context, name );
if ( null == s_langNames ) {
Resources res = context.getResources();
s_langNames = res.getStringArray( R.array.language_names );
}
return s_langNames[code];
}
public static int getLangCode( Context context, String name ) public static int getLangCode( Context context, String name )
{ {

View file

@ -26,7 +26,6 @@ import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ContextMenu; import android.view.ContextMenu;
@ -48,13 +47,10 @@ public class DictsActivity extends ListActivity
private class DictListAdapter extends XWListAdapter { private class DictListAdapter extends XWListAdapter {
private Context m_context; private Context m_context;
private String[] m_langNames;
public DictListAdapter( Context context ) { public DictListAdapter( Context context ) {
super( context, m_dicts.length ); super( context, m_dicts.length );
m_context = context; m_context = context;
Resources res = m_context.getResources();
m_langNames = res.getStringArray( R.array.language_names );
} }
public Object getItem( int position) { return m_dicts[position]; } public Object getItem( int position) { return m_dicts[position]; }
@ -65,10 +61,11 @@ public class DictsActivity extends ListActivity
= (XWListItem)factory.inflate( R.layout.list_item, null ); = (XWListItem)factory.inflate( R.layout.list_item, null );
view.setPosition( position ); view.setPosition( position );
// append language code // append language name
int code = DictLangCache.getLangCode( DictsActivity.this, view.setText( m_dicts[position] + " (" +
m_dicts[position] ); DictLangCache.getLangName( DictsActivity.this,
view.setText( m_dicts[position] + " (" + m_langNames[code] + ")" ); m_dicts[position] )
+ ")" );
if ( !GameUtils.dictIsBuiltin( DictsActivity.this, if ( !GameUtils.dictIsBuiltin( DictsActivity.this,
m_dicts[position] ) ) { m_dicts[position] ) ) {