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->hideTileValues = getBool( env, j_cp, "hideTileValues" );
cp->skipCommitConfirm = getBool( env, j_cp, "skipCommitConfirm" );
cp->showColors = getBool( env, j_cp, "showColors" );
}
static XWStreamCtxt*
@ -791,3 +792,19 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage
XWJNI_END();
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_view.startHandling( m_jniThread, m_jniGamePtr, m_gi );
@ -189,6 +190,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
}
if ( null != m_jniThread ) {
Utils.setThread( null );
m_jniThread.waitToStop();
Utils.logf( "onDestroy(): waitToStop() returned" );
@ -273,8 +275,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
Utils.notImpl(this);
break;
case R.id.board_menu_file_prefs:
Intent intent = new Intent( this, PrefsActivity.class );
startActivity( intent );
startActivity( new Intent( this, PrefsActivity.class ) );
break;
case R.id.board_menu_file_about:
Utils.about(this);

View file

@ -21,10 +21,12 @@ import android.widget.EditText;
import android.widget.TextView;
import org.eehouse.android.xw4.jni.*;
import org.eehouse.android.xw4.jni.JNIThread.*;
public class Utils {
static final String TAG = "EJAVA";
private static CommonPrefs m_cp;
private static JNIThread s_jniThread = null;
private Utils() {}
@ -50,6 +52,11 @@ public class Utils {
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 )
{
byte[] stream = null;
@ -257,6 +264,10 @@ public class Utils {
} else {
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_DO,
CMD_RECEIVE,
CMD_PREFS_CHANGE,
CMD_PEN_DOWN,
CMD_PEN_MOVE,
CMD_PEN_UP,
@ -196,6 +197,11 @@ public class JNIThread extends Thread {
handle( JNICmd.CMD_DO );
break;
case CMD_PREFS_CHANGE:
draw = XwJNI.board_prefsChanged( m_jniGamePtr,
(CommonPrefs)args[0] );
break;
case CMD_PEN_DOWN:
draw = XwJNI.board_handlePenDown( m_jniGamePtr,
((Integer)args[0]).intValue(),

View file

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