From 40e266dda0ddecf51ae259baba5b04f778dcaaea Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 26 Aug 2010 18:43:59 -0700 Subject: [PATCH] move lang strings into cache and add method to get 'em --- .../src/org/eehouse/android/xw4/DictLangCache.java | 12 ++++++++++++ .../src/org/eehouse/android/xw4/DictsActivity.java | 13 +++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) 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 8a485cd53..af470b405 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java @@ -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 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 ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 1d151af21..9f3b1796c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -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] ) ) {