From ecaca66a9603bfe31563d7ea88453cc3c5777136 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 18 Jul 2011 18:30:04 -0700 Subject: [PATCH 1/7] move turn-in-range assert to where it won't fail --- xwords4/common/model.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xwords4/common/model.c b/xwords4/common/model.c index eed5c2992..b7f77e9f9 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -401,6 +401,8 @@ getPendingTileFor( const ModelCtxt* model, XP_U16 turn, XP_U16 col, XP_U16 row, const PendingTile* pendings; XP_U16 i; + XP_ASSERT( turn < VSIZE(model->players) ); + player = &model->players[turn]; pendings = player->pendingTiles; for ( i = 0; i < player->nPending; ++i ) { @@ -424,7 +426,6 @@ model_getTile( const ModelCtxt* model, XP_U16 col, XP_U16 row, { CellTile cellTile = getModelTileRaw( model, col, row ); XP_Bool pending = XP_FALSE; - XP_ASSERT( turn >= 0 ); if ( (cellTile & TILE_PENDING_BIT) != 0 ) { if ( getPending From 5dd181398d1d4cbc1de0fba73cb9c37f62dad02a Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 18 Jul 2011 19:01:34 -0700 Subject: [PATCH 2/7] test theory about dropped moves --- .../XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java | 1 + 1 file changed, 1 insertion(+) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index fd35fbcc2..78406ebee 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -271,6 +271,7 @@ public class JNIThread extends Thread { if ( nextSame( JNICmd.CMD_SAVE ) ) { continue; } + (void)XwJNI.server_do( m_jniGamePtr ); XwJNI.game_getGi( m_jniGamePtr, m_gi ); GameSummary summary = new GameSummary( m_gi ); XwJNI.game_summarize( m_jniGamePtr, summary ); From 1d2c63d50fc02bd83bb69420f8b8932736a2ea39 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 19 Jul 2011 06:11:27 -0700 Subject: [PATCH 3/7] Duh. Make it f*cking compile --- .../XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index 78406ebee..846b9d545 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -271,7 +271,7 @@ public class JNIThread extends Thread { if ( nextSame( JNICmd.CMD_SAVE ) ) { continue; } - (void)XwJNI.server_do( m_jniGamePtr ); + XwJNI.server_do( m_jniGamePtr ); XwJNI.game_getGi( m_jniGamePtr, m_gi ); GameSummary summary = new GameSummary( m_gi ); XwJNI.game_summarize( m_jniGamePtr, summary ); From 39e752cbc90fe72726c416796bf44dedf6f983b6 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 19 Jul 2011 06:24:15 -0700 Subject: [PATCH 4/7] add comment explaining change --- .../XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index 846b9d545..a5ca73983 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -271,7 +271,12 @@ public class JNIThread extends Thread { if ( nextSame( JNICmd.CMD_SAVE ) ) { continue; } + // If server has any work to do, e.g. clean up after + // showing a remote- or robot-moved dialog, let it do + // so before saving state. In some cases it'll + // otherwise drop the move. XwJNI.server_do( m_jniGamePtr ); + XwJNI.game_getGi( m_jniGamePtr, m_gi ); GameSummary summary = new GameSummary( m_gi ); XwJNI.game_summarize( m_jniGamePtr, summary ); From e4ba5fb5fdcf806dd2b5617348c1a46de89bb489 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 19 Jul 2011 18:14:32 -0700 Subject: [PATCH 5/7] log svn rev --- xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java index dcdee3204..c1dfc3dbb 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java @@ -28,7 +28,7 @@ public class XWApp extends Application { public void onCreate() { Utils.logEnable( this ); - Utils.logf( "XWApp.onCreate()" ); + Utils.logf( "XWApp.onCreate(); svn_rev=%s", getString(R.string.git_rev_gen) ); super.onCreate(); } } From ea853e2e51a7f92ce2109c6aebeae601d1db233b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 19 Jul 2011 18:21:52 -0700 Subject: [PATCH 6/7] replace hard-coded list of preferences whose summaries are their values and code to enforce that with custom subclasses that do the right thing automatically. --- xwords4/android/XWords4/res/xml/xwprefs.xml | 331 +++++++++--------- .../android/xw4/DictListPreference.java | 2 +- .../eehouse/android/xw4/PrefsActivity.java | 41 --- .../android/xw4/XWEditTextPreference.java | 48 +++ .../eehouse/android/xw4/XWListPreference.java | 47 +++ 5 files changed, 265 insertions(+), 204 deletions(-) create mode 100644 xwords4/android/XWords4/src/org/eehouse/android/xw4/XWEditTextPreference.java create mode 100644 xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListPreference.java diff --git a/xwords4/android/XWords4/res/xml/xwprefs.xml b/xwords4/android/XWords4/res/xml/xwprefs.xml index 1ce6c99ff..5c5ae44ed 100644 --- a/xwords4/android/XWords4/res/xml/xwprefs.xml +++ b/xwords4/android/XWords4/res/xml/xwprefs.xml @@ -11,28 +11,32 @@ android:summary="@string/prefs_names_summary" > - - - - + + + + - + - + - + @@ -94,97 +101,97 @@ android:summary="@string/prefs_appearance_summary" > - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - - + + + - - + + @@ -244,42 +251,42 @@ - - - - + + + + - - - - - - + - - + + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictListPreference.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictListPreference.java index a74de55eb..072268dae 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictListPreference.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictListPreference.java @@ -26,7 +26,7 @@ import android.util.AttributeSet; import junit.framework.Assert; -public class DictListPreference extends ListPreference { +public class DictListPreference extends XWListPreference { public DictListPreference( Context context, AttributeSet attrs ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java index 318b6e22d..97f57db65 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java @@ -39,7 +39,6 @@ public class PrefsActivity extends PreferenceActivity private static final int REVERT_COLORS = 1; private static final int REVERT_ALL = 2; - private HashSet m_keys; private String m_keyEmpty; private String m_keyLogging; @@ -114,31 +113,6 @@ public class PrefsActivity extends PreferenceActivity // Load the preferences from an XML resource addPreferencesFromResource( R.xml.xwprefs ); - int[] textKeyIds = { R.string.key_relay_host, - R.string.key_redir_host, - R.string.key_relay_port, - R.string.key_proxy_port, - R.string.key_dict_host, - R.string.key_board_size, - R.string.key_initial_player_minutes, - R.string.key_default_dict, - R.string.key_default_robodict, - R.string.key_default_phonies, - R.string.key_player1_name, - R.string.key_player2_name, - R.string.key_player3_name, - R.string.key_player4_name, - }; - - SharedPreferences sp - = PreferenceManager.getDefaultSharedPreferences( this ); - m_keys = new HashSet( textKeyIds.length ); - for ( int ii = 0; ii < textKeyIds.length; ++ii ) { - int id = textKeyIds[ii]; - String key = getString( id ); - setSummary( sp, key ); - m_keys.add( key ); - } m_keyEmpty = getString( R.string.key_empty ); m_keyLogging = getString( R.string.key_logging_on ); } @@ -161,9 +135,6 @@ public class PrefsActivity extends PreferenceActivity public void onSharedPreferenceChanged( SharedPreferences sp, String key ) { - if ( m_keys.contains( key ) ) { - setSummary( sp, key ); - } if ( key.equals( m_keyLogging ) ) { Utils.logEnable( sp.getBoolean( key, false ) ); } @@ -197,18 +168,6 @@ public class PrefsActivity extends PreferenceActivity return handled; } - private void setSummary( SharedPreferences sp, String key ) - { - Preference pref = getPreferenceScreen().findPreference( key ); - String value = sp.getString( key, "" ); - // if ( pref instanceof android.preference.ListPreference ) { - // Utils.logf( "%s: want to do lookup of user string here", - // key ); - // } - pref.setSummary( value ); - } - - private void relaunch() { PreferenceManager.setDefaultValues( this, R.xml.xwprefs, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWEditTextPreference.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWEditTextPreference.java new file mode 100644 index 000000000..26639a685 --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWEditTextPreference.java @@ -0,0 +1,48 @@ +/* -*- compile-command: "cd ../../../../../; ant install"; -*- */ +/* + * Copyright 2010 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.preference.EditTextPreference; +import android.content.Context; +import android.util.AttributeSet; + +import junit.framework.Assert; + +public class XWEditTextPreference extends EditTextPreference { + + public XWEditTextPreference( Context context, AttributeSet attrs ) + { + super( context, attrs ); + } + + protected void onAttachedToActivity() + { + super.onAttachedToActivity(); + setSummary( getPersistedString( "" ) ); + } + + protected boolean persistString( String value ) + { + setSummary( value ); + return super.persistString( value ); + } + +} diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListPreference.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListPreference.java new file mode 100644 index 000000000..e608ba1d1 --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListPreference.java @@ -0,0 +1,47 @@ +/* -*- compile-command: "cd ../../../../../; ant install"; -*- */ +/* + * Copyright 2010 - 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.preference.ListPreference; +import android.content.Context; +import android.util.AttributeSet; + +import junit.framework.Assert; + +public class XWListPreference extends ListPreference { + + public XWListPreference( Context context, AttributeSet attrs ) + { + super( context, attrs ); + } + + protected void onAttachedToActivity() + { + super.onAttachedToActivity(); + setSummary( getPersistedString( "" ) ); + } + + protected boolean persistString( String value ) + { + setSummary( value ); + return super.persistString( value ); + } +} From 30b9df399ce736b8e6a5c875bb3185d0c4a6d351 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 19 Jul 2011 18:31:20 -0700 Subject: [PATCH 7/7] Address crash that happened when runnable ran too late by nulling out m_handler in onPause() and adding new methods that check if it's null before calling post(), postDelayed() or removeCallbacks() on it. --- .../eehouse/android/xw4/BoardActivity.java | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) 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 82a39d8d3..e5d1567c1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -77,7 +77,7 @@ public class BoardActivity extends XWActivity private GameUtils.GameLock m_gameLock; private CurGameInfo m_gi; CommsTransport m_xport; - private Handler m_handler; + private Handler m_handler = null; private TimerRunnable[] m_timers; private Runnable m_screenTimer; private String m_name; @@ -324,7 +324,6 @@ public class BoardActivity extends XWActivity m_utils = new BoardUtilCtxt(); m_jniu = JNIUtilsImpl.get(); setContentView( R.layout.board ); - m_handler = new Handler(); m_timers = new TimerRunnable[4]; // needs to be in sync with // XWTimerReason m_gi = new CurGameInfo( this ); @@ -343,6 +342,7 @@ public class BoardActivity extends XWActivity @Override protected void onPause() { + m_handler = null; waitCloseGame( true ); super.onPause(); } @@ -351,6 +351,7 @@ public class BoardActivity extends XWActivity protected void onResume() { super.onResume(); + m_handler = new Handler(); setKeepScreenOn(); loadGame(); } @@ -558,7 +559,7 @@ public class BoardActivity extends XWActivity public void tpmRelayConnd( final String room, final int devOrder, final boolean allHere, final int nMissing ) { - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { handleConndMessage( room, devOrder, allHere, nMissing ); } @@ -612,7 +613,7 @@ public class BoardActivity extends XWActivity } else if ( dlgID >= 0 ) { final int strIDf = strID; final int dlgIDf = dlgID; - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { m_dlgBytes = getString( strIDf ); m_dlgTitle = R.string.relay_alert; @@ -762,7 +763,7 @@ public class BoardActivity extends XWActivity public void requestTime() { - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { if ( null != m_jniThread ) { m_jniThread.handle( JNIThread.JNICmd.CMD_DO, false ); @@ -795,7 +796,7 @@ public class BoardActivity extends XWActivity public void setTimer( int why, int when, int handle ) { if ( null != m_timers[why] ) { - m_handler.removeCallbacks( m_timers[why] ); + removeCallbacks( m_timers[why] ); } m_timers[why] = new TimerRunnable( why, when, handle ); @@ -811,13 +812,13 @@ public class BoardActivity extends XWActivity default: inHowLong = 500; } - m_handler.postDelayed( m_timers[why], inHowLong ); + postDelayed( m_timers[why], inHowLong ); } public void clearTimer( int why ) { if ( null != m_timers[why] ) { - m_handler.removeCallbacks( m_timers[why] ); + removeCallbacks( m_timers[why] ); m_timers[why] = null; } } @@ -852,7 +853,7 @@ public class BoardActivity extends XWActivity public void turnChanged() { - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { showNotAgainDlgThen( R.string.not_again_turnchanged, R.string.key_notagain_turnchanged, @@ -870,7 +871,7 @@ public class BoardActivity extends XWActivity public void engineStarting( int nBlanks ) { if ( nBlanks > 0 ) { - m_handler.post( new Runnable() { + post( new Runnable() { // Need to keep this from running after activity dies!! public void run() { if ( m_isVisible ) { @@ -888,7 +889,7 @@ public class BoardActivity extends XWActivity public void engineStopping() { - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { if ( null != m_progress ) { m_progress.cancel(); @@ -1037,7 +1038,7 @@ public class BoardActivity extends XWActivity // chat-messages. public void showChat( final String msg ) { - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { DBUtils.appendChatHistory( BoardActivity.this, m_name, msg, false ); @@ -1238,7 +1239,7 @@ public class BoardActivity extends XWActivity } else { setBlockingThread(); - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { showDialog( dlgID ); // crash m_blockingDlgPosted = true; @@ -1276,7 +1277,7 @@ public class BoardActivity extends XWActivity } m_dlgBytes = txt; - m_handler.post( new Runnable() { + post( new Runnable() { public void run() { showDialog( dlgID ); } @@ -1369,9 +1370,36 @@ public class BoardActivity extends XWActivity } }; } - m_handler.removeCallbacks( m_screenTimer ); // needed? - m_handler.postDelayed( m_screenTimer, SCREEN_ON_TIME ); + removeCallbacks( m_screenTimer ); // needed? + postDelayed( m_screenTimer, SCREEN_ON_TIME ); } } + private void post( Runnable runnable ) + { + if ( null != m_handler ) { + m_handler.post( runnable ); + } else { + Utils.logf( "post: dropping because handler null" ); + } + } + + private void postDelayed( Runnable runnable, int when ) + { + if ( null != m_handler ) { + m_handler.postDelayed( runnable, when ); + } else { + Utils.logf( "postDelayed: dropping %d because handler null", when ); + } + } + + private void removeCallbacks( Runnable which ) + { + if ( null != m_handler ) { + m_handler.removeCallbacks( which ); + } else { + Utils.logf( "removeCallbacks: dropping %h because handler null", + which ); + } + } } // class BoardActivity