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 DLG_DELETED = DLG_OKONLY + 8;
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 SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins
@ -288,21 +287,6 @@ public class BoardActivity extends XWActivity
.create();
}
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:
// just drop it; super.onCreateDialog likely failed
break;
@ -1065,7 +1049,7 @@ public class BoardActivity extends XWActivity
GameUtils.DictPairs pairs = GameUtils.openDicts( this, dictNames );
if ( pairs.anyMissing( dictNames ) ) {
showDialog( DLG_NODICT );
showDictGoneFinish();
} else {
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 CONFIRM_THEN = 4;
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 String m_msg;
@ -78,6 +79,9 @@ public class DlgDelegate {
case TEXT_OR_HTML_THEN:
dialog = createHtmlThenDialog();
break;
case DLG_DICTGONE:
dialog = createDictGoneDialog();
break;
}
return dialog;
}
@ -141,6 +145,11 @@ public class DlgDelegate {
m_activity.showDialog( DIALOG_OKONLY );
}
public void showDictGoneFinish()
{
m_activity.showDialog( DLG_DICTGONE );
}
public void showAboutDialog()
{
m_activity.showDialog( DIALOG_ABOUT );
@ -283,4 +292,28 @@ public class DlgDelegate {
.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();
int gamePtr = XwJNI.initJNI();
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();
GameUtils.loadMakeGame( this, gamePtr, m_giOrig, m_gameLock );
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 );
int gamePtr = GameUtils.loadMakeGame( this, m_giOrig, m_gameLock );
if ( 0 == gamePtr ) {
showDictGoneFinish();
} else {
String relayName = CommonPrefs.getDefaultRelayHost( this );
int relayPort = CommonPrefs.getDefaultRelayPort( this );
XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort );
}
XwJNI.game_dispose( gamePtr );
m_gameStarted = XwJNI.model_getNMoves( gamePtr ) > 0
|| XwJNI.comms_isConnected( 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 );
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 );
}
};
check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
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
@Override

View file

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

View file

@ -67,10 +67,9 @@ public class RelayGameActivity extends XWActivity
{
super.onStart();
int gamePtr = XwJNI.initJNI();
m_gi = new CurGameInfo( this );
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 );
if ( XwJNI.game_hasComms( gamePtr ) ) {
XwJNI.comms_getAddr( gamePtr, m_car );

View file

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

View file

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