mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +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;
|
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 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -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] ) ) {
|
||||||
|
|
Loading…
Reference in a new issue