Merge branch 'send_in_background' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into send_in_background

This commit is contained in:
eehouse@eehouse.org 2011-09-30 06:39:23 -07:00 committed by Andy2
commit 554e497593
14 changed files with 184 additions and 94 deletions

View file

@ -1256,14 +1256,13 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1endGame
} }
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1listWordsPlayed Java_org_eehouse_android_xw4_jni_XwJNI_model_1getWordsPlayed
( JNIEnv* env, jclass C, jint gamePtr, jint nMoves ) ( JNIEnv* env, jclass C, jint gamePtr, jint nMoves )
{ {
jstring result; jstring result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
XP_ASSERT( !!state->game.server );
XWStreamCtxt* stream = and_empty_stream( MPPARM(mpool) globals ); XWStreamCtxt* stream = and_empty_stream( MPPARM(mpool) globals );
server_listWordsPlayed( state->game.server, stream, nMoves ); model_getWordsPlayed( state->game.model, nMoves, stream );
result = streamToJString( MPPARM(mpool) env, stream ); result = streamToJString( MPPARM(mpool) env, stream );
(*env)->DeleteLocalRef( env, result ); (*env)->DeleteLocalRef( env, result );
stream_destroy( stream ); stream_destroy( stream );
@ -1271,7 +1270,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1listWordsPlayed
return result; return result;
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1sendChat Java_org_eehouse_android_xw4_jni_XwJNI_server_1sendChat
( JNIEnv* env, jclass C, jint gamePtr, jstring jmsg ) ( JNIEnv* env, jclass C, jint gamePtr, jstring jmsg )

View file

@ -5,6 +5,21 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<TextView style="@style/config_separator"
android:text="@string/site_spinner_label"
/>
<Spinner android:id="@+id/site_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/site_spinner_prompt"
/>
<TextView style="@style/config_separator"
android:text="@string/word_list_label"
/>
<ListView android:id="@+id/words" <ListView android:id="@+id/words"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View file

@ -84,9 +84,6 @@
<string name="app_version">4.4 beta 34</string> <string name="app_version">4.4 beta 34</string>
<string name="game_url_pathf">//%1$s/newgame.php</string> <string name="game_url_pathf">//%1$s/newgame.php</string>
<!-- <string name="word_lookupf">http://dictionary.com/browse/%s</string> -->
<string name="word_lookupf">http://%1$s.thefreedictionary.com/_/dict.aspx?word=%2$s</string>
<!-- Debugging stuff. No point in localizing it. --> <!-- Debugging stuff. No point in localizing it. -->
<string name="advanced">For debugging</string> <string name="advanced">For debugging</string>
<string name="advanced_summary">You should never need these...</string> <string name="advanced_summary">You should never need these...</string>
@ -152,19 +149,19 @@
<string-array name="language_names"> <string-array name="language_names">
<item></item> <!-- Unknown --> <item></item> <!-- Unknown -->
<item>English</item> <item>English</item> <!-- 1 -->
<item>French</item> <item>French</item> <!-- 2 -->
<item>German</item> <item>German</item> <!-- 3 -->
<item>Turkish</item> <item>Turkish</item> <!-- 4 -->
<item>Arabic</item> <item>Arabic</item> <!-- 5 -->
<item>Spanish</item> <item>Spanish</item> <!-- 6 -->
<item>Swedish</item> <item>Swedish</item> <!-- 7 -->
<item>Polish</item> <item>Polish</item> <!-- 8 -->
<item>Danish</item> <item>Danish</item> <!-- 9 -->
<item>Italian</item> <item>Italian</item> <!-- A -->
<item>Dutch</item> <item>Dutch</item> <!-- B -->
<item>Catalan</item> <item>Catalan</item> <!-- C -->
<item>Portuguese</item> <item>Portuguese</item> <!-- D -->
<item></item> <!-- E --> <item></item> <!-- E -->
<item>Russian</item> <item>Russian</item>
<item></item> <!-- 10 --> <item></item> <!-- 10 -->
@ -173,6 +170,45 @@
<item>Slovak</item> <item>Slovak</item>
</string-array> </string-array>
<string-array name="language_codes">
<item></item>
<item>en</item>
<item>fr</item>
<item>de</item>
<item></item>
<item></item>
<item>es</item>
<item></item>
<item></item>
<item></item>
<item>it</item>
<item></item>
<item>ca</item>
<item></item>
<item></item>
<item></item>
<item></item>
<item></item>
<item></item>
<item></item>
</string-array>
<!-- Triples of Name, supported codes, and URL format string -->
<string-array name="lookup_urls">
<!-- -->
<item>Dictionary.com</item>
<item>:en:</item> <!-- means all supported -->
<item>http://dictionary.com/browse/%2$s</item> -->
<!-- -->
<item>TheFreeDictionary.com</item>
<item>:en:es:</item> <!-- means all supported -->
<item>http://%1$s.thefreedictionary.com/_/dict.aspx?word=%2$s</item>
<!-- -->
<item>Google</item>
<item></item> <!-- means all supported -->
<item>http://www.google.com/search?nl=%1$s\u0026q=%2$s</item>
</string-array>
<string-array name="game_summary_values"> <string-array name="game_summary_values">
<item>@string/game_summary_field_empty</item> <item>@string/game_summary_field_empty</item>
<item>@string/game_summary_field_language</item> <item>@string/game_summary_field_language</item>

View file

@ -1769,5 +1769,9 @@
<string name="title_lookup">Tap to lookup</string> <string name="title_lookup">Tap to lookup</string>
<string name="button_done">Done</string> <string name="button_done">Done</string>
<string name="site_spinner_label">Pick a site</string>
<string name="site_spinner_prompt">Pick a site</string>
<string name="word_list_label">Tap word to search</string>
</resources> </resources>

View file

@ -48,10 +48,12 @@ import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import junit.framework.Assert; import junit.framework.Assert;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.net.Uri; import android.net.Uri;
@ -143,6 +145,10 @@ public class BoardActivity extends XWActivity
private String m_room; private String m_room;
private String m_toastStr; private String m_toastStr;
private String[] m_words; private String[] m_words;
private String[] m_langCodes;
private String[] m_lookupUrls;
private String[] m_lookupNames;
private int m_missing; private int m_missing;
private boolean m_haveInvited = false; private boolean m_haveInvited = false;
@ -242,15 +248,13 @@ public class BoardActivity extends XWActivity
}; };
ab.setNegativeButton( R.string.button_no, lstnr ); ab.setNegativeButton( R.string.button_no, lstnr );
} else if ( DLG_SCORES_BLK == id ) { } else if ( DLG_SCORES_BLK == id ) {
if ( curLangSupported() ) { lstnr = new DialogInterface.OnClickListener() {
lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog,
public void onClick( DialogInterface dialog, int whichButton ) {
int whichButton ) { m_jniThread.handle( JNICmd.CMD_WORDS );
m_jniThread.handle( JNICmd.CMD_WORDS ); }
} };
}; ab.setNegativeButton( R.string.button_lookup, lstnr );
ab.setNegativeButton( R.string.button_lookup, lstnr );
}
} }
dialog = ab.create(); dialog = ab.create();
@ -322,26 +326,9 @@ public class BoardActivity extends XWActivity
} }
break; break;
case DLG_WORDPICK: case DLG_WORDPICK:
LinearLayout layout =
(LinearLayout)Utils.inflate( this, R.layout.wordlist_view );
ListView list = (ListView)layout.findViewById( R.id.words );
ArrayAdapter<String> adapter =
new ArrayAdapter<String>( this,
//android.R.layout.select_dialog_item,
android.R.layout.simple_list_item_1,
m_words ) ;
list.setAdapter( adapter );
OnItemClickListener oicl = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view,
int position, long id ) {
lookupWord( m_words[position] );
}
};
list.setOnItemClickListener( oicl );
dialog = new AlertDialog.Builder( this ) dialog = new AlertDialog.Builder( this )
.setTitle( R.string.title_lookup ) .setTitle( R.string.title_lookup )
.setView( layout ) .setView( buildLookupDlg() )
.setNegativeButton( R.string.button_done, null ) .setNegativeButton( R.string.button_done, null )
.create(); .create();
Utils.setRemoveOnDismiss( this, dialog, id ); Utils.setRemoveOnDismiss( this, dialog, id );
@ -1284,8 +1271,8 @@ public class BoardActivity extends XWActivity
TextUtils.split( (String)msg.obj, "\n" ); TextUtils.split( (String)msg.obj, "\n" );
if ( 0 == m_words.length ) { if ( 0 == m_words.length ) {
// drop it // drop it
} else if ( 1 == m_words.length ) { // } else if ( 1 == m_words.length ) {
lookupWord( m_words[0] ); // lookupWord( m_words[0] );
} else { } else {
showDialog( DLG_WORDPICK ); showDialog( DLG_WORDPICK );
} }
@ -1562,9 +1549,42 @@ public class BoardActivity extends XWActivity
} }
} }
private void lookupWord( String word ) private View buildLookupDlg()
{
initLookup();
LinearLayout layout =
(LinearLayout)Utils.inflate( this, R.layout.wordlist_view );
final Spinner spinner =
(Spinner)layout.findViewById( R.id.site_spinner );
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
m_lookupNames );
spinner.setAdapter( adapter );
ListView list = (ListView)layout.findViewById( R.id.words );
adapter = new ArrayAdapter<String>( this,
//android.R.layout.select_dialog_item,
// android.R.layout.simple_list_item_1,
android.R.layout.select_dialog_item,
m_words ) ;
list.setAdapter( adapter );
OnItemClickListener oicl = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view,
int position, long id ) {
int urlPos = spinner.getSelectedItemPosition();
lookupWord( m_words[position], m_lookupUrls[urlPos] );
}
};
list.setOnItemClickListener( oicl );
return layout;
}
private void lookupWord( String word, String fmt )
{ {
String fmt = getString( R.string.word_lookupf );
String dict_url = String.format( fmt, curLangCode(), word ); String dict_url = String.format( fmt, curLangCode(), word );
Uri uri = Uri.parse( dict_url ); Uri uri = Uri.parse( dict_url );
Intent intent = new Intent( Intent.ACTION_VIEW, uri ); Intent intent = new Intent( Intent.ACTION_VIEW, uri );
@ -1579,22 +1599,31 @@ public class BoardActivity extends XWActivity
private String curLangCode() private String curLangCode()
{ {
// from string-array name="language_names" in common_rsrc.xml initLookup();
switch( m_gi.dictLang ) { return m_langCodes[m_gi.dictLang];
case 1: }
return "en";
case 2: private void initLookup()
return "fr"; {
case 3: if ( null == m_langCodes ) {
return "de"; Resources res = getResources();
default: m_langCodes = res.getStringArray( R.array.language_codes );
return null;
String[] urls = res.getStringArray( R.array.lookup_urls );
ArrayList<String> tmpUrls = new ArrayList<String>();
ArrayList<String> tmpNames = new ArrayList<String>();
String langCode =
String.format( ":%s:", m_langCodes[m_gi.dictLang] );
for ( int ii = 0; ii < urls.length; ii += 3 ) {
String codes = urls[ii+1];
if ( 0 == codes.length() || codes.contains( langCode ) ) {
tmpNames.add( urls[ii] );
tmpUrls.add( urls[ii+2] );
}
}
m_lookupNames = tmpNames.toArray( new String[tmpNames.size()] );
m_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] );
} }
} }
private boolean curLangSupported()
{
return null != curLangCode();
}
} // class BoardActivity } // class BoardActivity

View file

@ -493,7 +493,7 @@ public class JNIThread extends Thread {
break; break;
case CMD_WORDS: case CMD_WORDS:
String words = XwJNI.server_listWordsPlayed( m_jniGamePtr, 1 ); String words = XwJNI.model_getWordsPlayed( m_jniGamePtr, 1 );
Message.obtain( m_handler, GOT_WORDS, words ).sendToTarget(); Message.obtain( m_handler, GOT_WORDS, words ).sendToTarget();
break; break;

View file

@ -209,7 +209,10 @@ public class XwJNI {
public static native String model_writeGameHistory( int gamePtr, public static native String model_writeGameHistory( int gamePtr,
boolean gameOver ); boolean gameOver );
public static native int model_getNMoves( int gamePtr ); public static native int model_getNMoves( int gamePtr );
public static native String model_getPlayersLastScore( int gamePtr, int player ); public static native String model_getPlayersLastScore( int gamePtr,
int player );
public static native String model_getWordsPlayed( int gamePtr,
int nTurns );
// Server // Server
public static native void server_reset( int gamePtr ); public static native void server_reset( int gamePtr );
@ -221,8 +224,6 @@ public class XwJNI {
public static native void server_initClientConnection( int gamePtr ); public static native void server_initClientConnection( int gamePtr );
public static native void server_endGame( int gamePtr ); public static native void server_endGame( int gamePtr );
public static native void server_sendChat( int gamePtr, String msg ); public static native void server_sendChat( int gamePtr, String msg );
public static native String server_listWordsPlayed( int gamePtr,
int nMoves );
// hybrid to save work // hybrid to save work
public static native boolean board_server_prefsChanged( int gamePtr, public static native boolean board_server_prefsChanged( int gamePtr,

View file

@ -1,4 +1,4 @@
/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE"; -*- */ /* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */
/* /*
* Copyright 2001-2011 by Eric House (xwords@eehouse.org). All rights * Copyright 2001-2011 by Eric House (xwords@eehouse.org). All rights
* reserved. * reserved.
@ -2170,12 +2170,10 @@ sendNoConn( CommsCtxt* comms, const MsgQueueElem* elem, XWHostID destID )
destID, elem->msg, elem->len ); destID, elem->msg, elem->len );
if ( NULL != stream ) { if ( NULL != stream ) {
XP_U16 len = stream_getSize( stream ); XP_U16 len = stream_getSize( stream );
XP_U8* buf = XP_MALLOC( comms->mpool, len ); if ( 0 < len ) {
if ( buf != NULL ) { success = (*comms->procs.sendNoConn)( stream_getPtr( stream ),
stream_getBytes( stream, buf, len ); len, relayID,
success = (*comms->procs.sendNoConn)( buf, len, relayID,
comms->procs.closure ); comms->procs.closure );
XP_FREE( comms->mpool, buf );
} }
stream_destroy( stream ); stream_destroy( stream );
} }

View file

@ -2052,9 +2052,8 @@ recordWord( const XP_UCHAR* word, XP_Bool isLegal, void* closure )
return XP_TRUE; return XP_TRUE;
} }
XP_Bool void
model_getWordsPlayed( ModelCtxt* model, PoolContext* pool, model_getWordsPlayed( ModelCtxt* model, XP_U16 nTurns, XWStreamCtxt* stream )
XP_U16 nTurns, XWStreamCtxt* stream )
{ {
XP_ASSERT( !!stream ); XP_ASSERT( !!stream );
StackCtxt* stack = model->vol.stack; StackCtxt* stack = model->vol.stack;
@ -2067,7 +2066,7 @@ model_getWordsPlayed( ModelCtxt* model, PoolContext* pool,
nTurns = nEntries; nTurns = nEntries;
} }
if ( model_undoLatestMoves( model, pool, nTurns, NULL, NULL ) ) { if ( model_undoLatestMoves( model, NULL, nTurns, NULL, NULL ) ) {
RecordWordsInfo info = { .stream = stream, .nWords = 0 }; RecordWordsInfo info = { .stream = stream, .nWords = 0 };
WordNotifierInfo notifyInfo = { .proc = recordWord, WordNotifierInfo notifyInfo = { .proc = recordWord,
.closure = &info, .closure = &info,
@ -2083,7 +2082,6 @@ model_getWordsPlayed( ModelCtxt* model, PoolContext* pool,
NULL ); NULL );
} }
stack_destroy( tmpStack ); stack_destroy( tmpStack );
return XP_TRUE;
} }
XP_Bool XP_Bool

View file

@ -252,8 +252,8 @@ XP_S16 model_getPlayerScore( ModelCtxt* model, XP_S16 player );
XP_Bool model_getPlayersLastScore( ModelCtxt* model, XP_S16 player, XP_Bool model_getPlayersLastScore( ModelCtxt* model, XP_S16 player,
XP_UCHAR* expl, XP_U16* explLen ); XP_UCHAR* expl, XP_U16* explLen );
XP_Bool model_getWordsPlayed( ModelCtxt* model, PoolContext* pool, void model_getWordsPlayed( ModelCtxt* model, XP_U16 nTurns,
XP_U16 nTurns, XWStreamCtxt* stream ); XWStreamCtxt* stream );
/* Have there been too many passes (so game should end)? */ /* Have there been too many passes (so game should end)? */
XP_Bool model_recentPassCountOk( ModelCtxt* model ); XP_Bool model_recentPassCountOk( ModelCtxt* model );

View file

@ -1,4 +1,4 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* -*- compile-command: "cd ../linux && make -j3 MEMDEBUG=TRUE"; -*- */
/* /*
* Copyright 2000 by Eric House (xwords@eehouse.org). All rights reserved. * Copyright 2000 by Eric House (xwords@eehouse.org). All rights reserved.
* *
@ -36,6 +36,13 @@ struct PoolContext {
MPSLOT MPSLOT
}; };
#ifdef DEBUG
static void checkTilesLeft( const PoolContext* pool );
#else
# define checkTilesLeft( pool )
#endif
PoolContext* PoolContext*
pool_make( MPFORMAL_NOCOMMA ) pool_make( MPFORMAL_NOCOMMA )
{ {
@ -247,5 +254,18 @@ pool_initFromDict( PoolContext* pool, DictionaryCtxt* dict )
pool->blankIndex = -1; pool->blankIndex = -1;
} }
#endif #endif
checkTilesLeft( pool );
} /* pool_initFromDict */ } /* pool_initFromDict */
#ifdef DEBUG
static void
checkTilesLeft( const PoolContext* pool )
{
XP_U16 ii, count;
for ( count = 0, ii = 0; ii < pool->numFaces; ++ii ) {
count += pool->lettersLeft[ii];
}
XP_ASSERT( count == pool->numTilesLeft );
}
#endif

View file

@ -2637,12 +2637,6 @@ server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
} }
} /* server_formatRemainingTiles */ } /* server_formatRemainingTiles */
void
server_listWordsPlayed( ServerCtxt* server, XWStreamCtxt* stream, XP_U16 nMoves )
{
(void)model_getWordsPlayed( server->vol.model, server->pool, nMoves, stream );
}
#define IMPOSSIBLY_LOW_SCORE -1000 #define IMPOSSIBLY_LOW_SCORE -1000
void void
server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream ) server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream )

View file

@ -124,9 +124,6 @@ void server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,
void server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream, void server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
XP_S16 player ); XP_S16 player );
void server_listWordsPlayed( ServerCtxt* server, XWStreamCtxt* stream,
XP_U16 nMoves );
void server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream ); void server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream );
#ifdef CPLUS #ifdef CPLUS

View file

@ -1714,7 +1714,7 @@ gtk_util_playerScoreHeld( XW_UtilCtxt* uc, XP_U16 player )
XWStreamCtxt* stream = XWStreamCtxt* stream =
mem_stream_make( MEMPOOL globals->cGlobals.params->vtMgr, globals, mem_stream_make( MEMPOOL globals->cGlobals.params->vtMgr, globals,
CHANNEL_NONE, catOnClose ); CHANNEL_NONE, catOnClose );
server_listWordsPlayed( globals->cGlobals.game.server, stream, 1000 ); (void)model_getWordsPlayed( globals->cGlobals.game.model, 1000, stream );
stream_destroy( stream ); stream_destroy( stream );
#else #else