XW[List]Activity now call removeDialog() every time a dialog is

dismissed so that they now all go through onCreateDialog() every time.
This allows to shrink or eliminate onPrepareDialog().  The hope is
that it will fix the occasional crash where restoreManagedDialogs
invokes onPrepareDialog() and some ivar I need isn't set because the
class was just reloaded.
This commit is contained in:
Andy2 2011-02-24 06:25:18 -08:00
parent 1529319a60
commit 7910aed896
5 changed files with 81 additions and 96 deletions

View file

@ -188,13 +188,15 @@ public class BoardActivity extends XWActivity {
break;
case ASK_PASSWORD_BLK:
m_passwdEdit.setText( "", TextView.BufferType.EDITABLE );
ab = new AlertDialog.Builder( this )
.setTitle( m_dlgTitleStr )
.setView( m_passwdEdit )
.setPositiveButton( R.string.button_ok,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int whichButton ) {
public void
onClick( DialogInterface dlg,
int whichButton ) {
m_resultCode = 1;
}
});
@ -208,15 +210,18 @@ public class BoardActivity extends XWActivity {
.setMessage( R.string.ids_endnow )
.setPositiveButton( R.string.button_yes,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int item ) {
m_jniThread.handle(JNICmd.CMD_ENDGAME);
public void
onClick( DialogInterface dlg,
int item ) {
m_jniThread.
handle(JNICmd.CMD_ENDGAME);
}
})
.setNegativeButton( R.string.button_no,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int item ) {
public void
onClick( DialogInterface dlg,
int item ) {
// do nothing
}
})
@ -231,28 +236,6 @@ public class BoardActivity extends XWActivity {
return dialog;
} // onCreateDialog
@Override
protected void onPrepareDialog( int id, Dialog dialog )
{
switch( id ) {
case DLG_OKONLY:
dialog.setTitle( m_dlgTitle );
// FALLTHRU
case DLG_BADWORDS:
case QUERY_REQUEST_BLK:
case QUERY_INFORM_BLK:
((AlertDialog)dialog).setMessage( m_dlgBytes );
break;
case ASK_PASSWORD_BLK:
m_passwdEdit.setText( "", TextView.BufferType.EDITABLE );
dialog.setTitle( m_dlgTitleStr );
break;
default:
super.onPrepareDialog( id, dialog );
break;
}
}
@Override
protected void onCreate( Bundle savedInstanceState )
{

View file

@ -86,7 +86,6 @@ public class GameConfig extends XWActivity
private CurGameInfo m_gi;
private CurGameInfo m_giOrig;
private int m_whichPlayer;
private Dialog m_curDialog;
// private Spinner m_roleSpinner;
// private Spinner m_connectSpinner;
private Spinner m_phoniesSpinner;
@ -163,9 +162,10 @@ public class GameConfig extends XWActivity
.setView(playerEditView)
.setPositiveButton( R.string.button_ok,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int whichButton ) {
getPlayerSettings();
public void
onClick( DialogInterface dlg,
int button ) {
getPlayerSettings( dlg );
loadPlayers();
}
})
@ -252,10 +252,14 @@ public class GameConfig extends XWActivity
});
break;
case NO_NAME_FOUND:
String format = getString( R.string.no_name_found_f );
String msg =
String.format( format, m_gi.nPlayers, DictLangCache.
getLangName( this, m_gi.dictLang ) );
dialog = new AlertDialog.Builder( this )
.setPositiveButton( R.string.button_ok, null )
// message added below since varies with language etc.
.setMessage("") // if not set here can't change later
.setMessage( msg )
.create();
break;
}
@ -266,11 +270,9 @@ public class GameConfig extends XWActivity
@Override
protected void onPrepareDialog( int id, Dialog dialog )
{
m_curDialog = dialog;
switch ( id ) {
case PLAYER_EDIT:
setPlayerSettings();
setPlayerSettings( dialog );
break;
// case ROLE_EDIT_RELAY:
// case ROLE_EDIT_SMS:
@ -282,28 +284,22 @@ public class GameConfig extends XWActivity
ListView listview = (ListView)dialog.findViewById( R.id.players );
listview.setAdapter( new RemoteChoices() );
break;
case NO_NAME_FOUND:
String format = getString( R.string.no_name_found_f );
String msg = String.format( format, m_gi.nPlayers, DictLangCache.
getLangName( this, m_gi.dictLang ) );
((AlertDialog)dialog).setMessage( msg );
break;
}
super.onPrepareDialog( id, dialog );
}
private void setPlayerSettings()
private void setPlayerSettings( final Dialog dialog )
{
// Hide remote option if in standalone mode...
boolean isServer = !m_notNetworkedGame;
LocalPlayer lp = m_gi.players[m_whichPlayer];
Utils.setText( m_curDialog, R.id.player_name_edit, lp.name );
Utils.setText( m_curDialog, R.id.password_edit, lp.password );
Utils.setText( dialog, R.id.player_name_edit, lp.name );
Utils.setText( dialog, R.id.password_edit, lp.password );
final View localSet = m_curDialog.findViewById( R.id.local_player_set );
final View localSet = dialog.findViewById( R.id.local_player_set );
CheckBox check = (CheckBox)
m_curDialog.findViewById( R.id.remote_check );
dialog.findViewById( R.id.remote_check );
if ( isServer ) {
CompoundButton.OnCheckedChangeListener lstnr =
new CompoundButton.OnCheckedChangeListener() {
@ -320,29 +316,30 @@ public class GameConfig extends XWActivity
localSet.setVisibility( View.VISIBLE );
}
check = (CheckBox)m_curDialog.findViewById( R.id.robot_check );
check = (CheckBox)dialog.findViewById( R.id.robot_check );
CompoundButton.OnCheckedChangeListener lstnr =
new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView,
boolean checked ) {
View view = m_curDialog.findViewById( R.id.password_set );
View view = dialog.findViewById( R.id.password_set );
view.setVisibility( checked ? View.GONE : View.VISIBLE );
}
};
check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( m_curDialog, R.id.robot_check, lp.isRobot() );
Utils.setChecked( m_curDialog, R.id.remote_check, ! lp.isLocal );
Utils.setChecked( dialog, R.id.robot_check, lp.isRobot() );
Utils.setChecked( dialog, R.id.remote_check, ! lp.isLocal );
}
private void getPlayerSettings()
private void getPlayerSettings( DialogInterface di )
{
Dialog dialog = (Dialog)di;
LocalPlayer lp = m_gi.players[m_whichPlayer];
lp.name = Utils.getText( m_curDialog, R.id.player_name_edit );
lp.password = Utils.getText( m_curDialog, R.id.password_edit );
lp.name = Utils.getText( dialog, R.id.player_name_edit );
lp.password = Utils.getText( dialog, R.id.password_edit );
lp.setIsRobot( Utils.getChecked( m_curDialog, R.id.robot_check ) );
lp.isLocal = !Utils.getChecked( m_curDialog, R.id.remote_check );
lp.setIsRobot( Utils.getChecked( dialog, R.id.robot_check ) );
lp.isLocal = !Utils.getChecked( dialog, R.id.remote_check );
}
@Override

View file

@ -80,21 +80,33 @@ public class GamesList extends XWListActivity
@Override
protected Dialog onCreateDialog( int id )
{
DialogInterface.OnClickListener lstnr;
Dialog dialog = super.onCreateDialog( id );
if ( null == dialog ) {
AlertDialog.Builder ab;
switch ( id ) {
case WARN_NODICT:
case WARN_NODICT_SUBST:
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
Intent intent =
Utils.mkDownloadActivity( GamesList.this,
m_missingDictName,
m_missingDictLang );
startActivity( intent );
}
};
int fmtId = WARN_NODICT == id? R.string.no_dictf
: R.string.no_dict_substf;
ab = new AlertDialog.Builder( this )
.setTitle( R.string.no_dict_title )
.setMessage( "" ) // required to get to change it later
.setMessage( String.format( getString( fmtId ),
m_missingDictName ) )
.setPositiveButton( R.string.button_ok, null )
.setNegativeButton( R.string.button_download, null ) // change
.setNegativeButton( R.string.button_download, lstnr )
;
if ( WARN_NODICT_SUBST == id ) {
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
showDialog( SHOW_SUBST );
}
@ -139,38 +151,7 @@ public class GamesList extends XWListActivity
}
}
return dialog;
}
@Override
protected void onPrepareDialog( int id, Dialog dialog )
{
DialogInterface.OnClickListener lstnr;
AlertDialog ad;
switch( id ) {
case WARN_NODICT:
case WARN_NODICT_SUBST:
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
Intent intent =
Utils.mkDownloadActivity( GamesList.this,
m_missingDictName,
m_missingDictLang );
startActivity( intent );
}
};
ad = (AlertDialog)dialog;
ad.setButton( AlertDialog.BUTTON_NEGATIVE,
getString( R.string.button_download ), lstnr );
int fmtId = WARN_NODICT == id? R.string.no_dictf
: R.string.no_dict_substf;
ad.setMessage( String.format( getString( fmtId ),
m_missingDictName ) );
break;
default:
super.onPrepareDialog( id, dialog );
}
}
} // onCreateDialog
@Override
protected void onCreate(Bundle savedInstanceState)

View file

@ -59,9 +59,21 @@ public class XWActivity extends Activity {
}
@Override
protected Dialog onCreateDialog( int id )
protected Dialog onCreateDialog( final int id )
{
return m_delegate.onCreateDialog( id );
Utils.logf( "%s.onCreateDialog() called", getClass().getName() );
Dialog dialog = m_delegate.onCreateDialog( id );
if ( null != dialog ) {
dialog.
setOnDismissListener( new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
Utils.logf( "%s.onDismiss() called",
getClass().getName() );
removeDialog( id );
}
} );
}
return dialog;
}
@Override

View file

@ -61,12 +61,24 @@ public class XWListActivity extends ListActivity {
}
@Override
protected Dialog onCreateDialog( int id )
protected Dialog onCreateDialog( final int id )
{
Utils.logf( "%s.onCreateDialog() called", getClass().getName() );
Dialog dialog = m_delegate.onCreateDialog( id );
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;
}