diff --git a/xwords4/android/XWords4/AndroidManifest.xml b/xwords4/android/XWords4/AndroidManifest.xml
index 6da83a9d3..c623d9b96 100644
--- a/xwords4/android/XWords4/AndroidManifest.xml
+++ b/xwords4/android/XWords4/AndroidManifest.xml
@@ -110,5 +110,7 @@
+
+
diff --git a/xwords4/android/XWords4/res/layout/chat.xml b/xwords4/android/XWords4/res/layout/chat.xml
new file mode 100644
index 000000000..6300ace05
--- /dev/null
+++ b/xwords4/android/XWords4/res/layout/chat.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml
index 3dd337056..d5ffd704b 100644
--- a/xwords4/android/XWords4/res/values/strings.xml
+++ b/xwords4/android/XWords4/res/values/strings.xml
@@ -399,10 +399,8 @@
No public rooms found for %d-player
games in %s. Try refreshing or creating your own.
- Message received
- Send
- Reply
- Message for all devices
+ local:
+ remote:
Moves made
New game moves have arrived
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java
index 2ed932dfb..f788c796d 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java
@@ -58,11 +58,11 @@ public class BoardActivity extends XWActivity {
private static final int QUERY_REQUEST_BLK = DLG_OKONLY + 2;
private static final int QUERY_INFORM_BLK = DLG_OKONLY + 3;
private static final int PICK_TILE_REQUEST_BLK = DLG_OKONLY + 4;
- private static final int GOT_MESSAGE_BLK = DLG_OKONLY + 5;
- private static final int ASK_PASSWORD_BLK = DLG_OKONLY + 6;
- private static final int DLG_RETRY = DLG_OKONLY + 7;
- private static final int GET_MESSAGE = DLG_OKONLY + 8;
- private static final int QUERY_ENDGAME = DLG_OKONLY + 9;
+ private static final int ASK_PASSWORD_BLK = DLG_OKONLY + 5;
+ private static final int DLG_RETRY = DLG_OKONLY + 6;
+ private static final int QUERY_ENDGAME = DLG_OKONLY + 7;
+
+ private static final int CHAT_REQUEST = 1;
private BoardView m_view;
private int m_jniGamePtr;
@@ -71,12 +71,12 @@ public class BoardActivity extends XWActivity {
private Handler m_handler;
private TimerRunnable[] m_timers;
private String m_path;
+ private Uri m_uri;
private int m_currentOrient;
private Toolbar m_toolbar;
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;
@@ -144,7 +144,6 @@ public class BoardActivity extends XWActivity {
case QUERY_REQUEST_BLK:
case QUERY_INFORM_BLK:
- case GOT_MESSAGE_BLK:
ab = new AlertDialog.Builder( this )
.setTitle( m_dlgTitle )
.setMessage( m_dlgBytes );
@@ -165,14 +164,6 @@ public class BoardActivity extends XWActivity {
}
};
ab.setNegativeButton( R.string.button_no, lstnr );
- } else if ( GOT_MESSAGE_BLK == id ) {
- lstnr = new DialogInterface.OnClickListener() {
- public void onClick( DialogInterface dlg,
- int whichButton ) {
- showDialog( GET_MESSAGE );
- }
- };
- ab.setNegativeButton( R.string.button_reply, lstnr );
}
dialog = ab.create();
@@ -230,28 +221,6 @@ public class BoardActivity extends XWActivity {
.create();
break;
- case GET_MESSAGE:
- if ( null == m_chatMsg ) {
- m_chatMsg = new EditText( this );
- }
- lstnr = new DialogInterface.OnClickListener() {
- public void onClick( DialogInterface dlg,
- int item ) {
- String msg = m_chatMsg.getText().toString();
- if ( msg.length() > 0 ) {
- m_jniThread.handle( JNICmd.CMD_SENDCHAT, msg );
- }
-
- }
- };
- dialog = new AlertDialog.Builder( this )
- .setMessage( R.string.compose_chat )
- .setPositiveButton(R.string.button_send, lstnr )
- .setNegativeButton( R.string.button_cancel, null )
- .setView( m_chatMsg )
- .create();
- break;
-
default:
// just drop it; super.onCreateDialog likely failed
break;
@@ -267,7 +236,6 @@ public class BoardActivity extends XWActivity {
case DLG_OKONLY:
dialog.setTitle( m_dlgTitle );
// FALLTHRU
- case GOT_MESSAGE_BLK:
case DLG_BADWORDS:
case QUERY_REQUEST_BLK:
case QUERY_INFORM_BLK:
@@ -277,9 +245,6 @@ public class BoardActivity extends XWActivity {
m_passwdEdit.setText( "", TextView.BufferType.EDITABLE );
dialog.setTitle( m_dlgTitleStr );
break;
- case GET_MESSAGE:
- m_chatMsg.setText("");
- break;
default:
super.onPrepareDialog( id, dialog );
break;
@@ -308,8 +273,8 @@ public class BoardActivity extends XWActivity {
m_volKeysZoom = CommonPrefs.getVolKeysZoom( this );
Intent intent = getIntent();
- Uri uri = intent.getData();
- m_path = uri.getPath();
+ m_uri = intent.getData();
+ m_path = m_uri.getPath();
if ( m_path.charAt(0) == '/' ) {
m_path = m_path.substring( 1 );
}
@@ -384,6 +349,19 @@ public class BoardActivity extends XWActivity {
super.onDestroy();
}
+ @Override
+ protected void onActivityResult( int requestCode, int resultCode, Intent data )
+ {
+ if ( Activity.RESULT_CANCELED != resultCode ) {
+ if ( CHAT_REQUEST == requestCode ) {
+ String msg = data.getStringExtra( "chat" );
+ if ( null != msg && msg.length() > 0 ) {
+ m_jniThread.handle( JNICmd.CMD_SENDCHAT, msg );
+ }
+ }
+ }
+ }
+
@Override
public void onWindowFocusChanged( boolean hasFocus )
{
@@ -1026,11 +1004,15 @@ public class BoardActivity extends XWActivity {
// we don't block the jni thread will continue processing messages
// and may stack dialogs on top of this one. Including later
// chat-messages.
- public void showChat( String msg )
+ public void showChat( final String msg )
{
- m_dlgBytes = msg;
- m_dlgTitle = R.string.chat_received;
- waitBlockingDialog( GOT_MESSAGE_BLK, 0 );
+ m_handler.post( new Runnable() {
+ public void run() {
+ DBUtils.appendChatHistory( BoardActivity.this,
+ m_path, msg, false );
+ startChatActivity();
+ }
+ } );
}
} // class BoardUtilCtxt
@@ -1193,7 +1175,7 @@ public class BoardActivity extends XWActivity {
new Runnable() {
@Override
public void run() {
- showDialog( GET_MESSAGE );
+ startChatActivity();
}
});
} // populateToolbar
@@ -1263,4 +1245,11 @@ public class BoardActivity extends XWActivity {
return handled;
}
+ private void startChatActivity()
+ {
+ Intent intent = new Intent( Intent.ACTION_EDIT,
+ m_uri, this, ChatActivity.class );
+ startActivityForResult( intent, CHAT_REQUEST );
+ }
+
} // class BoardActivity
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java
new file mode 100644
index 000000000..fd95df8d9
--- /dev/null
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java
@@ -0,0 +1,80 @@
+/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
+/*
+ * Copyright 2011 by Eric House (xwords@eehouse.org). All rights
+ * reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.eehouse.android.xw4;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextWatcher;
+import android.text.method.KeyListener;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.view.View;
+import android.view.KeyEvent;
+import android.text.Editable;
+import android.net.Uri;
+
+public class ChatActivity extends XWActivity {
+
+ private String m_path;
+
+ @Override
+ public void onCreate( Bundle savedInstanceState )
+ {
+ super.onCreate( savedInstanceState );
+
+ setContentView( R.layout.chat );
+
+ Intent intent = getIntent();
+ m_path = intent.getData().getPath();
+ if ( m_path.charAt(0) == '/' ) {
+ m_path = m_path.substring( 1 );
+ }
+
+ String history = DBUtils.getChatHistory( this, m_path );
+ Utils.logf( "got history: %s", null == history? "null" : history );
+ TextView textView = (TextView)findViewById( R.id.chat_history );
+ textView.setText( history );
+
+ final EditText edit = (EditText)findViewById( R.id.chat_edit );
+ edit.setOnKeyListener( new View.OnKeyListener() {
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ boolean consumed = KeyEvent.ACTION_DOWN == event.getAction()
+ && KeyEvent.KEYCODE_ENTER == keyCode;
+ if ( consumed ) {
+ String text = edit.getText().toString();
+ if ( null == text || text.length() == 0 ) {
+ setResult( Activity.RESULT_CANCELED );
+ } else {
+ DBUtils.appendChatHistory( ChatActivity.this,
+ m_path, text, true );
+
+ Intent result = new Intent();
+ result.putExtra( "chat", text );
+ setResult( Activity.RESULT_OK, result );
+ }
+ finish();
+ }
+ return consumed;
+ }
+ } );
+ }
+}
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java
index 5fb54857a..595bba6a0 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java
@@ -40,6 +40,7 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String NUM_PLAYERS = "NUM_PLAYERS";
public static final String GAME_OVER = "GAME_OVER";
public static final String SCORES = "SCORES";
+ public static final String CHAT_HISTORY = "CHAT_HISTORY";
// GAMEID: this isn't used yet but we'll want it to look up games
// for which messages arrive. Add now while changing the DB
// format
@@ -87,6 +88,7 @@ public class DBHelper extends SQLiteOpenHelper {
+ SMSPHONE + " TEXT,"
+ SCORES + " TEXT,"
+ + CHAT_HISTORY + " TEXT,"
+ GAMEID + " INTEGER,"
// HASMSGS: sqlite doesn't have bool; use 0 and 1
+ HASMSGS + " INTEGER DEFAULT 0,"
@@ -125,6 +127,8 @@ public class DBHelper extends SQLiteOpenHelper {
" ADD COLUMN " + TURN + "INTEGER;" );
db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM +
" ADD COLUMN " + GIFLAGS + "INTEGER;" );
+ db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM +
+ " ADD COLUMN " + CHAT_HISTORY + "TEXT;" );
} else {
db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" );
if ( oldVersion >= 6 ) {
diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java
index e65b0d1cd..7e318447e 100644
--- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java
+++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java
@@ -470,6 +470,63 @@ public class DBUtils {
return al.toArray( new String[al.size()] );
}
+ public static String getChatHistory( Context context, String path )
+ {
+ String result = null;
+ initDB( context );
+ synchronized( s_dbHelper ) {
+ SQLiteDatabase db = s_dbHelper.getReadableDatabase();
+
+ String[] columns = { DBHelper.CHAT_HISTORY };
+ String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
+ Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
+ selection, null, null, null, null );
+ if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
+ result =
+ cursor.getString( cursor
+ .getColumnIndex(DBHelper.CHAT_HISTORY));
+ }
+ cursor.close();
+ db.close();
+ }
+ return result;
+ }
+
+ public static void appendChatHistory( Context context, String path,
+ String msg, boolean local )
+ {
+
+ Assert.assertNotNull( msg );
+ int id;
+ if ( local ) {
+ id = R.string.chat_local_id;
+ } else {
+ id = R.string.chat_other_id;
+ }
+ msg = context.getString( id ) + msg;
+
+ String cur = getChatHistory( context, path );
+ if ( null != cur ) {
+ msg = cur + "\n" + msg;
+ }
+
+ initDB( context );
+ synchronized( s_dbHelper ) {
+ SQLiteDatabase db = s_dbHelper.getWritableDatabase();
+
+ String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
+ ContentValues values = new ContentValues();
+ values.put( DBHelper.CHAT_HISTORY, msg );
+
+ long timestamp = new Date().getTime();
+ values.put( DBHelper.LASTPLAY_TIME, timestamp );
+
+ int result = db.update( DBHelper.TABLE_NAME_SUM,
+ values, selection, null );
+ db.close();
+ }
+ } // appendChatHistory
+
private static String[] parsePlayers( final String players, int nPlayers ){
String[] result = null;
if ( null != players ) {