Need to show dict-gone-missing dialog when umount from GameConfig too,

so: change loadMakeGame() to return gamePtr rather than take one in,
and to return 0 when any dict no available.  Move dict-gone-missing
dialog into DlgDelegate.  Remove DlgDelegate always adding onDismiss
listener that removes the dialog, and instead add one to the
dict-gone-missing dialog that, like the onClick handler, calls
finish() on the activity.
This commit is contained in:
Andy2 2011-08-19 18:52:55 -07:00
parent fd4e627628
commit 8f60ca5af3
7 changed files with 153 additions and 122 deletions

View file

@ -69,7 +69,6 @@ public class BoardActivity extends XWActivity
private static final int QUERY_ENDGAME = DLG_OKONLY + 7; private static final int QUERY_ENDGAME = DLG_OKONLY + 7;
private static final int DLG_DELETED = DLG_OKONLY + 8; private static final int DLG_DELETED = DLG_OKONLY + 8;
private static final int DLG_INVITE = DLG_OKONLY + 9; private static final int DLG_INVITE = DLG_OKONLY + 9;
private static final int DLG_NODICT = DLG_OKONLY + 10;
private static final int CHAT_REQUEST = 1; private static final int CHAT_REQUEST = 1;
private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins
@ -288,21 +287,6 @@ public class BoardActivity extends XWActivity
.create(); .create();
} }
break; break;
case DLG_NODICT:
dialog = new AlertDialog.Builder( this )
.setTitle( R.string.no_dict_title )
.setMessage( R.string.no_dict_finish )
.setPositiveButton( R.string.button_close_game, null )
.create();
OnDismissListener dlstnr;
dlstnr = new OnDismissListener() {
public void onDismiss( DialogInterface di ) {
// removeDialog( DLG_NODICT );
finish();
}
};
dialog.setOnDismissListener( dlstnr );
break;
default: default:
// just drop it; super.onCreateDialog likely failed // just drop it; super.onCreateDialog likely failed
break; break;
@ -1065,7 +1049,7 @@ public class BoardActivity extends XWActivity
GameUtils.DictPairs pairs = GameUtils.openDicts( this, dictNames ); GameUtils.DictPairs pairs = GameUtils.openDicts( this, dictNames );
if ( pairs.anyMissing( dictNames ) ) { if ( pairs.anyMissing( dictNames ) ) {
showDialog( DLG_NODICT ); showDictGoneFinish();
} else { } else {
String langName = m_gi.langName(); String langName = m_gi.langName();

View file

@ -40,7 +40,8 @@ public class DlgDelegate {
public static final int DIALOG_NOTAGAIN = 3; public static final int DIALOG_NOTAGAIN = 3;
public static final int CONFIRM_THEN = 4; public static final int CONFIRM_THEN = 4;
public static final int TEXT_OR_HTML_THEN = 5; public static final int TEXT_OR_HTML_THEN = 5;
public static final int DIALOG_LAST = TEXT_OR_HTML_THEN; public static final int DLG_DICTGONE = 6;
public static final int DIALOG_LAST = DLG_DICTGONE;
private int m_msgID; private int m_msgID;
private String m_msg; private String m_msg;
@ -78,6 +79,9 @@ public class DlgDelegate {
case TEXT_OR_HTML_THEN: case TEXT_OR_HTML_THEN:
dialog = createHtmlThenDialog(); dialog = createHtmlThenDialog();
break; break;
case DLG_DICTGONE:
dialog = createDictGoneDialog();
break;
} }
return dialog; return dialog;
} }
@ -141,6 +145,11 @@ public class DlgDelegate {
m_activity.showDialog( DIALOG_OKONLY ); m_activity.showDialog( DIALOG_OKONLY );
} }
public void showDictGoneFinish()
{
m_activity.showDialog( DLG_DICTGONE );
}
public void showAboutDialog() public void showAboutDialog()
{ {
m_activity.showDialog( DIALOG_ABOUT ); m_activity.showDialog( DIALOG_ABOUT );
@ -283,4 +292,28 @@ public class DlgDelegate {
.create(); .create();
} }
private Dialog createDictGoneDialog()
{
Utils.logf( "DlgDelegate.createDictGoneDialog() called" );
Dialog 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,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
m_activity.finish();
}
} )
.create();
dialog.setOnDismissListener( new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
m_activity.finish();
}
} );
return dialog;
}
} }

View file

@ -396,88 +396,91 @@ public class GameConfig extends XWActivity
{ {
super.onResume(); super.onResume();
int gamePtr = XwJNI.initJNI();
m_giOrig = new CurGameInfo( this ); m_giOrig = new CurGameInfo( this );
// Lock in case we're going to config. We *could* re-get the // Lock in case we're going to config. We *could* re-get the
// lock once the user decides to make changes. PENDING. // lock once the user decides to make changes. PENDING.
m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock(); m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock();
GameUtils.loadMakeGame( this, gamePtr, m_giOrig, m_gameLock ); int gamePtr = GameUtils.loadMakeGame( this, m_giOrig, m_gameLock );
m_gameStarted = XwJNI.model_getNMoves( gamePtr ) > 0 if ( 0 == gamePtr ) {
|| XwJNI.comms_isConnected( gamePtr ); showDictGoneFinish();
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 { } else {
String relayName = CommonPrefs.getDefaultRelayHost( this ); m_gameStarted = XwJNI.model_getNMoves( gamePtr ) > 0
int relayPort = CommonPrefs.getDefaultRelayPort( this ); || XwJNI.comms_isConnected( gamePtr );
XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort );
}
XwJNI.game_dispose( gamePtr );
m_car = new CommsAddrRec( m_carOrig ); if ( m_gameStarted ) {
if ( null == m_gameLockedCheck ) {
m_notNetworkedGame = DeviceRole.SERVER_STANDALONE == m_gi.serverRole; m_gameLockedCheck =
setTitle(); (CheckBox)findViewById( R.id.game_locked_check );
m_gameLockedCheck.setVisibility( View.VISIBLE );
if ( !m_notNetworkedGame ) { m_gameLockedCheck.setChecked( true );
m_joinPublicCheck = m_gameLockedCheck.setOnClickListener( this );
(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 );
} }
}; handleLockedChange();
check.setOnCheckedChangeListener( lstnr ); }
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
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 } // onResume
@Override @Override

View file

@ -198,13 +198,12 @@ public class GameUtils {
public static GameLock resetGame( Context context, GameLock lockSrc, public static GameLock resetGame( Context context, GameLock lockSrc,
GameLock lockDest ) GameLock lockDest )
{ {
int gamePtr = XwJNI.initJNI();
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = new CurGameInfo( context );
CommsAddrRec addr = null; CommsAddrRec addr = null;
// loadMakeGame, if makinga new game, will add comms as long // loadMakeGame, if makinga new game, will add comms as long
// as DeviceRole.SERVER_STANDALONE != gi.serverRole // as DeviceRole.SERVER_STANDALONE != gi.serverRole
loadMakeGame( context, gamePtr, gi, lockSrc ); int gamePtr = loadMakeGame( context, gi, lockSrc );
String[] dictNames = gi.dictNames(); String[] dictNames = gi.dictNames();
DictPairs pairs = openDicts( context, dictNames ); DictPairs pairs = openDicts( context, dictNames );
@ -282,9 +281,8 @@ public class GameUtils {
public static GameSummary summarize( Context context, GameLock lock ) public static GameSummary summarize( Context context, GameLock lock )
{ {
int gamePtr = XwJNI.initJNI();
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = new CurGameInfo( context );
loadMakeGame( context, gamePtr, gi, lock ); int gamePtr = loadMakeGame( context, gi, lock );
return summarizeAndClose( context, lock, gamePtr, gi ); return summarizeAndClose( context, lock, gamePtr, gi );
} }
@ -321,33 +319,40 @@ public class GameUtils {
return result; return result;
} }
public static void loadMakeGame( Context context, int gamePtr, public static int loadMakeGame( Context context, CurGameInfo gi,
CurGameInfo gi, GameLock lock ) GameLock lock )
{ {
loadMakeGame( context, gamePtr, gi, null, lock ); return loadMakeGame( context, gi, null, lock );
} }
public static void loadMakeGame( Context context, int gamePtr, public static int loadMakeGame( Context context, CurGameInfo gi,
CurGameInfo gi, UtilCtxt util, UtilCtxt util, GameLock lock )
GameLock lock )
{ {
int gamePtr = 0;
byte[] stream = savedGame( context, lock ); byte[] stream = savedGame( context, lock );
XwJNI.gi_from_stream( gi, stream ); XwJNI.gi_from_stream( gi, stream );
String[] dictNames = gi.dictNames(); String[] dictNames = gi.dictNames();
DictPairs pairs = openDicts( context, dictNames ); DictPairs pairs = openDicts( context, dictNames );
String langName = gi.langName(); if ( pairs.anyMissing( dictNames ) ) {
Utils.logf( "loadMakeGame() failing: dict unavailable" );
} else {
gamePtr = XwJNI.initJNI();
boolean madeGame = XwJNI.game_makeFromStream( gamePtr, stream, String langName = gi.langName();
JNIUtilsImpl.get(), gi, boolean madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
dictNames, pairs.m_bytes, JNIUtilsImpl.get(), gi,
pairs.m_paths, langName, dictNames, pairs.m_bytes,
util, pairs.m_paths, langName,
CommonPrefs.get(context)); util,
if ( !madeGame ) { CommonPrefs.get(context));
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(), if ( !madeGame ) {
CommonPrefs.get(context), dictNames, XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
pairs.m_bytes, pairs.m_paths, langName ); CommonPrefs.get(context), dictNames,
pairs.m_bytes, pairs.m_paths, langName );
}
} }
return gamePtr;
} }
public static long saveGame( Context context, int gamePtr, public static long saveGame( Context context, int gamePtr,
@ -872,12 +877,11 @@ public class GameUtils {
boolean draw = false; boolean draw = false;
long rowid = DBUtils.getRowIDFor( context, relayID ); long rowid = DBUtils.getRowIDFor( context, relayID );
if ( -1 != rowid ) { if ( -1 != rowid ) {
int gamePtr = XwJNI.initJNI();
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = new CurGameInfo( context );
FeedUtilsImpl feedImpl = new FeedUtilsImpl( context, rowid ); FeedUtilsImpl feedImpl = new FeedUtilsImpl( context, rowid );
GameLock lock = new GameLock( rowid, true ); GameLock lock = new GameLock( rowid, true );
if ( lock.tryLock() ) { if ( lock.tryLock() ) {
loadMakeGame( context, gamePtr, gi, feedImpl, lock ); int gamePtr = loadMakeGame( context, gi, feedImpl, lock );
for ( byte[] msg : msgs ) { for ( byte[] msg : msgs ) {
draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw; draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw;

View file

@ -67,10 +67,9 @@ public class RelayGameActivity extends XWActivity
{ {
super.onStart(); super.onStart();
int gamePtr = XwJNI.initJNI();
m_gi = new CurGameInfo( this ); m_gi = new CurGameInfo( this );
m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock(); m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock();
GameUtils.loadMakeGame( this, gamePtr, m_gi, m_gameLock ); int gamePtr = GameUtils.loadMakeGame( this, m_gi, m_gameLock );
m_car = new CommsAddrRec( this ); m_car = new CommsAddrRec( this );
if ( XwJNI.game_hasComms( gamePtr ) ) { if ( XwJNI.game_hasComms( gamePtr ) ) {
XwJNI.comms_getAddr( gamePtr, m_car ); XwJNI.comms_getAddr( gamePtr, m_car );

View file

@ -36,6 +36,7 @@ public class XWActivity extends Activity {
private DlgDelegate m_delegate; private DlgDelegate m_delegate;
@Override
protected void onCreate( Bundle savedInstanceState ) protected void onCreate( Bundle savedInstanceState )
{ {
Utils.logf( "%s.onCreate(this=%H)", getClass().getName(), this ); Utils.logf( "%s.onCreate(this=%H)", getClass().getName(), this );
@ -84,10 +85,10 @@ public class XWActivity extends Activity {
@Override @Override
protected Dialog onCreateDialog( int id ) protected Dialog onCreateDialog( int id )
{ {
Utils.logf( "%s.onCreateDialog() called", getClass().getName() ); Dialog dialog = super.onCreateDialog( id );
Dialog dialog = m_delegate.onCreateDialog( id ); if ( null == dialog ) {
if ( null != dialog ) { Utils.logf( "%s.onCreateDialog() called", getClass().getName() );
setRemoveOnDismiss( dialog, id ); dialog = m_delegate.onCreateDialog( id );
} }
return dialog; return dialog;
} }
@ -100,6 +101,7 @@ public class XWActivity extends Activity {
@Override @Override
protected void onPrepareDialog( int id, Dialog dialog ) protected void onPrepareDialog( int id, Dialog dialog )
{ {
super.onPrepareDialog( id, dialog ); // docs say should call through
m_delegate.onPrepareDialog( id, dialog ); m_delegate.onPrepareDialog( id, dialog );
} }
@ -121,6 +123,11 @@ public class XWActivity extends Activity {
m_delegate.showOKOnlyDialog( msgID ); m_delegate.showOKOnlyDialog( msgID );
} }
protected void showDictGoneFinish()
{
m_delegate.showDictGoneFinish();
}
protected void showConfirmThen( int msgID, protected void showConfirmThen( int msgID,
DialogInterface.OnClickListener action ) DialogInterface.OnClickListener action )
{ {

View file

@ -106,6 +106,7 @@ public class XWListActivity extends ListActivity {
@Override @Override
protected void onPrepareDialog( int id, Dialog dialog ) protected void onPrepareDialog( int id, Dialog dialog )
{ {
super.onPrepareDialog( id, dialog );
m_delegate.onPrepareDialog( id, dialog ); m_delegate.onPrepareDialog( id, dialog );
} }