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
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 )
{
jstring result;
XWJNI_START_GLOBALS();
XP_ASSERT( !!state->game.server );
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 );
(*env)->DeleteLocalRef( env, result );
stream_destroy( stream );
@ -1271,7 +1270,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1listWordsPlayed
return result;
}
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1sendChat
( JNIEnv* env, jclass C, jint gamePtr, jstring jmsg )

View file

@ -5,6 +5,21 @@
android:layout_height="wrap_content"
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"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

View file

@ -84,9 +84,6 @@
<string name="app_version">4.4 beta 34</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. -->
<string name="advanced">For debugging</string>
<string name="advanced_summary">You should never need these...</string>
@ -152,19 +149,19 @@
<string-array name="language_names">
<item></item> <!-- Unknown -->
<item>English</item>
<item>French</item>
<item>German</item>
<item>Turkish</item>
<item>Arabic</item>
<item>Spanish</item>
<item>Swedish</item>
<item>Polish</item>
<item>Danish</item>
<item>Italian</item>
<item>Dutch</item>
<item>Catalan</item>
<item>Portuguese</item>
<item>English</item> <!-- 1 -->
<item>French</item> <!-- 2 -->
<item>German</item> <!-- 3 -->
<item>Turkish</item> <!-- 4 -->
<item>Arabic</item> <!-- 5 -->
<item>Spanish</item> <!-- 6 -->
<item>Swedish</item> <!-- 7 -->
<item>Polish</item> <!-- 8 -->
<item>Danish</item> <!-- 9 -->
<item>Italian</item> <!-- A -->
<item>Dutch</item> <!-- B -->
<item>Catalan</item> <!-- C -->
<item>Portuguese</item> <!-- D -->
<item></item> <!-- E -->
<item>Russian</item>
<item></item> <!-- 10 -->
@ -173,6 +170,45 @@
<item>Slovak</item>
</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">
<item>@string/game_summary_field_empty</item>
<item>@string/game_summary_field_language</item>

View file

@ -1769,5 +1769,9 @@
<string name="title_lookup">Tap to lookup</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>

View file

@ -48,10 +48,12 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import junit.framework.Assert;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.pm.ActivityInfo;
import android.net.Uri;
@ -143,6 +145,10 @@ public class BoardActivity extends XWActivity
private String m_room;
private String m_toastStr;
private String[] m_words;
private String[] m_langCodes;
private String[] m_lookupUrls;
private String[] m_lookupNames;
private int m_missing;
private boolean m_haveInvited = false;
@ -242,15 +248,13 @@ public class BoardActivity extends XWActivity
};
ab.setNegativeButton( R.string.button_no, lstnr );
} else if ( DLG_SCORES_BLK == id ) {
if ( curLangSupported() ) {
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog,
int whichButton ) {
m_jniThread.handle( JNICmd.CMD_WORDS );
}
};
ab.setNegativeButton( R.string.button_lookup, lstnr );
}
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog,
int whichButton ) {
m_jniThread.handle( JNICmd.CMD_WORDS );
}
};
ab.setNegativeButton( R.string.button_lookup, lstnr );
}
dialog = ab.create();
@ -322,26 +326,9 @@ public class BoardActivity extends XWActivity
}
break;
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 )
.setTitle( R.string.title_lookup )
.setView( layout )
.setView( buildLookupDlg() )
.setNegativeButton( R.string.button_done, null )
.create();
Utils.setRemoveOnDismiss( this, dialog, id );
@ -1284,8 +1271,8 @@ public class BoardActivity extends XWActivity
TextUtils.split( (String)msg.obj, "\n" );
if ( 0 == m_words.length ) {
// drop it
} else if ( 1 == m_words.length ) {
lookupWord( m_words[0] );
// } else if ( 1 == m_words.length ) {
// lookupWord( m_words[0] );
} else {
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 );
Uri uri = Uri.parse( dict_url );
Intent intent = new Intent( Intent.ACTION_VIEW, uri );
@ -1579,22 +1599,31 @@ public class BoardActivity extends XWActivity
private String curLangCode()
{
// from string-array name="language_names" in common_rsrc.xml
switch( m_gi.dictLang ) {
case 1:
return "en";
case 2:
return "fr";
case 3:
return "de";
default:
return null;
initLookup();
return m_langCodes[m_gi.dictLang];
}
private void initLookup()
{
if ( null == m_langCodes ) {
Resources res = getResources();
m_langCodes = res.getStringArray( R.array.language_codes );
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

View file

@ -493,7 +493,7 @@ public class JNIThread extends Thread {
break;
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();
break;

View file

@ -209,7 +209,10 @@ public class XwJNI {
public static native String model_writeGameHistory( int gamePtr,
boolean gameOver );
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
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_endGame( int gamePtr );
public static native void server_sendChat( int gamePtr, String msg );
public static native String server_listWordsPlayed( int gamePtr,
int nMoves );
// hybrid to save work
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
* reserved.
@ -2170,12 +2170,10 @@ sendNoConn( CommsCtxt* comms, const MsgQueueElem* elem, XWHostID destID )
destID, elem->msg, elem->len );
if ( NULL != stream ) {
XP_U16 len = stream_getSize( stream );
XP_U8* buf = XP_MALLOC( comms->mpool, len );
if ( buf != NULL ) {
stream_getBytes( stream, buf, len );
success = (*comms->procs.sendNoConn)( buf, len, relayID,
if ( 0 < len ) {
success = (*comms->procs.sendNoConn)( stream_getPtr( stream ),
len, relayID,
comms->procs.closure );
XP_FREE( comms->mpool, buf );
}
stream_destroy( stream );
}

View file

@ -2052,9 +2052,8 @@ recordWord( const XP_UCHAR* word, XP_Bool isLegal, void* closure )
return XP_TRUE;
}
XP_Bool
model_getWordsPlayed( ModelCtxt* model, PoolContext* pool,
XP_U16 nTurns, XWStreamCtxt* stream )
void
model_getWordsPlayed( ModelCtxt* model, XP_U16 nTurns, XWStreamCtxt* stream )
{
XP_ASSERT( !!stream );
StackCtxt* stack = model->vol.stack;
@ -2067,7 +2066,7 @@ model_getWordsPlayed( ModelCtxt* model, PoolContext* pool,
nTurns = nEntries;
}
if ( model_undoLatestMoves( model, pool, nTurns, NULL, NULL ) ) {
if ( model_undoLatestMoves( model, NULL, nTurns, NULL, NULL ) ) {
RecordWordsInfo info = { .stream = stream, .nWords = 0 };
WordNotifierInfo notifyInfo = { .proc = recordWord,
.closure = &info,
@ -2083,7 +2082,6 @@ model_getWordsPlayed( ModelCtxt* model, PoolContext* pool,
NULL );
}
stack_destroy( tmpStack );
return XP_TRUE;
}
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_UCHAR* expl, XP_U16* explLen );
XP_Bool model_getWordsPlayed( ModelCtxt* model, PoolContext* pool,
XP_U16 nTurns, XWStreamCtxt* stream );
void model_getWordsPlayed( ModelCtxt* model, XP_U16 nTurns,
XWStreamCtxt* stream );
/* Have there been too many passes (so game should end)? */
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.
*
@ -36,6 +36,13 @@ struct PoolContext {
MPSLOT
};
#ifdef DEBUG
static void checkTilesLeft( const PoolContext* pool );
#else
# define checkTilesLeft( pool )
#endif
PoolContext*
pool_make( MPFORMAL_NOCOMMA )
{
@ -247,5 +254,18 @@ pool_initFromDict( PoolContext* pool, DictionaryCtxt* dict )
pool->blankIndex = -1;
}
#endif
checkTilesLeft( pool );
} /* 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 */
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
void
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,
XP_S16 player );
void server_listWordsPlayed( ServerCtxt* server, XWStreamCtxt* stream,
XP_U16 nMoves );
void server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream );
#ifdef CPLUS

View file

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