When CommonPrefs field is changed mid-game, reflect it immediately.

Means adding board_prefsChanged() to jni and having Utils class call
it via JNIThread when prefs change.
This commit is contained in:
eehouse 2010-02-01 15:06:12 +00:00
parent 0df6bf873c
commit fb65fecebb
5 changed files with 39 additions and 3 deletions

View file

@ -126,6 +126,7 @@ loadCommonPrefs( JNIEnv* env, CommonPrefs* cp, jobject j_cp )
cp->showRobotScores = getBool( env, j_cp, "showRobotScores" ); cp->showRobotScores = getBool( env, j_cp, "showRobotScores" );
cp->hideTileValues = getBool( env, j_cp, "hideTileValues" ); cp->hideTileValues = getBool( env, j_cp, "hideTileValues" );
cp->skipCommitConfirm = getBool( env, j_cp, "skipCommitConfirm" ); cp->skipCommitConfirm = getBool( env, j_cp, "skipCommitConfirm" );
cp->showColors = getBool( env, j_cp, "showColors" );
} }
static XWStreamCtxt* static XWStreamCtxt*
@ -791,3 +792,19 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage
XWJNI_END(); XWJNI_END();
return result; return result;
} }
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1prefsChanged
( JNIEnv* env, jclass C, jint gamePtr, jobject jcp )
{
jboolean result;
XWJNI_START();
CommonPrefs cp;
loadCommonPrefs( env, &cp, jcp );
result = board_prefsChanged( state->game.board, &cp );
XWJNI_END();
return result;
}

View file

@ -166,6 +166,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
} }
} }
} ); } );
Utils.setThread( m_jniThread );
m_jniThread.start(); m_jniThread.start();
m_view.startHandling( m_jniThread, m_jniGamePtr, m_gi ); m_view.startHandling( m_jniThread, m_jniGamePtr, m_gi );
@ -189,6 +190,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
} }
if ( null != m_jniThread ) { if ( null != m_jniThread ) {
Utils.setThread( null );
m_jniThread.waitToStop(); m_jniThread.waitToStop();
Utils.logf( "onDestroy(): waitToStop() returned" ); Utils.logf( "onDestroy(): waitToStop() returned" );
@ -273,8 +275,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
Utils.notImpl(this); Utils.notImpl(this);
break; break;
case R.id.board_menu_file_prefs: case R.id.board_menu_file_prefs:
Intent intent = new Intent( this, PrefsActivity.class ); startActivity( new Intent( this, PrefsActivity.class ) );
startActivity( intent );
break; break;
case R.id.board_menu_file_about: case R.id.board_menu_file_about:
Utils.about(this); Utils.about(this);

View file

@ -21,10 +21,12 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import org.eehouse.android.xw4.jni.*; import org.eehouse.android.xw4.jni.*;
import org.eehouse.android.xw4.jni.JNIThread.*;
public class Utils { public class Utils {
static final String TAG = "EJAVA"; static final String TAG = "EJAVA";
private static CommonPrefs m_cp; private static CommonPrefs m_cp;
private static JNIThread s_jniThread = null;
private Utils() {} private Utils() {}
@ -50,6 +52,11 @@ public class Utils {
Toast.makeText( context, text, Toast.LENGTH_LONG ).show(); Toast.makeText( context, text, Toast.LENGTH_LONG ).show();
} }
public static void setThread( JNIThread thread )
{
s_jniThread = thread;
}
public static byte[] savedGame( Context context, String path ) public static byte[] savedGame( Context context, String path )
{ {
byte[] stream = null; byte[] stream = null;
@ -257,6 +264,10 @@ public class Utils {
} else { } else {
m_cp.copyFrom( cp ); m_cp.copyFrom( cp );
} }
if ( null != s_jniThread ) {
s_jniThread.handle( JNICmd.CMD_PREFS_CHANGE, m_cp );
}
} }
} }

View file

@ -20,6 +20,7 @@ public class JNIThread extends Thread {
CMD_START, CMD_START,
CMD_DO, CMD_DO,
CMD_RECEIVE, CMD_RECEIVE,
CMD_PREFS_CHANGE,
CMD_PEN_DOWN, CMD_PEN_DOWN,
CMD_PEN_MOVE, CMD_PEN_MOVE,
CMD_PEN_UP, CMD_PEN_UP,
@ -196,6 +197,11 @@ public class JNIThread extends Thread {
handle( JNICmd.CMD_DO ); handle( JNICmd.CMD_DO );
break; break;
case CMD_PREFS_CHANGE:
draw = XwJNI.board_prefsChanged( m_jniGamePtr,
(CommonPrefs)args[0] );
break;
case CMD_PEN_DOWN: case CMD_PEN_DOWN:
draw = XwJNI.board_handlePenDown( m_jniGamePtr, draw = XwJNI.board_handlePenDown( m_jniGamePtr,
((Integer)args[0]).intValue(), ((Integer)args[0]).intValue(),

View file

@ -81,7 +81,8 @@ public class XwJNI {
public static native boolean board_beginTrade( int gamePtr ); public static native boolean board_beginTrade( int gamePtr );
public static native String board_formatRemainingTiles( int gamePtr ); public static native String board_formatRemainingTiles( int gamePtr );
public static native boolean board_prefsChanged( int gamePtr,
CommonPrefs cp );
// Model // Model
public static native String model_writeGameHistory( int gamePtr, public static native String model_writeGameHistory( int gamePtr,
boolean gameOver ); boolean gameOver );