mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
Add new class to cache lang codes for dicts to prevent expensive
operation of loading them each time. Will have other uses later.
This commit is contained in:
parent
40d8aede88
commit
0313421634
2 changed files with 50 additions and 3 deletions
|
@ -0,0 +1,48 @@
|
||||||
|
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright 2010 by Eric House (xwords@eehouse.org). All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.eehouse.android.xw4.jni.JNIUtilsImpl;
|
||||||
|
import org.eehouse.android.xw4.jni.XwJNI;
|
||||||
|
|
||||||
|
public class DictLangCache {
|
||||||
|
private static HashMap<String,Integer> s_nameToLang;
|
||||||
|
|
||||||
|
public static int getLangCode( Context context, String name )
|
||||||
|
{
|
||||||
|
if ( null == s_nameToLang ) {
|
||||||
|
s_nameToLang = new HashMap<String,Integer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int code;
|
||||||
|
if ( s_nameToLang.containsKey( name ) ) {
|
||||||
|
code = s_nameToLang.get( name );
|
||||||
|
} else {
|
||||||
|
byte[] dict = GameUtils.openDict( context, name );
|
||||||
|
code = XwJNI.dict_getLanguageCode( dict, JNIUtilsImpl.get() );
|
||||||
|
s_nameToLang.put( name, new Integer(code) );
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,9 +66,8 @@ public class DictsActivity extends ListActivity
|
||||||
view.setPosition( position );
|
view.setPosition( position );
|
||||||
|
|
||||||
// append language code
|
// append language code
|
||||||
byte[] dict = GameUtils.openDict( DictsActivity.this,
|
int code = DictLangCache.getLangCode( DictsActivity.this,
|
||||||
m_dicts[position] );
|
m_dicts[position] );
|
||||||
int code = XwJNI.dict_getLanguageCode( dict, JNIUtilsImpl.get() );
|
|
||||||
view.setText( m_dicts[position] + " (" + m_langNames[code] + ")" );
|
view.setText( m_dicts[position] + " (" + m_langNames[code] + ")" );
|
||||||
|
|
||||||
if ( !GameUtils.dictIsBuiltin( DictsActivity.this,
|
if ( !GameUtils.dictIsBuiltin( DictsActivity.this,
|
||||||
|
|
Loading…
Add table
Reference in a new issue