mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
Merge branch 'android_branch' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_branch
This commit is contained in:
commit
8fe195e91c
10 changed files with 150 additions and 73 deletions
|
@ -1105,6 +1105,18 @@ public class BoardActivity extends XWActivity {
|
||||||
== Configuration.ORIENTATION_LANDSCAPE;
|
== Configuration.ORIENTATION_LANDSCAPE;
|
||||||
m_toolbar.orientChanged( isLandscape );
|
m_toolbar.orientChanged( isLandscape );
|
||||||
populateToolbar();
|
populateToolbar();
|
||||||
|
|
||||||
|
|
||||||
|
switch( DBUtils.getHasMsgs( m_path ) ) {
|
||||||
|
case MSG_LEVEL_CHAT:
|
||||||
|
startChatActivity();
|
||||||
|
// FALLTHRU
|
||||||
|
case MSG_LEVEL_TURN:
|
||||||
|
// clear it if non-NONE
|
||||||
|
DBUtils.setHasMsgs( m_path,
|
||||||
|
GameSummary.MsgLevel.MSG_LEVEL_NONE );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // loadGame
|
} // loadGame
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_path );
|
DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_path );
|
||||||
|
if ( null != pairs ) {
|
||||||
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
|
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
|
||||||
LayoutInflater factory = LayoutInflater.from( this );
|
LayoutInflater factory = LayoutInflater.from( this );
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
|
||||||
view.setText( pair.msg );
|
view.setText( pair.msg );
|
||||||
layout.addView( view );
|
layout.addView( view );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
((Button)findViewById( R.id.send_button )).setOnClickListener( this );
|
((Button)findViewById( R.id.send_button )).setOnClickListener( this );
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,8 @@ public class DBUtils {
|
||||||
|
|
||||||
col = cursor.getColumnIndex( DBHelper.HASMSGS );
|
col = cursor.getColumnIndex( DBHelper.HASMSGS );
|
||||||
if ( col >= 0 ) {
|
if ( col >= 0 ) {
|
||||||
summary.msgsPending = 0 != cursor.getInt( col );
|
summary.pendingMsgLevel =
|
||||||
|
GameSummary.MsgLevel.values()[cursor.getInt( col )];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
@ -164,7 +165,7 @@ public class DBUtils {
|
||||||
saveSummary( context, file, summary );
|
saveSummary( context, file, summary );
|
||||||
}
|
}
|
||||||
return summary;
|
return summary;
|
||||||
}
|
} // getSummary
|
||||||
|
|
||||||
public static void saveSummary( Context context, String path,
|
public static void saveSummary( Context context, String path,
|
||||||
GameSummary summary )
|
GameSummary summary )
|
||||||
|
@ -187,7 +188,6 @@ public class DBUtils {
|
||||||
values.put( DBHelper.DICTLANG, summary.dictLang );
|
values.put( DBHelper.DICTLANG, summary.dictLang );
|
||||||
values.put( DBHelper.DICTNAME, summary.dictName );
|
values.put( DBHelper.DICTNAME, summary.dictName );
|
||||||
values.put( DBHelper.GAME_OVER, summary.gameOver );
|
values.put( DBHelper.GAME_OVER, summary.gameOver );
|
||||||
values.put( DBHelper.HASMSGS, 0 );
|
|
||||||
|
|
||||||
if ( null != summary.scores ) {
|
if ( null != summary.scores ) {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
@ -237,14 +237,15 @@ public class DBUtils {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHasMsgs( String relayID )
|
// 0 means none; 1 just moves; 2 chat
|
||||||
|
public static void setHasMsgs( String path, GameSummary.MsgLevel level )
|
||||||
{
|
{
|
||||||
synchronized( s_dbHelper ) {
|
synchronized( s_dbHelper ) {
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
|
|
||||||
String selection = DBHelper.RELAYID + "=\'" + relayID + "\'";
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put( DBHelper.HASMSGS, 1 );
|
values.put( DBHelper.HASMSGS, level.ordinal() );
|
||||||
|
|
||||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||||
values, selection, null );
|
values, selection, null );
|
||||||
|
@ -253,6 +254,26 @@ public class DBUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GameSummary.MsgLevel getHasMsgs( String path )
|
||||||
|
{
|
||||||
|
GameSummary.MsgLevel result = GameSummary.MsgLevel.MSG_LEVEL_NONE;
|
||||||
|
synchronized( s_dbHelper ) {
|
||||||
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
|
String[] columns = { DBHelper.HASMSGS };
|
||||||
|
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||||
|
selection, null, null, null, null );
|
||||||
|
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||||
|
int level = cursor.getInt( cursor
|
||||||
|
.getColumnIndex(DBHelper.HASMSGS));
|
||||||
|
result = GameSummary.MsgLevel.values()[level];
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getPathFor( Context context, String relayID )
|
public static String getPathFor( Context context, String relayID )
|
||||||
{
|
{
|
||||||
String result = null;
|
String result = null;
|
||||||
|
@ -482,14 +503,18 @@ public class DBUtils {
|
||||||
|
|
||||||
public static HistoryPair[] getChatHistory( Context context, String path )
|
public static HistoryPair[] getChatHistory( Context context, String path )
|
||||||
{
|
{
|
||||||
|
HistoryPair[] result = null;
|
||||||
final String localPrefix = context.getString( R.string.chat_local_id );
|
final String localPrefix = context.getString( R.string.chat_local_id );
|
||||||
String[] msgs = getChatHistoryStr( context, path ).split( "\n" );
|
String history = getChatHistoryStr( context, path );
|
||||||
HistoryPair[] result = new HistoryPair[msgs.length];
|
if ( null != history ) {
|
||||||
|
String[] msgs = history.split( "\n" );
|
||||||
|
result = new HistoryPair[msgs.length];
|
||||||
for ( int ii = 0; ii < result.length; ++ii ) {
|
for ( int ii = 0; ii < result.length; ++ii ) {
|
||||||
String msg = msgs[ii];
|
String msg = msgs[ii];
|
||||||
boolean isLocal = msg.startsWith( localPrefix );
|
boolean isLocal = msg.startsWith( localPrefix );
|
||||||
result[ii] = new HistoryPair( msg, isLocal );
|
result[ii] = new HistoryPair( msg, isLocal );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,9 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
View marker = layout.findViewById( R.id.msg_marker );
|
View marker = layout.findViewById( R.id.msg_marker );
|
||||||
marker.setVisibility( summary.msgsPending?
|
marker.setVisibility( summary.pendingMsgLevel
|
||||||
View.VISIBLE : View.GONE );
|
== GameSummary.MsgLevel.MSG_LEVEL_NONE
|
||||||
|
? View.GONE : View.VISIBLE );
|
||||||
m_viewsCache.put( path, layout );
|
m_viewsCache.put( path, layout );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,26 @@ public class GameUtils {
|
||||||
private static GameSummary summarizeAndClose( Context context,
|
private static GameSummary summarizeAndClose( Context context,
|
||||||
String path,
|
String path,
|
||||||
int gamePtr, CurGameInfo gi )
|
int gamePtr, CurGameInfo gi )
|
||||||
|
{
|
||||||
|
return summarizeAndClose( context, path, gamePtr, gi, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameSummary summarizeAndClose( Context context,
|
||||||
|
String path,
|
||||||
|
int gamePtr, CurGameInfo gi,
|
||||||
|
FeedUtilsImpl feedImpl )
|
||||||
{
|
{
|
||||||
GameSummary summary = new GameSummary( gi );
|
GameSummary summary = new GameSummary( gi );
|
||||||
XwJNI.game_summarize( gamePtr, summary );
|
XwJNI.game_summarize( gamePtr, summary );
|
||||||
|
|
||||||
|
if ( null != feedImpl ) {
|
||||||
|
if ( feedImpl.m_gotChat ) {
|
||||||
|
summary.pendingMsgLevel = GameSummary.MsgLevel.MSG_LEVEL_CHAT;
|
||||||
|
} else if ( feedImpl.m_gotMsg ) {
|
||||||
|
summary.pendingMsgLevel = GameSummary.MsgLevel.MSG_LEVEL_TURN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DBUtils.saveSummary( context, path, summary );
|
DBUtils.saveSummary( context, path, summary );
|
||||||
|
|
||||||
XwJNI.game_dispose( gamePtr );
|
XwJNI.game_dispose( gamePtr );
|
||||||
|
@ -381,15 +398,23 @@ public class GameUtils {
|
||||||
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
private String m_path;
|
private String m_path;
|
||||||
|
public boolean m_gotMsg;
|
||||||
|
public boolean m_gotChat;
|
||||||
|
|
||||||
public FeedUtilsImpl( Context context, String path )
|
public FeedUtilsImpl( Context context, String path )
|
||||||
{
|
{
|
||||||
m_context = context;
|
m_context = context;
|
||||||
m_path = path;
|
m_path = path;
|
||||||
|
m_gotMsg = false;
|
||||||
}
|
}
|
||||||
public void showChat( String msg )
|
public void showChat( String msg )
|
||||||
{
|
{
|
||||||
DBUtils.appendChatHistory( m_context, m_path, msg, false );
|
DBUtils.appendChatHistory( m_context, m_path, msg, false );
|
||||||
|
m_gotChat = true;
|
||||||
|
}
|
||||||
|
public void turnChanged()
|
||||||
|
{
|
||||||
|
m_gotMsg = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,9 +426,8 @@ public class GameUtils {
|
||||||
if ( null != path ) {
|
if ( null != path ) {
|
||||||
int gamePtr = XwJNI.initJNI();
|
int gamePtr = XwJNI.initJNI();
|
||||||
CurGameInfo gi = new CurGameInfo( context );
|
CurGameInfo gi = new CurGameInfo( context );
|
||||||
loadMakeGame( context, gamePtr, gi,
|
FeedUtilsImpl feedImpl = new FeedUtilsImpl( context, path );
|
||||||
new FeedUtilsImpl(context, path),
|
loadMakeGame( context, gamePtr, gi, feedImpl, path );
|
||||||
path );
|
|
||||||
|
|
||||||
for ( byte[] msg : msgs ) {
|
for ( byte[] msg : msgs ) {
|
||||||
draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw;
|
draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw;
|
||||||
|
@ -412,7 +436,14 @@ public class GameUtils {
|
||||||
// update gi to reflect changes due to messages
|
// update gi to reflect changes due to messages
|
||||||
XwJNI.game_getGi( gamePtr, gi );
|
XwJNI.game_getGi( gamePtr, gi );
|
||||||
saveGame( context, gamePtr, gi, path, false );
|
saveGame( context, gamePtr, gi, path, false );
|
||||||
summarizeAndClose( context, path, gamePtr, gi );
|
summarizeAndClose( context, path, gamePtr, gi, feedImpl );
|
||||||
|
if ( feedImpl.m_gotChat ) {
|
||||||
|
DBUtils.setHasMsgs( path, GameSummary.MsgLevel.MSG_LEVEL_CHAT );
|
||||||
|
draw = true;
|
||||||
|
} else if ( feedImpl.m_gotMsg ) {
|
||||||
|
DBUtils.setHasMsgs( path, GameSummary.MsgLevel.MSG_LEVEL_TURN );
|
||||||
|
draw = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Utils.logf( "feedMessages=>%s", draw?"true":"false" );
|
Utils.logf( "feedMessages=>%s", draw?"true":"false" );
|
||||||
return draw;
|
return draw;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import android.net.NetworkInfo;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import android.os.Build;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
public class NetStateCache {
|
public class NetStateCache {
|
||||||
|
@ -40,6 +41,7 @@ public class NetStateCache {
|
||||||
private static HashSet<StateChangedIf> s_ifs;
|
private static HashSet<StateChangedIf> s_ifs;
|
||||||
private static boolean s_netAvail = false;
|
private static boolean s_netAvail = false;
|
||||||
private static CommsBroadcastReceiver s_receiver;
|
private static CommsBroadcastReceiver s_receiver;
|
||||||
|
private static final boolean s_onSim = Build.PRODUCT.contains("sdk");
|
||||||
|
|
||||||
public static void register( Context context, StateChangedIf proc )
|
public static void register( Context context, StateChangedIf proc )
|
||||||
{
|
{
|
||||||
|
@ -60,7 +62,7 @@ public class NetStateCache {
|
||||||
public static boolean netAvail( Context context )
|
public static boolean netAvail( Context context )
|
||||||
{
|
{
|
||||||
initIfNot( context );
|
initIfNot( context );
|
||||||
return s_netAvail;
|
return s_netAvail || s_onSim;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initIfNot( Context context )
|
private static void initIfNot( Context context )
|
||||||
|
|
|
@ -195,7 +195,6 @@ public class NetUtils {
|
||||||
if ( null != msgs[ii] ) {
|
if ( null != msgs[ii] ) {
|
||||||
if( GameUtils.feedMessages( context, ids[ii],
|
if( GameUtils.feedMessages( context, ids[ii],
|
||||||
msgs[ii] ) ) {
|
msgs[ii] ) ) {
|
||||||
DBUtils.setHasMsgs( ids[ii] );
|
|
||||||
idsWMsgs.add( ids[ii] );
|
idsWMsgs.add( ids[ii] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.eehouse.android.xw4.R;
|
||||||
* in CurGameInfo
|
* in CurGameInfo
|
||||||
*/
|
*/
|
||||||
public class GameSummary {
|
public class GameSummary {
|
||||||
|
public enum MsgLevel { MSG_LEVEL_NONE, MSG_LEVEL_TURN, MSG_LEVEL_CHAT };
|
||||||
|
|
||||||
public int nMoves;
|
public int nMoves;
|
||||||
public int turn;
|
public int turn;
|
||||||
public int giFlags;
|
public int giFlags;
|
||||||
|
@ -42,19 +44,23 @@ public class GameSummary {
|
||||||
public String roomName;
|
public String roomName;
|
||||||
public String relayID;
|
public String relayID;
|
||||||
public int seed;
|
public int seed;
|
||||||
public boolean msgsPending;
|
public MsgLevel pendingMsgLevel;
|
||||||
public long modtime;
|
public long modtime;
|
||||||
|
|
||||||
public int dictLang;
|
public int dictLang;
|
||||||
public String dictName;
|
public String dictName;
|
||||||
public CurGameInfo.DeviceRole serverRole;
|
public CurGameInfo.DeviceRole serverRole;
|
||||||
|
|
||||||
|
|
||||||
private CurGameInfo m_gi;
|
private CurGameInfo m_gi;
|
||||||
|
|
||||||
public GameSummary(){}
|
public GameSummary(){
|
||||||
|
pendingMsgLevel = MsgLevel.MSG_LEVEL_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
public GameSummary( CurGameInfo gi )
|
public GameSummary( CurGameInfo gi )
|
||||||
{
|
{
|
||||||
|
super();
|
||||||
nPlayers = gi.nPlayers;
|
nPlayers = gi.nPlayers;
|
||||||
dictLang = gi.dictLang;
|
dictLang = gi.dictLang;
|
||||||
dictName = gi.dictName;
|
dictName = gi.dictName;
|
||||||
|
|
|
@ -809,6 +809,7 @@ postponeRobotMove( ServerCtxt* server )
|
||||||
static void
|
static void
|
||||||
showPrevScore( ServerCtxt* server )
|
showPrevScore( ServerCtxt* server )
|
||||||
{
|
{
|
||||||
|
if ( server->nv.showRobotScores ) { /* this can be changed between turns */
|
||||||
XW_UtilCtxt* util = server->vol.util;
|
XW_UtilCtxt* util = server->vol.util;
|
||||||
XWStreamCtxt* stream;
|
XWStreamCtxt* stream;
|
||||||
const XP_UCHAR* str;
|
const XP_UCHAR* str;
|
||||||
|
@ -818,8 +819,6 @@ showPrevScore( ServerCtxt* server )
|
||||||
XP_U16 strCode;
|
XP_U16 strCode;
|
||||||
LocalPlayer* lp;
|
LocalPlayer* lp;
|
||||||
|
|
||||||
XP_ASSERT( server->nv.showRobotScores );
|
|
||||||
|
|
||||||
prevTurn = (server->nv.currentTurn + nPlayers - 1) % nPlayers;
|
prevTurn = (server->nv.currentTurn + nPlayers - 1) % nPlayers;
|
||||||
lp = &gi->players[prevTurn];
|
lp = &gi->players[prevTurn];
|
||||||
|
|
||||||
|
@ -850,7 +849,7 @@ showPrevScore( ServerCtxt* server )
|
||||||
|
|
||||||
(void)util_userQuery( util, QUERY_ROBOT_MOVE, stream );
|
(void)util_userQuery( util, QUERY_ROBOT_MOVE, stream );
|
||||||
stream_destroy( stream );
|
stream_destroy( stream );
|
||||||
|
}
|
||||||
SETSTATE( server, server->vol.stateAfterShow );
|
SETSTATE( server, server->vol.stateAfterShow );
|
||||||
} /* showPrevScore */
|
} /* showPrevScore */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue