From c990900913170abc2f35a0b0d7acecdf4395c31a Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 9 May 2011 06:49:45 -0700 Subject: [PATCH] cache list of langs. Performance is otherwise abysmal. May need to add mechanism to notify when the list is invalidated. (Or move caching into DictsLangCache class.) --- .../src/org/eehouse/android/xw4/DictLangCache.java | 2 +- .../src/org/eehouse/android/xw4/DictsActivity.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 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 c8d2f81d7..861593a03 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java @@ -224,7 +224,7 @@ public class DictLangCache { } } - private static String[] listLangs( Context context ) + public static String[] listLangs( Context context ) { return listLangs( context, GameUtils.dictList( context ) ); } 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 af9db3e8f..e5359544a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -66,10 +66,12 @@ public class DictsActivity extends ExpandableListActivity private class DictListAdapter implements ExpandableListAdapter { private Context m_context; + private String[] m_langs; public DictListAdapter( Context context ) { //super( context, m_dicts.length ); m_context = context; + m_langs = DictLangCache.listLangs( m_context ); } public boolean areAllItemsEnabled() { return false; } @@ -129,13 +131,13 @@ public class DictsActivity extends ExpandableListActivity public int getGroupCount() { - return DictLangCache.getLangNames( m_context ).length; + return m_langs.length; } public long getGroupId( int groupPosition ) { - String[] langNames = DictLangCache.getLangNames( m_context ); - int lang = DictLangCache.getLangLangCode( m_context, langNames[groupPosition] ); + int lang = DictLangCache.getLangLangCode( m_context, + m_langs[groupPosition] ); return lang; } @@ -145,7 +147,7 @@ public class DictsActivity extends ExpandableListActivity View row = LayoutInflater.from(DictsActivity.this). inflate(android.R.layout.simple_expandable_list_item_1, null ); TextView view = (TextView)row.findViewById( android.R.id.text1 ); - view.setText( DictLangCache.getLangNames(m_context)[groupPosition] ); + view.setText( m_langs[groupPosition] ); return view; } @@ -157,7 +159,6 @@ public class DictsActivity extends ExpandableListActivity public void registerDataSetObserver( DataSetObserver obs ){} public void unregisterDataSetObserver( DataSetObserver obs ){} - // public Object getItem( int position) { return m_dicts[position]; } // public View getView( final int position, View convertView, // ViewGroup parent ) {