mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
move lang strings into cache and add method to get 'em
This commit is contained in:
parent
ecd0280353
commit
40e266dda0
2 changed files with 17 additions and 8 deletions
|
@ -21,6 +21,7 @@
|
|||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eehouse.android.xw4.jni.JNIUtilsImpl;
|
||||
|
@ -28,6 +29,17 @@ import org.eehouse.android.xw4.jni.XwJNI;
|
|||
|
||||
public class DictLangCache {
|
||||
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 )
|
||||
{
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.widget.Button;
|
|||
import android.widget.TextView;
|
||||
import android.widget.AdapterView;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ContextMenu;
|
||||
|
@ -48,13 +47,10 @@ public class DictsActivity extends ListActivity
|
|||
|
||||
private class DictListAdapter extends XWListAdapter {
|
||||
private Context m_context;
|
||||
private String[] m_langNames;
|
||||
|
||||
public DictListAdapter( Context context ) {
|
||||
super( context, m_dicts.length );
|
||||
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]; }
|
||||
|
@ -65,10 +61,11 @@ public class DictsActivity extends ListActivity
|
|||
= (XWListItem)factory.inflate( R.layout.list_item, null );
|
||||
view.setPosition( position );
|
||||
|
||||
// append language code
|
||||
int code = DictLangCache.getLangCode( DictsActivity.this,
|
||||
m_dicts[position] );
|
||||
view.setText( m_dicts[position] + " (" + m_langNames[code] + ")" );
|
||||
// append language name
|
||||
view.setText( m_dicts[position] + " (" +
|
||||
DictLangCache.getLangName( DictsActivity.this,
|
||||
m_dicts[position] )
|
||||
+ ")" );
|
||||
|
||||
if ( !GameUtils.dictIsBuiltin( DictsActivity.this,
|
||||
m_dicts[position] ) ) {
|
||||
|
|
Loading…
Reference in a new issue