implement phonies: add jni->java for util_warnIllegalWord, jni changes

to preserve the field in CurGameInfo, and java changes to keep
correct text in reused dialogs.
This commit is contained in:
eehouse 2010-02-24 04:29:46 +00:00
parent 3fd42f8510
commit 8de2665642
4 changed files with 71 additions and 11 deletions

View file

@ -307,8 +307,16 @@ static XP_Bool
and_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
XP_U16 turn, XP_Bool turnLost )
{
LOG_FUNC();
return XP_FALSE;
jboolean result = XP_FALSE;
UTIL_CBK_HEADER("warnIllegalWord", "([Ljava/lang/String;IZ)Z" );
jobjectArray jwords = makeStringArray( env, bwi->nWords,
(const XP_UCHAR**)bwi->words );
result = (*env)->CallBooleanMethod( env, util->jutil, mid,
jwords, turn, turnLost );
(*env)->DeleteLocalRef( env, jwords );
UTIL_CBK_TAIL();
return result;
}

View file

@ -34,6 +34,9 @@ makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
gi->allowPickTiles = getBool( env, j_gi, "allowPickTiles" );
gi->allowHintRect = getBool( env, j_gi, "allowHintRect" );
gi->phoniesAction = jenumFieldToInt( env, j_gi, "phoniesAction",
"org/eehouse/android/xw4/jni/"
"CurGameInfo$XWPhoniesChoice");
gi->serverRole =
jenumFieldToInt( env, j_gi, "serverRole",
"org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole");
@ -86,9 +89,10 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
setBool( env, jgi, "hintsNotAllowed", gi->hintsNotAllowed );
setBool( env, jgi, "timerEnabled", gi->timerEnabled );
setBool( env, jgi, "allowPickTiles", gi->allowPickTiles );
setBool( env, jgi, "allowHintRect", gi->allowHintRect );
setString( env, jgi, "dictName", gi->dictName );
intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction",
"org/eehouse/android/xw4/jni/CurGameInfo$XWPhoniesChoice" );
intToJenumField( env, jgi, gi->serverRole, "serverRole",
"org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole" );

View file

@ -33,8 +33,9 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
public class BoardActivity extends Activity implements UtilCtxt {
private static final int DLG_OKONLY = 1;
private static final int QUERY_REQUEST_BLK = 2;
private static final int PICK_TILE_REQUEST_BLK = 3;
private static final int DLG_BADWORDS = 2;
private static final int QUERY_REQUEST_BLK = 3;
private static final int PICK_TILE_REQUEST_BLK = 4;
private BoardView m_view;
private int m_jniGamePtr;
@ -83,6 +84,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
switch ( id ) {
case DLG_OKONLY:
case DLG_BADWORDS:
dialog = new AlertDialog.Builder( BoardActivity.this )
//.setIcon( R.drawable.alert_dialog_icon )
.setTitle( m_dlgTitle )
@ -142,9 +144,13 @@ public class BoardActivity extends Activity implements UtilCtxt {
protected void onPrepareDialog( int id, Dialog dialog )
{
Utils.logf( "onPrepareDialog(id=" + id + ")" );
if ( DLG_OKONLY == id ) {
switch( id ) {
case DLG_OKONLY:
dialog.setTitle( m_dlgTitle );
case DLG_BADWORDS:
case QUERY_REQUEST_BLK:
((AlertDialog)dialog).setMessage( m_dlgBytes );
break;
}
super.onPrepareDialog( id, dialog );
}
@ -467,13 +473,23 @@ public class BoardActivity extends Activity implements UtilCtxt {
return m_resultCode;
}
private void nonBlockingDialog( String txt, int title )
private void nonBlockingDialog( final int dlgID, String txt )
{
switch ( dlgID ) {
case DLG_OKONLY:
m_dlgTitle = R.string.info_title;
break;
case DLG_BADWORDS:
m_dlgTitle = R.string.badwords_title;
break;
default:
Assert.fail();
}
m_dlgBytes = txt;
m_dlgTitle = title;
m_handler.post( new Runnable() {
public void run() {
showDialog( DLG_OKONLY );
showDialog( dlgID );
}
} );
}
@ -588,7 +604,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
// these two are not blocking; post showDialog and move on
case UtilCtxt.QUERY_ROBOT_MOVE:
case UtilCtxt.QUERY_ROBOT_TRADE:
nonBlockingDialog( query, R.string.info_title );
nonBlockingDialog( DLG_OKONLY, query );
result = true;
break;
@ -659,7 +675,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
}
if ( resid != 0 ) {
nonBlockingDialog( getString( resid ), R.string.info_title );
nonBlockingDialog( DLG_OKONLY, getString( resid ) );
}
} // userError
@ -668,4 +684,34 @@ public class BoardActivity extends Activity implements UtilCtxt {
m_jniThread.handle( JNIThread.JNICmd.CMD_POST_OVER,
R.string.finalscores_title );
}
public boolean warnIllegalWord( String[] words, int turn, boolean turnLost )
{
Utils.logf( "warnIllegalWord" );
boolean accept = turnLost;
StringBuffer sb = new StringBuffer();
for ( int ii = 0; ; ) {
sb.append( words[ii] );
if ( ++ii == words.length ) {
break;
}
sb.append( "; " );
}
String format = getString( R.string.ids_badwords );
String message = String.format( format, sb.toString() );
if ( turnLost ) {
nonBlockingDialog( DLG_BADWORDS,
message + getString(R.string.badwords_lost) );
} else {
m_dlgBytes = message + getString( R.string.badwords_accept );
accept = 0 != waitBlockingDialog( QUERY_REQUEST_BLK );
}
Utils.logf( "warnIllegalWord=>" + accept );
return accept;
}
} // class BoardActivity

View file

@ -83,4 +83,6 @@ public interface UtilCtxt {
void notifyGameOver();
// Don't need this unless we have a scroll thumb to indicate position
//void yOffsetChange( int oldOffset, int newOffset );
boolean warnIllegalWord( String[] words, int turn, boolean turnLost );
}