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 6349ae98b..f0b6028fa 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -58,7 +58,6 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole; public class BoardActivity extends XWActivity implements TransportProcs.TPMsgHandler, View.OnClickListener { - public static final String INTENT_KEY_ROWID = "rowid"; public static final String INTENT_KEY_CHAT = "chat"; private static final int DLG_OKONLY = DlgDelegate.DIALOG_LAST + 1; @@ -454,7 +453,7 @@ public class BoardActivity extends XWActivity m_volKeysZoom = CommonPrefs.getVolKeysZoom( this ); Intent intent = getIntent(); - m_rowid = intent.getLongExtra( INTENT_KEY_ROWID, -1 ); + m_rowid = intent.getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 ); m_haveInvited = intent.getBooleanExtra( GameUtils.INVITED, false ); setBackgroundColor(); @@ -1596,7 +1595,7 @@ public class BoardActivity extends XWActivity private void startChatActivity() { Intent intent = new Intent( this, ChatActivity.class ); - intent.putExtra( BoardActivity.INTENT_KEY_ROWID, m_rowid ); + intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid ); startActivityForResult( intent, CHAT_REQUEST ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java index 7b7e8c6cf..2a4c5543b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java @@ -44,7 +44,7 @@ public class ChatActivity extends XWActivity implements View.OnClickListener { setContentView( R.layout.chat ); - m_rowid = getIntent().getLongExtra( BoardActivity.INTENT_KEY_ROWID, -1 ); + m_rowid = getIntent().getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 ); DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_rowid ); if ( null != pairs ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index 56389e256..ee27a9a97 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -644,6 +644,13 @@ public class DBUtils { return result; } + public static void deleteGame( Context context, long rowid ) + { + GameUtils.GameLock lock = new GameUtils.GameLock( rowid, true ).lock(); + deleteGame( context, lock ); + lock.unlock(); + } + public static void deleteGame( Context context, GameUtils.GameLock lock ) { Assert.assertTrue( lock.canWrite() ); 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 381c7db40..aea17c8d3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java @@ -88,6 +88,7 @@ public class GameConfig extends XWActivity private Spinner m_roomChoose; // private Button m_configureButton; private long m_rowid; + private boolean m_forResult; private CurGameInfo m_gi; private CurGameInfo m_giOrig; private GameUtils.GameLock m_gameLock; @@ -392,7 +393,9 @@ public class GameConfig extends XWActivity m_cp = CommonPrefs.get( this ); Intent intent = getIntent(); - m_rowid = intent.getLongExtra( BoardActivity.INTENT_KEY_ROWID, -1 ); + m_rowid = intent.getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 ); + m_forResult = intent.getBooleanExtra( GameUtils.INTENT_FORRESULT_ROWID, + false ); setContentView(R.layout.game_config); @@ -601,7 +604,11 @@ public class GameConfig extends XWActivity // from here if there's no confirmation needed, or launch // a new dialog whose OK button does the same thing. saveChanges(); - if ( !m_gameStarted ) { // no confirm needed + if ( m_forResult ) { + applyChanges( true ); + setResult( Activity.RESULT_OK, null ); + finish(); + } else if ( !m_gameStarted ) { // no confirm needed applyChanges( true ); launchGame(); } else if ( m_giOrig.changesMatter(m_gi) 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 678490044..602a8749d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -48,6 +48,8 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole; public class GameUtils { public static final String INVITED = "invited"; + public static final String INTENT_KEY_ROWID = "rowid"; + public static final String INTENT_FORRESULT_ROWID = "forresult"; private static Random s_random = new Random(); // Implements read-locks and write-locks per game. A read lock is @@ -575,7 +577,7 @@ public class GameUtils { { Intent intent = new Intent( activity, BoardActivity.class ); intent.setAction( Intent.ACTION_EDIT ); - intent.putExtra( BoardActivity.INTENT_KEY_ROWID, rowid ); + intent.putExtra( INTENT_KEY_ROWID, rowid ); if ( invited ) { intent.putExtra( INVITED, true ); } @@ -785,7 +787,7 @@ public class GameUtils { { Intent intent = new Intent( activity, clazz ); intent.setAction( Intent.ACTION_EDIT ); - intent.putExtra( BoardActivity.INTENT_KEY_ROWID, rowid ); + intent.putExtra( INTENT_KEY_ROWID, rowid ); activity.startActivity( intent ); } 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 baa91d707..160d8fb3d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java @@ -49,12 +49,14 @@ public class NewGameActivity extends XWActivity { private static final int NEW_GAME_ACTION = 1; private static final String SAVE_DEVNAMES = "DEVNAMES"; private static final int PICK_BTDEV_DLG = DlgDelegate.DIALOG_LAST + 1; + private static final int CONFIG_BT = 1; private boolean m_showsOn; private Handler m_handler = null; private int m_chosen; private String[] m_btDevNames; private int m_lang = 0; + private long m_btRowID = -1; @Override protected void onCreate( Bundle savedInstanceState ) @@ -203,6 +205,22 @@ public class NewGameActivity extends XWActivity { checkEnableBT( false ); } + @Override + protected void onActivityResult( int requestCode, int resultCode, + Intent data ) + { + if ( CONFIG_BT == requestCode ) { + if ( Activity.RESULT_CANCELED == resultCode ) { + DBUtils.deleteGame( this, m_btRowID ); + } else { + // We'll leave it up to BoardActivity to detect that + // it's not had any remote connections yet. + GameUtils.launchGame( this, m_btRowID ); + finish(); + } + } + } + @Override protected void onSaveInstanceState( Bundle outState ) { @@ -316,10 +334,14 @@ public class NewGameActivity extends XWActivity { { int gameID = GameUtils.newGameID(); if ( !useDefaults ) { - DbgUtils.showf( this, "For debugging only..." ); - GameUtils.makeNewBTGame( NewGameActivity.this, gameID, - null, m_lang, 2, 1 ); - finish(); + m_btRowID = GameUtils.makeNewBTGame( NewGameActivity.this, + gameID, null, m_lang, + 2, 1 ); + Intent intent = new Intent( this, GameConfig.class ); + intent.setAction( Intent.ACTION_EDIT ); + intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_btRowID ); + intent.putExtra( GameUtils.INTENT_FORRESULT_ROWID, true ); + startActivityForResult( intent, CONFIG_BT ); } else if ( null == m_btDevNames || 0 == m_btDevNames.length ) { startProgress( R.string.scan_progress ); BTService.rescan( this ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java index 7363acc59..2ec8fabdd 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java @@ -53,7 +53,7 @@ public class RelayGameActivity extends XWActivity setContentView( R.layout.relay_game_config ); - m_rowid = getIntent().getLongExtra( BoardActivity.INTENT_KEY_ROWID, -1 ); + m_rowid = getIntent().getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 ); m_playButton = (Button)findViewById( R.id.play_button ); m_playButton.setOnClickListener( this );