start on sending chat messages. Doesn't even compile -- committing to get onto another machine.

This commit is contained in:
Eric House 2010-10-04 05:38:05 -07:00
parent 1e13e92deb
commit b3c7cb3711
6 changed files with 48 additions and 1 deletions

View file

@ -1184,3 +1184,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1endGame
server_endGame( state->game.server );
XWJNI_END();
}
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1sendChat
( JNIEnv* env, jclass C, jint gamePtr, jstring jmsg )
{
XWJNI_START();
XP_ASSERT( !!state->game.server );
const char* msg = (*env)->GetStringUTFChars( env, jmsg, NULL );
server_sendChat( state->game.server, msg );
(*env)->ReleaseStringUTFChars( env, jmsg, msg );
XWJNI_END();
}

View file

@ -46,6 +46,8 @@
android:title="@string/board_menu_game_final" />
<item android:id="@+id/board_menu_game_resend"
android:title="@string/board_menu_game_resend" />
<item android:id="@+id/board_menu_game_chat"
android:title="@string/board_menu_game_chat" />
</menu>
</item>

View file

@ -91,6 +91,7 @@
<string name="board_menu_game_history">Game history</string>
<string name="board_menu_game_final">Final scores</string>
<string name="board_menu_game_resend">Resend messages</string>
<string name="board_menu_game_chat">Send message</string>
<string name="board_submenu_file">File</string>
<string name="board_menu_file_new">New game</string>
<string name="board_menu_file_about">About Crosswords</string>
@ -387,5 +388,6 @@
refreshing or creating your own.</string>
<string name="chat_received">Message received</string>
<string name="button_send">Send</string>
<string name="compose_chat">Message for all devices</string>
</resources>

View file

@ -61,6 +61,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
private static final int QUERY_ENDGAME = Utils.DIALOG_LAST + 6;
private static final int ASK_PASSWORD_BLK = Utils.DIALOG_LAST + 7;
private static final int DLG_RETRY = Utils.DIALOG_LAST + 8;
private static final int GET_MESSAGE = Utils.DIALOG_LAST + 9;
private BoardView m_view;
private int m_jniGamePtr;
@ -74,6 +75,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
private String m_dlgBytes = null;
private EditText m_passwdEdit = null;
private EditText m_chatMsg = null;
private int m_dlgTitle;
private String m_dlgTitleStr;
private String[] m_texts;
@ -213,6 +215,26 @@ public class BoardActivity extends Activity implements UtilCtxt {
})
.create();
break;
case GET_MESSAGE:
if ( null == m_chatMsg ) {
m_chatMsg = new EditText( this );
}
dialog = new AlertDialog.Builder( this )
.setMessage( R.string.compose_chat )
.setPositiveButton(R.string.button_send,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int item ) {
m_jniThread.handle( JNICmd.CMD_SENDCHAT,
m_chatMsg.getText().toString() );
}
})
.setNegativeButton( R.string.button_cancel, null )
.setView( m_chatMsg )
.create();
break;
default:
dialog = Utils.onCreateDialog( this, id );
Assert.assertTrue( null != dialog );
@ -467,6 +489,9 @@ public class BoardActivity extends Activity implements UtilCtxt {
case R.id.board_menu_game_resend:
m_jniThread.handle( JNIThread.JNICmd.CMD_RESEND );
break;
case R.id.board_menu_game_chat:
showDialog( GET_MESSAGE );
break;
case R.id.board_menu_file_prefs:
m_firingPrefs = true;
startActivity( new Intent( this, PrefsActivity.class ) );

View file

@ -77,6 +77,7 @@ public class JNIThread extends Thread {
CMD_FINAL,
CMD_ENDGAME,
CMD_POST_OVER,
CMD_SENDCHAT,
CMD_DRAW_CONNS_STATUS,
};
@ -454,6 +455,10 @@ public class JNIThread extends Thread {
XwJNI.server_writeFinalScores( m_jniGamePtr ) );
break;
case CMD_SENDCHAT:
XwJNI.server_sendChat( m_jniGamePtr, (String)args[0] );
break;
case CMD_DRAW_CONNS_STATUS:
int newID = 0;
switch( (TransportProcs.CommsRelayState)(args[0]) ) {

View file

@ -190,6 +190,7 @@ public class XwJNI {
public static native String server_writeFinalScores( int gamePtr );
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 );
// hybrid to save work
public static native boolean board_server_prefsChanged( int gamePtr,