From 1ee0dfdd6dd6adfa49a7d9d28d0a25b5f011d97f Mon Sep 17 00:00:00 2001 From: Andy2 Date: Sun, 21 Aug 2011 22:13:18 -0700 Subject: [PATCH 01/30] set wordlist spinner prompt and include language --- xwords4/android/XWords4/res/layout/player_edit.xml | 1 - .../XWords4/src/org/eehouse/android/xw4/GameConfig.java | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/res/layout/player_edit.xml b/xwords4/android/XWords4/res/layout/player_edit.xml index fb302e3ff..cf5427b14 100644 --- a/xwords4/android/XWords4/res/layout/player_edit.xml +++ b/xwords4/android/XWords4/res/layout/player_edit.xml @@ -72,7 +72,6 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" - android:prompt="@string/dicts_list_promptf" /> Date: Mon, 22 Aug 2011 07:03:46 -0700 Subject: [PATCH 02/30] display three states of relay connectedness in games list items: configured, connected but waiting for players, and game-in-play. --- .../android/XWords4/res/values/strings.xml | 6 ++++- .../eehouse/android/xw4/jni/GameSummary.java | 24 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index c5650e22f..521660c42 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -365,7 +365,11 @@ check off-device players. Modified first player. - Connecting via Relay, room \"%s\" + Configured for room + \"%s\" + Waiting for players in room + \"%s\" + Game in play in room \"%s\" Game over %d moves played diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java index 6a2dee187..d6953d405 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java @@ -118,10 +118,18 @@ public class GameSummary { { String result = null; if ( isRelayGame() ) { + Assert.assertTrue( CommsAddrRec.CommsConnType.COMMS_CONN_RELAY == conType ); - String fmt = m_context.getString( R.string.summary_fmt_relay ); - result = String.format( fmt, roomName ); + int fmtID; + if ( null == relayID || 0 == relayID.length() ) { + fmtID = R.string.summary_relay_conff; + } else if ( anyMissing() ) { + fmtID = R.string.summary_relay_waitf; + } else { + fmtID = R.string.summary_relay_connf; + } + result = String.format( m_context.getString(fmtID), roomName ); } return result; } @@ -144,6 +152,18 @@ public class GameSummary { return result; } + private boolean anyMissing() + { + boolean missing = false; + for ( int ii = 0; ii < nPlayers; ++ii ) { + if ( !isLocal(ii) && (0 != ((1 << ii) & missingPlayers) ) ) { + missing = true; + break; + } + } + return missing; + } + public int giflags() { int result; if ( null == m_gi ) { From 7e6daa5797cf3b3e9f20915b508a834677645491 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 22 Aug 2011 07:05:33 -0700 Subject: [PATCH 03/30] move role out of players column to where it can be a full line long, preventing it from increasing the size of the item by line-wrapping. For now it's outside the View that gets hidden, but that may need to change. --- .../XWords4/res/layout/game_list_item.xml | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/xwords4/android/XWords4/res/layout/game_list_item.xml b/xwords4/android/XWords4/res/layout/game_list_item.xml index 62555d926..d5e06ef77 100644 --- a/xwords4/android/XWords4/res/layout/game_list_item.xml +++ b/xwords4/android/XWords4/res/layout/game_list_item.xml @@ -58,25 +58,12 @@ android:padding="4sp"> - - - - - - - - + /> + + + From 3296cad731b9ca170425798fa8101988572c6332 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 22 Aug 2011 18:10:22 -0700 Subject: [PATCH 04/30] pass bundle into DlgDelegate so state can be saved and restored. Not doing anything with it yet because any scheme to survive OS-restoration has to deal with the Runnables I'm saving that can't be bundled. Work in progress.... --- .../src/org/eehouse/android/xw4/DictsActivity.java | 11 +++++++++-- .../src/org/eehouse/android/xw4/DlgDelegate.java | 13 ++++++++++--- .../src/org/eehouse/android/xw4/XWActivity.java | 9 ++++++++- .../src/org/eehouse/android/xw4/XWListActivity.java | 9 ++++++++- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 45aabc836..c49cd95c1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -294,14 +294,14 @@ public class DictsActivity extends ExpandableListActivity } @Override - protected void onCreate(Bundle savedInstanceState) + protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); Resources res = getResources(); m_locNames = res.getStringArray( R.array.loc_names ); - m_delegate = new DlgDelegate( this ); + m_delegate = new DlgDelegate( this, savedInstanceState ); m_factory = LayoutInflater.from( this ); m_download = getString( R.string.download_dicts ); @@ -338,6 +338,13 @@ public class DictsActivity extends ExpandableListActivity expandGroups(); } + @Override + protected void onSaveInstanceState( Bundle outState ) + { + super.onSaveInstanceState( outState ); + m_delegate.onSaveInstanceState( outState ); + } + protected void onPause() { m_cardWatcher.close(); m_cardWatcher = null; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index abc2ee79f..970a445da 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -21,14 +21,16 @@ package org.eehouse.android.xw4; import android.app.Activity; +import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; -import junit.framework.Assert; +import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.Toast; -import android.app.AlertDialog; + +import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommonPrefs; @@ -56,9 +58,14 @@ public class DlgDelegate { }; private TextOrHtmlClicked m_txt_or_html; - public DlgDelegate( Activity activity ) { + public DlgDelegate( Activity activity, Bundle bundle ) { m_activity = activity; } + + public void onSaveInstanceState( Bundle outState ) + { + // not doing anything yet + } public Dialog onCreateDialog( int id ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index d094a9adf..7cfdacf79 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -41,7 +41,7 @@ public class XWActivity extends Activity { { Utils.logf( "%s.onCreate(this=%H)", getClass().getName(), this ); super.onCreate( savedInstanceState ); - m_delegate = new DlgDelegate( this ); + m_delegate = new DlgDelegate( this, savedInstanceState ); } @Override @@ -82,6 +82,13 @@ public class XWActivity extends Activity { super.onDestroy(); } + @Override + protected void onSaveInstanceState( Bundle outState ) + { + super.onSaveInstanceState( outState ); + m_delegate.onSaveInstanceState( outState ); + } + @Override protected Dialog onCreateDialog( int id ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index bb1206eff..67a850cd2 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -35,7 +35,7 @@ public class XWListActivity extends ListActivity { { Utils.logf( "%s.onCreate(this=%H)", getClass().getName(), this ); super.onCreate( savedInstanceState ); - m_delegate = new DlgDelegate( this ); + m_delegate = new DlgDelegate( this, savedInstanceState ); } @Override @@ -76,6 +76,13 @@ public class XWListActivity extends ListActivity { super.onDestroy(); } + @Override + protected void onSaveInstanceState( Bundle outState ) + { + super.onSaveInstanceState( outState ); + m_delegate.onSaveInstanceState( outState ); + } + @Override protected Dialog onCreateDialog( final int id ) { From 3537161d3b12c75ca177af7dd3e33fd573de7a1c Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 22 Aug 2011 18:40:30 -0700 Subject: [PATCH 05/30] add change --- xwords4/android/XWords4/res/raw/changes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xwords4/android/XWords4/res/raw/changes b/xwords4/android/XWords4/res/raw/changes index 7ef1b14a2..9f9e0fd1c 100644 --- a/xwords4/android/XWords4/res/raw/changes +++ b/xwords4/android/XWords4/res/raw/changes @@ -24,6 +24,9 @@
  • Make a game's language one of several configurable attributes that can be displayed along with the game
  • +
  • Display relay connection state as being in one of three phases: + configured, connected, and with all players present.
  • +
  • Fix rename of games to work when keyboard opened while dialog up.
  • From 953909d0f05d31c4c82b41baf9348cf746e2a8a5 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 22 Aug 2011 18:40:44 -0700 Subject: [PATCH 06/30] remove logging --- .../XWords4/src/org/eehouse/android/xw4/DlgDelegate.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 970a445da..7dcee5058 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -301,9 +301,7 @@ public class DlgDelegate { private Dialog createDictGoneDialog() { - Utils.logf( "DlgDelegate.createDictGoneDialog() called" ); - Dialog dialog; - dialog = new AlertDialog.Builder( m_activity ) + Dialog dialog = new AlertDialog.Builder( m_activity ) .setTitle( R.string.no_dict_title ) .setMessage( R.string.no_dict_finish ) .setPositiveButton( R.string.button_close_game, null ) From 84e61f3b3f5667e68f0ab56010df2e2c3b853c73 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 22 Aug 2011 18:43:42 -0700 Subject: [PATCH 07/30] remove no-op line --- xwords4/android/XWords4/jni/anddict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/jni/anddict.c b/xwords4/android/XWords4/jni/anddict.c index 1e6ffe3c7..84ce56000 100644 --- a/xwords4/android/XWords4/jni/anddict.c +++ b/xwords4/android/XWords4/jni/anddict.c @@ -487,7 +487,7 @@ makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jstring jname, anddict->bytes = (*env)->GetByteArrayElements( env, anddict->byteArray, NULL ); } else { - anddict->byteArray = NULL; + XP_ASSERT( NULL == anddict->byteArray ); const char* path = (*env)->GetStringUTFChars( env, jpath, NULL ); struct stat statbuf; From 7da5b24e0fd738f0a17d210a97dcf2b25452619c Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 23 Aug 2011 18:41:19 -0700 Subject: [PATCH 08/30] rewrite DictsActivity to not crash when un- and re-loaded: make dialogs depend only on bundleable ivars -- ints and strings, not Views -- and bundle them. Don't use onPrepareDialog, only onCreateDialog, and so call removeDialog() every time one's dismissed. Do some refactoring to support this. --- .../eehouse/android/xw4/BoardActivity.java | 2 +- .../eehouse/android/xw4/DictsActivity.java | 208 +++++++++++------- .../org/eehouse/android/xw4/DlgDelegate.java | 11 - .../org/eehouse/android/xw4/GamesList.java | 2 +- .../src/org/eehouse/android/xw4/Utils.java | 17 +- .../org/eehouse/android/xw4/XWActivity.java | 5 - .../eehouse/android/xw4/XWListActivity.java | 5 - 7 files changed, 149 insertions(+), 101 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 436809680..128792ad4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -157,7 +157,7 @@ public class BoardActivity extends XWActivity ab.setNegativeButton( R.string.button_retry, lstnr ); } dialog = ab.create(); - setRemoveOnDismiss( dialog, id ); + Utils.setRemoveOnDismiss( this, dialog, id ); break; case DLG_DELETED: diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index c49cd95c1..9f5784956 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -61,6 +61,12 @@ public class DictsActivity extends ExpandableListActivity private static final String DICT_DOLAUNCH = "do_launch"; private static final String DICT_LANG_EXTRA = "use_lang"; private static final String DICT_NAME_EXTRA = "use_dict"; + private static final String PACKED_POSITION = "packed_position"; + private static final String NAME = "name"; + private static final String LANG = "lang"; + private static final String MOVEFROMLOC = "movefromloc"; + private static final String MOVETOLOC = "movetoloc"; + private static final int PICK_STORAGE = DlgDelegate.DIALOG_LAST + 1; private static final int MOVE_DICT = DlgDelegate.DIALOG_LAST + 2; @@ -72,17 +78,18 @@ public class DictsActivity extends ExpandableListActivity private ExpandableListView m_expView; private DlgDelegate m_delegate; private String[] m_locNames; + private DictListAdapter m_adapter; - private XWListItem m_rowView; - GameUtils.DictLoc m_moveFromLoc; - GameUtils.DictLoc m_moveToLoc; + private long m_packedPosition; + private GameUtils.DictLoc m_moveFromLoc; + private GameUtils.DictLoc m_moveToLoc; private SDCardWatcher m_cardWatcher; - private String m_moveName; private LayoutInflater m_factory; private class DictListAdapter implements ExpandableListAdapter { private Context m_context; + private XWListItem[][] m_cache; public DictListAdapter( Context context ) { //super( context, m_dicts.length ); @@ -105,29 +112,41 @@ public class DictsActivity extends ExpandableListActivity boolean isLastChild, View convertView, ViewGroup parent) { - int lang = (int)getGroupId( groupPosition ); - String[] dicts = DictLangCache.getHaveLang( m_context, lang ); - String text; - boolean canDelete = false; - if ( null != dicts && childPosition < dicts.length ) { - text = dicts[childPosition]; - canDelete = !GameUtils.dictIsBuiltin( DictsActivity.this, - text ); - } else { - text = m_download; - } - XWListItem view = - (XWListItem)m_factory.inflate( R.layout.list_item, null ); - view.setText( text ); - if ( canDelete ) { - view.setDeleteCallback( DictsActivity.this ); + return getChildView( groupPosition, childPosition ); + } + + private View getChildView( int groupPosition, int childPosition ) + { + XWListItem view = null; + if ( null != m_cache && null != m_cache[groupPosition] ) { + view = m_cache[groupPosition][childPosition]; } - GameUtils.DictLoc loc = - GameUtils.getDictLoc( DictsActivity.this, text ); - view.setComment( m_locNames[loc.ordinal()] ); - view.cache( loc ); + if ( null == view ) { + int lang = (int)getGroupId( groupPosition ); + String[] dicts = DictLangCache.getHaveLang( m_context, lang ); + String text; + boolean canDelete = false; + if ( null != dicts && childPosition < dicts.length ) { + text = dicts[childPosition]; + canDelete = !GameUtils.dictIsBuiltin( DictsActivity.this, + text ); + } else { + text = m_download; + } + view = (XWListItem)m_factory.inflate( R.layout.list_item, null ); + view.setText( text ); + if ( canDelete ) { + view.setDeleteCallback( DictsActivity.this ); + } + GameUtils.DictLoc loc = + GameUtils.getDictLoc( DictsActivity.this, text ); + view.setComment( m_locNames[loc.ordinal()] ); + view.cache( loc ); + + addToCache( groupPosition, childPosition, view ); + } return view; } @@ -188,17 +207,40 @@ public class DictsActivity extends ExpandableListActivity public void onGroupExpanded(int groupPosition){} public void registerDataSetObserver( DataSetObserver obs ){} public void unregisterDataSetObserver( DataSetObserver obs ){} + + protected XWListItem getSelChildView() + { + int groupPosition = + ExpandableListView.getPackedPositionGroup( m_packedPosition ); + int childPosition = + ExpandableListView.getPackedPositionChild( m_packedPosition ); + return (XWListItem)getChildView( groupPosition, childPosition ); + } + + private void addToCache( int group, int child, XWListItem view ) + { + if ( null == m_cache ) { + m_cache = new XWListItem[getGroupCount()][]; + } + if ( null == m_cache[group] ) { + m_cache[group] = new XWListItem[getChildrenCount(group)]; + } + Assert.assertTrue( null == m_cache[group][child] ); + m_cache[group][child] = view; + } } @Override protected Dialog onCreateDialog( int id ) { - Dialog dialog; DialogInterface.OnClickListener lstnr; + Dialog dialog; + String format; + String message; + boolean doRemove = true; switch( id ) { case PICK_STORAGE: - lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int item ) { startDownload( m_lang, m_name, item != @@ -216,21 +258,28 @@ public class DictsActivity extends ExpandableListActivity case MOVE_DICT: lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int item ) { + XWListItem rowView = m_adapter.getSelChildView(); if ( GameUtils.moveDict( DictsActivity.this, - m_moveName, + rowView.getText(), m_moveFromLoc, m_moveToLoc ) ) { - m_rowView. + rowView. setComment( m_locNames[m_moveToLoc.ordinal()]); - m_rowView.cache( m_moveToLoc ); - m_rowView.invalidate(); + rowView.cache( m_moveToLoc ); + rowView.invalidate(); } else { Utils.logf( "moveDict failed" ); } } }; + format = getString( R.string.move_dictf ); + message = String.format( format, + m_adapter.getSelChildView().getText(), + m_locNames[ m_moveFromLoc.ordinal() ], + m_locNames[ m_moveToLoc.ordinal() ] ); + dialog = new AlertDialog.Builder( this ) - .setMessage( "" ) // will set later + .setMessage( message ) .setPositiveButton( R.string.button_ok, lstnr ) .setNegativeButton( R.string.button_cancel, null ) .create(); @@ -240,18 +289,22 @@ public class DictsActivity extends ExpandableListActivity public void onClick( DialogInterface dlg, int item ) { if ( DialogInterface.BUTTON_NEGATIVE == item || DialogInterface.BUTTON_POSITIVE == item ) { - setDefault( R.string.key_default_dict, m_rowView ); + setDefault( R.string.key_default_dict ); } if ( DialogInterface.BUTTON_NEGATIVE == item || DialogInterface.BUTTON_NEUTRAL == item ) { - setDefault( R.string.key_default_robodict, - m_rowView ); + setDefault( R.string.key_default_robodict ); } } }; + XWListItem rowView = m_adapter.getSelChildView(); + String lang = + DictLangCache.getLangName( this, rowView.getText() ); + format = getString( R.string.set_default_messagef ); + message = String.format( format, lang ); dialog = new AlertDialog.Builder( this ) .setTitle( R.string.query_title ) - .setMessage( "" ) // or can't change it later! + .setMessage( message ) .setPositiveButton( R.string.button_default_human, lstnr ) .setNeutralButton( R.string.button_default_robot, lstnr ) .setNegativeButton( R.string.button_default_both, lstnr ) @@ -259,44 +312,22 @@ public class DictsActivity extends ExpandableListActivity break; default: dialog = m_delegate.onCreateDialog( id ); + doRemove = false; break; } + + if ( doRemove && null != dialog ) { + Utils.setRemoveOnDismiss( this, dialog, id ); + } + return dialog; - } - - @Override - public void onPrepareDialog( int id, Dialog dialog ) - { - AlertDialog ad = (AlertDialog)dialog; - String format; - String message; - - switch( id ) { - case PICK_STORAGE: - break; - case MOVE_DICT: - format = getString( R.string.move_dictf ); - message = String.format( format, m_moveName, - m_locNames[ m_moveFromLoc.ordinal() ], - m_locNames[ m_moveToLoc.ordinal() ] ); - ad.setMessage( message ); - break; - case SET_DEFAULT: - String lang = - DictLangCache.getLangName( this, m_rowView.getText() ); - format = getString( R.string.set_default_messagef ); - message = String.format( format, lang ); - ad.setMessage( message ); - break; - default: - m_delegate.onPrepareDialog( id, dialog ); - } - } + } // onCreateDialog @Override protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); + getBundledData( savedInstanceState ); Resources res = getResources(); m_locNames = res.getStringArray( R.array.loc_names ); @@ -343,8 +374,37 @@ public class DictsActivity extends ExpandableListActivity { super.onSaveInstanceState( outState ); m_delegate.onSaveInstanceState( outState ); + + outState.putLong( PACKED_POSITION, m_packedPosition ); + outState.putString( NAME, m_name ); + outState.putInt( LANG, m_lang ); + if ( null != m_moveFromLoc ) { + outState.putInt( MOVEFROMLOC, m_moveFromLoc.ordinal() ); + } + if ( null != m_moveToLoc ) { + outState.putInt( MOVETOLOC, m_moveToLoc.ordinal() ); + } } + private void getBundledData( Bundle savedInstanceState ) + { + if ( null != savedInstanceState ) { + m_packedPosition = savedInstanceState.getLong( PACKED_POSITION ); + m_name = savedInstanceState.getString( NAME ); + m_lang = savedInstanceState.getInt( LANG ); + + int tmp = savedInstanceState.getInt( MOVEFROMLOC, -1 ); + if ( -1 != tmp ) { + m_moveFromLoc = GameUtils.DictLoc.values()[tmp]; + } + tmp = savedInstanceState.getInt( MOVETOLOC, -1 ); + if ( -1 != tmp ) { + m_moveToLoc = GameUtils.DictLoc.values()[tmp]; + } + } + } + + @Override protected void onPause() { m_cardWatcher.close(); m_cardWatcher = null; @@ -402,14 +462,14 @@ public class DictsActivity extends ExpandableListActivity return false; } - XWListItem row = (XWListItem)info.targetView; + m_packedPosition = info.packedPosition; + int id = item.getItemId(); switch( id ) { case R.id.dicts_item_move: - askMoveDict( row ); + askMoveDict( (XWListItem)info.targetView ); break; case R.id.dicts_item_select: - m_rowView = row; showDialog( SET_DEFAULT ); break; case R.id.dicts_item_details: @@ -420,13 +480,14 @@ public class DictsActivity extends ExpandableListActivity return handled; } - private void setDefault( int keyId, final XWListItem text ) + private void setDefault( int keyId ) { + XWListItem view = m_adapter.getSelChildView(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences( this ); SharedPreferences.Editor editor = sp.edit(); String key = getString( keyId ); - String name = text.getText(); + String name = view.getText(); editor.putString( key, name ); editor.commit(); } @@ -436,14 +497,12 @@ public class DictsActivity extends ExpandableListActivity // options for YY? private void askMoveDict( XWListItem item ) { - m_rowView = item; m_moveFromLoc = (GameUtils.DictLoc)item.getCached(); if ( m_moveFromLoc == GameUtils.DictLoc.INTERNAL ) { m_moveToLoc = GameUtils.DictLoc.EXTERNAL; } else { m_moveToLoc = GameUtils.DictLoc.INTERNAL; } - m_moveName = item.getText(); showDialog( MOVE_DICT ); } @@ -515,9 +574,8 @@ public class DictsActivity extends ExpandableListActivity private void mkListAdapter() { m_langs = DictLangCache.listLangs( this ); - //m_langs = DictLangCache.getLangNames( this ); - ExpandableListAdapter adapter = new DictListAdapter( this ); - setListAdapter( adapter ); + m_adapter = new DictListAdapter( this ); + setListAdapter( m_adapter ); } private void expandGroups() diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 7dcee5058..1027e9fc4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -93,17 +93,6 @@ public class DlgDelegate { return dialog; } - protected void setRemoveOnDismiss( Dialog dialog, final int id ) - { - dialog.setOnDismissListener( new DialogInterface.OnDismissListener() { - public void onDismiss( DialogInterface di ) { - Utils.logf( "%s.onDismiss() called", - getClass().getName() ); - m_activity.removeDialog( id ); - } - } ); - } - public void onPrepareDialog( int id, Dialog dialog ) { AlertDialog ad = (AlertDialog)dialog; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index e91a13658..29257fa57 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -124,7 +124,7 @@ public class GamesList extends XWListActivity ab.setNeutralButton( R.string.button_substdict, lstnr ); } dialog = ab.create(); - setRemoveOnDismiss( dialog, id ); + Utils.setRemoveOnDismiss( this, dialog, id ); break; case SHOW_SUBST: m_sameLangDicts = diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index ec785a166..5edf3f811 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -22,14 +22,15 @@ package org.eehouse.android.xw4; import android.util.Log; import java.lang.Thread; -import android.widget.Toast; +import android.app.Activity; +import android.app.Dialog; +import android.content.DialogInterface; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.widget.CheckBox; -import android.app.Activity; -import android.app.Dialog; +import android.widget.Toast; import android.widget.EditText; import android.widget.TextView; import android.view.LayoutInflater; @@ -105,6 +106,16 @@ public class Utils { Toast.makeText( context, text, Toast.LENGTH_SHORT).show(); } + public static void setRemoveOnDismiss( final Activity activity, + Dialog dialog, final int id ) + { + dialog.setOnDismissListener( new DialogInterface.OnDismissListener() { + public void onDismiss( DialogInterface di ) { + activity.removeDialog( id ); + } + } ); + } + public static View inflate( Context context, int layoutId ) { LayoutInflater factory = LayoutInflater.from( context ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index 7cfdacf79..3185c74bc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -100,11 +100,6 @@ public class XWActivity extends Activity { return dialog; } - protected void setRemoveOnDismiss( Dialog dialog, int id ) - { - m_delegate.setRemoveOnDismiss( dialog, id ); - } - @Override protected void onPrepareDialog( int id, Dialog dialog ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index 67a850cd2..a9e85f969 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -105,11 +105,6 @@ public class XWListActivity extends ListActivity { return dialog; } - protected void setRemoveOnDismiss( Dialog dialog, int id ) - { - m_delegate.setRemoveOnDismiss( dialog, id ); - } - @Override protected void onPrepareDialog( int id, Dialog dialog ) { From 7a235ed6b627d6209dafc5f36d0eff7e9557d6e5 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 23 Aug 2011 18:51:48 -0700 Subject: [PATCH 09/30] put onPrepareDialog() back -- it's required to use DlgDelegate dialogs. --- .../XWords4/src/org/eehouse/android/xw4/DictsActivity.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 9f5784956..74086008a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -323,6 +323,13 @@ public class DictsActivity extends ExpandableListActivity return dialog; } // onCreateDialog + @Override + protected void onPrepareDialog( int id, Dialog dialog ) + { + super.onPrepareDialog( id, dialog ); + m_delegate.onPrepareDialog( id, dialog ); + } + @Override protected void onCreate( Bundle savedInstanceState ) { From 0d85a67700e8f40e43aa17b9df5f50215b7e55cb Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 23 Aug 2011 19:18:45 -0700 Subject: [PATCH 10/30] verify that bundle saving works in DlgDelegate and fix one disappearing message. Still need solution for callbacks passed in. --- .../src/org/eehouse/android/xw4/DlgDelegate.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 1027e9fc4..d8d8d013e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -45,6 +45,8 @@ public class DlgDelegate { public static final int DLG_DICTGONE = 6; public static final int DIALOG_LAST = DLG_DICTGONE; + public static final String MSG = "msg"; + private int m_msgID; private String m_msg; private Runnable m_proc = null; @@ -58,13 +60,18 @@ public class DlgDelegate { }; private TextOrHtmlClicked m_txt_or_html; - public DlgDelegate( Activity activity, Bundle bundle ) { + public DlgDelegate( Activity activity, Bundle bundle ) + { m_activity = activity; + + if ( null != bundle ) { + m_msg = bundle.getString( MSG ); + } } public void onSaveInstanceState( Bundle outState ) { - // not doing anything yet + outState.putString( MSG, m_msg ); } public Dialog onCreateDialog( int id ) From 05607a15b94d92d0a21ef1e6b89e945278808a2b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 23 Aug 2011 19:50:01 -0700 Subject: [PATCH 11/30] toward a bundleable DlgDelegate: add new interface to replace OnClickListerners passed on, have clients of DlgDelegate implement it, and convert one dialog to use it. Will eventually remove old code. --- .../eehouse/android/xw4/DictsActivity.java | 33 +++++++++++------ .../org/eehouse/android/xw4/DlgDelegate.java | 36 +++++++++++++++++-- .../org/eehouse/android/xw4/XWActivity.java | 12 +++++-- .../eehouse/android/xw4/XWListActivity.java | 14 ++++++-- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 74086008a..6dbbcfea1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -56,17 +56,20 @@ import org.eehouse.android.xw4.jni.CommonPrefs; public class DictsActivity extends ExpandableListActivity implements View.OnClickListener, XWListItem.DeleteCallback, - SDCardWatcher.SDCardNotifiee { + SDCardWatcher.SDCardNotifiee, DlgDelegate.DlgClickNotify { private static final String DICT_DOLAUNCH = "do_launch"; private static final String DICT_LANG_EXTRA = "use_lang"; private static final String DICT_NAME_EXTRA = "use_dict"; private static final String PACKED_POSITION = "packed_position"; + private static final String DELETE_DICT = "delete_dict"; private static final String NAME = "name"; private static final String LANG = "lang"; private static final String MOVEFROMLOC = "movefromloc"; private static final String MOVETOLOC = "movetoloc"; + // For new callback alternative + private static final int DELETE_DICT_ACTION = 1; private static final int PICK_STORAGE = DlgDelegate.DIALOG_LAST + 1; private static final int MOVE_DICT = DlgDelegate.DIALOG_LAST + 2; @@ -74,6 +77,7 @@ public class DictsActivity extends ExpandableListActivity private int m_lang = 0; private String[] m_langs; private String m_name = null; + private String m_deleteDict = null; private String m_download; private ExpandableListView m_expView; private DlgDelegate m_delegate; @@ -339,7 +343,7 @@ public class DictsActivity extends ExpandableListActivity Resources res = getResources(); m_locNames = res.getStringArray( R.array.loc_names ); - m_delegate = new DlgDelegate( this, savedInstanceState ); + m_delegate = new DlgDelegate( this, this, savedInstanceState ); m_factory = LayoutInflater.from( this ); m_download = getString( R.string.download_dicts ); @@ -385,6 +389,7 @@ public class DictsActivity extends ExpandableListActivity outState.putLong( PACKED_POSITION, m_packedPosition ); outState.putString( NAME, m_name ); outState.putInt( LANG, m_lang ); + outState.putString( DELETE_DICT, m_deleteDict ); if ( null != m_moveFromLoc ) { outState.putInt( MOVEFROMLOC, m_moveFromLoc.ordinal() ); } @@ -399,6 +404,7 @@ public class DictsActivity extends ExpandableListActivity m_packedPosition = savedInstanceState.getLong( PACKED_POSITION ); m_name = savedInstanceState.getString( NAME ); m_lang = savedInstanceState.getInt( LANG ); + m_deleteDict = savedInstanceState.getString( DELETE_DICT ); int tmp = savedInstanceState.getInt( MOVEFROMLOC, -1 ); if ( -1 != tmp ) { @@ -515,19 +521,14 @@ public class DictsActivity extends ExpandableListActivity } // XWListItem.DeleteCallback interface - public void deleteCalled( int myPosition, final String dict ) + public void deleteCalled( int myPosition, String dict ) { int code = DictLangCache.getDictLangCode( this, dict ); String lang = DictLangCache.getLangName( this, code ); int nGames = DBUtils.countGamesUsing( this, code ); String msg = String.format( getString( R.string.confirm_delete_dictf ), dict ); - DialogInterface.OnClickListener action = - new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int item ) { - deleteDict( dict ); - } - }; + m_deleteDict = dict; if ( nGames > 0 ) { int fmt; @@ -539,7 +540,7 @@ public class DictsActivity extends ExpandableListActivity msg += String.format( getString(fmt), lang ); } - m_delegate.showConfirmThen( msg, action ); + m_delegate.showConfirmThen( msg, DELETE_DICT_ACTION ); } // SDCardWatcher.SDCardNotifiee interface @@ -549,6 +550,18 @@ public class DictsActivity extends ExpandableListActivity expandGroups(); } + // DlgDelegate.DlgClickNotify interface + public void buttonClicked( int id ) + { + switch( id ) { + case DELETE_DICT_ACTION: + deleteDict( m_deleteDict ); + break; + default: + Assert.fail(); + } + } + private void deleteDict( String dict ) { GameUtils.deleteDict( this, dict ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index d8d8d013e..96288554e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -43,15 +43,23 @@ public class DlgDelegate { public static final int CONFIRM_THEN = 4; public static final int TEXT_OR_HTML_THEN = 5; public static final int DLG_DICTGONE = 6; - public static final int DIALOG_LAST = DLG_DICTGONE; + public static final int CONFIRM_THEN2 = 7; + public static final int DIALOG_LAST = CONFIRM_THEN2; public static final String MSG = "msg"; + public static final String CALLBACK = "callback"; + + public interface DlgClickNotify { + void buttonClicked( int id ); + } private int m_msgID; + private int m_cbckID; private String m_msg; private Runnable m_proc = null; private int m_prefsKey; private Activity m_activity; + private DlgClickNotify m_clickCallback; private String m_dictName = null; DialogInterface.OnClickListener m_then; @@ -60,18 +68,22 @@ public class DlgDelegate { }; private TextOrHtmlClicked m_txt_or_html; - public DlgDelegate( Activity activity, Bundle bundle ) + public DlgDelegate( Activity activity, DlgClickNotify callback, + Bundle bundle ) { m_activity = activity; + m_clickCallback = callback; if ( null != bundle ) { m_msg = bundle.getString( MSG ); + m_cbckID = bundle.getInt( CALLBACK ); } } public void onSaveInstanceState( Bundle outState ) { outState.putString( MSG, m_msg ); + outState.putInt( CALLBACK, m_cbckID ); } public Dialog onCreateDialog( int id ) @@ -90,6 +102,9 @@ public class DlgDelegate { case CONFIRM_THEN: dialog = createConfirmThenDialog(); break; + case CONFIRM_THEN2: + dialog = createConfirmThenDialog(); + break; case TEXT_OR_HTML_THEN: dialog = createHtmlThenDialog(); break; @@ -123,6 +138,16 @@ public class DlgDelegate { ad.setButton( AlertDialog.BUTTON_POSITIVE, m_activity.getString( R.string.button_ok ), m_then ); break; + case CONFIRM_THEN2: + ad.setMessage( m_msg ); + lstnr = new DialogInterface.OnClickListener() { + public void onClick( DialogInterface dlg, int button ) { + m_clickCallback.buttonClicked( m_cbckID ); + } + }; + ad.setButton( AlertDialog.BUTTON_POSITIVE, + m_activity.getString( R.string.button_ok ), lstnr ); + break; case TEXT_OR_HTML_THEN: lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { @@ -181,6 +206,13 @@ public class DlgDelegate { m_activity.showDialog( CONFIRM_THEN ); } + public void showConfirmThen( String msg, int callbackID ) + { + m_msg = msg; + m_cbckID = callbackID; + m_activity.showDialog( CONFIRM_THEN2 ); + } + public void showTextOrHtmlThen( TextOrHtmlClicked txtOrHtml ) { m_txt_or_html = txtOrHtml; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index 3185c74bc..8a8786421 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -32,7 +32,8 @@ import android.os.Bundle; import org.eehouse.android.xw4.jni.CommonPrefs; -public class XWActivity extends Activity { +public class XWActivity extends Activity + implements DlgDelegate.DlgClickNotify { private DlgDelegate m_delegate; @@ -41,7 +42,7 @@ public class XWActivity extends Activity { { Utils.logf( "%s.onCreate(this=%H)", getClass().getName(), this ); super.onCreate( savedInstanceState ); - m_delegate = new DlgDelegate( this, savedInstanceState ); + m_delegate = new DlgDelegate( this, this, savedInstanceState ); } @Override @@ -145,4 +146,11 @@ public class XWActivity extends Activity { { m_delegate.doSyncMenuitem(); } + + // DlgDelegate.DlgClickNotify interface + public void buttonClicked( int id ) + { + Assert.fail(); + } + } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index a9e85f969..82488c0a8 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -25,9 +25,13 @@ import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; +import junit.framework.Assert; + import org.eehouse.android.xw4.jni.CommonPrefs; -public class XWListActivity extends ListActivity { +public class XWListActivity extends ListActivity + implements DlgDelegate.DlgClickNotify { + private DlgDelegate m_delegate; @Override @@ -35,7 +39,7 @@ public class XWListActivity extends ListActivity { { Utils.logf( "%s.onCreate(this=%H)", getClass().getName(), this ); super.onCreate( savedInstanceState ); - m_delegate = new DlgDelegate( this, savedInstanceState ); + m_delegate = new DlgDelegate( this, this, savedInstanceState ); } @Override @@ -151,4 +155,10 @@ public class XWListActivity extends ListActivity { m_delegate.doSyncMenuitem(); } + // DlgDelegate.DlgClickNotify interface + public void buttonClicked( int id ) + { + Assert.fail(); + } + } From fbb467af80f20f77c091a5c98176bcf776468722 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 23 Aug 2011 20:25:59 -0700 Subject: [PATCH 12/30] convert some more callbacks to ints passed back: GamesList done. --- .../org/eehouse/android/xw4/GamesList.java | 83 ++++++++++--------- .../eehouse/android/xw4/NetLaunchInfo.java | 26 ++++++ .../eehouse/android/xw4/XWListActivity.java | 10 +++ 3 files changed, 82 insertions(+), 37 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 29257fa57..219234dbb 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -63,6 +63,11 @@ public class GamesList extends XWListActivity private static final String SAVE_ROWID = "SAVE_ROWID"; + private static final int NEW_NET_GAME_ACTION = 1; + private static final int RESET_GAME_ACTION = 2; + private static final int DELETE_GAME_ACTION = 3; + private static final int DELETE_ALL_ACTION = 4; + private GameListAdapter m_adapter; private String m_missingDict; private Handler m_handler; @@ -72,6 +77,7 @@ public class GamesList extends XWListActivity private int m_missingDictLang; private long m_rowid; private String m_nameField; + private NetLaunchInfo m_netLaunchInfo; @Override protected Dialog onCreateDialog( int id ) @@ -334,12 +340,16 @@ public class GamesList extends XWListActivity { super.onSaveInstanceState( outState ); outState.putLong( SAVE_ROWID, m_rowid ); + if ( null != m_netLaunchInfo ) { + m_netLaunchInfo.putSelf( outState ); + } } private void getBundledData( Bundle bundle ) { if ( null != bundle ) { m_rowid = bundle.getLong( SAVE_ROWID ); + m_netLaunchInfo = new NetLaunchInfo( bundle ); } } @@ -393,6 +403,32 @@ public class GamesList extends XWListActivity onContentChanged(); } + // DlgDelegate.DlgClickNotify interface + public void buttonClicked( int id ) + { + switch( id ) { + case NEW_NET_GAME_ACTION: + long rowid = GameUtils.makeNewNetGame( this, m_netLaunchInfo ); + GameUtils.launchGame( this, rowid, true ); + break; + case RESET_GAME_ACTION: + GameUtils.resetGame( this, m_rowid ); + break; + case DELETE_GAME_ACTION: + GameUtils.deleteGame( this, m_rowid, true ); + break; + case DELETE_ALL_ACTION: + long[] games = DBUtils.gamesList( this ); + for ( int ii = games.length - 1; ii >= 0; --ii ) { + GameUtils.deleteGame( this, games[ii], ii == 0 ); + m_adapter.inval( games[ii] ); + } + break; + default: + Assert.fail(); + } + } + public void itemClicked( long rowid ) { // We need a way to let the user get back to the basic-config @@ -466,19 +502,9 @@ public class GamesList extends XWListActivity break; case R.id.gamel_menu_delete_all: - final long[] games = DBUtils.gamesList( this ); - if ( games.length > 0 ) { - DialogInterface.OnClickListener lstnr = - new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int item ) { - for ( int ii = games.length - 1; ii >= 0; --ii ) { - GameUtils.deleteGame( GamesList.this, games[ii], - ii == 0 ); - m_adapter.inval( games[ii] ); - } - } - }; - showConfirmThen( R.string.confirm_delete_all, lstnr ); + if ( DBUtils.gamesList( this ).length > 0 ) { + showConfirmThen( R.string.confirm_delete_all, + DELETE_ALL_ACTION ); } handled = true; break; @@ -525,22 +551,14 @@ public class GamesList extends XWListActivity final long rowid = DBUtils.gamesList( this )[position]; if ( R.id.list_item_delete == menuID ) { - lstnr = new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int ii ) { - GameUtils.deleteGame( GamesList.this, rowid, true ); - } - }; - showConfirmThen( R.string.confirm_delete, lstnr ); + m_rowid = rowid; + showConfirmThen( R.string.confirm_delete, DELETE_GAME_ACTION ); } else { if ( checkWarnNoDict( rowid ) ) { switch ( menuID ) { case R.id.list_item_reset: - lstnr = new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int ii ) { - GameUtils.resetGame( GamesList.this, rowid ); - } - }; - showConfirmThen( R.string.confirm_reset, lstnr ); + m_rowid = rowid; + showConfirmThen( R.string.confirm_reset, RESET_GAME_ACTION ); break; case R.id.list_item_config: GameUtils.doConfig( this, rowid, GameConfig.class ); @@ -656,7 +674,7 @@ public class GamesList extends XWListActivity startActivity( new Intent( this, NewGameActivity.class ) ); } - private void startNewNetGame( final NetLaunchInfo info ) + private void startNewNetGame( NetLaunchInfo info ) { long rowid = DBUtils.getRowIDForOpen( this, info.room, info.lang, info.nPlayers ); @@ -665,19 +683,10 @@ public class GamesList extends XWListActivity rowid = GameUtils.makeNewNetGame( this, info ); GameUtils.launchGame( this, rowid, true ); } else { - DialogInterface.OnClickListener then = - new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, - int ii ) { - long rowid = GameUtils. - makeNewNetGame( GamesList.this, info ); - GameUtils.launchGame( GamesList.this, - rowid, true ); - } - }; String fmt = getString( R.string.dup_game_queryf ); String msg = String.format( fmt, info.room ); - showConfirmThen( msg, then ); + m_netLaunchInfo = info; + showConfirmThen( msg, NEW_NET_GAME_ACTION ); } } // startNewNetGame diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java index 83619ac0a..ce8499a7f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java @@ -23,6 +23,7 @@ package org.eehouse.android.xw4; import android.content.Context; import android.net.Uri; import android.net.Uri.Builder; +import android.os.Bundle; import java.net.URLEncoder; import org.eehouse.android.xw4.jni.CommonPrefs; @@ -33,8 +34,33 @@ public class NetLaunchInfo { public int lang; public int nPlayers; + private static final String LANG = "netlaunchinfo_lang"; + private static final String ROOM = "netlaunchinfo_room"; + private static final String NPLAYERS = "netlaunchinfo_nplayers"; + private static final String VALID = "netlaunchinfo_valid"; + private boolean m_valid; + public void putSelf( Bundle bundle ) + { + bundle.putInt( LANG, lang ); + bundle.putString( ROOM, room ); + bundle.putInt( NPLAYERS, nPlayers ); + bundle.putBoolean( VALID, m_valid ); + Utils.logf( "bundling NetLaunchInfo: %d, %s, %d, %b", + lang, room, nPlayers, m_valid ); + } + + public NetLaunchInfo( Bundle bundle ) + { + lang = bundle.getInt( LANG ); + room = bundle.getString( ROOM ); + nPlayers = bundle.getInt( NPLAYERS ); + m_valid = bundle.getBoolean( VALID ); + Utils.logf( "unbundled NetLaunchInfo: %d, %s, %d, %b", + lang, room, nPlayers, m_valid ); + } + public static Uri makeLaunchUri( Context context, String room, int lang, int nPlayers ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index 82488c0a8..3b6a0629a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -144,6 +144,16 @@ public class XWListActivity extends ListActivity m_delegate.showConfirmThen( msg, action ); } + protected void showConfirmThen( String msg, int action ) + { + m_delegate.showConfirmThen( msg, action ); + } + + protected void showConfirmThen( int msg, int action ) + { + m_delegate.showConfirmThen( getString(msg), action ); + } + protected void showConfirmThen( int msgID, DialogInterface.OnClickListener action ) { From 85c38e831f109ab0fb6f76025656a24e001dd781 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 05:40:13 -0700 Subject: [PATCH 13/30] cleanup: null's same as empty onClick handler --- .../eehouse/android/xw4/BoardActivity.java | 60 +++++++++---------- 1 file changed, 27 insertions(+), 33 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 128792ad4..a4e5dfd5d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -258,14 +258,7 @@ public class BoardActivity extends XWActivity handle(JNICmd.CMD_ENDGAME); } }) - .setNegativeButton( R.string.button_no, - new DialogInterface.OnClickListener() { - public void - onClick( DialogInterface dlg, - int item ) { - // do nothing - } - }) + .setNegativeButton( R.string.button_no, null ) .create(); break; case DLG_INVITE: @@ -1079,31 +1072,32 @@ public class BoardActivity extends XWActivity langName ); } - m_jniThread = new - JNIThread( m_jniGamePtr, m_gi, m_view, m_gameLock, this, - new Handler() { - public void handleMessage( Message msg ) { - switch( msg.what ) { - case JNIThread.DRAW: - m_view.invalidate(); - break; - case JNIThread.DIALOG: - m_dlgBytes = (String)msg.obj; - m_dlgTitle = msg.arg1; - showDialog( DLG_OKONLY ); - break; - case JNIThread.QUERY_ENDGAME: - showDialog( QUERY_ENDGAME ); - break; - case JNIThread.TOOLBAR_STATES: - if ( null != m_jniThread ) { - m_gsi = m_jniThread.getGameStateInfo(); - updateToolbar(); - } - break; - } - } - } ); + Handler handler = new Handler() { + public void handleMessage( Message msg ) { + switch( msg.what ) { + case JNIThread.DRAW: + m_view.invalidate(); + break; + case JNIThread.DIALOG: + m_dlgBytes = (String)msg.obj; + m_dlgTitle = msg.arg1; + showDialog( DLG_OKONLY ); + break; + case JNIThread.QUERY_ENDGAME: + showDialog( QUERY_ENDGAME ); + break; + case JNIThread.TOOLBAR_STATES: + if ( null != m_jniThread ) { + m_gsi = + m_jniThread.getGameStateInfo(); + updateToolbar(); + } + break; + } + } + }; + m_jniThread = new JNIThread( m_jniGamePtr, m_gi, m_view, + m_gameLock, this, handler ); // see http://stackoverflow.com/questions/680180/where-to-stop-\ // destroy-threads-in-android-service-class m_jniThread.setDaemon( true ); From 7d0cbcf07f6ce184ed9d38cb75955cfa94f19b0e Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 06:12:57 -0700 Subject: [PATCH 14/30] use new showConfirmThen scheme --- .../eehouse/android/xw4/BoardActivity.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 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 a4e5dfd5d..ff98d7495 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -73,6 +73,8 @@ public class BoardActivity extends XWActivity private static final int CHAT_REQUEST = 1; private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins + private static final int UNDO_LAST_ACTION = 1; + private static final String DLG_TITLE = "DLG_TITLE"; private static final String DLG_TITLESTR = "DLG_TITLESTR"; private static final String DLG_BYTES = "DLG_BYTES"; @@ -509,14 +511,7 @@ public class BoardActivity extends XWActivity // cmd = JNIThread.JNICmd.CMD_UNDO_CUR; // break; case R.id.board_menu_undo_last: - showConfirmThen( R.string.confirm_undo_last, - new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, - int whichButton ) { - m_jniThread.handle( JNIThread.JNICmd. - CMD_UNDO_LAST ); - } - } ); + showConfirmThen( R.string.confirm_undo_last, UNDO_LAST_ACTION ); break; case R.id.board_menu_values: cmd = JNIThread.JNICmd.CMD_VALUES; @@ -568,6 +563,22 @@ public class BoardActivity extends XWActivity return handled; } + ////////////////////////////////////////////////// + // DlgDelegate.DlgClickNotify interface + ////////////////////////////////////////////////// + + public void buttonClicked( int id, boolean cancelled ) + { + switch ( id ) { + case UNDO_LAST_ACTION: + if ( !cancelled ) { + m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_LAST ); + } + break; + default: + Assert.fail(); + } + } ////////////////////////////////////////////////// // TransportProcs.TPMsgHandler interface From f88697fd3fa5d9a74ea057c4c677f4b96dd8b0ac Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 06:14:42 -0700 Subject: [PATCH 15/30] complete conversion of showConfirmThen, removing old methods and adding second param to buttonClicked() callback indicating which button was cancelled. --- .../eehouse/android/xw4/DictsActivity.java | 6 ++- .../org/eehouse/android/xw4/DlgDelegate.java | 34 +++++---------- .../org/eehouse/android/xw4/GamesList.java | 42 ++++++++++--------- .../org/eehouse/android/xw4/XWActivity.java | 5 +-- .../eehouse/android/xw4/XWListActivity.java | 14 +------ 5 files changed, 40 insertions(+), 61 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 6dbbcfea1..19ae6a706 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -551,11 +551,13 @@ public class DictsActivity extends ExpandableListActivity } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id ) + public void buttonClicked( int id, boolean cancelled ) { switch( id ) { case DELETE_DICT_ACTION: - deleteDict( m_deleteDict ); + if ( !cancelled ) { + deleteDict( m_deleteDict ); + } break; default: Assert.fail(); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 96288554e..a8f93ee68 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -43,14 +43,14 @@ public class DlgDelegate { public static final int CONFIRM_THEN = 4; public static final int TEXT_OR_HTML_THEN = 5; public static final int DLG_DICTGONE = 6; - public static final int CONFIRM_THEN2 = 7; - public static final int DIALOG_LAST = CONFIRM_THEN2; + public static final int DIALOG_LAST = DLG_DICTGONE; public static final String MSG = "msg"; public static final String CALLBACK = "callback"; + public static final String MSGID = "msgid"; public interface DlgClickNotify { - void buttonClicked( int id ); + void buttonClicked( int id, boolean cancelled ); } private int m_msgID; @@ -61,7 +61,6 @@ public class DlgDelegate { private Activity m_activity; private DlgClickNotify m_clickCallback; private String m_dictName = null; - DialogInterface.OnClickListener m_then; public interface TextOrHtmlClicked { public void clicked( boolean choseText ); @@ -77,6 +76,7 @@ public class DlgDelegate { if ( null != bundle ) { m_msg = bundle.getString( MSG ); m_cbckID = bundle.getInt( CALLBACK ); + m_msgID = bundle.getInt( MSGID ); } } @@ -84,6 +84,7 @@ public class DlgDelegate { { outState.putString( MSG, m_msg ); outState.putInt( CALLBACK, m_cbckID ); + outState.putInt( MSGID, m_msgID ); } public Dialog onCreateDialog( int id ) @@ -102,9 +103,6 @@ public class DlgDelegate { case CONFIRM_THEN: dialog = createConfirmThenDialog(); break; - case CONFIRM_THEN2: - dialog = createConfirmThenDialog(); - break; case TEXT_OR_HTML_THEN: dialog = createHtmlThenDialog(); break; @@ -132,21 +130,18 @@ public class DlgDelegate { ad.setMessage( m_activity.getString(m_msgID) ); break; case CONFIRM_THEN: - // I'm getting an occasional 0 here on device only. May - // be related to screen orientation changes. Let's be safe - ad.setMessage( m_msg ); - ad.setButton( AlertDialog.BUTTON_POSITIVE, - m_activity.getString( R.string.button_ok ), m_then ); - break; - case CONFIRM_THEN2: ad.setMessage( m_msg ); lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { - m_clickCallback.buttonClicked( m_cbckID ); + boolean cancelled = + button == DialogInterface.BUTTON_NEGATIVE; + m_clickCallback.buttonClicked( m_cbckID, cancelled ); } }; ad.setButton( AlertDialog.BUTTON_POSITIVE, m_activity.getString( R.string.button_ok ), lstnr ); + ad.setButton( AlertDialog.BUTTON_NEGATIVE, + m_activity.getString( R.string.button_ok ), lstnr ); break; case TEXT_OR_HTML_THEN: lstnr = new DialogInterface.OnClickListener() { @@ -199,18 +194,11 @@ public class DlgDelegate { } } - public void showConfirmThen( String msg, DialogInterface.OnClickListener then ) - { - m_msg = msg; - m_then = then; - m_activity.showDialog( CONFIRM_THEN ); - } - public void showConfirmThen( String msg, int callbackID ) { m_msg = msg; m_cbckID = callbackID; - m_activity.showDialog( CONFIRM_THEN2 ); + m_activity.showDialog( CONFIRM_THEN ); } public void showTextOrHtmlThen( TextOrHtmlClicked txtOrHtml ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 219234dbb..2180538c1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -404,28 +404,30 @@ public class GamesList extends XWListActivity } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id ) + public void buttonClicked( int id, boolean cancelled ) { - switch( id ) { - case NEW_NET_GAME_ACTION: - long rowid = GameUtils.makeNewNetGame( this, m_netLaunchInfo ); - GameUtils.launchGame( this, rowid, true ); - break; - case RESET_GAME_ACTION: - GameUtils.resetGame( this, m_rowid ); - break; - case DELETE_GAME_ACTION: - GameUtils.deleteGame( this, m_rowid, true ); - break; - case DELETE_ALL_ACTION: - long[] games = DBUtils.gamesList( this ); - for ( int ii = games.length - 1; ii >= 0; --ii ) { - GameUtils.deleteGame( this, games[ii], ii == 0 ); - m_adapter.inval( games[ii] ); + if ( !cancelled ) { + switch( id ) { + case NEW_NET_GAME_ACTION: + long rowid = GameUtils.makeNewNetGame( this, m_netLaunchInfo ); + GameUtils.launchGame( this, rowid, true ); + break; + case RESET_GAME_ACTION: + GameUtils.resetGame( this, m_rowid ); + break; + case DELETE_GAME_ACTION: + GameUtils.deleteGame( this, m_rowid, true ); + break; + case DELETE_ALL_ACTION: + long[] games = DBUtils.gamesList( this ); + for ( int ii = games.length - 1; ii >= 0; --ii ) { + GameUtils.deleteGame( this, games[ii], ii == 0 ); + m_adapter.inval( games[ii] ); + } + break; + default: + Assert.fail(); } - break; - default: - Assert.fail(); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index 8a8786421..9ab43b70c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -131,8 +131,7 @@ public class XWActivity extends Activity m_delegate.showDictGoneFinish(); } - protected void showConfirmThen( int msgID, - DialogInterface.OnClickListener action ) + protected void showConfirmThen( int msgID, int action ) { m_delegate.showConfirmThen( getString(msgID), action ); } @@ -148,7 +147,7 @@ public class XWActivity extends Activity } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id ) + public void buttonClicked( int id, boolean cancelled ) { Assert.fail(); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index 3b6a0629a..f595a6e1e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -138,12 +138,6 @@ public class XWListActivity extends ListActivity m_delegate.showOKOnlyDialog( msgID ); } - protected void showConfirmThen( String msg, - DialogInterface.OnClickListener action ) - { - m_delegate.showConfirmThen( msg, action ); - } - protected void showConfirmThen( String msg, int action ) { m_delegate.showConfirmThen( msg, action ); @@ -154,19 +148,13 @@ public class XWListActivity extends ListActivity m_delegate.showConfirmThen( getString(msg), action ); } - protected void showConfirmThen( int msgID, - DialogInterface.OnClickListener action ) - { - showConfirmThen( getString(msgID), action ); - } - protected void doSyncMenuitem() { m_delegate.doSyncMenuitem(); } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id ) + public void buttonClicked( int id, boolean cancelled ) { Assert.fail(); } From 3a2af96c2450bbecd5f4d4408cb2b478c4c6cbe0 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 06:51:00 -0700 Subject: [PATCH 16/30] use new callback-replaced-by-id mechanism to query for html/text choice. --- .../eehouse/android/xw4/DictsActivity.java | 2 +- .../org/eehouse/android/xw4/DlgDelegate.java | 41 +++++++------------ .../org/eehouse/android/xw4/GameUtils.java | 15 ------- .../org/eehouse/android/xw4/GamesList.java | 2 +- .../eehouse/android/xw4/NewGameActivity.java | 20 ++++++--- .../org/eehouse/android/xw4/XWActivity.java | 6 +-- .../eehouse/android/xw4/XWListActivity.java | 2 +- 7 files changed, 35 insertions(+), 53 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 19ae6a706..921664968 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -551,7 +551,7 @@ public class DictsActivity extends ExpandableListActivity } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id, boolean cancelled ) + public void dlgButtonClicked( int id, boolean cancelled ) { switch( id ) { case DELETE_DICT_ACTION: diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index a8f93ee68..8ab96b1c2 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -50,7 +50,7 @@ public class DlgDelegate { public static final String MSGID = "msgid"; public interface DlgClickNotify { - void buttonClicked( int id, boolean cancelled ); + void dlgButtonClicked( int id, boolean cancelled ); } private int m_msgID; @@ -62,11 +62,6 @@ public class DlgDelegate { private DlgClickNotify m_clickCallback; private String m_dictName = null; - public interface TextOrHtmlClicked { - public void clicked( boolean choseText ); - }; - private TextOrHtmlClicked m_txt_or_html; - public DlgDelegate( Activity activity, DlgClickNotify callback, Bundle bundle ) { @@ -135,7 +130,7 @@ public class DlgDelegate { public void onClick( DialogInterface dlg, int button ) { boolean cancelled = button == DialogInterface.BUTTON_NEGATIVE; - m_clickCallback.buttonClicked( m_cbckID, cancelled ); + m_clickCallback.dlgButtonClicked( m_cbckID, cancelled ); } }; ad.setButton( AlertDialog.BUTTON_POSITIVE, @@ -143,22 +138,6 @@ public class DlgDelegate { ad.setButton( AlertDialog.BUTTON_NEGATIVE, m_activity.getString( R.string.button_ok ), lstnr ); break; - case TEXT_OR_HTML_THEN: - lstnr = new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int button ) { - if ( null != m_txt_or_html ) { - m_txt_or_html. - clicked( button == AlertDialog.BUTTON_POSITIVE ); - } - } - }; - ad.setButton( AlertDialog.BUTTON_POSITIVE, - m_activity.getString( R.string.button_text ), - lstnr ); - ad.setButton( AlertDialog.BUTTON_NEGATIVE, - m_activity.getString( R.string.button_html ), - lstnr ); - break; } } @@ -201,9 +180,9 @@ public class DlgDelegate { m_activity.showDialog( CONFIRM_THEN ); } - public void showTextOrHtmlThen( TextOrHtmlClicked txtOrHtml ) + public void showTextOrHtmlThen( int callbackID ) { - m_txt_or_html = txtOrHtml; + m_cbckID = callbackID; m_activity.showDialog( TEXT_OR_HTML_THEN ); } @@ -307,11 +286,19 @@ public class DlgDelegate { private Dialog createHtmlThenDialog() { + DialogInterface.OnClickListener lstnr = + new DialogInterface.OnClickListener() { + public void onClick( DialogInterface dlg, int button ) { + boolean cancelled = + button == DialogInterface.BUTTON_NEGATIVE; + m_clickCallback.dlgButtonClicked( m_cbckID, cancelled ); + } + }; return new AlertDialog.Builder( m_activity ) .setTitle( R.string.query_title ) .setMessage( R.string.text_or_html ) - .setPositiveButton( R.string.button_text, null ) // will change - .setNegativeButton( R.string.button_html, null ) + .setPositiveButton( R.string.button_text, lstnr ) + .setNegativeButton( R.string.button_html, lstnr ) .create(); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index 975daa65f..d202df276 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -460,21 +460,6 @@ public class GameUtils { } } - public static void launchInviteActivity( final XWActivity activity, - final String room, - final int lang, - final int nPlayers ) - { - DlgDelegate.TextOrHtmlClicked cb = - new DlgDelegate.TextOrHtmlClicked() { - public void clicked( boolean choseText ) { - launchInviteActivity( activity, choseText, room, - lang, nPlayers ); - } - }; - activity.showTextOrHtmlThen( cb ); - } - public static boolean gameDictsHere( Context context, long rowid ) { return gameDictsHere( context, rowid, null, null ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 2180538c1..0320ea5f3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -404,7 +404,7 @@ public class GamesList extends XWListActivity } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id, boolean cancelled ) + public void dlgButtonClicked( int id, boolean cancelled ) { if ( !cancelled ) { switch( id ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java index 1e8fdeaef..067ae0896 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java @@ -29,6 +29,7 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; import java.util.Random; +import junit.framework.Assert; import org.eehouse.android.xw4.jni.CurGameInfo; import org.eehouse.android.xw4.jni.CommonPrefs; @@ -38,6 +39,8 @@ import org.eehouse.android.xw4.jni.XwJNI; public class NewGameActivity extends XWActivity { + private static final int NEW_GAME_ACTION = 1; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -84,15 +87,22 @@ public class NewGameActivity extends XWActivity { } + public void dlgButtonClicked( int id, boolean cancelled ) + { + switch( id ) { + case NEW_GAME_ACTION: + makeNewGame( true, true, !cancelled ); + break; + default: + Assert.fail(); + } + } + private void makeNewGame( boolean networked, boolean launch ) { if ( launch && networked ) { // Let 'em cancel before we make the game - showTextOrHtmlThen( new DlgDelegate.TextOrHtmlClicked() { - public void clicked( boolean choseText ) { - makeNewGame( true, true, choseText ); - } - } ); + showTextOrHtmlThen( NEW_GAME_ACTION ); } else { makeNewGame( networked, launch, false ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index 9ab43b70c..212c818e2 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -136,9 +136,9 @@ public class XWActivity extends Activity m_delegate.showConfirmThen( getString(msgID), action ); } - public void showTextOrHtmlThen( DlgDelegate.TextOrHtmlClicked txtOrHtml ) + public void showTextOrHtmlThen( int action ) { - m_delegate.showTextOrHtmlThen( txtOrHtml ); + m_delegate.showTextOrHtmlThen( action ); } protected void doSyncMenuitem() @@ -147,7 +147,7 @@ public class XWActivity extends Activity } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id, boolean cancelled ) + public void dlgButtonClicked( int id, boolean cancelled ) { Assert.fail(); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index f595a6e1e..f5cfd781a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -154,7 +154,7 @@ public class XWListActivity extends ListActivity } // DlgDelegate.DlgClickNotify interface - public void buttonClicked( int id, boolean cancelled ) + public void dlgButtonClicked( int id, boolean cancelled ) { Assert.fail(); } From 50c692024b37e755b4d67391a3aaf69e7b101c41 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 18:18:17 -0700 Subject: [PATCH 17/30] fix crashes when reloading (rare unless android:configChanges removed from AndroidManifest.xml). Problem was that managed dialogs are recreated between onStart() and onResume() yet onResume() was where ivars (specifically m_gi) were set. Can't just set them in onStart() because then I'd want to save state them in onStop() which isn't guaranteed to be called. So create a function loadGame() and call it from both, using a flag to prevent its running twice (which flag is cleared in onPause()) --- .../org/eehouse/android/xw4/GameConfig.java | 208 ++++++++++-------- 1 file changed, 120 insertions(+), 88 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java index f51a684e7..f0d95fba8 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java @@ -68,6 +68,8 @@ public class GameConfig extends XWActivity private static final int CONFIRM_CHANGE_PLAY = PLAYER_EDIT + 3; private static final int NO_NAME_FOUND = PLAYER_EDIT + 4; + private static final String WHICH_PLAYER = "WHICH_PLAYER"; + private CheckBox m_joinPublicCheck; private CheckBox m_gameLockedCheck; private boolean m_isLocked; @@ -202,7 +204,7 @@ public class GameConfig extends XWActivity .create(); dialog.setOnDismissListener( new DialogInterface.OnDismissListener() { @Override - public void onDismiss( DialogInterface di ) + public void onDismiss( DialogInterface di ) { if ( m_gi.forceRemoteConsistent() ) { Toast.makeText( GameConfig.this, @@ -358,6 +360,7 @@ public class GameConfig extends XWActivity public void onCreate( Bundle savedInstanceState ) { super.onCreate(savedInstanceState); + getBundledData( savedInstanceState ); // 1.5 doesn't have SDK_INT. So parse the string version. // int sdk_int = 0; @@ -391,97 +394,19 @@ public class GameConfig extends XWActivity setTitle(); } // onCreate + @Override + protected void onStart() + { + super.onStart(); + loadGame(); + } + @Override protected void onResume() { super.onResume(); - - m_giOrig = new CurGameInfo( this ); - // Lock in case we're going to config. We *could* re-get the - // lock once the user decides to make changes. PENDING. - m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock(); - int gamePtr = GameUtils.loadMakeGame( this, m_giOrig, m_gameLock ); - if ( 0 == gamePtr ) { - showDictGoneFinish(); - } else { - m_gameStarted = XwJNI.model_getNMoves( gamePtr ) > 0 - || XwJNI.comms_isConnected( gamePtr ); - - if ( m_gameStarted ) { - if ( null == m_gameLockedCheck ) { - m_gameLockedCheck = - (CheckBox)findViewById( R.id.game_locked_check ); - m_gameLockedCheck.setVisibility( View.VISIBLE ); - m_gameLockedCheck.setChecked( true ); - m_gameLockedCheck.setOnClickListener( this ); - } - handleLockedChange(); - } - - m_gi = new CurGameInfo( this, m_giOrig ); - - m_carOrig = new CommsAddrRec( this ); - if ( XwJNI.game_hasComms( gamePtr ) ) { - XwJNI.comms_getAddr( gamePtr, m_carOrig ); - } else { - String relayName = CommonPrefs.getDefaultRelayHost( this ); - int relayPort = CommonPrefs.getDefaultRelayPort( this ); - XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort ); - } - XwJNI.game_dispose( gamePtr ); - - m_car = new CommsAddrRec( m_carOrig ); - - m_notNetworkedGame = DeviceRole.SERVER_STANDALONE == m_gi.serverRole; - setTitle(); - - if ( !m_notNetworkedGame ) { - m_joinPublicCheck = - (CheckBox)findViewById(R.id.join_public_room_check); - m_joinPublicCheck.setOnClickListener( this ); - m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom ); - Utils.setChecked( this, R.id.advertise_new_room_check, - m_car.ip_relay_advertiseRoom ); - m_publicRoomsSet = - (LinearLayout)findViewById(R.id.public_rooms_set ); - m_privateRoomsSet = - (LinearLayout)findViewById(R.id.private_rooms_set ); - - Utils.setText( this, R.id.room_edit, m_car.ip_relay_invite ); - - m_roomChoose = (Spinner)findViewById( R.id.room_spinner ); - - m_refreshRoomsButton = - (ImageButton)findViewById( R.id.refresh_button ); - m_refreshRoomsButton.setOnClickListener( this ); - - adjustConnectStuff(); - } - - loadPlayers(); - configLangSpinner(); - - m_phoniesSpinner.setSelection( m_gi.phoniesAction.ordinal() ); - - setSmartnessSpinner(); - - Utils.setChecked( this, R.id.hints_allowed, !m_gi.hintsNotAllowed ); - Utils.setInt( this, R.id.timer_minutes_edit, - m_gi.gameSeconds/60/m_gi.nPlayers ); - - CheckBox check = (CheckBox)findViewById( R.id.use_timer ); - CompoundButton.OnCheckedChangeListener lstnr = - new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged( CompoundButton buttonView, - boolean checked ) { - View view = findViewById( R.id.timer_set ); - view.setVisibility( checked ? View.VISIBLE : View.GONE ); - } - }; - check.setOnCheckedChangeListener( lstnr ); - Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled ); - } - } // onResume + loadGame(); + } @Override protected void onPause() @@ -490,9 +415,116 @@ public class GameConfig extends XWActivity m_gameLock.unlock(); m_gameLock = null; } + m_giOrig = null; // flag for onStart and onResume super.onPause(); } + @Override + protected void onSaveInstanceState( Bundle outState ) + { + super.onSaveInstanceState( outState ); + outState.putInt( WHICH_PLAYER, m_whichPlayer ); + } + + private void loadGame() + { + if ( null == m_giOrig ) { + m_giOrig = new CurGameInfo( this ); + + // Lock in case we're going to config. We *could* re-get the + // lock once the user decides to make changes. PENDING. + m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock(); + int gamePtr = GameUtils.loadMakeGame( this, m_giOrig, m_gameLock ); + if ( 0 == gamePtr ) { + showDictGoneFinish(); + } else { + m_gameStarted = XwJNI.model_getNMoves( gamePtr ) > 0 + || XwJNI.comms_isConnected( gamePtr ); + + if ( m_gameStarted ) { + if ( null == m_gameLockedCheck ) { + m_gameLockedCheck = + (CheckBox)findViewById( R.id.game_locked_check ); + m_gameLockedCheck.setVisibility( View.VISIBLE ); + m_gameLockedCheck.setChecked( true ); + m_gameLockedCheck.setOnClickListener( this ); + } + handleLockedChange(); + } + + m_gi = new CurGameInfo( this, m_giOrig ); + + m_carOrig = new CommsAddrRec( this ); + if ( XwJNI.game_hasComms( gamePtr ) ) { + XwJNI.comms_getAddr( gamePtr, m_carOrig ); + } else { + String relayName = CommonPrefs.getDefaultRelayHost( this ); + int relayPort = CommonPrefs.getDefaultRelayPort( this ); + XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort ); + } + XwJNI.game_dispose( gamePtr ); + + m_car = new CommsAddrRec( m_carOrig ); + + m_notNetworkedGame = DeviceRole.SERVER_STANDALONE == m_gi.serverRole; + setTitle(); + + if ( !m_notNetworkedGame ) { + m_joinPublicCheck = + (CheckBox)findViewById(R.id.join_public_room_check); + m_joinPublicCheck.setOnClickListener( this ); + m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom ); + Utils.setChecked( this, R.id.advertise_new_room_check, + m_car.ip_relay_advertiseRoom ); + m_publicRoomsSet = + (LinearLayout)findViewById(R.id.public_rooms_set ); + m_privateRoomsSet = + (LinearLayout)findViewById(R.id.private_rooms_set ); + + Utils.setText( this, R.id.room_edit, m_car.ip_relay_invite ); + + m_roomChoose = (Spinner)findViewById( R.id.room_spinner ); + + m_refreshRoomsButton = + (ImageButton)findViewById( R.id.refresh_button ); + m_refreshRoomsButton.setOnClickListener( this ); + + adjustConnectStuff(); + } + + loadPlayers(); + configLangSpinner(); + + m_phoniesSpinner.setSelection( m_gi.phoniesAction.ordinal() ); + + setSmartnessSpinner(); + + Utils.setChecked( this, R.id.hints_allowed, !m_gi.hintsNotAllowed ); + Utils.setInt( this, R.id.timer_minutes_edit, + m_gi.gameSeconds/60/m_gi.nPlayers ); + + CheckBox check = (CheckBox)findViewById( R.id.use_timer ); + CompoundButton.OnCheckedChangeListener lstnr = + new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged( CompoundButton buttonView, + boolean checked ) { + View view = findViewById( R.id.timer_set ); + view.setVisibility( checked ? View.VISIBLE : View.GONE ); + } + }; + check.setOnCheckedChangeListener( lstnr ); + Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled ); + } + } + } // loadGame + + private void getBundledData( Bundle bundle ) + { + if ( null != bundle ) { + m_whichPlayer = bundle.getInt( WHICH_PLAYER ); + } + } + // DeleteCallback interface public void deleteCalled( int myPosition, final String name ) { From 4ac84dde239e22262156e60fc30e2f43d3d975a8 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 18:22:21 -0700 Subject: [PATCH 18/30] change sig of DlgDelegate's dlgButtonClicked() method to include id of button rather than just boolean. Add onDismissListener so can tell if whole thing was backed-out of (since that's a different choice from the two buttons "text" and "html" used in one case.) Fix compile error that slipped by earlier: frequent clean builds required with java. --- .../eehouse/android/xw4/BoardActivity.java | 24 ++++++++++----- .../eehouse/android/xw4/DictsActivity.java | 4 +-- .../org/eehouse/android/xw4/DlgDelegate.java | 29 ++++++++++++------- .../org/eehouse/android/xw4/GamesList.java | 5 ++-- .../eehouse/android/xw4/NewGameActivity.java | 8 +++-- .../org/eehouse/android/xw4/XWActivity.java | 2 +- .../eehouse/android/xw4/XWListActivity.java | 2 +- 7 files changed, 48 insertions(+), 26 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 ff98d7495..33ca877ba 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -74,10 +74,12 @@ public class BoardActivity extends XWActivity private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins private static final int UNDO_LAST_ACTION = 1; + private static final int LAUNCH_INVITE_ACTION = 2; private static final String DLG_TITLE = "DLG_TITLE"; private static final String DLG_TITLESTR = "DLG_TITLESTR"; private static final String DLG_BYTES = "DLG_BYTES"; + private static final String ROOM = "ROOM"; private BoardView m_view; private int m_jniGamePtr; @@ -268,10 +270,7 @@ public class BoardActivity extends XWActivity lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int item ) { - GameUtils.launchInviteActivity( BoardActivity.this, - m_room, - m_gi.dictLang, - m_gi.nPlayers ); + showTextOrHtmlThen( LAUNCH_INVITE_ACTION ); } }; dialog = new AlertDialog.Builder( this ) @@ -364,6 +363,7 @@ public class BoardActivity extends XWActivity outState.putInt( DLG_TITLESTR, m_dlgTitle ); outState.putString( DLG_TITLESTR, m_dlgTitleStr ); outState.putString( DLG_BYTES, m_dlgBytes ); + outState.putString( ROOM, m_room ); } private void getBundledData( Bundle bundle ) @@ -372,6 +372,7 @@ public class BoardActivity extends XWActivity m_dlgTitleStr = bundle.getString( DLG_TITLESTR ); m_dlgTitle = bundle.getInt( DLG_TITLE ); m_dlgBytes = bundle.getString( DLG_BYTES ); + m_room = bundle.getString( ROOM ); } } @@ -566,15 +567,24 @@ public class BoardActivity extends XWActivity ////////////////////////////////////////////////// // DlgDelegate.DlgClickNotify interface ////////////////////////////////////////////////// - - public void buttonClicked( int id, boolean cancelled ) + @Override + public void dlgButtonClicked( int id, int which ) { switch ( id ) { case UNDO_LAST_ACTION: - if ( !cancelled ) { + if ( AlertDialog.BUTTON_POSITIVE == which ) { m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_LAST ); } break; + case LAUNCH_INVITE_ACTION: + if ( -1 != which ) { + GameUtils.launchInviteActivity( BoardActivity.this, + DlgDelegate.TEXT_BTN == which, + m_room, + m_gi.dictLang, + m_gi.nPlayers ); + } + break; default: Assert.fail(); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 921664968..7475222d1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -551,11 +551,11 @@ public class DictsActivity extends ExpandableListActivity } // DlgDelegate.DlgClickNotify interface - public void dlgButtonClicked( int id, boolean cancelled ) + public void dlgButtonClicked( int id, int which ) { switch( id ) { case DELETE_DICT_ACTION: - if ( !cancelled ) { + if ( DialogInterface.BUTTON_POSITIVE == which ) { deleteDict( m_deleteDict ); } break; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 8ab96b1c2..a9763a631 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -45,12 +45,15 @@ public class DlgDelegate { public static final int DLG_DICTGONE = 6; public static final int DIALOG_LAST = DLG_DICTGONE; - public static final String MSG = "msg"; - public static final String CALLBACK = "callback"; - public static final String MSGID = "msgid"; + public static final int TEXT_BTN = AlertDialog.BUTTON_POSITIVE; + public static final int HTML_BTN = AlertDialog.BUTTON_NEGATIVE; + + private static final String MSG = "msg"; + private static final String CALLBACK = "callback"; + private static final String MSGID = "msgid"; public interface DlgClickNotify { - void dlgButtonClicked( int id, boolean cancelled ); + void dlgButtonClicked( int id, int which ); } private int m_msgID; @@ -128,9 +131,7 @@ public class DlgDelegate { ad.setMessage( m_msg ); lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { - boolean cancelled = - button == DialogInterface.BUTTON_NEGATIVE; - m_clickCallback.dlgButtonClicked( m_cbckID, cancelled ); + m_clickCallback.dlgButtonClicked( m_cbckID, button ); } }; ad.setButton( AlertDialog.BUTTON_POSITIVE, @@ -289,17 +290,23 @@ public class DlgDelegate { DialogInterface.OnClickListener lstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { - boolean cancelled = - button == DialogInterface.BUTTON_NEGATIVE; - m_clickCallback.dlgButtonClicked( m_cbckID, cancelled ); + m_clickCallback.dlgButtonClicked( m_cbckID, button ); } }; - return new AlertDialog.Builder( m_activity ) + Dialog dialog = new AlertDialog.Builder( m_activity ) .setTitle( R.string.query_title ) .setMessage( R.string.text_or_html ) .setPositiveButton( R.string.button_text, lstnr ) .setNegativeButton( R.string.button_html, lstnr ) .create(); + + dialog.setOnDismissListener( new DialogInterface.OnDismissListener() { + public void onDismiss( DialogInterface di ) { + m_clickCallback.dlgButtonClicked( m_cbckID, -1 ); + } + } ); + + return dialog; } private Dialog createDictGoneDialog() diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 0320ea5f3..c193da570 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -404,9 +404,10 @@ public class GamesList extends XWListActivity } // DlgDelegate.DlgClickNotify interface - public void dlgButtonClicked( int id, boolean cancelled ) + @Override + public void dlgButtonClicked( int id, int which ) { - if ( !cancelled ) { + if ( AlertDialog.BUTTON_POSITIVE == which ) { switch( id ) { case NEW_NET_GAME_ACTION: long rowid = GameUtils.makeNewNetGame( this, m_netLaunchInfo ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java index 067ae0896..1f44dcddd 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java @@ -87,11 +87,15 @@ public class NewGameActivity extends XWActivity { } - public void dlgButtonClicked( int id, boolean cancelled ) + // DlgDelegate.DlgClickNotify interface + @Override + public void dlgButtonClicked( int id, int which ) { switch( id ) { case NEW_GAME_ACTION: - makeNewGame( true, true, !cancelled ); + if ( -1 != which ) { + makeNewGame( true, true, DlgDelegate.TEXT_BTN == which ); + } break; default: Assert.fail(); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index 212c818e2..e8bf0e62c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -147,7 +147,7 @@ public class XWActivity extends Activity } // DlgDelegate.DlgClickNotify interface - public void dlgButtonClicked( int id, boolean cancelled ) + public void dlgButtonClicked( int id, int which ) { Assert.fail(); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index f5cfd781a..fd6e85055 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -154,7 +154,7 @@ public class XWListActivity extends ListActivity } // DlgDelegate.DlgClickNotify interface - public void dlgButtonClicked( int id, boolean cancelled ) + public void dlgButtonClicked( int id, int which ) { Assert.fail(); } From 5769ae6a319ae5b6a1038b5d785bc68569f69b0c Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 18:51:47 -0700 Subject: [PATCH 19/30] cleanup: there are two listeners created over and over; better to store in a class static and reuse. --- .../org/eehouse/android/xw4/DlgDelegate.java | 64 +++++++++++-------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index a9763a631..7b566212a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -52,8 +52,12 @@ public class DlgDelegate { private static final String CALLBACK = "callback"; private static final String MSGID = "msgid"; + // Cache a couple of callback implementations that never change: + private static DialogInterface.OnClickListener s_cbkOnClickLstnr = null; + private static DialogInterface.OnDismissListener s_cbkOnDismissLstnr = null; + public interface DlgClickNotify { - void dlgButtonClicked( int id, int which ); + void dlgButtonClicked( int id, int button ); } private int m_msgID; @@ -129,15 +133,6 @@ public class DlgDelegate { break; case CONFIRM_THEN: ad.setMessage( m_msg ); - lstnr = new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int button ) { - m_clickCallback.dlgButtonClicked( m_cbckID, button ); - } - }; - ad.setButton( AlertDialog.BUTTON_POSITIVE, - m_activity.getString( R.string.button_ok ), lstnr ); - ad.setButton( AlertDialog.BUTTON_NEGATIVE, - m_activity.getString( R.string.button_ok ), lstnr ); break; } } @@ -276,23 +271,21 @@ public class DlgDelegate { private Dialog createConfirmThenDialog() { + DialogInterface.OnClickListener lstnr = mkCallbackClickListener(); + Dialog dialog = new AlertDialog.Builder( m_activity ) .setTitle( R.string.query_title ) .setMessage( "" ) - .setPositiveButton( R.string.button_ok, null ) // will change - .setNegativeButton( R.string.button_cancel, null ) + .setPositiveButton( R.string.button_ok, lstnr ) + .setNegativeButton( R.string.button_cancel, lstnr ) .create(); - return dialog; + + return setCallbackDismissListener( dialog ); } private Dialog createHtmlThenDialog() { - DialogInterface.OnClickListener lstnr = - new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int button ) { - m_clickCallback.dlgButtonClicked( m_cbckID, button ); - } - }; + DialogInterface.OnClickListener lstnr = mkCallbackClickListener(); Dialog dialog = new AlertDialog.Builder( m_activity ) .setTitle( R.string.query_title ) .setMessage( R.string.text_or_html ) @@ -300,13 +293,7 @@ public class DlgDelegate { .setNegativeButton( R.string.button_html, lstnr ) .create(); - dialog.setOnDismissListener( new DialogInterface.OnDismissListener() { - public void onDismiss( DialogInterface di ) { - m_clickCallback.dlgButtonClicked( m_cbckID, -1 ); - } - } ); - - return dialog; + return setCallbackDismissListener( dialog ); } private Dialog createDictGoneDialog() @@ -326,4 +313,29 @@ public class DlgDelegate { return dialog; } + private DialogInterface.OnClickListener mkCallbackClickListener() + { + if ( null == s_cbkOnClickLstnr ) { + s_cbkOnClickLstnr = new DialogInterface.OnClickListener() { + public void onClick( DialogInterface dlg, int button ) { + m_clickCallback.dlgButtonClicked( m_cbckID, button ); + } + }; + } + return s_cbkOnClickLstnr; + } + + private Dialog setCallbackDismissListener( Dialog dialog ) + { + if ( null == s_cbkOnDismissLstnr ) { + s_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() { + public void onDismiss( DialogInterface di ) { + m_clickCallback.dlgButtonClicked( m_cbckID, -1 ); + } + }; + } + dialog.setOnDismissListener( s_cbkOnDismissLstnr ); + return dialog; + } + } From 1cd1a849e6c7fb80c56fe08694bbf74b462e8b2b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 21:41:35 -0700 Subject: [PATCH 20/30] don't put dismiss listeners on every damn dialog! They replace rather than chaining. --- .../src/org/eehouse/android/xw4/XWListActivity.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index fd6e85055..3cb2b29be 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -95,17 +95,6 @@ public class XWListActivity extends ListActivity if ( null == dialog ) { dialog = super.onCreateDialog( id ); } - if ( null != dialog ) { - DialogInterface.OnDismissListener lstnr = - new DialogInterface.OnDismissListener() { - public void onDismiss( DialogInterface di ) { - Utils.logf( "%s.onDismiss() called", - getClass().getName() ); - removeDialog( id ); - } - }; - dialog.setOnDismissListener( lstnr ); - } return dialog; } From 5aeac29787a96f2c48f2c4e1982d61478d97fdfd Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 21:44:10 -0700 Subject: [PATCH 21/30] Pass 0 to dlgButtonClicked() for dismiss, as -1 is the value of a button! Also assert the heck out of callbackIds to see if Android is guaranteeing that no two dialogs can be up at once. I'm counting on that, and need to know if it's not true. --- .../src/org/eehouse/android/xw4/DlgDelegate.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 7b566212a..121b30369 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -61,7 +61,8 @@ public class DlgDelegate { } private int m_msgID; - private int m_cbckID; + private int m_cbckID = 0; // if this can be set twice I have a + // problem. See asserts below. private String m_msg; private Runnable m_proc = null; private int m_prefsKey; @@ -172,12 +173,16 @@ public class DlgDelegate { public void showConfirmThen( String msg, int callbackID ) { m_msg = msg; + Assert.assertTrue( 0 != callbackID ); + Assert.assertTrue( 0 == m_cbckID ); m_cbckID = callbackID; m_activity.showDialog( CONFIRM_THEN ); } public void showTextOrHtmlThen( int callbackID ) { + Assert.assertTrue( 0 != callbackID ); + Assert.assertTrue( 0 == m_cbckID ); m_cbckID = callbackID; m_activity.showDialog( TEXT_OR_HTML_THEN ); } @@ -318,6 +323,7 @@ public class DlgDelegate { if ( null == s_cbkOnClickLstnr ) { s_cbkOnClickLstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { + Assert.assertTrue( 0 != m_cbckID ); m_clickCallback.dlgButtonClicked( m_cbckID, button ); } }; @@ -330,7 +336,9 @@ public class DlgDelegate { if ( null == s_cbkOnDismissLstnr ) { s_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() { public void onDismiss( DialogInterface di ) { - m_clickCallback.dlgButtonClicked( m_cbckID, -1 ); + Assert.assertTrue( 0 != m_cbckID ); + m_clickCallback.dlgButtonClicked( m_cbckID, 0 ); + m_cbckID = 0; } }; } From 3416ae59a7c531559f98ef355afdf7b2cfbc9d02 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 24 Aug 2011 22:43:54 -0700 Subject: [PATCH 22/30] use a constant for the DISMISS button. And don't use static listeners. They wind up getting called with mixed DlgDelegate.this values, including one belonging to an Activity that's long-since stopped and so the wrong ids are getting passed back. --- .../eehouse/android/xw4/BoardActivity.java | 2 +- .../org/eehouse/android/xw4/DlgDelegate.java | 22 ++++++++----------- .../eehouse/android/xw4/NewGameActivity.java | 2 +- 3 files changed, 11 insertions(+), 15 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 33ca877ba..e5a7b2f3c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -577,7 +577,7 @@ public class BoardActivity extends XWActivity } break; case LAUNCH_INVITE_ACTION: - if ( -1 != which ) { + if ( DlgDelegate.DISMISS_BUTTON != which ) { GameUtils.launchInviteActivity( BoardActivity.this, DlgDelegate.TEXT_BTN == which, m_room, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 121b30369..57301c642 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -47,15 +47,12 @@ public class DlgDelegate { public static final int TEXT_BTN = AlertDialog.BUTTON_POSITIVE; public static final int HTML_BTN = AlertDialog.BUTTON_NEGATIVE; + public static final int DISMISS_BUTTON = 0; private static final String MSG = "msg"; private static final String CALLBACK = "callback"; private static final String MSGID = "msgid"; - // Cache a couple of callback implementations that never change: - private static DialogInterface.OnClickListener s_cbkOnClickLstnr = null; - private static DialogInterface.OnDismissListener s_cbkOnDismissLstnr = null; - public interface DlgClickNotify { void dlgButtonClicked( int id, int button ); } @@ -320,29 +317,28 @@ public class DlgDelegate { private DialogInterface.OnClickListener mkCallbackClickListener() { - if ( null == s_cbkOnClickLstnr ) { - s_cbkOnClickLstnr = new DialogInterface.OnClickListener() { + DialogInterface.OnClickListener lstnr = + new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { Assert.assertTrue( 0 != m_cbckID ); m_clickCallback.dlgButtonClicked( m_cbckID, button ); } }; - } - return s_cbkOnClickLstnr; + return lstnr; } private Dialog setCallbackDismissListener( Dialog dialog ) { - if ( null == s_cbkOnDismissLstnr ) { - s_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() { + DialogInterface.OnDismissListener lstnr = + new DialogInterface.OnDismissListener() { public void onDismiss( DialogInterface di ) { Assert.assertTrue( 0 != m_cbckID ); - m_clickCallback.dlgButtonClicked( m_cbckID, 0 ); + m_clickCallback.dlgButtonClicked( m_cbckID, + DISMISS_BUTTON ); m_cbckID = 0; } }; - } - dialog.setOnDismissListener( s_cbkOnDismissLstnr ); + dialog.setOnDismissListener( lstnr ); return dialog; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java index 1f44dcddd..af638595f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java @@ -93,7 +93,7 @@ public class NewGameActivity extends XWActivity { { switch( id ) { case NEW_GAME_ACTION: - if ( -1 != which ) { + if ( DlgDelegate.DISMISS_BUTTON != which ) { makeNewGame( true, true, DlgDelegate.TEXT_BTN == which ); } break; From 711f12fa9ec23fa3be2da22e82dbb107cca9293e Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 25 Aug 2011 05:49:09 -0700 Subject: [PATCH 23/30] It's ok to cache listeners but only with the instance whose ivars they reference: revert prev change but make cache vars non-static. --- .../org/eehouse/android/xw4/DlgDelegate.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 57301c642..71f5b433a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -53,6 +53,10 @@ public class DlgDelegate { private static final String CALLBACK = "callback"; private static final String MSGID = "msgid"; + // Cache a couple of callback implementations that never change: + private DialogInterface.OnClickListener m_cbkOnClickLstnr = null; + private DialogInterface.OnDismissListener m_cbkOnDismissLstnr = null; + public interface DlgClickNotify { void dlgButtonClicked( int id, int button ); } @@ -317,20 +321,21 @@ public class DlgDelegate { private DialogInterface.OnClickListener mkCallbackClickListener() { - DialogInterface.OnClickListener lstnr = - new DialogInterface.OnClickListener() { + if ( null == m_cbkOnClickLstnr ) { + m_cbkOnClickLstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { Assert.assertTrue( 0 != m_cbckID ); m_clickCallback.dlgButtonClicked( m_cbckID, button ); } }; - return lstnr; + } + return m_cbkOnClickLstnr; } private Dialog setCallbackDismissListener( Dialog dialog ) { - DialogInterface.OnDismissListener lstnr = - new DialogInterface.OnDismissListener() { + if ( null == m_cbkOnDismissLstnr ) { + m_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() { public void onDismiss( DialogInterface di ) { Assert.assertTrue( 0 != m_cbckID ); m_clickCallback.dlgButtonClicked( m_cbckID, @@ -338,7 +343,8 @@ public class DlgDelegate { m_cbckID = 0; } }; - dialog.setOnDismissListener( lstnr ); + } + dialog.setOnDismissListener( m_cbkOnDismissLstnr ); return dialog; } From 79acccc6bfc7542d490c16b1b03969b828ce7c68 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 25 Aug 2011 06:52:12 -0700 Subject: [PATCH 24/30] record, commented out, attempt to send NBS message. sendDataMessage() crashes internally, and googling finds lots of reports/questions and no answers. It appears NBS is broken on Android, at least for CDMA. Might want to revisit on a newer OS version that the 2.1 I'm running now. --- xwords4/android/XWords4/AndroidManifest.xml | 10 ++++ .../org/eehouse/android/xw4/NBSReceiver.java | 54 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSReceiver.java diff --git a/xwords4/android/XWords4/AndroidManifest.xml b/xwords4/android/XWords4/AndroidManifest.xml index 3067e89a4..35d24d603 100644 --- a/xwords4/android/XWords4/AndroidManifest.xml +++ b/xwords4/android/XWords4/AndroidManifest.xml @@ -31,6 +31,8 @@ + + @@ -122,5 +124,13 @@ + + + + + + + + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSReceiver.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSReceiver.java new file mode 100644 index 000000000..51d2a5a5d --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NBSReceiver.java @@ -0,0 +1,54 @@ +// /* -*- 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.content.BroadcastReceiver; +// import android.content.Context; +// import android.content.Intent; + +// import android.telephony.SmsManager; + +// public class NBSReceiver extends BroadcastReceiver { + +// @Override +// public void onReceive( Context context, Intent intent ) +// { +// Utils.logf( "NBSReceiver::onReceive(intent=%s)!!!!", +// intent.toString() ); +// } + +// static void tryNBSMessage() +// { +// byte[] data = { 'a', 'b', 'c' }; + +// SmsManager mgr = SmsManager.getDefault(); + +// try { +// mgr.sendDataMessage( "123-456-7890", null, (short)50009, +// data, null, null ); +// // PendingIntent sentIntent, +// // PendingIntent deliveryIntent ); +// Utils.logf( "sendDataMessage finished" ); +// } catch ( IllegalArgumentException iae ) { +// Utils.logf( "%s", iae.toString() ); +// } +// } +// } From 5acc2205bea628678b22db4950176b934470e552 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 25 Aug 2011 18:13:42 -0700 Subject: [PATCH 25/30] add pref to edit color used to draw bonus hints on cells --- xwords4/android/XWords4/res/values/common_rsrc.xml | 1 + xwords4/android/XWords4/res/values/strings.xml | 1 + xwords4/android/XWords4/res/xml/xwprefs.xml | 7 +++++++ .../XWords4/src/org/eehouse/android/xw4/BoardView.java | 4 ++-- .../src/org/eehouse/android/xw4/jni/CommonPrefs.java | 4 +++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index 66a2c3a4d..8172480d4 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -26,6 +26,7 @@ key_clr_empty key_clr_background key_clr_crosshairs + key_clr_bonushint key_relay_host key_redir_host diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 521660c42..e1111221d 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -332,6 +332,7 @@ Empty cell/background Crosshairs color Board background + In-square bonus hint Internet/Relay SMS (broken) diff --git a/xwords4/android/XWords4/res/xml/xwprefs.xml b/xwords4/android/XWords4/res/xml/xwprefs.xml index cf0774ab7..e5e700cc3 100644 --- a/xwords4/android/XWords4/res/xml/xwprefs.xml +++ b/xwords4/android/XWords4/res/xml/xwprefs.xml @@ -177,6 +177,13 @@ android:title="@string/clr_crosshairs" android:defaultValue="0x7070FF" /> + + + Date: Thu, 25 Aug 2011 18:26:34 -0700 Subject: [PATCH 26/30] Oops: add new pref color to list restored. --- .../XWords4/src/org/eehouse/android/xw4/PrefsActivity.java | 1 + 1 file changed, 1 insertion(+) 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 8f5440b68..ba45c5052 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java @@ -68,6 +68,7 @@ public class PrefsActivity extends PreferenceActivity R.string.key_clr_crosshairs, R.string.key_empty, R.string.key_background, + R.string.key_clr_bonushint, }; for ( int colorKey : colorKeys ) { editor.remove( getString(colorKey) ); From 0a2255a8fee9d6413c769a5b3020e0b1fba3edb1 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 25 Aug 2011 18:26:49 -0700 Subject: [PATCH 27/30] add two recent changes --- xwords4/android/XWords4/res/raw/changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xwords4/android/XWords4/res/raw/changes b/xwords4/android/XWords4/res/raw/changes index 9f9e0fd1c..fa4b47bc4 100644 --- a/xwords4/android/XWords4/res/raw/changes +++ b/xwords4/android/XWords4/res/raw/changes @@ -13,6 +13,9 @@
  • Use the term "wordlist" instead of "dictionary" to not imply that there are definitions provided.
  • +
  • Add color of bonus hints -- the 2L etc. that appear on the board + -- to set of editable colors
  • +
  • Change how downloaded wordlists are opened to consume much less Java memory. Downside: wordlists on external storage are not available when that storage is mounted on a computer over USB.
  • @@ -34,6 +37,9 @@ from standalone. These are placeholders until I can get an artist to help out. :-) +
  • Fix a family of crashes that occurred when dialogs were up and + memory got low: rare, but annoying.
  • +

    Please remember that this is beta software. Please let me know (at From 656110841f67f47713e523ded14eb245c84613e9 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 25 Aug 2011 18:48:41 -0700 Subject: [PATCH 28/30] cleanup after review of recent changes: remove logging etc. didn't mean to check in. --- .../XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java | 4 ---- .../XWords4/src/org/eehouse/android/xw4/XWListActivity.java | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java index ce8499a7f..1893bb0a3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java @@ -47,8 +47,6 @@ public class NetLaunchInfo { bundle.putString( ROOM, room ); bundle.putInt( NPLAYERS, nPlayers ); bundle.putBoolean( VALID, m_valid ); - Utils.logf( "bundling NetLaunchInfo: %d, %s, %d, %b", - lang, room, nPlayers, m_valid ); } public NetLaunchInfo( Bundle bundle ) @@ -57,8 +55,6 @@ public class NetLaunchInfo { room = bundle.getString( ROOM ); nPlayers = bundle.getInt( NPLAYERS ); m_valid = bundle.getBoolean( VALID ); - Utils.logf( "unbundled NetLaunchInfo: %d, %s, %d, %b", - lang, room, nPlayers, m_valid ); } public static Uri makeLaunchUri( Context context, String room, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index 3cb2b29be..b9088c291 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -134,7 +134,7 @@ public class XWListActivity extends ListActivity protected void showConfirmThen( int msg, int action ) { - m_delegate.showConfirmThen( getString(msg), action ); + showConfirmThen( getString(msg), action ); } protected void doSyncMenuitem() From 5bc63edeb662e0ec0645f6c4976f8567fabd83e3 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Sun, 28 Aug 2011 15:38:52 -0700 Subject: [PATCH 29/30] replace Runnable passed to showNotAgainDlgThen() with callbackID, same scheme as the rest of DlgDelegate. I'm still using a single ivar for all dialogs, meaning they can't stack, but except for duplicate showNotAgainDlgThen calls (where the message can be ignored) it doesn't seem to be happening. Asserts are still in place to tell me if I'm wrong. --- .../eehouse/android/xw4/BoardActivity.java | 146 +++++++++--------- .../org/eehouse/android/xw4/BoardView.java | 3 +- .../org/eehouse/android/xw4/DlgDelegate.java | 87 ++++++----- .../org/eehouse/android/xw4/GameConfig.java | 21 ++- .../org/eehouse/android/xw4/GamesList.java | 45 +++--- .../src/org/eehouse/android/xw4/Toolbar.java | 4 +- .../org/eehouse/android/xw4/XWActivity.java | 9 +- .../eehouse/android/xw4/XWListActivity.java | 6 +- 8 files changed, 169 insertions(+), 152 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 e5a7b2f3c..7d5fe9d27 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -75,11 +75,22 @@ public class BoardActivity extends XWActivity private static final int UNDO_LAST_ACTION = 1; private static final int LAUNCH_INVITE_ACTION = 2; + private static final int SYNC_ACTION = 3; + private static final int COMMIT_ACTION = 4; + private static final int SHOW_EXPL_ACTION = 5; + private static final int PREV_HINT_ACTION = 6; + private static final int NEXT_HINT_ACTION = 7; + private static final int JUGGLE_ACTION = 8; + private static final int FLIP_ACTION = 9; + private static final int ZOOM_ACTION = 10; + private static final int UNDO_ACTION = 11; + private static final int CHAT_ACTION = 12; private static final String DLG_TITLE = "DLG_TITLE"; private static final String DLG_TITLESTR = "DLG_TITLESTR"; private static final String DLG_BYTES = "DLG_BYTES"; private static final String ROOM = "ROOM"; + private static final String TOASTSTR = "TOASTSTR"; private BoardView m_view; private int m_jniGamePtr; @@ -114,6 +125,7 @@ public class BoardActivity extends XWActivity private boolean m_blockingDlgPosted = false; private String m_room; + private String m_toastStr; private int m_missing; private boolean m_haveInvited = false; @@ -364,6 +376,7 @@ public class BoardActivity extends XWActivity outState.putString( DLG_TITLESTR, m_dlgTitleStr ); outState.putString( DLG_BYTES, m_dlgBytes ); outState.putString( ROOM, m_room ); + outState.putString( TOASTSTR, m_toastStr ); } private void getBundledData( Bundle bundle ) @@ -373,6 +386,7 @@ public class BoardActivity extends XWActivity m_dlgTitle = bundle.getInt( DLG_TITLE ); m_dlgBytes = bundle.getString( DLG_BYTES ); m_room = bundle.getString( ROOM ); + m_toastStr = bundle.getString( TOASTSTR ); } } @@ -481,13 +495,8 @@ public class BoardActivity extends XWActivity int id = item.getItemId(); switch ( id ) { case R.id.board_menu_done: - proc = new Runnable() { - public void run() { - checkAndHandle( JNIThread.JNICmd.CMD_COMMIT ); - } - }; showNotAgainDlgThen( R.string.not_again_done, - R.string.key_notagain_done, proc ); + R.string.key_notagain_done, COMMIT_ACTION ); break; // case R.id.board_menu_juggle: // cmd = JNIThread.JNICmd.CMD_JUGGLE; @@ -541,7 +550,9 @@ public class BoardActivity extends XWActivity break; case R.id.gamel_menu_checkmoves: - doSyncMenuitem(); + showNotAgainDlgThen( R.string.not_again_sync, + R.string.key_notagain_sync, + SYNC_ACTION ); break; case R.id.board_menu_file_prefs: @@ -570,13 +581,7 @@ public class BoardActivity extends XWActivity @Override public void dlgButtonClicked( int id, int which ) { - switch ( id ) { - case UNDO_LAST_ACTION: - if ( AlertDialog.BUTTON_POSITIVE == which ) { - m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_LAST ); - } - break; - case LAUNCH_INVITE_ACTION: + if ( LAUNCH_INVITE_ACTION == id ) { if ( DlgDelegate.DISMISS_BUTTON != which ) { GameUtils.launchInviteActivity( BoardActivity.this, DlgDelegate.TEXT_BTN == which, @@ -584,9 +589,46 @@ public class BoardActivity extends XWActivity m_gi.dictLang, m_gi.nPlayers ); } - break; - default: - Assert.fail(); + } else if ( AlertDialog.BUTTON_POSITIVE == which ) { + switch ( id ) { + case UNDO_LAST_ACTION: + m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_LAST ); + break; + case SYNC_ACTION: + doSyncMenuitem(); + break; + case COMMIT_ACTION: + checkAndHandle( JNIThread.JNICmd.CMD_COMMIT ); + break; + case SHOW_EXPL_ACTION: + Toast.makeText( BoardActivity.this, m_toastStr, + Toast.LENGTH_SHORT).show(); + m_toastStr = null; + break; + case PREV_HINT_ACTION: + checkAndHandle( JNIThread.JNICmd.CMD_PREV_HINT ); + break; + case NEXT_HINT_ACTION: + checkAndHandle( JNIThread.JNICmd.CMD_NEXT_HINT ); + break; + case JUGGLE_ACTION: + checkAndHandle( JNIThread.JNICmd.CMD_JUGGLE ); + break; + case FLIP_ACTION: + checkAndHandle( JNIThread.JNICmd.CMD_FLIP ); + break; + case ZOOM_ACTION: + checkAndHandle( JNIThread.JNICmd.CMD_TOGGLEZOOM ); + break; + case UNDO_ACTION: + checkAndHandle( JNIThread.JNICmd.CMD_UNDO_CUR ); + break; + case CHAT_ACTION: + startChatActivity(); + break; + default: + Assert.fail(); + } } } @@ -777,17 +819,12 @@ public class BoardActivity extends XWActivity } if ( null != str ) { - final String fstr = str; - Runnable proc = new Runnable() { - public void run() { - Toast.makeText( BoardActivity.this, fstr, - Toast.LENGTH_SHORT).show(); - } - }; + m_toastStr = str; if ( naMsg == 0 ) { - proc.run(); + dlgButtonClicked( SHOW_EXPL_ACTION, + AlertDialog.BUTTON_POSITIVE ); } else { - showNotAgainDlgThen( naMsg, naKey, proc ); + showNotAgainDlgThen( naMsg, naKey, SHOW_EXPL_ACTION ); } } } // handleConndMessage @@ -894,8 +931,7 @@ public class BoardActivity extends XWActivity post( new Runnable() { public void run() { showNotAgainDlgThen( R.string.not_again_turnchanged, - R.string.key_notagain_turnchanged, - null ); + R.string.key_notagain_turnchanged ); } } ); m_jniThread.handle( JNIThread.JNICmd. CMD_ZOOM, -8 ); @@ -1165,71 +1201,31 @@ public class BoardActivity extends XWActivity m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV, R.string.not_again_hintprev, R.string.key_notagain_hintprev, - new Runnable() { - public void run() { - checkAndHandle( JNIThread.JNICmd. - CMD_PREV_HINT ); - } - } ); + PREV_HINT_ACTION ); m_toolbar.setListener( Toolbar.BUTTON_HINT_NEXT, R.string.not_again_hintnext, R.string.key_notagain_hintnext, - new Runnable() { - @Override - public void run() { - checkAndHandle( JNIThread.JNICmd - .CMD_NEXT_HINT ); - } - } ); + NEXT_HINT_ACTION ); m_toolbar.setListener( Toolbar.BUTTON_JUGGLE, R.string.not_again_juggle, R.string.key_notagain_juggle, - new Runnable() { - @Override - public void run() { - checkAndHandle( JNIThread.JNICmd - .CMD_JUGGLE ); - } - } ); + JUGGLE_ACTION ); m_toolbar.setListener( Toolbar.BUTTON_FLIP, R.string.not_again_flip, R.string.key_notagain_flip, - new Runnable() { - @Override - public void run() { - checkAndHandle( JNIThread.JNICmd - .CMD_FLIP ); - } - } ); + FLIP_ACTION ); m_toolbar.setListener( Toolbar.BUTTON_ZOOM, R.string.not_again_zoom, R.string.key_notagain_zoom, - new Runnable() { - @Override - public void run() { - checkAndHandle( JNIThread.JNICmd - .CMD_TOGGLEZOOM ); - } - } ); + ZOOM_ACTION ); m_toolbar.setListener( Toolbar.BUTTON_UNDO, R.string.not_again_undo, R.string.key_notagain_undo, - new Runnable() { - @Override - public void run() { - checkAndHandle( JNIThread.JNICmd - .CMD_UNDO_CUR ); - } - }); + UNDO_ACTION ); m_toolbar.setListener( Toolbar.BUTTON_CHAT, R.string.not_again_chat, R.string.key_notagain_chat, - new Runnable() { - @Override - public void run() { - startChatActivity(); - } - }); + CHAT_ACTION ); } // populateToolbar private OnDismissListener makeODLforBlocking( final int id ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index f2c897546..0b049e79c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -562,8 +562,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler, public void run() { m_parent. showNotAgainDlgThen( R.string.not_again_arrow, - R.string.key_notagain_arrow, - null ); + R.string.key_notagain_arrow ); } } ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 71f5b433a..f2043d933 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -48,10 +48,12 @@ public class DlgDelegate { public static final int TEXT_BTN = AlertDialog.BUTTON_POSITIVE; public static final int HTML_BTN = AlertDialog.BUTTON_NEGATIVE; public static final int DISMISS_BUTTON = 0; + public static final int SKIP_CALLBACK = -1; private static final String MSG = "msg"; private static final String CALLBACK = "callback"; private static final String MSGID = "msgid"; + private static final String PREFSKEY = "prefskey"; // Cache a couple of callback implementations that never change: private DialogInterface.OnClickListener m_cbkOnClickLstnr = null; @@ -65,7 +67,6 @@ public class DlgDelegate { private int m_cbckID = 0; // if this can be set twice I have a // problem. See asserts below. private String m_msg; - private Runnable m_proc = null; private int m_prefsKey; private Activity m_activity; private DlgClickNotify m_clickCallback; @@ -81,6 +82,7 @@ public class DlgDelegate { m_msg = bundle.getString( MSG ); m_cbckID = bundle.getInt( CALLBACK ); m_msgID = bundle.getInt( MSGID ); + m_prefsKey = bundle.getInt( PREFSKEY ); } } @@ -89,6 +91,7 @@ public class DlgDelegate { outState.putString( MSG, m_msg ); outState.putInt( CALLBACK, m_cbckID ); outState.putInt( MSGID, m_msgID ); + outState.putInt( PREFSKEY, m_prefsKey ); } public Dialog onCreateDialog( int id ) @@ -156,21 +159,31 @@ public class DlgDelegate { } public void showNotAgainDlgThen( int msgID, int prefsKey, - Runnable proc ) + int callbackID ) { boolean set = CommonPrefs.getPrefsBoolean( m_activity, prefsKey, false ); - if ( set ) { - if ( null != proc ) { - proc.run(); - } + if ( set || 0 != m_cbckID ) { + // If it's set, do the action without bothering with the + // dialog + if ( SKIP_CALLBACK != callbackID ) { + m_clickCallback.dlgButtonClicked( callbackID, + AlertDialog.BUTTON_POSITIVE ); + } } else { m_msgID = msgID; - m_proc = proc; + Assert.assertTrue( 0 != callbackID ); + Assert.assertTrue( 0 == m_cbckID ); // fired + m_cbckID = callbackID; m_prefsKey = prefsKey; m_activity.showDialog( DIALOG_NOTAGAIN ); } } + public void showNotAgainDlgThen( int msgID, int prefsKey ) + { + showNotAgainDlgThen( msgID, prefsKey, SKIP_CALLBACK ); + } + public void showConfirmThen( String msg, int callbackID ) { m_msg = msg; @@ -243,36 +256,29 @@ public class DlgDelegate { private Dialog createNotAgainDialog() { - Dialog dialog = null; - if ( 0 != m_msgID ) { - DialogInterface.OnClickListener lstnr_p = - new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int item ) { - if ( null != m_proc ) { - m_proc.run(); - } - } - }; + DialogInterface.OnClickListener lstnr_p = mkCallbackClickListener(); - DialogInterface.OnClickListener lstnr_n = - new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dlg, int item ) { - CommonPrefs.setPrefsBoolean( m_activity, m_prefsKey, - true ); - if ( null != m_proc ) { - m_proc.run(); - } + DialogInterface.OnClickListener lstnr_n = + new DialogInterface.OnClickListener() { + public void onClick( DialogInterface dlg, int item ) { + CommonPrefs.setPrefsBoolean( m_activity, m_prefsKey, + true ); + if ( SKIP_CALLBACK != m_cbckID ) { + m_clickCallback. + dlgButtonClicked( m_cbckID, + AlertDialog.BUTTON_POSITIVE ); } - }; + } + }; - dialog = new AlertDialog.Builder( m_activity ) - .setTitle( R.string.newbie_title ) - .setMessage( m_msgID ) - .setPositiveButton( R.string.button_ok, lstnr_p ) - .setNegativeButton( R.string.button_notagain, lstnr_n ) - .create(); - } - return dialog; + Dialog dialog = new AlertDialog.Builder( m_activity ) + .setTitle( R.string.newbie_title ) + .setMessage( m_msgID ) + .setPositiveButton( R.string.button_ok, lstnr_p ) + .setNegativeButton( R.string.button_notagain, lstnr_n ) + .create(); + + return setCallbackDismissListener( dialog ); } // createNotAgainDialog private Dialog createConfirmThenDialog() @@ -324,8 +330,10 @@ public class DlgDelegate { if ( null == m_cbkOnClickLstnr ) { m_cbkOnClickLstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { - Assert.assertTrue( 0 != m_cbckID ); - m_clickCallback.dlgButtonClicked( m_cbckID, button ); + if ( SKIP_CALLBACK != m_cbckID ) { + m_clickCallback.dlgButtonClicked( m_cbckID, + button ); + } } }; } @@ -337,9 +345,10 @@ public class DlgDelegate { if ( null == m_cbkOnDismissLstnr ) { m_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() { public void onDismiss( DialogInterface di ) { - Assert.assertTrue( 0 != m_cbckID ); - m_clickCallback.dlgButtonClicked( m_cbckID, - DISMISS_BUTTON ); + if ( SKIP_CALLBACK != m_cbckID ) { + m_clickCallback.dlgButtonClicked( m_cbckID, + DISMISS_BUTTON ); + } m_cbckID = 0; } }; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java index f0d95fba8..79a75a6f1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java @@ -69,6 +69,7 @@ public class GameConfig extends XWActivity private static final int NO_NAME_FOUND = PLAYER_EDIT + 4; private static final String WHICH_PLAYER = "WHICH_PLAYER"; + private static final int LOCKED_CHANGE_ACTION = 1; private CheckBox m_joinPublicCheck; private CheckBox m_gameLockedCheck; @@ -539,6 +540,20 @@ public class GameConfig extends XWActivity showDialog( NO_NAME_FOUND ); } + @Override + public void dlgButtonClicked( int id, int button ) + { + switch( id ) { + case LOCKED_CHANGE_ACTION: + if ( AlertDialog.BUTTON_POSITIVE == button ) { + handleLockedChange(); + } + break; + default: + Assert.fail(); + } + } + public void onClick( View view ) { if ( m_addPlayerButton == view ) { @@ -555,11 +570,7 @@ public class GameConfig extends XWActivity } else if ( m_gameLockedCheck == view ) { showNotAgainDlgThen( R.string.not_again_unlock, R.string.key_notagain_unlock, - new Runnable() { - public void run() { - handleLockedChange(); - } - }); + LOCKED_CHANGE_ACTION ); } else if ( m_refreshRoomsButton == view ) { refreshNames(); } else if ( m_playButton == view ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index c193da570..7976d5c22 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -67,6 +67,8 @@ public class GamesList extends XWListActivity private static final int RESET_GAME_ACTION = 2; private static final int DELETE_GAME_ACTION = 3; private static final int DELETE_ALL_ACTION = 4; + private static final int SYNC_MENU_ACTION = 5; + private static final int DUPE_GAME_ACTION = 6; private GameListAdapter m_adapter; private String m_missingDict; @@ -426,6 +428,15 @@ public class GamesList extends XWListActivity m_adapter.inval( games[ii] ); } break; + case SYNC_MENU_ACTION: + doSyncMenuitem(); + break; + case DUPE_GAME_ACTION: + long newid = GameUtils.dupeGame( GamesList.this, m_rowid ); + if ( null != m_adapter ) { + m_adapter.inval( newid ); + } + break; default: Assert.fail(); } @@ -520,11 +531,7 @@ public class GamesList extends XWListActivity case R.id.gamel_menu_checkmoves: showNotAgainDlgThen( R.string.not_again_sync, R.string.key_notagain_sync, - new Runnable() { - public void run() { - doSyncMenuitem(); - } - } ); + SYNC_MENU_ACTION ); break; case R.id.gamel_menu_prefs: @@ -551,46 +558,36 @@ public class GamesList extends XWListActivity boolean handled = true; DialogInterface.OnClickListener lstnr; - final long rowid = DBUtils.gamesList( this )[position]; - + m_rowid = DBUtils.gamesList( this )[position]; + if ( R.id.list_item_delete == menuID ) { - m_rowid = rowid; showConfirmThen( R.string.confirm_delete, DELETE_GAME_ACTION ); } else { - if ( checkWarnNoDict( rowid ) ) { + if ( checkWarnNoDict( m_rowid ) ) { switch ( menuID ) { case R.id.list_item_reset: - m_rowid = rowid; showConfirmThen( R.string.confirm_reset, RESET_GAME_ACTION ); break; case R.id.list_item_config: - GameUtils.doConfig( this, rowid, GameConfig.class ); + GameUtils.doConfig( this, m_rowid, GameConfig.class ); break; case R.id.list_item_rename: - m_rowid = rowid; showDialog( RENAME_GAME ); break; case R.id.list_item_new_from: - Runnable proc = new Runnable() { - public void run() { - long newid = - GameUtils.dupeGame( GamesList.this, rowid ); - if ( null != m_adapter ) { - m_adapter.inval( newid ); - } - } - }; showNotAgainDlgThen( R.string.not_again_newfrom, - R.string.key_notagain_newfrom, proc ); + R.string.key_notagain_newfrom, + DUPE_GAME_ACTION ); break; case R.id.list_item_copy: - GameSummary summary = DBUtils.getSummary( this, rowid, true ); + GameSummary summary = DBUtils.getSummary( this, + m_rowid, true ); if ( summary.inNetworkGame() ) { showOKOnlyDialog( R.string.no_copy_network ); } else { - byte[] stream = GameUtils.savedGame( this, rowid ); + byte[] stream = GameUtils.savedGame( this, m_rowid ); GameUtils.GameLock lock = GameUtils.saveNewGame( this, stream ); DBUtils.saveSummary( this, lock, summary ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Toolbar.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Toolbar.java index 9f5d256c5..29698742e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Toolbar.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Toolbar.java @@ -85,11 +85,11 @@ public class Toolbar { } public void setListener( int index, final int msgID, final int prefsKey, - final Runnable proc ) + final int callback ) { View.OnClickListener listener = new View.OnClickListener() { public void onClick( View view ) { - m_activity.showNotAgainDlgThen( msgID, prefsKey, proc ); + m_activity.showNotAgainDlgThen( msgID, prefsKey, callback ); } }; setListener( index, listener ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index e8bf0e62c..fd4a2158b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -116,9 +116,14 @@ public class XWActivity extends Activity } protected void showNotAgainDlgThen( int msgID, int prefsKey, - Runnable proc ) + int action ) { - m_delegate.showNotAgainDlgThen( msgID, prefsKey, proc ); + m_delegate.showNotAgainDlgThen( msgID, prefsKey, action ); + } + + protected void showNotAgainDlgThen( int msgID, int prefsKey ) + { + m_delegate.showNotAgainDlgThen( msgID, prefsKey ); } protected void showOKOnlyDialog( int msgID ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index b9088c291..9d918e508 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -112,14 +112,14 @@ public class XWListActivity extends ListActivity } protected void showNotAgainDlgThen( int msgID, int prefsKey, - Runnable proc ) + int action ) { - m_delegate.showNotAgainDlgThen( msgID, prefsKey, proc ); + m_delegate.showNotAgainDlgThen( msgID, prefsKey, action ); } protected void showNotAgainDlg( int msgID, int prefsKey ) { - m_delegate.showNotAgainDlgThen( msgID, prefsKey, null ); + m_delegate.showNotAgainDlgThen( msgID, prefsKey ); } protected void showOKOnlyDialog( int msgID ) From 45421e8f8661687361c6873d0c492fa2b9f1ea2d Mon Sep 17 00:00:00 2001 From: Andy2 Date: Sun, 28 Aug 2011 15:44:23 -0700 Subject: [PATCH 30/30] add a bit of space between players column and column to right so numbers don't run together. --- xwords4/android/XWords4/res/layout/game_list_item.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/xwords4/android/XWords4/res/layout/game_list_item.xml b/xwords4/android/XWords4/res/layout/game_list_item.xml index d5e06ef77..45d33d64a 100644 --- a/xwords4/android/XWords4/res/layout/game_list_item.xml +++ b/xwords4/android/XWords4/res/layout/game_list_item.xml @@ -63,6 +63,7 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" + android:layout_marginRight="4dip" />