mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-01 06:19:57 +01:00
LangCode->ISOCode replacement, Android side
Now we use only ISOCode string internally to identify languages, and since that's universal it can be built into an wordlist and used without the build of CrossWords knowing about that language specifically (though it'll have to know about it to have the language name be localizable.) For legacy support, though, the old int codes are transmitted in invitations and URLs IFF available, otherwise the string's used. If a newer build invites and older build to play in a too-new language there will be trouble.
This commit is contained in:
parent
ba132bb23d
commit
20908284f5
38 changed files with 619 additions and 505 deletions
|
@ -254,7 +254,7 @@ public class BoardDelegate extends DelegateBase
|
|||
setGotGameDict( m_mySIS.getDict );
|
||||
} else {
|
||||
DwnldDelegate
|
||||
.downloadDictInBack( m_activity, m_gi.dictLang,
|
||||
.downloadDictInBack( m_activity, m_gi.isoCode,
|
||||
m_mySIS.getDict,
|
||||
BoardDelegate.this );
|
||||
}
|
||||
|
@ -925,7 +925,7 @@ public class BoardDelegate extends DelegateBase
|
|||
cmd = JNICmd.CMD_TOGGLE_TRAY;
|
||||
break;
|
||||
case R.id.board_menu_study:
|
||||
StudyListDelegate.launchOrAlert( getDelegator(), m_gi.dictLang, this );
|
||||
StudyListDelegate.launchOrAlert( getDelegator(), m_gi.isoCode, this );
|
||||
break;
|
||||
case R.id.board_menu_game_netstats:
|
||||
handleViaThread( JNICmd.CMD_NETSTATS, R.string.netstats_title );
|
||||
|
@ -1021,12 +1021,13 @@ public class BoardDelegate extends DelegateBase
|
|||
case BUTTON_BROWSE_ACTION:
|
||||
String curDict = m_gi.dictName( m_view.getCurPlayer() );
|
||||
View button = m_toolbar.getButtonFor( Buttons.BUTTON_BROWSE_DICT );
|
||||
Assert.assertTrueNR( null != m_gi.isoCode );
|
||||
if ( Action.BUTTON_BROWSEALL_ACTION == action &&
|
||||
DictsDelegate.handleDictsPopup( getDelegator(), button,
|
||||
curDict, m_gi.dictLang ) ) {
|
||||
curDict, m_gi.isoCode ) ) {
|
||||
// do nothing
|
||||
} else {
|
||||
String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.dictLang );
|
||||
String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.isoCode );
|
||||
if ( null == selDict ) {
|
||||
selDict = curDict;
|
||||
}
|
||||
|
@ -1059,7 +1060,7 @@ public class BoardDelegate extends DelegateBase
|
|||
cmd = JNICmd.CMD_TRADE;
|
||||
break;
|
||||
case LOOKUP_ACTION:
|
||||
launchLookup( m_mySIS.words, m_gi.dictLang );
|
||||
launchLookup( m_mySIS.words, m_gi.isoCode );
|
||||
break;
|
||||
case DROP_MQTT_ACTION:
|
||||
dropConViaAndRestart( CommsConnType.COMMS_CONN_MQTT );
|
||||
|
@ -1761,7 +1762,7 @@ public class BoardDelegate extends DelegateBase
|
|||
post( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launchLookup( wordsToArray( words ), m_gi.dictLang );
|
||||
launchLookup( wordsToArray( words ), m_gi.isoCode );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
@ -2023,7 +2024,7 @@ public class BoardDelegate extends DelegateBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void informNetDict( int code, String oldName,
|
||||
public void informNetDict( String isoCode, String oldName,
|
||||
String newName, String newSum,
|
||||
CurGameInfo.XWPhoniesChoice phonies )
|
||||
{
|
||||
|
@ -2046,7 +2047,7 @@ public class BoardDelegate extends DelegateBase
|
|||
DlgID dlgID;
|
||||
msg = getString( R.string.inform_dict_diffdict_fmt,
|
||||
oldName, newName, newName );
|
||||
if ( DictLangCache.haveDict( m_activity, code,
|
||||
if ( DictLangCache.haveDict( m_activity, isoCode,
|
||||
newName ) ) {
|
||||
dlgID = DlgID.DLG_USEDICT;
|
||||
} else {
|
||||
|
|
|
@ -26,11 +26,15 @@ import android.database.Cursor;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.text.TextUtils;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
|
||||
import org.eehouse.android.xw4.jni.XwJNI;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper {
|
||||
private static final String TAG = DBHelper.class.getSimpleName();
|
||||
|
@ -56,7 +60,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
private int addedVersion() { return mAddedVersion; }
|
||||
}
|
||||
private static final String DB_NAME = BuildConfig.DB_NAME;
|
||||
private static final int DB_VERSION = 31;
|
||||
private static final int DB_VERSION = 32;
|
||||
|
||||
public static final String GAME_NAME = "GAME_NAME";
|
||||
public static final String VISID = "VISID";
|
||||
|
@ -75,7 +79,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
public static final String GAMEID = "GAMEID";
|
||||
public static final String REMOTEDEVS = "REMOTEDEVS";
|
||||
public static final String EXTRAS = "EXTRAS";
|
||||
public static final String DICTLANG = "DICTLANG";
|
||||
private static final String DICTLANG = "DICTLANG";
|
||||
public static final String ISOCODE = "ISOCODE";
|
||||
public static final String LANGNAME = "LANGNAME";
|
||||
public static final String DICTLIST = "DICTLIST";
|
||||
public static final String HASMSGS = "HASMSGS";
|
||||
public static final String CONTRACTED = "CONTRACTED";
|
||||
|
@ -100,7 +106,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
public static final String FULLSUM = "FULLSUM";
|
||||
public static final String WORDCOUNT = "WORDCOUNT";
|
||||
public static final String WORDCOUNTS = "WORDCOUNTS";
|
||||
public static final String LANGCODE = "LANGCODE";
|
||||
private static final String LANGCODE = "LANGCODE";
|
||||
public static final String LOC = "LOC";
|
||||
public static final String ITERMIN = "ITERMIN";
|
||||
public static final String ITERMAX = "ITERMAX";
|
||||
|
@ -115,7 +121,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
public static final String EXPANDED = "EXPANDED";
|
||||
|
||||
public static final String WORD = "WORD";
|
||||
public static final String LANGUAGE = "LANGUAGE";
|
||||
private static final String LANGUAGE = "LANGUAGE";
|
||||
|
||||
public static final String KEY = "KEY";
|
||||
public static final String VALUE = "VALUE";
|
||||
|
@ -275,6 +281,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
boolean madeSumTable = false;
|
||||
boolean madeChatTable = false;
|
||||
boolean madeDITable = false;
|
||||
boolean madeStudyTable = false;
|
||||
switch( oldVersion ) {
|
||||
case 6:
|
||||
addSumColumn( db, TURN );
|
||||
|
@ -313,6 +320,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
case 18:
|
||||
createStudyTable( db );
|
||||
madeStudyTable = true;
|
||||
case 19:
|
||||
if ( !madeSumTable ) {
|
||||
// NPACKETSPENDING also added by makeAutoincrement above
|
||||
|
@ -354,9 +362,25 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, FULLSUM );
|
||||
}
|
||||
|
||||
// case 31:
|
||||
// drop table obits
|
||||
|
||||
case 31:
|
||||
if ( !madeSumTable ) {
|
||||
addSumColumn( db, ISOCODE );
|
||||
}
|
||||
langCodeToISOCode( db, TABLE_NAMES.SUM, DICTLANG, ISOCODE );
|
||||
if ( !madeStudyTable ) {
|
||||
addColumn( db, TABLE_NAMES.STUDYLIST, s_studySchema, ISOCODE );
|
||||
}
|
||||
langCodeToISOCode( db, TABLE_NAMES.STUDYLIST, LANGUAGE, ISOCODE );
|
||||
if ( !madeDITable ) {
|
||||
addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, ISOCODE );
|
||||
addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, LANGNAME );
|
||||
}
|
||||
langCodeToISOCode( db, TABLE_NAMES.DICTINFO, LANGCODE, ISOCODE );
|
||||
try {
|
||||
db.execSQL( "DROP TABLE " + TABLE_NAMES._OBITS + ";" );
|
||||
} catch ( SQLiteException ex ) {
|
||||
Log.ex( TAG, ex );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
for ( TABLE_NAMES table : TABLE_NAMES.values() ) {
|
||||
|
@ -368,6 +392,37 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void langCodeToISOCode( SQLiteDatabase db, TABLE_NAMES table,
|
||||
String oldIntCol, String newIsoStringCol )
|
||||
{
|
||||
String[] columns = { oldIntCol };
|
||||
String groupBy = columns[0];
|
||||
|
||||
// First gather all the lang codes
|
||||
Map<Integer, String> map = new HashMap<>();
|
||||
Cursor cursor = db.query( table.toString(),
|
||||
columns, null, null, groupBy, null, null );
|
||||
int colIndex = cursor.getColumnIndex( columns[0] );
|
||||
while ( cursor.moveToNext() ) {
|
||||
int code = cursor.getInt( colIndex );
|
||||
String isoCode = XwJNI.lcToLocale( code );
|
||||
map.put( code, isoCode );
|
||||
Log.d( TAG, "added %d => %s", code, isoCode );
|
||||
}
|
||||
|
||||
// Then update the DB
|
||||
for ( Integer code : map.keySet() ) {
|
||||
StringBuffer sb = new StringBuffer()
|
||||
.append("Update ").append(table)
|
||||
.append(" SET ").append(newIsoStringCol).append(" = '").append(map.get(code)).append("'")
|
||||
.append( " WHERE ").append(oldIntCol).append(" = ").append(code)
|
||||
.append(";");
|
||||
String query = sb.toString();
|
||||
// Log.d( TAG, "langCodeToISOCode() query: %s", query );
|
||||
db.execSQL( query );
|
||||
}
|
||||
}
|
||||
|
||||
private void addSumColumn( SQLiteDatabase db, String colName )
|
||||
{
|
||||
addColumn( db, TABLE_NAMES.SUM, s_summaryColsAndTypes, colName );
|
||||
|
|
|
@ -97,7 +97,7 @@ public class DBUtils {
|
|||
new HashSet<>();
|
||||
|
||||
public static interface StudyListListener {
|
||||
void onWordAdded( String word, int langCode );
|
||||
void onWordAdded( String word, String isoCode );
|
||||
}
|
||||
private static Set<StudyListListener> s_slListeners
|
||||
= new HashSet<>();
|
||||
|
@ -131,7 +131,7 @@ public class DBUtils {
|
|||
DBHelper.CONTYPE, DBHelper.SERVERROLE,
|
||||
DBHelper.ROOMNAME, DBHelper.RELAYID,
|
||||
/*DBHelper.SMSPHONE,*/ DBHelper.SEED,
|
||||
DBHelper.DICTLANG, DBHelper.GAMEID,
|
||||
DBHelper.ISOCODE, DBHelper.GAMEID,
|
||||
DBHelper.SCORES,
|
||||
DBHelper.LASTPLAY_TIME, DBHelper.REMOTEDEVS,
|
||||
DBHelper.LASTMOVE, DBHelper.NPACKETSPENDING,
|
||||
|
@ -173,9 +173,11 @@ public class DBUtils {
|
|||
getString(cursor.getColumnIndex( DBHelper.PLAYERS ));
|
||||
summary.readPlayers( context, players );
|
||||
|
||||
summary.dictLang =
|
||||
cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.DICTLANG));
|
||||
summary.isoCode = cursor
|
||||
.getString(cursor.getColumnIndex(DBHelper.ISOCODE));
|
||||
// isoCode will be null when game first created
|
||||
// Assert.assertTrueNR( null != summary.isoCode ); // fired!
|
||||
|
||||
summary.modtime =
|
||||
cursor.getLong(cursor.
|
||||
getColumnIndex(DBHelper.LASTPLAY_TIME));
|
||||
|
@ -292,7 +294,8 @@ public class DBUtils {
|
|||
values.put( DBHelper.GIFLAGS, summary.giflags() );
|
||||
values.put( DBHelper.PLAYERS,
|
||||
summary.summarizePlayers() );
|
||||
values.put( DBHelper.DICTLANG, summary.dictLang );
|
||||
Assert.assertTrueNR( null != summary.isoCode );
|
||||
values.put( DBHelper.ISOCODE, summary.isoCode );
|
||||
values.put( DBHelper.GAMEID, summary.gameID );
|
||||
values.put( DBHelper.GAME_OVER, summary.gameOver? 1 : 0 );
|
||||
values.put( DBHelper.LASTMOVE, summary.lastMoveTime );
|
||||
|
@ -402,13 +405,13 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static int countGamesUsingLang( Context context, int lang )
|
||||
public static int countGamesUsingISOCode( Context context, String isoCode )
|
||||
{
|
||||
int result = 0;
|
||||
String selection = String.format( "%s = %d", DBHelper.DICTLANG,
|
||||
lang );
|
||||
String[] columns = { DBHelper.ISOCODE };
|
||||
String selection = String.format( "%s = '%s'", columns[0],
|
||||
isoCode );
|
||||
// null for columns will return whole rows: bad
|
||||
String[] columns = { DBHelper.DICTLANG };
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
Cursor cursor = query( TABLE_NAMES.SUM, columns, selection );
|
||||
|
@ -428,7 +431,7 @@ public class DBUtils {
|
|||
DBHelper.DICTLIST, pattern );
|
||||
// null for columns will return whole rows: bad. But
|
||||
// might as well make it an int for speed
|
||||
String[] columns = { DBHelper.DICTLANG };
|
||||
String[] columns = { DBHelper.ISOCODE };
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
Cursor cursor = query( TABLE_NAMES.SUM, columns, selection );
|
||||
|
@ -1910,7 +1913,8 @@ public class DBUtils {
|
|||
public static DictInfo dictsGetInfo( Context context, String name )
|
||||
{
|
||||
DictInfo result = null;
|
||||
String[] columns = { DBHelper.LANGCODE,
|
||||
String[] columns = { DBHelper.ISOCODE,
|
||||
DBHelper.LANGNAME,
|
||||
DBHelper.WORDCOUNT,
|
||||
DBHelper.MD5SUM,
|
||||
DBHelper.FULLSUM,
|
||||
|
@ -1922,14 +1926,16 @@ public class DBUtils {
|
|||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = new DictInfo();
|
||||
result.name = name;
|
||||
result.langCode =
|
||||
cursor.getInt( cursor.getColumnIndex(DBHelper.LANGCODE));
|
||||
result.isoCode =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.ISOCODE));
|
||||
result.wordCount =
|
||||
cursor.getInt( cursor.getColumnIndex(DBHelper.WORDCOUNT));
|
||||
result.md5Sum =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.MD5SUM));
|
||||
result.fullSum =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.FULLSUM));
|
||||
result.langName =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.LANGNAME));
|
||||
// int loc = cursor.getInt(cursor.getColumnIndex(DBHelper.LOC));
|
||||
// Log.d( TAG, "dictsGetInfo(): read sum %s/loc %d for %s", result.md5Sum,
|
||||
// loc, name );
|
||||
|
@ -1951,7 +1957,8 @@ public class DBUtils {
|
|||
String.format( NAME_FMT, DBHelper.DICTNAME, dal.name );
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put( DBHelper.LANGCODE, info.langCode );
|
||||
values.put( DBHelper.ISOCODE, info.isoCode );
|
||||
values.put( DBHelper.LANGNAME, info.langName );
|
||||
values.put( DBHelper.WORDCOUNT, info.wordCount );
|
||||
values.put( DBHelper.MD5SUM, info.md5Sum );
|
||||
values.put( DBHelper.FULLSUM, info.fullSum );
|
||||
|
@ -2012,37 +2019,37 @@ public class DBUtils {
|
|||
}
|
||||
|
||||
public static void addToStudyList( Context context, String word,
|
||||
int lang )
|
||||
String isoCode )
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.WORD, word );
|
||||
values.put( DBHelper.LANGUAGE, lang );
|
||||
values.put( DBHelper.ISOCODE, isoCode );
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
insert( TABLE_NAMES.STUDYLIST, values );
|
||||
}
|
||||
notifyStudyListListeners( word, lang );
|
||||
notifyStudyListListeners( word, isoCode );
|
||||
}
|
||||
|
||||
public static int[] studyListLangs( Context context )
|
||||
public static String[] studyListLangs( Context context )
|
||||
{
|
||||
int[] result = null;
|
||||
String groupBy = DBHelper.LANGUAGE;
|
||||
String[] result = null;
|
||||
String selection = null;//DBHelper.LANGUAGE;
|
||||
String[] columns = { DBHelper.LANGUAGE };
|
||||
String[] columns = { DBHelper.ISOCODE };
|
||||
String groupBy = columns[0];
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
Cursor cursor = s_db.query( TABLE_NAMES.STUDYLIST.toString(), columns,
|
||||
null, null, groupBy, null, null );
|
||||
int count = cursor.getCount();
|
||||
result = new int[count];
|
||||
result = new String[count];
|
||||
if ( 0 < count ) {
|
||||
int index = 0;
|
||||
int colIndex = cursor.getColumnIndex( DBHelper.LANGUAGE );
|
||||
int colIndex = cursor.getColumnIndex( columns[0] );
|
||||
while ( cursor.moveToNext() ) {
|
||||
result[index++] = cursor.getInt(colIndex);
|
||||
result[index++] = cursor.getString(colIndex);
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
@ -2050,12 +2057,12 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String[] studyListWords( Context context, int lang )
|
||||
public static String[] studyListWords( Context context, String isoCode )
|
||||
{
|
||||
String[] result = null;
|
||||
String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang );
|
||||
String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode );
|
||||
String[] columns = { DBHelper.WORD };
|
||||
String orderBy = DBHelper.WORD;
|
||||
String orderBy = columns[0];
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
|
@ -2075,9 +2082,9 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void studyListClear( Context context, int lang, String[] words )
|
||||
public static void studyListClear( Context context, String isoCode, String[] words )
|
||||
{
|
||||
String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang );
|
||||
String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode );
|
||||
if ( null != words ) {
|
||||
selection += String.format( " AND %s in ('%s')", DBHelper.WORD,
|
||||
TextUtils.join("','", words) );
|
||||
|
@ -2089,9 +2096,9 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void studyListClear( Context context, int lang )
|
||||
public static void studyListClear( Context context, String isoCode )
|
||||
{
|
||||
studyListClear( context, lang, null );
|
||||
studyListClear( context, isoCode, null );
|
||||
}
|
||||
|
||||
public static void saveXlations( Context context, String locale,
|
||||
|
@ -2598,11 +2605,11 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static void notifyStudyListListeners( String word, int lang )
|
||||
private static void notifyStudyListListeners( String word, String isoCode )
|
||||
{
|
||||
synchronized( s_slListeners ) {
|
||||
for ( StudyListListener listener : s_slListeners ) {
|
||||
listener.onWordAdded( word, lang );
|
||||
listener.onWordAdded( word, isoCode );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -599,15 +599,15 @@ public abstract class DelegateBase implements DlgClickNotify,
|
|||
return m_dlgDelegate.post( runnable );
|
||||
}
|
||||
|
||||
protected void launchLookup( String[] words, int lang, boolean noStudy )
|
||||
protected void launchLookup( String[] words, String isoCode, boolean noStudy )
|
||||
{
|
||||
m_dlgDelegate.launchLookup( words, lang, noStudy );
|
||||
m_dlgDelegate.launchLookup( words, isoCode, noStudy );
|
||||
}
|
||||
|
||||
protected void launchLookup( String[] words, int lang )
|
||||
protected void launchLookup( String[] words, String isoCode )
|
||||
{
|
||||
boolean studyOn = XWPrefs.getStudyEnabled( m_activity );
|
||||
m_dlgDelegate.launchLookup( words, lang, !studyOn );
|
||||
m_dlgDelegate.launchLookup( words, isoCode, !studyOn );
|
||||
}
|
||||
|
||||
protected void showInviteChoicesThen( Action action, NetLaunchInfo nli,
|
||||
|
|
|
@ -127,7 +127,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
}
|
||||
|
||||
private Activity m_activity;
|
||||
private int m_lang;
|
||||
private String m_lang;
|
||||
private String m_name;
|
||||
private String mAboutStr;
|
||||
private DictUtils.DictLoc m_loc;
|
||||
|
@ -242,7 +242,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
m_name = name;
|
||||
m_loc =
|
||||
DictUtils.DictLoc.values()[args.getInt( DICT_LOC, 0 )];
|
||||
m_lang = DictLangCache.getDictLangCode( m_activity, name );
|
||||
m_lang = DictLangCache.getDictISOCode( m_activity, name );
|
||||
|
||||
findTableRows();
|
||||
m_spinnerMin = ((LabeledSpinner)findViewById( R.id.spinner_min ))
|
||||
|
@ -345,7 +345,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
View tilesView = inflate( R.layout.tiles_table );
|
||||
addTileRows( tilesView, info );
|
||||
|
||||
String langName = DictLangCache.getLangName( m_activity, m_lang );
|
||||
String langName = DictLangCache.getLangNameForISOCode( m_activity, m_lang );
|
||||
title = getString( R.string.show_tiles_title_fmt, langName );
|
||||
dialog = makeAlertBuilder()
|
||||
.setView( tilesView )
|
||||
|
@ -615,7 +615,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
if ( null != strPat && 0 < strPat.length() ) {
|
||||
byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat );
|
||||
if ( null == choices || 0 == choices.length ) {
|
||||
String langName = DictLangCache.getLangName( m_activity, m_lang );
|
||||
String langName = DictLangCache.getLangNameForISOCode( m_activity, m_lang );
|
||||
String msg = getString( R.string.no_tiles_exist, strPat, langName );
|
||||
makeOkOnlyBuilder( msg )
|
||||
.setActionPair( Action.SHOW_TILES, R.string.show_tiles_button )
|
||||
|
|
|
@ -41,22 +41,21 @@ import java.util.Comparator;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DictLangCache {
|
||||
private static final String TAG = DictLangCache.class.getSimpleName();
|
||||
private static Map<Integer, String> s_langNames;
|
||||
private static Map<String, Integer> s_langCodes;
|
||||
private static Map<Integer, String> s_langCodeStrs;
|
||||
private static Map<String, String> s_langNames;
|
||||
private static Map<String, String> s_langCodes;
|
||||
|
||||
private static int s_adaptedLang = -1;
|
||||
private static String s_adaptedLang = null;
|
||||
private static LangsArrayAdapter s_langsAdapter;
|
||||
private static ArrayAdapter<String> s_dictsAdapter;
|
||||
private static String s_last;
|
||||
private static Handler s_handler;
|
||||
|
||||
|
||||
public static class LangsArrayAdapter extends ArrayAdapter<String> {
|
||||
private Context m_context;
|
||||
private Map<String, String> m_map;
|
||||
|
@ -145,43 +144,27 @@ public class DictLangCache {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String annotatedDictName( Context context, String name,
|
||||
int lang )
|
||||
{
|
||||
return name + " (" + getLangName( context, lang ) + ")";
|
||||
}
|
||||
|
||||
public static String getLangName( Context context, int code )
|
||||
{
|
||||
makeMaps( context );
|
||||
String name = s_langNames.get( code );
|
||||
if ( null == name ) {
|
||||
name = s_langNames.get( 0 );
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
// This populates the cache and will take significant time if it's
|
||||
// mostly empty and there are a lot of dicts.
|
||||
public static int getLangCount( Context context, int code )
|
||||
// This populates the cache and will take significant time if it's mostly
|
||||
// empty and there are a lot of dicts.
|
||||
public static int getLangCount( Context context, String isoCode )
|
||||
{
|
||||
int count = 0;
|
||||
DictAndLoc[] dals = DictUtils.dictList( context );
|
||||
for ( DictAndLoc dal : dals ) {
|
||||
if ( code == getDictLangCode( context, dal ) ) {
|
||||
if ( isoCode.equals( getDictISOCode( context, dal ) ) ) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static DictInfo[] getInfosHaveLang( Context context, int code )
|
||||
private static DictInfo[] getInfosHaveLang( Context context, String isoCode )
|
||||
{
|
||||
ArrayList<DictInfo> al = new ArrayList<>();
|
||||
List<DictInfo> al = new ArrayList<>();
|
||||
DictAndLoc[] dals = DictUtils.dictList( context );
|
||||
for ( DictAndLoc dal : dals ) {
|
||||
DictInfo info = getInfo( context, dal );
|
||||
if ( null != info && code == info.langCode ) {
|
||||
if ( null != info && isoCode.equals( info.isoCode ) ) {
|
||||
al.add( info );
|
||||
}
|
||||
}
|
||||
|
@ -189,21 +172,10 @@ public class DictLangCache {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static boolean haveDict( Context context, String lang, String name )
|
||||
{
|
||||
boolean result = false;
|
||||
makeMaps( context );
|
||||
Integer code = s_langCodes.get( lang );
|
||||
if ( null != code ) {
|
||||
result = haveDict( context, code, name );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean haveDict( Context context, int code, String name )
|
||||
public static boolean haveDict( Context context, String isoCode, String name )
|
||||
{
|
||||
boolean found = false;
|
||||
DictInfo[] infos = getInfosHaveLang( context, code );
|
||||
DictInfo[] infos = getInfosHaveLang( context, isoCode );
|
||||
for ( DictInfo info : infos ) {
|
||||
if ( info.name.equals( name ) ) {
|
||||
found = true;
|
||||
|
@ -213,17 +185,17 @@ public class DictLangCache {
|
|||
return found;
|
||||
}
|
||||
|
||||
private static String[] getHaveLang( Context context, int code,
|
||||
private static String[] getHaveLang( Context context, String isoCode,
|
||||
Comparator<DictInfo> comp,
|
||||
boolean withCounts )
|
||||
{
|
||||
DictInfo[] infos = getInfosHaveLang( context, code );
|
||||
DictInfo[] infos = getInfosHaveLang( context, isoCode );
|
||||
|
||||
if ( null != comp ) {
|
||||
Arrays.sort( infos, comp );
|
||||
}
|
||||
|
||||
ArrayList<String> al = new ArrayList<>();
|
||||
List<String> al = new ArrayList<>();
|
||||
String fmt = "%s (%d)"; // must match stripCount below
|
||||
for ( DictInfo info : infos ) {
|
||||
String name = info.name;
|
||||
|
@ -239,29 +211,30 @@ public class DictLangCache {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String[] getHaveLang( Context context, int code )
|
||||
public static String[] getHaveLang( Context context, String isoCode )
|
||||
{
|
||||
return getHaveLang( context, code, null, false );
|
||||
return getHaveLang( context, isoCode, null, false );
|
||||
}
|
||||
|
||||
public static DictAndLoc[] getDALsHaveLang( Context context, int code )
|
||||
public static DictAndLoc[] getDALsHaveLang( Context context, String isoCode )
|
||||
{
|
||||
ArrayList<DictAndLoc> al = new ArrayList<>();
|
||||
Assert.assertNotNull( isoCode );
|
||||
List<DictAndLoc> al = new ArrayList<>();
|
||||
DictAndLoc[] dals = DictUtils.dictList( context );
|
||||
|
||||
makeMaps( context );
|
||||
|
||||
for ( DictAndLoc dal : dals ) {
|
||||
DictInfo info = getInfo( context, dal );
|
||||
int langCode = info.langCode;
|
||||
if ( !s_langNames.containsKey( langCode ) ) {
|
||||
langCode = 0;
|
||||
}
|
||||
if ( null != info && code == langCode ) {
|
||||
al.add( dal );
|
||||
if ( null != info ) {
|
||||
Assert.assertTrueNR( s_langNames.containsKey( info.isoCode ) );
|
||||
if ( isoCode.equals( info.isoCode ) ) {
|
||||
al.add( dal );
|
||||
}
|
||||
}
|
||||
}
|
||||
DictAndLoc[] result = al.toArray( new DictAndLoc[al.size()] );
|
||||
Log.d( TAG, "getDALsHaveLang(%s) => %s", isoCode, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -273,14 +246,14 @@ public class DictLangCache {
|
|||
}
|
||||
};
|
||||
|
||||
public static String[] getHaveLangByCount( Context context, int code )
|
||||
public static String[] getHaveLangByCount( Context context, String isoCode )
|
||||
{
|
||||
return getHaveLang( context, code, s_ByCount, false );
|
||||
return getHaveLang( context, isoCode, s_ByCount, false );
|
||||
}
|
||||
|
||||
public static String[] getHaveLangCounts( Context context, int code )
|
||||
public static String[] getHaveLangCounts( Context context, String isoCode )
|
||||
{
|
||||
return getHaveLang( context, code, null, true );
|
||||
return getHaveLang( context, isoCode, null, true );
|
||||
}
|
||||
|
||||
public static String stripCount( String nameWithCount )
|
||||
|
@ -289,15 +262,42 @@ public class DictLangCache {
|
|||
return nameWithCount.substring( 0, indx );
|
||||
}
|
||||
|
||||
public static int getDictLangCode( Context context, DictAndLoc dal )
|
||||
public static String getDictISOCode( Context context, DictAndLoc dal )
|
||||
{
|
||||
return getInfo( context, dal ).langCode;
|
||||
return getInfo( context, dal ).isoCode;
|
||||
}
|
||||
|
||||
public static String getLangCodeStr( Context context, int code )
|
||||
public static String getDictISOCode( Context context, String dictName )
|
||||
{
|
||||
DictInfo info = getInfo( context, dictName );
|
||||
return info.isoCode;
|
||||
}
|
||||
|
||||
public static String getLangNameForISOCode( Context context, String isoCode )
|
||||
{
|
||||
makeMaps( context );
|
||||
return s_langCodeStrs.get( code );
|
||||
return s_langNames.get( isoCode );
|
||||
}
|
||||
|
||||
public static void setLangNameForISOCode( Context context, String isoCode,
|
||||
String langName )
|
||||
{
|
||||
makeMaps( context );
|
||||
putTwo( isoCode, langName );
|
||||
}
|
||||
|
||||
public static String getLangIsoCode( Context context, String langName )
|
||||
{
|
||||
makeMaps( context );
|
||||
String result = s_langCodes.get( langName );
|
||||
Log.d( TAG, "getLangIsoCode(%s) => %s", langName, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getDictLangName( Context context, String dictName )
|
||||
{
|
||||
String isoCode = getDictISOCode( context, dictName );
|
||||
return getLangNameForISOCode( context, isoCode );
|
||||
}
|
||||
|
||||
public static String[] getDictMD5Sums( Context context, String dict )
|
||||
|
@ -317,41 +317,10 @@ public class DictLangCache {
|
|||
return path.length();
|
||||
}
|
||||
|
||||
public static int getDictLangCode( Context context, String dict )
|
||||
public static String getLangName( Context context, String dictName )
|
||||
{
|
||||
return getInfo( context, dict ).langCode;
|
||||
}
|
||||
|
||||
public static int getLangLangCode( Context context, String lang )
|
||||
{
|
||||
makeMaps( context );
|
||||
|
||||
Integer code = s_langCodes.get( lang );
|
||||
if ( null == code ) {
|
||||
code = 0;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
public static String userLangForLc( Context context, String lc )
|
||||
{
|
||||
makeMaps( context );
|
||||
String result = null;
|
||||
|
||||
for ( Integer code : s_langCodeStrs.keySet() ) {
|
||||
if ( s_langCodeStrs.get(code).equals(lc) ) {
|
||||
result = s_langNames.get(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getLangName( Context context, String dict )
|
||||
{
|
||||
int code = getDictLangCode( context, dict );
|
||||
return getLangName( context, code );
|
||||
String isoCode = getDictISOCode( context, dictName );
|
||||
return getLangNameForISOCode( context, isoCode );
|
||||
}
|
||||
|
||||
// May be called from background thread
|
||||
|
@ -402,21 +371,21 @@ public class DictLangCache {
|
|||
return langs.toArray( result );
|
||||
}
|
||||
|
||||
public static String getBestDefault( Context context, int lang,
|
||||
public static String getBestDefault( Context context, String isoCode,
|
||||
boolean human )
|
||||
{
|
||||
String dict = human? CommonPrefs.getDefaultHumanDict( context )
|
||||
String dictName = human? CommonPrefs.getDefaultHumanDict( context )
|
||||
: CommonPrefs.getDefaultRobotDict( context );
|
||||
if ( lang != DictLangCache.getDictLangCode( context, dict ) ) {
|
||||
String dicts[] = getHaveLangByCount( context, lang );
|
||||
if ( ! isoCode.equals( getDictISOCode( context, dictName ) ) ) {
|
||||
String dicts[] = getHaveLangByCount( context, isoCode );
|
||||
if ( dicts.length > 0 ) {
|
||||
// Human gets biggest; robot gets smallest
|
||||
dict = dicts[ human ? 0 : dicts.length-1 ];
|
||||
dictName = dicts[ human ? 0 : dicts.length-1 ];
|
||||
} else {
|
||||
dict = null;
|
||||
dictName = null;
|
||||
}
|
||||
}
|
||||
return dict;
|
||||
return dictName;
|
||||
}
|
||||
|
||||
private static void rebuildAdapter( ArrayAdapter<String> adapter,
|
||||
|
@ -451,47 +420,53 @@ public class DictLangCache {
|
|||
}
|
||||
|
||||
public static ArrayAdapter<String> getDictsAdapter( Context context,
|
||||
int lang )
|
||||
String isoCode )
|
||||
{
|
||||
if ( lang != s_adaptedLang ) {
|
||||
if ( ! isoCode.equals( s_adaptedLang ) ) {
|
||||
s_dictsAdapter =
|
||||
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item);
|
||||
rebuildAdapter( s_dictsAdapter, getHaveLang( context, lang ) );
|
||||
s_adaptedLang = lang;
|
||||
rebuildAdapter( s_dictsAdapter, getHaveLang( context, isoCode ) );
|
||||
s_adaptedLang = isoCode;
|
||||
}
|
||||
return s_dictsAdapter;
|
||||
}
|
||||
|
||||
private static void putTwo( String isoCode, String langName )
|
||||
{
|
||||
Log.d( TAG, "putTwo(): adding %s => %s", langName, isoCode );
|
||||
s_langCodes.put( langName, isoCode );
|
||||
s_langNames.put( isoCode, langName );
|
||||
}
|
||||
|
||||
private static void makeMaps( Context context )
|
||||
{
|
||||
if ( null == s_langNames ) {
|
||||
s_langCodes = new HashMap<>();
|
||||
s_langNames = new HashMap<>();
|
||||
s_langCodeStrs = new HashMap<>();
|
||||
|
||||
Resources res = context.getResources();
|
||||
String[] entries = res.getStringArray( R.array.languages_map );
|
||||
for ( int ii = 0; ii < entries.length; ii += 3 ) {
|
||||
Integer code = Integer.parseInt(entries[ii]);
|
||||
String name = entries[ii+1];
|
||||
String lc = entries[ii+2];
|
||||
s_langCodes.put( name, code );
|
||||
s_langNames.put( code, name );
|
||||
s_langCodeStrs.put( code, lc );
|
||||
String[] entries = res.getStringArray( R.array.language_names );
|
||||
for ( int ii = 0; ii < entries.length; ii += 2 ) {
|
||||
String isoCode = entries[ii];
|
||||
String langName = entries[ii+1];
|
||||
putTwo( isoCode, langName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getDictCount( Context context, String name )
|
||||
{
|
||||
int result = 0;
|
||||
for ( DictAndLoc dal : DictUtils.dictList( context ) ) {
|
||||
if ( name.equals( dal.name ) ) {
|
||||
++result;
|
||||
// Now deal with any dicts too new for their isoCodes to be in
|
||||
// language_names
|
||||
DictAndLoc[] dals = DictUtils.dictList( context ) ;
|
||||
for ( DictAndLoc dal : dals ) {
|
||||
DictInfo info = getInfo( context, dal );
|
||||
String isoCode = info.isoCode;
|
||||
if ( !s_langNames.containsKey( isoCode ) ) {
|
||||
Log.d( TAG, "looking at info %s", info );
|
||||
Assert.assertTrueNR( null != info.langName );
|
||||
Log.d( TAG, "makeMaps(2): adding %s => %s", info.langName, isoCode );
|
||||
putTwo( isoCode, info.langName );
|
||||
}
|
||||
}
|
||||
Log.d( TAG, "makeMaps() DONE" );
|
||||
}
|
||||
Assert.assertTrue( result > 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
private static DictInfo getInfo( Context context, String name )
|
||||
|
@ -509,7 +484,7 @@ public class DictLangCache {
|
|||
DictInfo info = DBUtils.dictsGetInfo( context, dal.name );
|
||||
|
||||
// Tmp test that recovers from problem with new background download code
|
||||
if ( null != info && 0 == info.langCode ) {
|
||||
if ( null != info && null == info.isoCode ) {
|
||||
Log.w( TAG, "getInfo: dropping info for %s b/c lang code wrong",
|
||||
dal.name );
|
||||
info = null;
|
||||
|
|
|
@ -25,6 +25,8 @@ import android.util.AttributeSet;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class DictListPreference extends XWListPreference {
|
||||
|
||||
public DictListPreference( Context context, AttributeSet attrs )
|
||||
|
@ -43,18 +45,20 @@ public class DictListPreference extends XWListPreference {
|
|||
private String[] setEntriesForLang()
|
||||
{
|
||||
Context context = getContext();
|
||||
String curLang = XWPrefs.getPrefsString( context, R.string.key_default_language );
|
||||
int langCode = DictLangCache.getLangLangCode( context, curLang );
|
||||
String curLang = XWPrefs
|
||||
.getPrefsString( context, R.string.key_default_language, null );
|
||||
if ( null == curLang ) {
|
||||
curLang = LocUtils.getString( context, R.string.lang_name_english );
|
||||
}
|
||||
String isoCode = DictLangCache.getLangIsoCode( context, curLang );
|
||||
|
||||
DictUtils.DictAndLoc[] dals = DictUtils.dictList( context );
|
||||
ArrayList<String> dictEntries = new ArrayList<>();
|
||||
ArrayList<String> values = new ArrayList<>();
|
||||
for ( int ii = 0; ii < dals.length; ++ii ) {
|
||||
String name = dals[ii].name;
|
||||
if ( langCode == DictLangCache.getDictLangCode( context, name ) ) {
|
||||
values.add( name );
|
||||
dictEntries.add( DictLangCache.annotatedDictName( context,
|
||||
dals[ii] ) );
|
||||
for ( DictUtils.DictAndLoc dal : dals ) {
|
||||
if ( isoCode.equals( DictLangCache.getDictISOCode( context, dal ) ) ) {
|
||||
values.add( dal.name );
|
||||
dictEntries.add( DictLangCache.annotatedDictName( context, dal ) );
|
||||
}
|
||||
}
|
||||
setEntries( dictEntries.toArray( new String[dictEntries.size()] ) );
|
||||
|
|
|
@ -114,16 +114,16 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private static class DictInfo implements Comparable, Serializable {
|
||||
public String m_name;
|
||||
public String m_localLang; // what we display to user, i.e. translated
|
||||
public String m_urlLang; // what needs to be in URL
|
||||
public String mISOCode; // what needs to be in URL
|
||||
public int m_nWords;
|
||||
public long m_nBytes;
|
||||
public String m_note;
|
||||
public DictInfo( String name, String urlLang, String localLang,
|
||||
public DictInfo( String name, String isoCode, String localLang,
|
||||
int nWords, long nBytes, String note )
|
||||
{
|
||||
m_name = name;
|
||||
m_localLang = localLang;
|
||||
m_urlLang = urlLang;
|
||||
mISOCode = isoCode;
|
||||
m_nWords = nWords;
|
||||
m_nBytes = nBytes;
|
||||
m_note = note;
|
||||
|
@ -292,8 +292,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
ArrayList<Object> result = new ArrayList<>();
|
||||
|
||||
HashSet<String> locals = new HashSet<>();
|
||||
int lang = DictLangCache.getLangLangCode( m_context, langName );
|
||||
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context, lang );
|
||||
String isoCode = DictLangCache.getLangIsoCode( m_context, langName );
|
||||
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context, isoCode );
|
||||
if ( null != dals ) {
|
||||
for ( DictAndLoc dal : dals ) {
|
||||
locals.add( dal.name );
|
||||
|
@ -381,25 +381,27 @@ public class DictsDelegate extends ListDelegateBase
|
|||
break;
|
||||
|
||||
case SET_DEFAULT: {
|
||||
final String name = m_selDicts.keySet().iterator().next();
|
||||
final String dictName = m_selDicts.keySet().iterator().next();
|
||||
lstnr = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
if ( DialogInterface.BUTTON_NEGATIVE == item
|
||||
|| DialogInterface.BUTTON_POSITIVE == item ) {
|
||||
setDefault( name, R.string.key_default_dict,
|
||||
setDefault( dictName, R.string.key_default_dict,
|
||||
R.string.key_default_robodict );
|
||||
}
|
||||
if ( DialogInterface.BUTTON_NEGATIVE == item
|
||||
|| DialogInterface.BUTTON_NEUTRAL == item ) {
|
||||
setDefault( name, R.string.key_default_robodict,
|
||||
setDefault( dictName, R.string.key_default_robodict,
|
||||
R.string.key_default_dict );
|
||||
}
|
||||
}
|
||||
};
|
||||
String lang = DictLangCache.getLangName( m_activity, name);
|
||||
String lang = DictLangCache.getDictLangName( m_activity,
|
||||
dictName );
|
||||
lang = xlateLang( lang );
|
||||
message = getString( R.string.set_default_message_fmt, name, lang );
|
||||
message = getString( R.string.set_default_message_fmt,
|
||||
dictName, lang );
|
||||
dialog = makeAlertBuilder()
|
||||
.setTitle( R.string.query_title )
|
||||
.setMessage( message )
|
||||
|
@ -415,11 +417,11 @@ public class DictsDelegate extends ListDelegateBase
|
|||
@Override
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
Intent intent = getIntent();
|
||||
int lang = intent.getIntExtra( MultiService.LANG, -1 );
|
||||
String isoCode = intent.getStringExtra( MultiService.ISO );
|
||||
String name = intent.getStringExtra( MultiService.DICT );
|
||||
m_launchedForMissing = true;
|
||||
DwnldDelegate
|
||||
.downloadDictInBack( m_activity, lang, name,
|
||||
.downloadDictInBack( m_activity, isoCode, name,
|
||||
DictsDelegate.this );
|
||||
}
|
||||
};
|
||||
|
@ -476,9 +478,9 @@ public class DictsDelegate extends ListDelegateBase
|
|||
m_showRemote = true;
|
||||
m_checkbox.setVisibility( View.GONE );
|
||||
|
||||
int lang = args.getInt( DICT_LANG_EXTRA, 0 );
|
||||
if ( 0 < lang ) {
|
||||
m_filterLang = DictLangCache.getLangName( m_activity, lang );
|
||||
String isoCode = args.getString( DICT_LANG_EXTRA );
|
||||
if ( null != isoCode ) {
|
||||
m_filterLang = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
m_closedLangs.remove( m_filterLang );
|
||||
}
|
||||
String name = args.getString( DICT_NAME_EXTRA );
|
||||
|
@ -486,7 +488,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
new FetchListTask( m_activity ).execute();
|
||||
} else {
|
||||
m_finishOnName = name;
|
||||
startDownload( lang, name );
|
||||
startDownload( isoCode, name );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -620,8 +622,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
if ( cached instanceof DictInfo ) {
|
||||
DictInfo info = (DictInfo)cached;
|
||||
String name = entry.getKey();
|
||||
Uri uri = Utils.makeDictUri( m_activity, info.m_urlLang,
|
||||
name );
|
||||
Uri uri = Utils.makeDictUriFromCode( m_activity,
|
||||
info.mISOCode, name );
|
||||
uris[count] = uri;
|
||||
names[count] = name;
|
||||
++count;
|
||||
|
@ -721,10 +723,10 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
private void setDefault( String name, int keyId, int otherKey )
|
||||
{
|
||||
int langCode = DictLangCache.getDictLangCode( m_activity, name );
|
||||
String isoCode = DictLangCache.getDictISOCode( m_activity, name );
|
||||
String curLangName = XWPrefs.getPrefsString( m_activity, R.string.key_default_language );
|
||||
int curLangCode = DictLangCache.getLangLangCode( m_activity, curLangName );
|
||||
boolean changeLang = langCode != curLangCode;
|
||||
String curISOCode = DictLangCache.getLangIsoCode( m_activity, curLangName );
|
||||
boolean changeLang = !isoCode.equals( curISOCode );
|
||||
|
||||
SharedPreferences sp
|
||||
= PreferenceManager.getDefaultSharedPreferences( m_activity );
|
||||
|
@ -738,7 +740,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
editor.putString( key, name );
|
||||
|
||||
// and change language
|
||||
String langName = DictLangCache.getLangName( m_activity, langCode );
|
||||
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
key = getString( R.string.key_default_language );
|
||||
editor.putString( key, langName );
|
||||
}
|
||||
|
@ -807,10 +809,10 @@ public class DictsDelegate extends ListDelegateBase
|
|||
// a different same-lang wordlist to open a game.
|
||||
|
||||
class LangDelData {
|
||||
public LangDelData( int langCode ) {
|
||||
public LangDelData( String isoCode ) {
|
||||
delDicts = new HashSet<>();
|
||||
langName = DictLangCache.getLangName( m_activity, langCode );
|
||||
nDicts = DictLangCache.getDALsHaveLang( m_activity, langCode ).length;
|
||||
langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
nDicts = DictLangCache.getDALsHaveLang( m_activity, isoCode ).length;
|
||||
}
|
||||
public String dictsStr()
|
||||
{
|
||||
|
@ -826,22 +828,22 @@ public class DictsDelegate extends ListDelegateBase
|
|||
int nDicts;
|
||||
}
|
||||
|
||||
Map<Integer, LangDelData> dels = new HashMap<>();
|
||||
Set<Integer> skipLangs = new HashSet<>();
|
||||
Map<String, LangDelData> dels = new HashMap<>();
|
||||
Set<String> skipLangs = new HashSet<>();
|
||||
for ( String dict : m_selDicts.keySet() ) {
|
||||
int langCode = DictLangCache.getDictLangCode( m_activity, dict );
|
||||
if ( skipLangs.contains( langCode ) ) {
|
||||
String isoCode = DictLangCache.getDictISOCode( m_activity, dict );
|
||||
if ( skipLangs.contains( isoCode ) ) {
|
||||
continue;
|
||||
}
|
||||
int nUsingLang = DBUtils.countGamesUsingLang( m_activity, langCode );
|
||||
int nUsingLang = DBUtils.countGamesUsingISOCode( m_activity, isoCode );
|
||||
if ( 0 == nUsingLang ) {
|
||||
// remember, since countGamesUsingLang is expensive
|
||||
skipLangs.add( langCode );
|
||||
skipLangs.add( isoCode );
|
||||
} else {
|
||||
LangDelData data = dels.get( langCode );
|
||||
LangDelData data = dels.get( isoCode );
|
||||
if ( null == data ) {
|
||||
data = new LangDelData( langCode );
|
||||
dels.put( langCode, data );
|
||||
data = new LangDelData( isoCode );
|
||||
dels.put( isoCode, data );
|
||||
}
|
||||
data.delDicts.add( dict );
|
||||
}
|
||||
|
@ -950,9 +952,9 @@ public class DictsDelegate extends ListDelegateBase
|
|||
DictLangCache.inval( m_activity, dict, loc, false );
|
||||
}
|
||||
|
||||
private void startDownload( int lang, String name )
|
||||
private void startDownload( String isoCode, String name )
|
||||
{
|
||||
DwnldDelegate.downloadDictInBack( m_activity, lang, name, this );
|
||||
DwnldDelegate.downloadDictInBack( m_activity, isoCode, name, this );
|
||||
}
|
||||
|
||||
private void resetLangs()
|
||||
|
@ -1058,20 +1060,20 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
public static void downloadForResult( Delegator delegator, RequestCode requestCode,
|
||||
int lang )
|
||||
String isoCode )
|
||||
{
|
||||
downloadForResult( delegator, requestCode, lang, null );
|
||||
downloadForResult( delegator, requestCode, isoCode, null );
|
||||
}
|
||||
|
||||
public static void downloadForResult( Delegator delegator, RequestCode requestCode )
|
||||
{
|
||||
downloadForResult( delegator, requestCode, 0, null );
|
||||
downloadForResult( delegator, requestCode, null, null );
|
||||
}
|
||||
|
||||
public static void downloadDefaultDict( Context context, String lc,
|
||||
public static void downloadDefaultDict( Context context, String isoCode,
|
||||
OnGotLcDictListener lstnr )
|
||||
{
|
||||
new GetDefaultDictTask( context, lc, lstnr ).execute();
|
||||
new GetDefaultDictTask( context, isoCode, lstnr ).execute();
|
||||
}
|
||||
|
||||
private static final int FAKE_GROUP = 101;
|
||||
|
@ -1081,7 +1083,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
private static void doPopup( final Delegator dlgtor, View button,
|
||||
String curDict, final int lang ) {
|
||||
String curDict, final String isoCode ) {
|
||||
|
||||
final HashMap<MenuItem, DictAndLoc> itemData
|
||||
= new HashMap<>();
|
||||
|
@ -1093,7 +1095,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
public boolean onMenuItemClick( MenuItem item )
|
||||
{
|
||||
DictAndLoc dal = itemData.get( item );
|
||||
String prevKey = keyForLang( lang );
|
||||
String prevKey = keyForLang( isoCode );
|
||||
DBUtils.setStringFor( context, prevKey, dal.name );
|
||||
DictBrowseDelegate.launch( dlgtor, dal.name,
|
||||
dal.loc );
|
||||
|
@ -1101,7 +1103,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
};
|
||||
|
||||
String prevSel = prevSelFor( context, lang );
|
||||
String prevSel = prevSelFor( context, isoCode );
|
||||
if ( null == prevSel ) {
|
||||
prevSel = curDict;
|
||||
}
|
||||
|
@ -1113,7 +1115,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
LocUtils.getString( context,
|
||||
R.string.cur_menu_marker_fmt,
|
||||
curDict ) );
|
||||
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, lang );
|
||||
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, isoCode );
|
||||
for ( DictAndLoc dal : dals ) {
|
||||
boolean isCur = dal.name.equals(curDict);
|
||||
MenuItem item = isCur ? curItem : addItem( menu, dal.name );
|
||||
|
@ -1127,24 +1129,24 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
public static boolean handleDictsPopup( Delegator delegator, View button,
|
||||
String curDict, int lang )
|
||||
String curDict, String isoCode )
|
||||
{
|
||||
int nDicts = DictLangCache.getLangCount( delegator.getActivity(), lang );
|
||||
int nDicts = DictLangCache.getLangCount( delegator.getActivity(), isoCode );
|
||||
boolean canHandle = 1 < nDicts;
|
||||
if ( canHandle ) {
|
||||
doPopup( delegator, button, curDict, lang );
|
||||
doPopup( delegator, button, curDict, isoCode );
|
||||
}
|
||||
return canHandle;
|
||||
}
|
||||
|
||||
private static String keyForLang(int lang)
|
||||
private static String keyForLang( String isoCode )
|
||||
{
|
||||
return String.format( "%s:lang=%d", TAG, lang );
|
||||
return String.format( "%s:lang=%s", TAG, isoCode );
|
||||
}
|
||||
|
||||
static String prevSelFor( Context context, int lang )
|
||||
static String prevSelFor( Context context, String isoCode )
|
||||
{
|
||||
String key = keyForLang( lang );
|
||||
String key = keyForLang( isoCode );
|
||||
return DBUtils.getStringFor( context, key );
|
||||
}
|
||||
|
||||
|
@ -1169,7 +1171,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
@Override
|
||||
public void onClick( View view ) {
|
||||
DwnldDelegate.
|
||||
downloadDictInBack( m_activity, info.m_urlLang,
|
||||
downloadDictInBack( m_activity, info.mISOCode,
|
||||
info.m_name,
|
||||
DictsDelegate.this );
|
||||
}
|
||||
|
@ -1440,14 +1442,17 @@ public class DictsDelegate extends ListDelegateBase
|
|||
m_remoteInfo = new HashMap<>();
|
||||
for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) {
|
||||
JSONObject langObj = langs.getJSONObject( ii );
|
||||
String lc = langObj.optString( "lc", null );
|
||||
String isoCode = langObj.optString( "lc", null );
|
||||
String urlLangName = langObj.getString( "lang" );
|
||||
String localLangName = null;
|
||||
if ( null != lc ) {
|
||||
localLangName = DictLangCache.userLangForLc( m_activity, lc );
|
||||
if ( null != isoCode ) {
|
||||
localLangName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
}
|
||||
if ( null == localLangName ) {
|
||||
localLangName = urlLangName;
|
||||
DictLangCache.setLangNameForISOCode( m_context,
|
||||
isoCode,
|
||||
urlLangName );
|
||||
}
|
||||
|
||||
if ( null != m_filterLang &&
|
||||
|
@ -1473,7 +1478,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
if ( 0 == note.length() ) {
|
||||
note = null;
|
||||
}
|
||||
DictInfo info = new DictInfo( name, urlLangName, localLangName,
|
||||
DictInfo info = new DictInfo( name, isoCode, localLangName,
|
||||
nWords, nBytes, note );
|
||||
|
||||
if ( !m_quickFetchMode ) {
|
||||
|
@ -1495,8 +1500,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
if ( !matches ) {
|
||||
Uri uri =
|
||||
Utils.makeDictUri( m_activity,
|
||||
urlLangName, name );
|
||||
Utils.makeDictUriFromName( m_activity,
|
||||
urlLangName, name );
|
||||
m_needUpdates.put( name, uri );
|
||||
}
|
||||
}
|
||||
|
@ -1550,15 +1555,15 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
public static void downloadForResult( Delegator delegator,
|
||||
RequestCode requestCode,
|
||||
int lang, String name )
|
||||
String isoCode, String name )
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean( DICT_SHOWREMOTE, true );
|
||||
if ( lang > 0 ) {
|
||||
bundle.putInt( DICT_LANG_EXTRA, lang );
|
||||
if ( null != isoCode ) {
|
||||
bundle.putString( DICT_LANG_EXTRA, isoCode );
|
||||
}
|
||||
if ( null != name ) {
|
||||
Assert.assertTrue( lang != 0 );
|
||||
Assert.assertTrue( null != isoCode );
|
||||
bundle.putString( DICT_NAME_EXTRA, name );
|
||||
}
|
||||
delegator.addFragmentForResult( DictsFrag.newInstance( delegator ),
|
||||
|
|
|
@ -414,9 +414,9 @@ public class DlgDelegate {
|
|||
m_dlgt.show( state );
|
||||
}
|
||||
|
||||
public void launchLookup( String[] words, int lang, boolean noStudy )
|
||||
public void launchLookup( String[] words, String isoCode, boolean noStudy )
|
||||
{
|
||||
m_dlgt.show( LookupAlert.newInstance( words, lang, noStudy ) );
|
||||
m_dlgt.show( LookupAlert.newInstance( words, isoCode, noStudy ) );
|
||||
}
|
||||
|
||||
public void startProgress( int titleID, int msgID, OnCancelListener lstnr )
|
||||
|
|
|
@ -64,11 +64,11 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
private ArrayList<DownloadFilesTask> m_dfts;
|
||||
|
||||
public interface DownloadFinishedListener {
|
||||
void downloadFinished( String lang, String name, boolean success );
|
||||
void downloadFinished( String isoCode, String name, boolean success );
|
||||
}
|
||||
|
||||
public interface OnGotLcDictListener {
|
||||
void gotDictInfo( boolean success, String lc, String name );
|
||||
void gotDictInfo( boolean success, String isoCode, String name );
|
||||
}
|
||||
|
||||
public DwnldDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
|
@ -478,28 +478,20 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
}
|
||||
}
|
||||
|
||||
public static void downloadDictInBack( Context context, String langName,
|
||||
String name,
|
||||
public static void downloadDictInBack( Context context, String isoCode,
|
||||
String dictName,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
Uri uri = Utils.makeDictUri( context, langName, name );
|
||||
downloadDictInBack( context, uri, name, lstnr );
|
||||
}
|
||||
|
||||
public static void downloadDictInBack( Context context, int lang,
|
||||
String name,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
Uri uri = Utils.makeDictUri( context, lang, name );
|
||||
downloadDictInBack( context, uri, name, lstnr );
|
||||
Uri uri = Utils.makeDictUriFromCode( context, isoCode, dictName );
|
||||
downloadDictInBack( context, uri, dictName, lstnr );
|
||||
}
|
||||
|
||||
public static void downloadDictInBack( Context context, Uri uri,
|
||||
String name,
|
||||
String dictName,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
Uri[] uris = { uri };
|
||||
String[] names = { name };
|
||||
String[] names = { dictName };
|
||||
downloadDictsInBack( context, uris, names, lstnr );
|
||||
}
|
||||
|
||||
|
|
|
@ -353,7 +353,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
TextView dictLabel = (TextView)playerView
|
||||
.findViewById( R.id.dict_label );
|
||||
if ( localOnlyGame() ) {
|
||||
String langName = DictLangCache.getLangName( m_activity, m_gi.dictLang );
|
||||
String langName = DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode );
|
||||
String label = getString( R.string.dict_lang_label_fmt, langName );
|
||||
dictLabel.setText( label );
|
||||
} else {
|
||||
|
@ -363,7 +363,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
.findViewById( R.id.player_dict_spinner ))
|
||||
.getSpinner();
|
||||
if ( localOnlyGame() ) {
|
||||
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, m_gi.dictName(lp) );
|
||||
configDictSpinner( m_playerDictSpinner, m_gi.isoCode, m_gi.dictName(lp) );
|
||||
} else {
|
||||
m_playerDictSpinner.setVisibility( View.GONE );
|
||||
m_playerDictSpinner = null;
|
||||
|
@ -544,12 +544,12 @@ public class GameConfigDelegate extends DelegateBase
|
|||
case REQUEST_DICT:
|
||||
String dictName = cancelled ? m_gi.dictName
|
||||
: data.getStringExtra( DictsDelegate.RESULT_LAST_DICT );
|
||||
configDictSpinner( m_dictSpinner, m_gi.dictLang, dictName );
|
||||
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, dictName );
|
||||
configDictSpinner( m_dictSpinner, m_gi.isoCode, dictName );
|
||||
configDictSpinner( m_playerDictSpinner, m_gi.isoCode, dictName );
|
||||
break;
|
||||
case REQUEST_LANG_GC:
|
||||
String langName = cancelled
|
||||
? DictLangCache.getLangName( m_activity, m_gi.dictLang )
|
||||
? DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode )
|
||||
: data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
|
||||
selLangChanged( langName );
|
||||
setLangSpinnerSelection( langName );
|
||||
|
@ -990,11 +990,11 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
} // loadPlayersList
|
||||
|
||||
private void configDictSpinner( Spinner dictsSpinner, int lang,
|
||||
private void configDictSpinner( Spinner dictsSpinner, final String isoCode,
|
||||
String curDict )
|
||||
{
|
||||
if ( null != dictsSpinner ) {
|
||||
String langName = DictLangCache.getLangName( m_activity, lang );
|
||||
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
dictsSpinner.setPrompt( getString( R.string.dicts_list_prompt_fmt,
|
||||
langName ) );
|
||||
|
||||
|
@ -1009,13 +1009,14 @@ public class GameConfigDelegate extends DelegateBase
|
|||
if ( chosen.equals( m_browseText ) ) {
|
||||
DictsDelegate.downloadForResult( getDelegator(),
|
||||
RequestCode.REQUEST_DICT,
|
||||
m_gi.dictLang );
|
||||
m_gi.isoCode );
|
||||
Assert.assertTrueNR( isoCode.equals(m_gi.isoCode) );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ArrayAdapter<String> adapter =
|
||||
DictLangCache.getDictsAdapter( m_activity, lang );
|
||||
DictLangCache.getDictsAdapter( m_activity, isoCode );
|
||||
|
||||
configSpinnerWDownload( dictsSpinner, adapter, onSel, curDict );
|
||||
}
|
||||
|
@ -1048,17 +1049,17 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
};
|
||||
|
||||
String lang = DictLangCache.getLangName( m_activity, m_gi.dictLang );
|
||||
String lang = DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode );
|
||||
configSpinnerWDownload( m_langSpinner, adapter, onSel, lang );
|
||||
}
|
||||
}
|
||||
|
||||
private void selLangChanged( String chosen )
|
||||
{
|
||||
m_gi.setLang( m_activity, DictLangCache
|
||||
.getLangLangCode( m_activity, chosen ) );
|
||||
String isoCode = DictLangCache.getLangIsoCode( m_activity, chosen );
|
||||
m_gi.setLang( m_activity, isoCode );
|
||||
loadPlayersList();
|
||||
configDictSpinner( m_dictSpinner, m_gi.dictLang, m_gi.dictName );
|
||||
configDictSpinner( m_dictSpinner, m_gi.isoCode, m_gi.dictName );
|
||||
}
|
||||
|
||||
private void configSpinnerWDownload( Spinner spinner,
|
||||
|
|
|
@ -275,8 +275,7 @@ public class GameListItem extends LinearLayout
|
|||
break;
|
||||
case R.string.game_summary_field_language:
|
||||
value =
|
||||
DictLangCache.getLangName( m_context,
|
||||
m_summary.dictLang );
|
||||
DictLangCache.getLangNameForISOCode( m_context, m_summary.isoCode );
|
||||
value = LocUtils.xlateLang( m_context, value, true );
|
||||
break;
|
||||
case R.string.game_summary_field_opponents:
|
||||
|
|
|
@ -406,7 +406,7 @@ public class GameUtils {
|
|||
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
|
||||
if ( pairs.anyMissing( dictNames ) ) {
|
||||
postMoveDroppedForDictNotification( context, rowid, gi.gameID,
|
||||
gi.dictLang );
|
||||
gi.isoCode );
|
||||
} else {
|
||||
String langName = gi.langName( context );
|
||||
gamePtr = XwJNI.initFromStream( rowid, stream, gi, util, null,
|
||||
|
@ -598,7 +598,7 @@ public class GameUtils {
|
|||
CommsAddrRec addr = nli.makeAddrRec( context );
|
||||
|
||||
return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC,
|
||||
addr, new int[] {nli.lang},
|
||||
addr, new String[] {nli.isoCode},
|
||||
new String[] { nli.dict }, null, nli.nPlayersT,
|
||||
nli.nPlayersH, nli.forceChannel,
|
||||
nli.inviteID(), nli.gameID(),
|
||||
|
@ -608,27 +608,28 @@ public class GameUtils {
|
|||
public static long makeNewMultiGame( Context context, long groupID,
|
||||
String gameName )
|
||||
{
|
||||
return makeNewMultiGame( context, groupID, null, 0, null,
|
||||
return makeNewMultiGame( context, groupID, null, null, null,
|
||||
(CommsConnTypeSet)null, gameName );
|
||||
}
|
||||
|
||||
public static long makeNewMultiGame( Context context, long groupID,
|
||||
String dict, int lang, String jsonData,
|
||||
String dict, String isoCode,
|
||||
String jsonData,
|
||||
CommsConnTypeSet addrSet,
|
||||
String gameName )
|
||||
{
|
||||
String inviteID = makeRandomID();
|
||||
return makeNewMultiGame( context, groupID, inviteID, dict, lang,
|
||||
return makeNewMultiGame( context, groupID, inviteID, dict, isoCode,
|
||||
jsonData, addrSet, gameName );
|
||||
}
|
||||
|
||||
private static long makeNewMultiGame( Context context, long groupID,
|
||||
String inviteID, String dict,
|
||||
int lang, String jsonData,
|
||||
String isoCode, String jsonData,
|
||||
CommsConnTypeSet addrSet,
|
||||
String gameName )
|
||||
{
|
||||
int[] langArray = {lang};
|
||||
String[] langArray = {isoCode};
|
||||
String[] dictArray = {dict};
|
||||
if ( null == addrSet ) {
|
||||
addrSet = XWPrefs.getAddrTypes( context );
|
||||
|
@ -653,7 +654,7 @@ public class GameUtils {
|
|||
private static long makeNewMultiGame( Context context, MultiMsgSink sink,
|
||||
UtilCtxt util, long groupID,
|
||||
CommsAddrRec addr,
|
||||
int[] lang, String[] dict,
|
||||
String[] isoCode, String[] dict,
|
||||
String jsonData,
|
||||
int nPlayersT, int nPlayersH,
|
||||
int forceChannel, String inviteID,
|
||||
|
@ -665,9 +666,9 @@ public class GameUtils {
|
|||
Assert.assertNotNull( inviteID );
|
||||
CurGameInfo gi = new CurGameInfo( context, inviteID );
|
||||
gi.setFrom( jsonData );
|
||||
gi.setLang( context, lang[0], dict[0] );
|
||||
gi.setLang( context, isoCode[0], dict[0] );
|
||||
gi.forceChannel = forceChannel;
|
||||
lang[0] = gi.dictLang;
|
||||
isoCode[0] = gi.isoCode;
|
||||
dict[0] = gi.dictName;
|
||||
gi.setNPlayers( nPlayersT, nPlayersH, localsRobots );
|
||||
gi.juggle();
|
||||
|
@ -829,14 +830,14 @@ public class GameUtils {
|
|||
}
|
||||
|
||||
public static String[] dictNames( Context context, long rowid,
|
||||
int[] missingLang )
|
||||
String[] missingLang )
|
||||
{
|
||||
String[] result = null;
|
||||
byte[] stream = savedGame( context, rowid );
|
||||
CurGameInfo gi = giFromStream( context, stream );
|
||||
if ( null != gi ) {
|
||||
if ( null != missingLang ) {
|
||||
missingLang[0] = gi.dictLang;
|
||||
missingLang[0] = gi.isoCode;
|
||||
}
|
||||
result = gi.dictNames();
|
||||
}
|
||||
|
@ -863,7 +864,7 @@ public class GameUtils {
|
|||
// are not.
|
||||
public static boolean gameDictsHere( Context context, long rowid,
|
||||
String[][] missingNames,
|
||||
int[] missingLang )
|
||||
String[] missingLang )
|
||||
{
|
||||
String[] gameDicts = dictNames( context, rowid, missingLang );
|
||||
return null != gameDicts
|
||||
|
@ -1234,11 +1235,11 @@ public class GameUtils {
|
|||
}
|
||||
|
||||
private static void postMoveDroppedForDictNotification( Context context, long rowid,
|
||||
int gameID, int lang )
|
||||
int gameID, String isoCode )
|
||||
{
|
||||
Intent intent = GamesListDelegate.makeGameIDIntent( context, gameID );
|
||||
|
||||
String langName = DictLangCache.getLangName( context, lang );
|
||||
String langName = DictLangCache.getLangNameForISOCode( context, isoCode );
|
||||
String body = LocUtils.getString( context, R.string.no_dict_for_move_fmt,
|
||||
langName );
|
||||
Utils.postNotification( context, intent, R.string.no_dict_for_move_title,
|
||||
|
|
|
@ -607,7 +607,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
case WARN_NODICT_SUBST: {
|
||||
final long rowid = (Long)params[0];
|
||||
final String missingDictName = (String)params[1];
|
||||
final int missingDictLang = (Integer)params[2];
|
||||
final String missingDictLang = (String)params[2];
|
||||
|
||||
lstnr = new OnClickListener() {
|
||||
@Override
|
||||
|
@ -629,7 +629,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
};
|
||||
String message;
|
||||
String langName =
|
||||
DictLangCache.getLangName( m_activity, missingDictLang );
|
||||
DictLangCache.getLangNameForISOCode( m_activity, missingDictLang );
|
||||
String locLang = xlateLang( langName );
|
||||
String gameName = GameUtils.getName( m_activity, rowid );
|
||||
if ( DlgID.WARN_NODICT_GENERIC == dlgID ) {
|
||||
|
@ -674,11 +674,12 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
case SHOW_SUBST: {
|
||||
final long rowid = (Long)params[0];
|
||||
final String missingDict = (String)params[1];
|
||||
final int lang = (Integer)params[2];
|
||||
final String isoCode = (String)params[2];
|
||||
|
||||
final String[] sameLangDicts =
|
||||
DictLangCache.getHaveLangCounts( m_activity, lang );
|
||||
DictLangCache.getHaveLangCounts( m_activity, isoCode );
|
||||
lstnr = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick( DialogInterface dlg,
|
||||
int which ) {
|
||||
int pos = ((AlertDialog)dlg).getListView().
|
||||
|
@ -1792,7 +1793,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
break;
|
||||
|
||||
case R.id.games_menu_study:
|
||||
StudyListDelegate.launchOrAlert( getDelegator(), StudyListDelegate.NO_LANG, this );
|
||||
StudyListDelegate.launchOrAlert( getDelegator(), this );
|
||||
break;
|
||||
|
||||
case R.id.games_menu_knownplyrs:
|
||||
|
@ -2250,7 +2251,8 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
// check that we have the dict required
|
||||
boolean haveDict;
|
||||
if ( null == nli.dict ) { // can only test for language support
|
||||
String[] dicts = DictLangCache.getHaveLang( m_activity, nli.lang );
|
||||
|
||||
String[] dicts = DictLangCache.getHaveLang( m_activity, nli.isoCode );
|
||||
haveDict = 0 < dicts.length;
|
||||
if ( haveDict ) {
|
||||
// Just pick one -- good enough for the period when
|
||||
|
@ -2260,11 +2262,11 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
} else {
|
||||
haveDict =
|
||||
DictLangCache.haveDict( m_activity, nli.lang, nli.dict );
|
||||
DictLangCache.haveDict( m_activity, nli.isoCode, nli.dict );
|
||||
}
|
||||
if ( !haveDict ) {
|
||||
m_netLaunchInfo = nli;
|
||||
showDialogFragment( DlgID.WARN_NODICT_INVITED, 0L, nli.dict, nli.lang );
|
||||
showDialogFragment( DlgID.WARN_NODICT_INVITED, 0L, nli.dict, nli.isoCode );
|
||||
}
|
||||
return haveDict;
|
||||
}
|
||||
|
@ -2277,7 +2279,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
private boolean checkWarnNoDict( long rowid, int forMenu )
|
||||
{
|
||||
String[][] missingNames = new String[1][];
|
||||
int[] missingLang = new int[1];
|
||||
String[] missingLang = { "en" };
|
||||
boolean hasDicts;
|
||||
try {
|
||||
hasDicts = GameUtils.gameDictsHere( m_activity, rowid, missingNames,
|
||||
|
@ -2288,7 +2290,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
|
||||
if ( !hasDicts ) {
|
||||
String missingDictName = null;
|
||||
int missingDictLang = missingLang[0];
|
||||
String missingDictLang = missingLang[0];
|
||||
if ( 0 < missingNames[0].length ) {
|
||||
missingDictName = missingNames[0][0];
|
||||
}
|
||||
|
@ -2573,12 +2575,12 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
String phone = extras.getString( REMATCH_PHONE_EXTRA );
|
||||
String p2pMacAddress = extras.getString( REMATCH_P2PADDR_EXTRA );
|
||||
String dict = extras.getString( REMATCH_DICT_EXTRA );
|
||||
int lang = extras.getInt( REMATCH_LANG_EXTRA, -1 );
|
||||
String isoCode = extras.getString( REMATCH_LANG_EXTRA );
|
||||
String mqttDevID = extras.getString( GameSummary.EXTRA_REMATCH_MQTT );
|
||||
String json = extras.getString( REMATCH_PREFS_EXTRA );
|
||||
|
||||
newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict,
|
||||
lang, json, addrs, gameName );
|
||||
isoCode, json, addrs, gameName );
|
||||
DBUtils.addRematchInfo( m_activity, newid, btAddr, phone,
|
||||
p2pMacAddress, mqttDevID );
|
||||
}
|
||||
|
@ -2634,37 +2636,35 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
false ) ) {
|
||||
m_haveShownGetDict = true;
|
||||
|
||||
String lc = LocUtils.getCurLangCode( m_activity );
|
||||
if ( !lc.equals("en") ) {
|
||||
int code = DictLangCache.getLangLangCode( m_activity, lc );
|
||||
if ( 0 < code ) {
|
||||
String[] names = DictLangCache.getHaveLang( m_activity, code );
|
||||
if ( 0 == names.length ) {
|
||||
String isoCode = LocUtils.getCurLangCode( m_activity );
|
||||
if ( !isoCode.equals("en") ) {
|
||||
String[] names = DictLangCache.getHaveLang( m_activity, isoCode );
|
||||
if ( 0 == names.length ) {
|
||||
|
||||
OnGotLcDictListener lstnr = new OnGotLcDictListener() {
|
||||
public void gotDictInfo( boolean success, String lang,
|
||||
String name ) {
|
||||
stopProgress();
|
||||
if ( success ) {
|
||||
String msg =
|
||||
getString( R.string.confirm_get_locdict_fmt,
|
||||
xlateLang( lang ) );
|
||||
makeConfirmThenBuilder( msg, Action.DWNLD_LOC_DICT )
|
||||
.setPosButton( R.string.button_download )
|
||||
.setNegButton( R.string.button_no )
|
||||
.setNAKey( R.string.key_got_langdict )
|
||||
.setParams( lang, name )
|
||||
.show();
|
||||
}
|
||||
OnGotLcDictListener lstnr = new OnGotLcDictListener() {
|
||||
@Override
|
||||
public void gotDictInfo( boolean success, String lang,
|
||||
String name ) {
|
||||
stopProgress();
|
||||
if ( success ) {
|
||||
String msg =
|
||||
getString( R.string.confirm_get_locdict_fmt,
|
||||
xlateLang( lang ) );
|
||||
makeConfirmThenBuilder( msg, Action.DWNLD_LOC_DICT )
|
||||
.setPosButton( R.string.button_download )
|
||||
.setNegButton( R.string.button_no )
|
||||
.setNAKey( R.string.key_got_langdict )
|
||||
.setParams( lang, name )
|
||||
.show();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
String langName = DictLangCache.getLangName( m_activity, code );
|
||||
String locLang = xlateLang( langName );
|
||||
String msg = getString( R.string.checking_for_fmt, locLang );
|
||||
startProgress( R.string.checking_title, msg );
|
||||
DictsDelegate.downloadDefaultDict( m_activity, lc, lstnr );
|
||||
}
|
||||
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
String locLang = xlateLang( langName );
|
||||
String msg = getString( R.string.checking_for_fmt, locLang );
|
||||
startProgress( R.string.checking_title, msg );
|
||||
DictsDelegate.downloadDefaultDict( m_activity, isoCode, lstnr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3084,7 +3084,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
.putExtra( REMATCH_GROUPID_EXTRA, groupID )
|
||||
.putExtra( REMATCH_DICT_EXTRA, gi.dictName )
|
||||
.putExtra( REMATCH_IS_SOLO, isSolo )
|
||||
.putExtra( REMATCH_LANG_EXTRA, gi.dictLang )
|
||||
.putExtra( REMATCH_LANG_EXTRA, gi.isoCode )
|
||||
.putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() )
|
||||
.putExtra( REMATCH_NEWNAME_EXTRA, newName );
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ public class LangListPreference extends XWListPreference
|
|||
}
|
||||
|
||||
if ( !haveDictForLang ) {
|
||||
curLang = DictLangCache.getLangName( mContext, 1 ); // English, unlocalized
|
||||
curLang = DictLangCache.getLangNameForISOCode( mContext, "en" ); // English, unlocalized
|
||||
setValue( curLang );
|
||||
}
|
||||
forceDictsMatch( curLang );
|
||||
|
@ -97,7 +97,7 @@ public class LangListPreference extends XWListPreference
|
|||
private void forceDictsMatch( String newLang )
|
||||
{
|
||||
if ( null != newLang ) {
|
||||
int code = DictLangCache.getLangLangCode( mContext, newLang );
|
||||
String isoCode = DictLangCache.getLangIsoCode( mContext, newLang );
|
||||
int[] keyIds = { R.string.key_default_dict,
|
||||
R.string.key_default_robodict };
|
||||
for ( int id : keyIds ) {
|
||||
|
@ -111,9 +111,9 @@ public class LangListPreference extends XWListPreference
|
|||
|
||||
String curDict = pref.getValue().toString();
|
||||
if ( ! DictUtils.dictExists( mContext, curDict )
|
||||
|| code != DictLangCache.getDictLangCode( mContext,
|
||||
curDict ) ) {
|
||||
pref.invalidate();
|
||||
|| ! isoCode.equals( DictLangCache.getDictISOCode( mContext,
|
||||
curDict ) ) ) {
|
||||
pref.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@ public class LookupAlert extends XWDialogFragment {
|
|||
private static final String TAG = LookupAlert.class.getSimpleName();
|
||||
private LookupAlertView m_view;
|
||||
|
||||
public static LookupAlert newInstance( String[] words, int lang, boolean noStudy )
|
||||
public static LookupAlert newInstance( String[] words, String isoCode, boolean noStudy )
|
||||
{
|
||||
LookupAlert result = new LookupAlert();
|
||||
Bundle bundle = LookupAlertView.makeParams( words, lang, noStudy );
|
||||
Bundle bundle = LookupAlertView.makeParams( words, isoCode, noStudy );
|
||||
result.setArguments( bundle );
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class LookupAlertView extends LinearLayout
|
|||
private static ArrayAdapter<String> s_urlsAdapter;
|
||||
private static final int LIST_LAYOUT = android.R.layout.simple_list_item_1;
|
||||
|
||||
private static int s_lang = -1;
|
||||
private static String s_lang = null;
|
||||
private static String s_langName;
|
||||
|
||||
// These two are probably always the same object
|
||||
|
@ -93,8 +93,8 @@ public class LookupAlertView extends LinearLayout
|
|||
{
|
||||
m_onDone = lstn;
|
||||
m_words = bundle.getStringArray( WORDS );
|
||||
int lang = bundle.getInt( LANG, 0 );
|
||||
setLang( m_context, lang );
|
||||
String isoCode = bundle.getString( LANG );
|
||||
setLang( m_context, isoCode );
|
||||
m_studyOn = XWPrefs.getStudyEnabled( m_context )
|
||||
&& bundle.getBoolean( STUDY_ON, true );
|
||||
|
||||
|
@ -234,8 +234,7 @@ public class LookupAlertView extends LinearLayout
|
|||
|
||||
private void lookupWord( Context context, String word, String fmt )
|
||||
{
|
||||
String langCode = DictLangCache.getLangCodeStr( context, s_lang );
|
||||
String dict_url = String.format( fmt, langCode, word );
|
||||
String dict_url = String.format( fmt, s_lang, word );
|
||||
Uri uri = Uri.parse( dict_url );
|
||||
Intent intent = new Intent( Intent.ACTION_VIEW, uri );
|
||||
intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
|
@ -247,14 +246,13 @@ public class LookupAlertView extends LinearLayout
|
|||
}
|
||||
} // lookupWord
|
||||
|
||||
private void setLang( Context context, int lang )
|
||||
private void setLang( Context context, String isoCode )
|
||||
{
|
||||
if ( s_lang != lang ) {
|
||||
if ( ! isoCode.equals( s_lang ) ) {
|
||||
String[] urls = context.getResources().getStringArray( R.array.lookup_urls );
|
||||
ArrayList<String> tmpUrls = new ArrayList<>();
|
||||
ArrayList<String> tmpNames = new ArrayList<>();
|
||||
String langCode = String
|
||||
.format( ":%s:", DictLangCache.getLangCodeStr( context, lang ) );
|
||||
String langCode = String.format( ":%s:", isoCode );
|
||||
for ( int ii = 0; ii < urls.length; ii += 3 ) {
|
||||
String codes = urls[ii+1];
|
||||
if ( 0 == codes.length() || codes.contains( langCode ) ) {
|
||||
|
@ -269,8 +267,8 @@ public class LookupAlertView extends LinearLayout
|
|||
s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] );
|
||||
s_urlsAdapter = new ArrayAdapter<>( context, LIST_LAYOUT,
|
||||
s_lookupNames );
|
||||
s_lang = lang;
|
||||
String langName = DictLangCache.getLangName( context, lang );
|
||||
s_lang = isoCode;
|
||||
String langName = DictLangCache.getLangNameForISOCode( context, isoCode );
|
||||
s_langName = LocUtils.xlateLang( context, langName );
|
||||
}
|
||||
}
|
||||
|
@ -300,19 +298,19 @@ public class LookupAlertView extends LinearLayout
|
|||
return handled;
|
||||
}
|
||||
|
||||
private static void addParams( Bundle bundle, String[] words, int lang,
|
||||
private static void addParams( Bundle bundle, String[] words, String isoCode,
|
||||
boolean studyOn )
|
||||
{
|
||||
bundle.putStringArray( WORDS, words );
|
||||
bundle.putInt( LANG, lang );
|
||||
bundle.putString( LANG, isoCode );
|
||||
bundle.putBoolean( STUDY_ON, studyOn );
|
||||
}
|
||||
|
||||
protected static Bundle makeParams( String[] words, int lang,
|
||||
protected static Bundle makeParams( String[] words, String isoCode,
|
||||
boolean noStudyOption )
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
addParams( bundle, words, lang, !noStudyOption );
|
||||
addParams( bundle, words, isoCode, !noStudyOption );
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public class MultiService {
|
|||
|
||||
public static final String FORCECHANNEL = "FC";
|
||||
public static final String LANG = "LANG";
|
||||
public static final String ISO = "ISO";
|
||||
public static final String DICT = "DICT";
|
||||
public static final String GAMEID = "GAMEID";
|
||||
public static final String INVITEID = "INVITEID"; // relay only
|
||||
|
@ -131,7 +132,7 @@ public class MultiService {
|
|||
{
|
||||
Intent intent = new Intent( context, MainActivity.class ); // PENDING TEST THIS!!!
|
||||
intent.setAction( ACTION_FETCH_DICT );
|
||||
intent.putExtra( LANG, nli.lang );
|
||||
intent.putExtra( ISO, nli.isoCode );
|
||||
intent.putExtra( DICT, nli.dict );
|
||||
intent.putExtra( OWNER, owner.ordinal() );
|
||||
intent.putExtra( NLI_DATA, nli.toString() );
|
||||
|
@ -169,7 +170,8 @@ public class MultiService {
|
|||
OnClickListener onDecline )
|
||||
{
|
||||
int lang = intent.getIntExtra( LANG, -1 );
|
||||
String langStr = DictLangCache.getLangName( context, lang );
|
||||
String isoCode = intent.getStringExtra( ISO );
|
||||
String langStr = DictLangCache.getLangNameForISOCode( context, isoCode );
|
||||
String dict = intent.getStringExtra( DICT );
|
||||
String inviter = intent.getStringExtra( INVITER );
|
||||
int msgID = (null == inviter) ? R.string.invite_dict_missing_body_noname_fmt
|
||||
|
@ -199,9 +201,9 @@ public class MultiService {
|
|||
{
|
||||
boolean downloaded = isMissingDictIntent( intent );
|
||||
if ( downloaded ) {
|
||||
int lang = intent.getIntExtra( LANG, -1 );
|
||||
String isoCode = intent.getStringExtra( ISO );
|
||||
String dict = intent.getStringExtra( DICT );
|
||||
downloaded = DictLangCache.haveDict( context, lang, dict );
|
||||
downloaded = DictLangCache.haveDict( context, isoCode, dict );
|
||||
if ( downloaded ) {
|
||||
int ordinal = intent.getIntExtra( OWNER, -1 );
|
||||
if ( -1 == ordinal ) {
|
||||
|
|
|
@ -60,6 +60,7 @@ public class NetLaunchInfo implements Serializable {
|
|||
private static final String ID_KEY = "id";
|
||||
private static final String WORDLIST_KEY = "wl";
|
||||
private static final String LANG_KEY = "lang";
|
||||
private static final String ISO_KEY = "iso";
|
||||
private static final String TOTPLAYERS_KEY = "np";
|
||||
private static final String HEREPLAYERS_KEY = "nh";
|
||||
private static final String GID_KEY = "gid";
|
||||
|
@ -73,7 +74,7 @@ public class NetLaunchInfo implements Serializable {
|
|||
|
||||
protected String gameName;
|
||||
protected String dict;
|
||||
protected int lang;
|
||||
protected String isoCode; // added in version 2
|
||||
protected int forceChannel;
|
||||
protected int nPlayersT;
|
||||
protected int nPlayersH;
|
||||
|
@ -109,7 +110,14 @@ public class NetLaunchInfo implements Serializable {
|
|||
|
||||
private NetLaunchInfo( Bundle bundle )
|
||||
{
|
||||
lang = bundle.getInt( MultiService.LANG );
|
||||
isoCode = bundle.getString( MultiService.ISO );
|
||||
if ( null == isoCode ) {
|
||||
int lang = bundle.getInt( MultiService.LANG, 0 );
|
||||
if ( 0 != lang ) {
|
||||
isoCode = XwJNI.lcToLocale( lang );
|
||||
}
|
||||
}
|
||||
Assert.assertTrueNR( null != isoCode );
|
||||
room = bundle.getString( MultiService.ROOM );
|
||||
inviteID = bundle.getString( MultiService.INVITEID );
|
||||
forceChannel = bundle.getInt( MultiService.FORCECHANNEL );
|
||||
|
@ -132,7 +140,8 @@ public class NetLaunchInfo implements Serializable {
|
|||
public static NetLaunchInfo makeFrom( Bundle bundle )
|
||||
{
|
||||
NetLaunchInfo nli = null;
|
||||
if ( 0 != bundle.getInt( MultiService.LANG ) ) { // quick test: valid?
|
||||
if ( 0 != bundle.getInt( MultiService.LANG )
|
||||
|| null != bundle.getString( MultiService.ISO ) ) { // quick test: valid?
|
||||
nli = new NetLaunchInfo( bundle );
|
||||
nli.calcValid();
|
||||
if ( !nli.isValid() ) {
|
||||
|
@ -161,6 +170,7 @@ public class NetLaunchInfo implements Serializable {
|
|||
DataInputStream dis = new DataInputStream( bais );
|
||||
String nliData = dis.readUTF();
|
||||
nli = NetLaunchInfo.makeFrom( context, nliData );
|
||||
Assert.assertTrueNR( null != nli.isoCode );
|
||||
} catch ( java.io.IOException ex ) {
|
||||
Log.d( TAG, "not an nli" );
|
||||
}
|
||||
|
@ -247,8 +257,16 @@ public class NetLaunchInfo implements Serializable {
|
|||
removeUnsupported( supported );
|
||||
|
||||
dict = data.getQueryParameter( WORDLIST_KEY );
|
||||
String langStr = data.getQueryParameter( LANG_KEY );
|
||||
lang = Integer.decode( langStr );
|
||||
isoCode = data.getQueryParameter( ISO_KEY );
|
||||
if ( null == isoCode ) {
|
||||
String langStr = data.getQueryParameter( LANG_KEY );
|
||||
if ( null != langStr && !langStr.equals("0") ) {
|
||||
int lang = Integer.decode( langStr );
|
||||
isoCode = XwJNI.lcToLocale( lang );
|
||||
}
|
||||
}
|
||||
Assert.assertTrueNR( null != isoCode );
|
||||
|
||||
String np = data.getQueryParameter( TOTPLAYERS_KEY );
|
||||
nPlayersT = Integer.decode( np );
|
||||
String nh = data.getQueryParameter( HEREPLAYERS_KEY );
|
||||
|
@ -270,13 +288,14 @@ public class NetLaunchInfo implements Serializable {
|
|||
calcValid();
|
||||
}
|
||||
|
||||
private NetLaunchInfo( int gamID, String gamNam, int dictLang,
|
||||
private NetLaunchInfo( int gamID, String gamNam, String isoCodeIn,
|
||||
String dictName, int nPlayers, boolean dupMode )
|
||||
{
|
||||
this();
|
||||
Assert.assertTrueNR( null != isoCodeIn );
|
||||
gameName = gamNam;
|
||||
dict = dictName;
|
||||
lang = dictLang;
|
||||
isoCode = isoCodeIn;
|
||||
nPlayersT = nPlayers;
|
||||
nPlayersH = 1;
|
||||
gameID = gamID;
|
||||
|
@ -293,8 +312,8 @@ public class NetLaunchInfo implements Serializable {
|
|||
|
||||
public NetLaunchInfo( CurGameInfo gi )
|
||||
{
|
||||
this( gi.gameID, gi.getName(), gi.dictLang, gi.dictName, gi.nPlayers,
|
||||
gi.inDuplicateMode );
|
||||
this( gi.gameID, gi.getName(), gi.isoCode,
|
||||
gi.dictName, gi.nPlayers, gi.inDuplicateMode );
|
||||
}
|
||||
|
||||
public NetLaunchInfo( Context context, GameSummary summary, CurGameInfo gi )
|
||||
|
@ -369,7 +388,12 @@ public class NetLaunchInfo implements Serializable {
|
|||
{
|
||||
bundle.putString( MultiService.ROOM, room );
|
||||
bundle.putString( MultiService.INVITEID, inviteID );
|
||||
bundle.putInt( MultiService.LANG, lang );
|
||||
int[] lang = {0};
|
||||
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
|
||||
bundle.putInt( MultiService.LANG, lang[0] );
|
||||
} else {
|
||||
bundle.putString( MultiService.ISO, isoCode );
|
||||
}
|
||||
bundle.putString( MultiService.DICT, dict );
|
||||
bundle.putString( MultiService.GAMENAME, gameName );
|
||||
bundle.putInt( MultiService.NPLAYERST, nPlayersT );
|
||||
|
@ -399,7 +423,7 @@ public class NetLaunchInfo implements Serializable {
|
|||
other = (NetLaunchInfo)obj;
|
||||
result = TextUtils.equals( gameName, other.gameName )
|
||||
&& TextUtils.equals( dict, other.dict )
|
||||
&& lang == other.lang
|
||||
&& TextUtils.equals( isoCode, other.isoCode )
|
||||
&& forceChannel == other.forceChannel
|
||||
&& nPlayersT == other.nPlayersT
|
||||
&& nPlayersH == other.nPlayersH
|
||||
|
@ -429,7 +453,6 @@ public class NetLaunchInfo implements Serializable {
|
|||
try {
|
||||
JSONObject obj = new JSONObject()
|
||||
.put( ADDRS_KEY, _conTypes )
|
||||
.put( MultiService.LANG, lang )
|
||||
.put( MultiService.DICT, dict )
|
||||
.put( MultiService.GAMENAME, gameName )
|
||||
.put( MultiService.NPLAYERST, nPlayersT )
|
||||
|
@ -438,6 +461,12 @@ public class NetLaunchInfo implements Serializable {
|
|||
.put( MultiService.GAMEID, gameID() )
|
||||
.put( MultiService.FORCECHANNEL, forceChannel )
|
||||
;
|
||||
int[] lang = {0};
|
||||
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
|
||||
obj.put( MultiService.LANG, lang[0] );
|
||||
} else {
|
||||
obj.put( MultiService.ISO, isoCode );
|
||||
}
|
||||
|
||||
if ( dupeMode ) {
|
||||
obj.put( MultiService.DUPEMODE, dupeMode );
|
||||
|
@ -518,7 +547,15 @@ public class NetLaunchInfo implements Serializable {
|
|||
boolean hasAddrs = -1 != flags;
|
||||
_conTypes = hasAddrs ? flags : EMPTY_SET;
|
||||
|
||||
lang = json.optInt( MultiService.LANG, -1 );
|
||||
isoCode = json.optString( MultiService.ISO );
|
||||
if ( null == isoCode ) {
|
||||
int lang = json.optInt( MultiService.LANG, 0 );
|
||||
if ( 0 != lang ) {
|
||||
isoCode = XwJNI.lcToLocale( lang );
|
||||
}
|
||||
}
|
||||
Assert.assertTrueNR( null != isoCode );
|
||||
|
||||
forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 );
|
||||
dupeMode = json.optBoolean( MultiService.DUPEMODE, false );
|
||||
dict = json.optString( MultiService.DICT );
|
||||
|
@ -590,8 +627,17 @@ public class NetLaunchInfo implements Serializable {
|
|||
Uri.Builder ub = new Uri.Builder()
|
||||
.scheme( "http" ) // PENDING: should be https soon
|
||||
.path( String.format( "//%s%s", host,
|
||||
LocUtils.getString(context, R.string.invite_prefix) ) );
|
||||
appendInt( ub, LANG_KEY, lang );
|
||||
LocUtils.getString(context,
|
||||
R.string.invite_prefix) ) );
|
||||
|
||||
// We'll use lang rather than ISO IFF we have it.
|
||||
int[] lang = {0};
|
||||
Assert.assertTrueNR( null != isoCode );
|
||||
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
|
||||
appendInt( ub, LANG_KEY, lang[0] );
|
||||
} else {
|
||||
ub.appendQueryParameter( ISO_KEY, isoCode );
|
||||
}
|
||||
appendInt( ub, TOTPLAYERS_KEY, nPlayersT );
|
||||
appendInt( ub, HEREPLAYERS_KEY, nPlayersH );
|
||||
appendInt( ub, GID_KEY, gameID() );
|
||||
|
@ -737,10 +783,12 @@ public class NetLaunchInfo implements Serializable {
|
|||
|
||||
private boolean hasCommon()
|
||||
{
|
||||
return null != dict
|
||||
&& 0 < lang
|
||||
boolean good = null != dict
|
||||
&& null != isoCode
|
||||
&& 0 < nPlayersT
|
||||
&& 0 != gameID();
|
||||
// Log.d( TAG, "hasCommon() => %b", good );
|
||||
return good;
|
||||
}
|
||||
|
||||
private void removeUnsupported( List<CommsConnType> supported )
|
||||
|
|
|
@ -51,8 +51,6 @@ public class StudyListDelegate extends ListDelegateBase
|
|||
DBUtils.StudyListListener {
|
||||
private static final String TAG = StudyListDelegate.class.getSimpleName();
|
||||
|
||||
protected static final int NO_LANG = -1;
|
||||
|
||||
protected static final String START_LANG = "START_LANG";
|
||||
|
||||
private static final String CHECKED_KEY = "CHECKED_KEY";
|
||||
|
@ -60,7 +58,7 @@ public class StudyListDelegate extends ListDelegateBase
|
|||
private Activity m_activity;
|
||||
private Spinner m_spinner;
|
||||
private LabeledSpinner m_pickView;
|
||||
private int[] m_langCodes;
|
||||
private String[] m_langCodes;
|
||||
private String[] m_words;
|
||||
private Set<String> m_checkeds;
|
||||
private int m_langPosition;
|
||||
|
@ -183,9 +181,9 @@ public class StudyListDelegate extends ListDelegateBase
|
|||
// DBUtils.StudyListListener
|
||||
//////////////////////////////////////////////////
|
||||
@Override
|
||||
public void onWordAdded( String word, int langCode )
|
||||
public void onWordAdded( String word, String isoCode )
|
||||
{
|
||||
if ( langCode == m_langCodes[m_langPosition] ) {
|
||||
if ( isoCode.equals( m_langCodes[m_langPosition] ) ) {
|
||||
loadList();
|
||||
}
|
||||
}
|
||||
|
@ -295,12 +293,12 @@ public class StudyListDelegate extends ListDelegateBase
|
|||
|
||||
private void loadList()
|
||||
{
|
||||
int lang = m_langCodes[m_langPosition];
|
||||
m_words = DBUtils.studyListWords( m_activity, lang );
|
||||
String isoCode = m_langCodes[m_langPosition];
|
||||
m_words = DBUtils.studyListWords( m_activity, isoCode );
|
||||
|
||||
makeAdapter();
|
||||
|
||||
String langName = DictLangCache.getLangName( m_activity, lang );
|
||||
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
m_origTitle = getString( R.string.studylist_title_fmt,
|
||||
xlateLang( langName ) );
|
||||
setTitleBar();
|
||||
|
@ -322,18 +320,18 @@ public class StudyListDelegate extends ListDelegateBase
|
|||
m_langPosition = 0;
|
||||
loadList();
|
||||
} else {
|
||||
int startLang = NO_LANG;
|
||||
String startLang = null;
|
||||
int startIndex = -1;
|
||||
if ( null != args ) {
|
||||
startLang = args.getInt( START_LANG, NO_LANG );
|
||||
startLang = args.getString( START_LANG );
|
||||
}
|
||||
|
||||
String[] myNames = new String[m_langCodes.length];
|
||||
for ( int ii = 0; ii < m_langCodes.length; ++ii ) {
|
||||
int lang = m_langCodes[ii];
|
||||
String name = DictLangCache.getLangName( m_activity, lang );
|
||||
String isoCode = m_langCodes[ii];
|
||||
String name = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||
myNames[ii] = xlateLang( name, true );
|
||||
if ( lang == startLang ) {
|
||||
if ( isoCode.equals( startLang ) ) {
|
||||
startIndex = ii;
|
||||
}
|
||||
}
|
||||
|
@ -385,22 +383,27 @@ public class StudyListDelegate extends ListDelegateBase
|
|||
setTitleBar();
|
||||
}
|
||||
|
||||
public static void launchOrAlert( Delegator delegator, int lang,
|
||||
public static void launchOrAlert( Delegator delegator, DlgDelegate.HasDlgDelegate dlg )
|
||||
{
|
||||
launchOrAlert( delegator, null, dlg );
|
||||
}
|
||||
|
||||
public static void launchOrAlert( Delegator delegator, String isoCode,
|
||||
DlgDelegate.HasDlgDelegate dlg )
|
||||
{
|
||||
String msg = null;
|
||||
Activity activity = delegator.getActivity();
|
||||
if ( 0 == DBUtils.studyListLangs( activity ).length ) {
|
||||
msg = LocUtils.getString( activity, R.string.study_no_lists );
|
||||
} else if ( NO_LANG != lang &&
|
||||
0 == DBUtils.studyListWords( activity, lang ).length ) {
|
||||
String langname = DictLangCache.getLangName( activity, lang );
|
||||
} else if ( null != isoCode &&
|
||||
0 == DBUtils.studyListWords( activity, isoCode ).length ) {
|
||||
String langname = DictLangCache.getLangNameForISOCode( activity, isoCode );
|
||||
msg = LocUtils.getString( activity, R.string.study_no_lang_fmt,
|
||||
langname );
|
||||
} else {
|
||||
Bundle bundle = new Bundle();
|
||||
if ( NO_LANG != lang ) {
|
||||
bundle.putInt( START_LANG, lang );
|
||||
if ( null != isoCode ) {
|
||||
bundle.putString( START_LANG, isoCode );
|
||||
}
|
||||
|
||||
delegator.addFragment( StudyListFrag.newInstance( delegator ),
|
||||
|
|
|
@ -215,16 +215,15 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
int index )
|
||||
{
|
||||
JSONObject params = new JSONObject();
|
||||
int lang = DictLangCache.getDictLangCode( context, dal );
|
||||
String langCode = DictLangCache.getLangCodeStr( context, lang );
|
||||
String langStr = DictLangCache.getLangName( context, lang );
|
||||
String isoCode = DictLangCache.getDictISOCode( context, dal );
|
||||
String langStr = DictLangCache.getLangNameForISOCode( context, isoCode );
|
||||
String[] sums = DictLangCache.getDictMD5Sums( context, dal.name );
|
||||
Assert.assertTrueNR( null != sums[1] );
|
||||
long len = DictLangCache.getFileLen( context, dal );
|
||||
try {
|
||||
params.put( k_NAME, dal.name );
|
||||
params.put( k_LANG, langStr );
|
||||
params.put( k_LANGCODE, langCode );
|
||||
params.put( k_LANGCODE, isoCode );
|
||||
params.put( k_MD5SUM, sums[0] );
|
||||
params.put( k_FULLSUM, sums[1] );
|
||||
params.put( k_INDEX, index );
|
||||
|
|
|
@ -636,30 +636,27 @@ public class Utils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static Uri makeDictUri( Context context, String langName, String name )
|
||||
public static Uri makeDictUriFromName( Context context,
|
||||
String langName, String dictName )
|
||||
{
|
||||
String isoCode = DictLangCache.getLangIsoCode( context, langName );
|
||||
return makeDictUriFromCode( context, isoCode, dictName );
|
||||
}
|
||||
|
||||
public static Uri makeDictUriFromCode( Context context, String isoCode, String name )
|
||||
{
|
||||
String dictUrl = CommonPrefs.getDefaultDictURL( context );
|
||||
Uri.Builder builder = Uri.parse( dictUrl ).buildUpon();
|
||||
if ( null != langName ) {
|
||||
builder.appendPath( langName );
|
||||
if ( null != isoCode ) {
|
||||
builder.appendPath( isoCode );
|
||||
}
|
||||
if ( null != name ) {
|
||||
Assert.assertNotNull( langName );
|
||||
Assert.assertNotNull( isoCode );
|
||||
builder.appendPath( DictUtils.addDictExtn( name ) );
|
||||
}
|
||||
Uri result = builder.build();
|
||||
// Log.d( TAG, "makeDictUri(langName=%s, name=%s) => %s", langName, name, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Uri makeDictUri( Context context, int lang, String name )
|
||||
{
|
||||
String langName = null;
|
||||
if ( 0 < lang ) {
|
||||
langName = DictLangCache.getLangName( context, lang );
|
||||
}
|
||||
Uri result = makeDictUri( context, langName, name );
|
||||
// Log.d( TAG, "makeDictUri(lang=%d, name=%s) => %s", lang, name, result );
|
||||
DbgUtils.printStack( TAG );
|
||||
Log.d( TAG, "makeDictUriFromCode(isoCode=%s, name=%s) => %s", isoCode, name, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -362,12 +362,17 @@ public class XWPrefs {
|
|||
return getPrefsBoolean( context, R.string.key_studyon, true );
|
||||
}
|
||||
|
||||
protected static String getPrefsString( Context context, int keyID )
|
||||
protected static String getPrefsString( Context context, int keyID, String dflt )
|
||||
{
|
||||
String key = context.getString( keyID );
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences( context );
|
||||
return sp.getString( key, "" );
|
||||
return sp.getString( key, dflt );
|
||||
}
|
||||
|
||||
protected static String getPrefsString( Context context, int keyID )
|
||||
{
|
||||
return getPrefsString( context, keyID, "" );
|
||||
}
|
||||
|
||||
protected static void setPrefsString( Context context, int keyID,
|
||||
|
|
|
@ -156,7 +156,7 @@ abstract class XWServiceHelper {
|
|||
}
|
||||
|
||||
if ( success ) {
|
||||
if ( DictLangCache.haveDict( mContext, nli.lang, nli.dict ) ) {
|
||||
if ( DictLangCache.haveDict( mContext, nli.isoCode, nli.dict ) ) {
|
||||
long rowid = GameUtils.makeNewMultiGame( mContext, nli,
|
||||
getSink( 0 ),
|
||||
getUtilCtxt() );
|
||||
|
|
|
@ -60,7 +60,7 @@ public class CurGameInfo implements Serializable {
|
|||
|
||||
public String dictName;
|
||||
public LocalPlayer[] players;
|
||||
public int dictLang;
|
||||
public String isoCode;
|
||||
public int gameID;
|
||||
public int gameSeconds;
|
||||
public int nPlayers;
|
||||
|
@ -138,7 +138,7 @@ public class CurGameInfo implements Serializable {
|
|||
juggle();
|
||||
}
|
||||
|
||||
setLang( context, 0 );
|
||||
setLang( context, null );
|
||||
}
|
||||
|
||||
public CurGameInfo( CurGameInfo src )
|
||||
|
@ -153,7 +153,7 @@ public class CurGameInfo implements Serializable {
|
|||
players = new LocalPlayer[MAX_NUM_PLAYERS];
|
||||
serverRole = src.serverRole;
|
||||
dictName = src.dictName;
|
||||
dictLang = src.dictLang;
|
||||
isoCode = src.isoCode;
|
||||
hintsNotAllowed = src.hintsNotAllowed;
|
||||
inDuplicateMode = src.inDuplicateMode;
|
||||
phoniesAction = src.phoniesAction;
|
||||
|
@ -246,22 +246,24 @@ public class CurGameInfo implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void setLang( Context context, int lang, String dict )
|
||||
public void setLang( Context context, String isoCode, String dict )
|
||||
{
|
||||
if ( null != dict ) {
|
||||
dictName = dict;
|
||||
}
|
||||
setLang( context, lang );
|
||||
setLang( context, isoCode );
|
||||
}
|
||||
|
||||
public void setLang( Context context, int lang )
|
||||
public void setLang( Context context, String isoCodeNew )
|
||||
{
|
||||
if ( 0 == lang ) {
|
||||
if ( null == isoCodeNew ) {
|
||||
String dictName = CommonPrefs.getDefaultHumanDict( context );
|
||||
lang = DictLangCache.getDictLangCode( context, dictName );
|
||||
isoCodeNew = DictLangCache.getDictISOCode( context, dictName );
|
||||
}
|
||||
if ( dictLang != lang ) {
|
||||
dictLang = lang;
|
||||
Assert.assertTrueNR( null != isoCodeNew );
|
||||
|
||||
if ( ! TextUtils.equals( isoCodeNew, this.isoCode ) ) {
|
||||
isoCode = isoCodeNew;
|
||||
assignDicts( context );
|
||||
}
|
||||
}
|
||||
|
@ -299,7 +301,7 @@ public class CurGameInfo implements Serializable {
|
|||
{
|
||||
boolean matter = nPlayers != other.nPlayers
|
||||
|| serverRole != other.serverRole
|
||||
|| dictLang != other.dictLang
|
||||
|| ! TextUtils.equals(isoCode, other.isoCode)
|
||||
|| boardSize != other.boardSize
|
||||
|| traySize != other.traySize
|
||||
|| bingoMin != other.bingoMin
|
||||
|
@ -331,7 +333,7 @@ public class CurGameInfo implements Serializable {
|
|||
result = null != obj && obj instanceof CurGameInfo;
|
||||
if ( result ) {
|
||||
other = (CurGameInfo)obj;
|
||||
result = dictLang == other.dictLang
|
||||
result = TextUtils.equals( isoCode, other.isoCode)
|
||||
&& gameID == other.gameID
|
||||
&& gameSeconds == other.gameSeconds
|
||||
&& nPlayers == other.nPlayers
|
||||
|
@ -442,7 +444,7 @@ public class CurGameInfo implements Serializable {
|
|||
public void replaceDicts( Context context, String newDict )
|
||||
{
|
||||
String[] dicts =
|
||||
DictLangCache.getHaveLang( context, dictLang );
|
||||
DictLangCache.getHaveLang( context, isoCode );
|
||||
HashSet<String> installed = new HashSet<>( Arrays.asList(dicts) );
|
||||
|
||||
if ( !installed.contains( dictName ) ) {
|
||||
|
@ -461,7 +463,7 @@ public class CurGameInfo implements Serializable {
|
|||
|
||||
public String langName( Context context )
|
||||
{
|
||||
return DictLangCache.getLangName( context, dictLang );
|
||||
return DictLangCache.getLangNameForISOCode( context, isoCode );
|
||||
}
|
||||
|
||||
public String dictName( final LocalPlayer lp )
|
||||
|
@ -586,14 +588,14 @@ public class CurGameInfo implements Serializable {
|
|||
// right language.
|
||||
|
||||
String humanDict =
|
||||
DictLangCache.getBestDefault( context, dictLang, true );
|
||||
DictLangCache.getBestDefault( context, isoCode, true );
|
||||
String robotDict =
|
||||
DictLangCache.getBestDefault( context, dictLang, false );
|
||||
DictLangCache.getBestDefault( context, isoCode, false );
|
||||
|
||||
if ( null == dictName
|
||||
|| ! DictUtils.dictExists( context, dictName )
|
||||
|| dictLang != DictLangCache.getDictLangCode( context,
|
||||
dictName ) ) {
|
||||
|| ! isoCode.equals( DictLangCache.getDictISOCode( context,
|
||||
dictName ) ) ) {
|
||||
dictName = humanDict;
|
||||
}
|
||||
|
||||
|
@ -601,8 +603,8 @@ public class CurGameInfo implements Serializable {
|
|||
LocalPlayer lp = players[ii];
|
||||
|
||||
if ( null != lp.dictName &&
|
||||
dictLang != DictLangCache.getDictLangCode( context,
|
||||
lp.dictName ) ) {
|
||||
!isoCode.equals( DictLangCache.getDictISOCode( context,
|
||||
lp.dictName ) ) ) {
|
||||
lp.dictName = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -295,9 +295,9 @@ public class DUtilCtxt {
|
|||
return msg;
|
||||
}
|
||||
|
||||
public void getDictPath( int lang, String name, String[] path, byte[][] bytes )
|
||||
public void getDictPath( String isoCode, String name, String[] path, byte[][] bytes )
|
||||
{
|
||||
// Log.d( TAG, "getDictPath(%d, %s)", lang, name );
|
||||
// Log.d( TAG, "getDictPath(%s, %s)", isoCode, name );
|
||||
String[] names = { name };
|
||||
DictUtils.DictPairs pairs = DictUtils.openDicts( m_context, names );
|
||||
// Log.d( TAG, "openDicts() => %s", pairs );
|
||||
|
|
|
@ -28,9 +28,9 @@ public class DictInfo {
|
|||
public String fullSum; // md5sum of the whole file
|
||||
|
||||
// set in jni code
|
||||
public int langCode;
|
||||
public int wordCount;
|
||||
public String isoCode;
|
||||
public String langName;
|
||||
public String md5Sum; // internal (skipping header?)
|
||||
|
||||
@Override
|
||||
|
|
|
@ -81,7 +81,7 @@ public class GameSummary implements Serializable {
|
|||
public int gameID;
|
||||
public String[] remoteDevs; // BTAddrs and phone numbers
|
||||
|
||||
public int dictLang;
|
||||
public String isoCode;
|
||||
public DeviceRole serverRole;
|
||||
public int nPacketsPending;
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class GameSummary implements Serializable {
|
|||
public GameSummary( CurGameInfo gi )
|
||||
{
|
||||
nPlayers = gi.nPlayers;
|
||||
dictLang = gi.dictLang;
|
||||
isoCode = gi.isoCode;
|
||||
serverRole = gi.serverRole;
|
||||
gameID = gi.gameID;
|
||||
m_gi = gi;
|
||||
|
@ -127,7 +127,7 @@ public class GameSummary implements Serializable {
|
|||
&& modtime == other.modtime
|
||||
&& created == other.created
|
||||
&& gameID == other.gameID
|
||||
&& dictLang == other.dictLang
|
||||
&& TextUtils.equals( isoCode, other.isoCode)
|
||||
&& nPacketsPending == other.nPacketsPending
|
||||
&& Arrays.equals( scores, other.scores )
|
||||
&& Arrays.equals( m_players, other.m_players )
|
||||
|
|
|
@ -104,7 +104,7 @@ public interface UtilCtxt {
|
|||
void informMove( int turn, String expl, String words );
|
||||
void informUndo();
|
||||
|
||||
void informNetDict( int lang, String oldName, String newName,
|
||||
void informNetDict( String isoCode, String oldName, String newName,
|
||||
String newSum, CurGameInfo.XWPhoniesChoice phonies );
|
||||
|
||||
void informMissing( boolean isServer, CommsConnTypeSet connTypes,
|
||||
|
|
|
@ -217,7 +217,7 @@ public class UtilCtxtImpl implements UtilCtxt {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void informNetDict( int lang, String oldName,
|
||||
public void informNetDict( String isoCode, String oldName,
|
||||
String newName, String newSum,
|
||||
CurGameInfo.XWPhoniesChoice phonies )
|
||||
{
|
||||
|
|
|
@ -277,6 +277,7 @@ public class XwJNI {
|
|||
public static native CommsAddrRec comms_getInitialAddr();
|
||||
public static native String comms_getUUID();
|
||||
public static native String lcToLocale( int lc );
|
||||
public static native boolean haveLocaleToLc( String isoCode, int[] lc );
|
||||
|
||||
// Game methods
|
||||
private static GamePtr initGameJNI( long rowid )
|
||||
|
|
|
@ -202,6 +202,7 @@ public class LocUtils {
|
|||
if ( lang.contains( "-" ) ) {
|
||||
lang = TextUtils.split(lang, "-")[0];
|
||||
}
|
||||
Assert.assertTrueNR( 2 == lang.length() );
|
||||
s_curLang = lang;
|
||||
}
|
||||
return s_curLang;
|
||||
|
|
|
@ -237,30 +237,31 @@
|
|||
<item>@string/loc_downloads</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="languages_map">
|
||||
<item>0</item><item>@string/lang_unknown</item><item>--</item>
|
||||
<item>1</item><item>@string/lang_name_english</item><item>en</item>
|
||||
<item>2</item><item>@string/lang_name_french</item><item>fr</item>
|
||||
<item>3</item><item>@string/lang_name_german</item><item>de</item>
|
||||
<item>4</item><item>@string/lang_name_turkish</item><item>tr</item>
|
||||
<item>5</item><item>@string/lang_name_arabic</item><item>ar</item>
|
||||
<item>6</item><item>@string/lang_name_spanish</item><item>es</item>
|
||||
<item>7</item><item>@string/lang_name_swedish</item><item>sv</item>
|
||||
<item>8</item><item>@string/lang_name_polish</item><item>pl</item>
|
||||
<item>9</item><item>@string/lang_name_danish</item><item>da</item>
|
||||
<item>10</item><item>@string/lang_name_italian</item><item>it</item>
|
||||
<item>11</item><item>@string/lang_name_dutch</item><item>nl</item>
|
||||
<item>12</item><item>@string/lang_name_catalan</item><item>ca</item>
|
||||
<item>13</item><item>@string/lang_name_portuguese</item><item>pt</item>
|
||||
<item>15</item><item>@string/lang_name_russian</item><item>ru</item>
|
||||
<item>17</item><item>@string/lang_name_czech</item><item>cs</item>
|
||||
<item>18</item><item>@string/lang_name_greek</item><item>el</item>
|
||||
<item>19</item><item>@string/lang_name_slovak</item><item>sk</item>
|
||||
<item>20</item><item>@string/lang_name_hungarian</item><item>hu</item>
|
||||
<item>21</item><item>@string/lang_name_romanian</item><item>ro</item>
|
||||
<item>25</item><item>@string/lang_name_finnish</item><item>fi</item>
|
||||
|
||||
<item>127</item><item>Hex</item><item>--</item>
|
||||
<!-- We can function without an entry here for a new language, but
|
||||
only the unlocalized name from the wordlist itself will be
|
||||
displayed. -->
|
||||
<string-array name="language_names">
|
||||
<item>en</item><item>@string/lang_name_english</item>
|
||||
<item>fr</item><item>@string/lang_name_french</item>
|
||||
<item>de</item><item>@string/lang_name_german</item>
|
||||
<item>tr</item><item>@string/lang_name_turkish</item>
|
||||
<item>ar</item><item>@string/lang_name_arabic</item>
|
||||
<item>es</item><item>@string/lang_name_spanish</item>
|
||||
<item>sv</item><item>@string/lang_name_swedish</item>
|
||||
<item>pl</item><item>@string/lang_name_polish</item>
|
||||
<item>da</item><item>@string/lang_name_danish</item>
|
||||
<item>it</item><item>@string/lang_name_italian</item>
|
||||
<item>nl</item><item>@string/lang_name_dutch</item>
|
||||
<item>ca</item><item>@string/lang_name_catalan</item>
|
||||
<item>pt</item><item>@string/lang_name_portuguese</item>
|
||||
<item>ru</item><item>@string/lang_name_russian</item>
|
||||
<item>cs</item><item>@string/lang_name_czech</item>
|
||||
<item>el</item><item>@string/lang_name_greek</item>
|
||||
<item>sk</item><item>@string/lang_name_slovak</item>
|
||||
<item>hu</item><item>@string/lang_name_hungarian</item>
|
||||
<item>ro</item><item>@string/lang_name_romanian</item>
|
||||
<item>fi</item><item>@string/lang_name_finnish</item>
|
||||
<item>hex</item><item>Hex</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Triples of Name, supported codes, and URL format string -->
|
||||
|
|
|
@ -11,7 +11,7 @@ LOCAL_C_INCLUDES+= \
|
|||
LOCAL_LDLIBS += -llog
|
||||
|
||||
ifeq ($(BUILD_TARGET),debug)
|
||||
LOCAL_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING -DCOMMS_CHECKSUM -DNLI_VERSION=1 -Wno-unused-variable
|
||||
LOCAL_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING -DCOMMS_CHECKSUM -Wno-unused-variable
|
||||
endif
|
||||
LOCAL_DEFINES += \
|
||||
$(LOCAL_DEBUG) \
|
||||
|
|
|
@ -762,7 +762,6 @@ jEnumToInt( JNIEnv* env, jobject jenum )
|
|||
|
||||
static const SetInfo nli_ints[] = {
|
||||
ARR_MEMBER( NetLaunchInfo, _conTypes ),
|
||||
ARR_MEMBER( NetLaunchInfo, lang ),
|
||||
ARR_MEMBER( NetLaunchInfo, forceChannel ),
|
||||
ARR_MEMBER( NetLaunchInfo, nPlayersT ),
|
||||
ARR_MEMBER( NetLaunchInfo, nPlayersH ),
|
||||
|
@ -777,6 +776,7 @@ static const SetInfo nli_bools[] = {
|
|||
|
||||
static const SetInfo nli_strs[] = {
|
||||
ARR_MEMBER( NetLaunchInfo, dict ),
|
||||
ARR_MEMBER( NetLaunchInfo, isoCode ),
|
||||
ARR_MEMBER( NetLaunchInfo, gameName ),
|
||||
ARR_MEMBER( NetLaunchInfo, room ),
|
||||
ARR_MEMBER( NetLaunchInfo, btName ),
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef struct _AndDraw {
|
|||
EnvThreadInfo* ti;
|
||||
#endif
|
||||
jobject jdraw; /* global ref; free it! */
|
||||
XP_LangCode curLang;
|
||||
XP_UCHAR curISOCode[MAX_ISO_CODE_LEN+1];
|
||||
jobject jCache[JCACHE_COUNT];
|
||||
jobject jTvType;
|
||||
XP_UCHAR miniTextBuf[128];
|
||||
|
@ -600,13 +600,13 @@ and_draw_dictChanged( DrawCtx* dctx, XWEnv xwe, XP_S16 playerNum,
|
|||
AndDraw* draw = (AndDraw*)dctx;
|
||||
if ( !!dict && !!draw->jdraw ) {
|
||||
XP_LOGFF( "(dict=%p/%s); code=%x", dict, dict_getName(dict), andDictID(dict) );
|
||||
XP_LangCode code = 0; /* A null dict means no-lang */
|
||||
const XP_UCHAR* isoCode = NULL; /* A null dict means no-lang */
|
||||
if ( NULL != dict ) {
|
||||
code = dict_getLangCode( dict );
|
||||
isoCode = dict_getISOCode( dict );
|
||||
}
|
||||
/* Don't bother sending repeats. */
|
||||
if ( code != draw->curLang ) {
|
||||
draw->curLang = code;
|
||||
if ( 0 != XP_STRCMP( isoCode, draw->curISOCode ) ) {
|
||||
XP_STRNCPY( draw->curISOCode, isoCode, VSIZE(draw->curISOCode) );
|
||||
|
||||
DRAW_CBK_HEADER( "dictChanged", "(J)V" );
|
||||
|
||||
|
|
|
@ -245,33 +245,34 @@ and_util_informUndo( XW_UtilCtxt* uc, XWEnv xwe )
|
|||
}
|
||||
|
||||
static void
|
||||
and_util_informNetDict( XW_UtilCtxt* uc, XWEnv xwe, XP_LangCode lang,
|
||||
const XP_UCHAR* oldName,
|
||||
const XP_UCHAR* newName, const XP_UCHAR* newSum,
|
||||
XWPhoniesChoice phoniesAction )
|
||||
and_util_informNetDict( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* isoCode,
|
||||
const XP_UCHAR* oldName, const XP_UCHAR* newName,
|
||||
const XP_UCHAR* newSum, XWPhoniesChoice phoniesAction )
|
||||
{
|
||||
LOG_FUNC();
|
||||
UTIL_CBK_HEADER( "informNetDict",
|
||||
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;L"
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
|
||||
"Ljava/lang/String;L"
|
||||
PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") ";)V" );
|
||||
jstring jIsoCode = (*env)->NewStringUTF( env, isoCode );
|
||||
jstring jnew = (*env)->NewStringUTF( env, newName );
|
||||
jstring jsum = (*env)->NewStringUTF( env, newSum );
|
||||
jstring jold = (*env)->NewStringUTF( env, oldName );
|
||||
jobject jphon = intToJEnum( env, phoniesAction,
|
||||
PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") );
|
||||
|
||||
(*env)->CallVoidMethod( env, util->jutil, mid, lang, jold, jnew, jsum,
|
||||
(*env)->CallVoidMethod( env, util->jutil, mid, jIsoCode, jold, jnew, jsum,
|
||||
jphon );
|
||||
deleteLocalRefs( env, jnew, jold, jsum, jphon, DELETE_NO_REF );
|
||||
deleteLocalRefs( env, jnew, jold, jsum, jphon, jIsoCode, DELETE_NO_REF );
|
||||
|
||||
UTIL_CBK_TAIL();
|
||||
}
|
||||
|
||||
const DictionaryCtxt*
|
||||
and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
|
||||
XP_LangCode lang, const XP_UCHAR* dictName )
|
||||
const XP_UCHAR* isoCode, const XP_UCHAR* dictName )
|
||||
{
|
||||
XP_LOGFF( "(lang: %d, name: %s)", lang, dictName );
|
||||
XP_LOGFF( "(isoCode: %s, name: %s)", isoCode, dictName );
|
||||
JNIEnv* env = xwe;
|
||||
XW_DUtilCtxt* duc = util_getDevUtilCtxt( uc, xwe );
|
||||
|
||||
|
@ -280,12 +281,14 @@ and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
|
|||
dmgr_get( dictMgr, xwe, dictName );
|
||||
if ( !dict ) {
|
||||
jstring jname = (*env)->NewStringUTF( env, dictName );
|
||||
jstring jISOCode = (*env)->NewStringUTF( env, isoCode );
|
||||
|
||||
jobjectArray jstrs = makeStringArray( env, 1, NULL );
|
||||
jobjectArray jbytes = makeByteArrayArray( env, 1 );
|
||||
|
||||
DUTIL_CBK_HEADER( "getDictPath", "(ILjava/lang/String;[Ljava/lang/String;[[B)V" );
|
||||
(*env)->CallVoidMethod( env, dutil->jdutil, mid, lang, jname, jstrs, jbytes );
|
||||
DUTIL_CBK_HEADER( "getDictPath",
|
||||
"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[[B)V" );
|
||||
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jISOCode, jname, jstrs, jbytes );
|
||||
DUTIL_CBK_TAIL();
|
||||
|
||||
jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 );
|
||||
|
@ -295,7 +298,7 @@ and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
|
|||
TI_IF(&globalState->ti)
|
||||
dictMgr, ((AndDUtil*)duc)->jniutil,
|
||||
jname, jdata, jpath, NULL, false );
|
||||
deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, DELETE_NO_REF );
|
||||
deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, jISOCode, DELETE_NO_REF );
|
||||
}
|
||||
LOG_RETURNF( "%p", dict );
|
||||
return dict;
|
||||
|
|
|
@ -424,7 +424,6 @@ static const SetInfo gi_ints[] = {
|
|||
,ARR_MEMBER( CurGameInfo, traySize )
|
||||
,ARR_MEMBER( CurGameInfo, bingoMin )
|
||||
,ARR_MEMBER( CurGameInfo, gameID )
|
||||
,ARR_MEMBER( CurGameInfo, dictLang )
|
||||
,ARR_MEMBER( CurGameInfo, forceChannel )
|
||||
};
|
||||
|
||||
|
@ -469,6 +468,8 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi )
|
|||
|
||||
getString( env, jgi, "dictName", AANDS(buf) );
|
||||
gi->dictName = copyString( mpool, buf );
|
||||
getString( env, jgi, "isoCode", AANDS(buf) );
|
||||
XP_STRNCPY( gi->isoCode, buf, VSIZE(gi->isoCode) );
|
||||
|
||||
XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS );
|
||||
|
||||
|
@ -511,6 +512,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
|
|||
setBools( env, jgi, (void*)gi, AANDS(gi_bools) );
|
||||
|
||||
setString( env, jgi, "dictName", gi->dictName );
|
||||
setString( env, jgi, "isoCode", gi->isoCode );
|
||||
|
||||
intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction",
|
||||
PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") );
|
||||
|
@ -995,12 +997,25 @@ Java_org_eehouse_android_xw4_jni_XwJNI_lcToLocale
|
|||
const XP_UCHAR* locale = lcToLocale( lc );
|
||||
if ( !!locale ) {
|
||||
result = (*env)->NewStringUTF( env, locale );
|
||||
} else {
|
||||
XP_LOGFF( "(%d) => NULL", lc );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_haveLocaleToLc
|
||||
( JNIEnv* env, jclass C, jstring jIsoCode, jintArray jOutArray )
|
||||
{
|
||||
XP_ASSERT( !!jIsoCode );
|
||||
XP_LangCode lc;
|
||||
const char* isoCode = (*env)->GetStringUTFChars( env, jIsoCode, NULL );
|
||||
jboolean result = haveLocaleToLc( isoCode, &lc );
|
||||
if ( result ) {
|
||||
setIntInArray( env, jOutArray, 0, lc );
|
||||
}
|
||||
(*env)->ReleaseStringUTFChars( env, jIsoCode, isoCode );
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1make
|
||||
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jbyteArray jDictBytes,
|
||||
|
@ -1151,11 +1166,10 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
|
|||
DictionaryCtxt* dict = (DictionaryCtxt*)dictPtr;
|
||||
if ( NULL != dict ) {
|
||||
jinfo = makeObjectEmptyConst( env, PKG_PATH("jni/DictInfo") );
|
||||
XP_LangCode code = dict_getLangCode( dict );
|
||||
setInt( env, jinfo, "langCode", code );
|
||||
setInt( env, jinfo, "wordCount", dict_getWordCount( dict, env ) );
|
||||
setString( env, jinfo, "md5Sum", dict_getMd5Sum( dict ) );
|
||||
setString( env, jinfo, "isoCode", dict_getISOCode( dict ) );
|
||||
setString( env, jinfo, "langName", dict_getLangName( dict ) );
|
||||
}
|
||||
|
||||
return jinfo;
|
||||
|
|
Loading…
Reference in a new issue