convert remaining DelegateBase Alerts

Includes a hack in DBAlert that's required I think because
GameConfigDelegate is launched "for result". onCreateDialog() always
fails after a rotation the first time because GameConfigDelegate isn't
there to have its makeDialog() dispatched to. So it puts up a dummy
alert and then post()s code that is successful in calling makeDialog()
to get an alert from GameConfigDelegate that can replace the
dummy. Nothing shows on the screen on simulator anyway.

The major problem remaining is that blocking alerts in BoardDelegate are
recreated after rotation but the thread that was blocking has been freed
so nothing can be done after the new alert returns. E.g. blank tile
picker will be posted again, user will pick a tile, but the common
code's not in a state to do anything with that choice (which cannot even
be "returned.") Options are to find a way to make the JNIThread survive
the configuration change without unblocking or to rewrite all the common
code to not expect return values from util_ methods.

This commit is not well tested, and diffs don't allow a thorough check
of the conversion of each DlgID type.
This commit is contained in:
Eric House 2017-02-16 07:25:20 -08:00
parent 13adebdc51
commit e631d57e9b
10 changed files with 697 additions and 697 deletions

View file

@ -20,15 +20,21 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import org.eehouse.android.xw4.loc.LocUtils;
import java.io.Serializable; import java.io.Serializable;
import junit.framework.Assert; import junit.framework.Assert;
public class DBAlert extends DialogFragment { public class DBAlert extends DialogFragment {
private static final String TAG = DBAlert.class.getSimpleName();
private static final String DLG_ID_KEY = "DLG_ID_KEY"; private static final String DLG_ID_KEY = "DLG_ID_KEY";
private static final String PARMS_KEY = "PARMS_KEY"; private static final String PARMS_KEY = "PARMS_KEY";
@ -44,7 +50,11 @@ public class DBAlert extends DialogFragment {
{ {
if ( BuildConfig.DEBUG ) { if ( BuildConfig.DEBUG ) {
for ( Object obj : params ) { for ( Object obj : params ) {
Assert.assertTrue( obj instanceof Serializable ); if ( !(obj instanceof Serializable) ) {
DbgUtils.logd( TAG, "OOPS: %s not Serializable",
obj.getClass().getName() );
// Assert.fail();
}
} }
} }
@ -68,6 +78,15 @@ public class DBAlert extends DialogFragment {
bundle.putSerializable( PARMS_KEY, mParams ); bundle.putSerializable( PARMS_KEY, mParams );
} }
@Override
public void onDismiss( DialogInterface dif )
{
if ( null != m_onDismiss ) {
m_onDismiss.onDismissed();
}
super.onDismiss( dif );
}
@Override @Override
public Dialog onCreateDialog( Bundle sis ) public Dialog onCreateDialog( Bundle sis )
{ {
@ -78,19 +97,36 @@ public class DBAlert extends DialogFragment {
mParams = (Object[])sis.getSerializable(PARMS_KEY); mParams = (Object[])sis.getSerializable(PARMS_KEY);
XWActivity activity = (XWActivity)getActivity(); XWActivity activity = (XWActivity)getActivity();
return activity.makeDialog( this, mParams ); Dialog dialog = activity.makeDialog( this, mParams );
}
@Override if ( null == dialog ) {
public void onDismiss( DialogInterface dif ) dialog = LocUtils.makeAlertBuilder( getActivity() )
{ .setTitle( "Stub Alert" )
if ( null != m_onDismiss ) { .setMessage( String.format( "Unable to create for %s", mDlgID.toString() ) )
m_onDismiss.onDismissed(); .setPositiveButton( "Bummer", null )
// .setNegativeButton( "Try now", new OnClickListener() {
// @Override
// public void onClick( DialogInterface dlg, int button ) {
// DBAlert alrt = newInstance( mDlgID, mParams );
// ((MainActivity)getActivity()).show( alrt );
// }
// })
.create();
new Handler().post( new Runnable() {
@Override
public void run() {
DBAlert newMe = newInstance( mDlgID, mParams );
((MainActivity)getActivity()).show( newMe );
dismiss(); // kill myself...
}
} );
} }
super.onDismiss( dif ); return dialog;
} }
protected void setOnDismiss( OnDismissListener lstnr ) protected void setOnDismissListener( OnDismissListener lstnr )
{ {
m_onDismiss = lstnr; m_onDismiss = lstnr;
} }

View file

@ -481,11 +481,6 @@ public class DelegateBase implements DlgClickNotify,
return LocUtils.makeAlertBuilder( m_activity ); return LocUtils.makeAlertBuilder( m_activity );
} }
protected void setRemoveOnDismiss( Dialog dialog, DlgID dlgID )
{
Utils.setRemoveOnDismiss( m_activity, dialog, dlgID );
}
public NotAgainBuilder public NotAgainBuilder
makeNotAgainBuilder( String msg, int key, Action action ) makeNotAgainBuilder( String msg, int key, Action action )
{ {

View file

@ -465,7 +465,7 @@ public class DictsDelegate extends ListDelegateBase
} }
return dialog; return dialog;
} // onCreateDialog } // makeDialog
@Override @Override
protected void init( Bundle savedInstanceState ) protected void init( Bundle savedInstanceState )

View file

@ -450,8 +450,11 @@ public class DlgDelegate {
} }
} else { } else {
DlgState state = new DlgState( DlgID.DIALOG_NOTAGAIN ) DlgState state = new DlgState( DlgID.DIALOG_NOTAGAIN )
.setMsg( msg).setPrefsKey( prefsKey ).setAction( action ) .setMsg( msg)
.setActionPair( more ).setParams( params ); .setPrefsKey( prefsKey )
.setAction( action )
.setActionPair( more )
.setParams( params );
m_dlgt.show( NotAgainAlert.newInstance( state ) ); m_dlgt.show( NotAgainAlert.newInstance( state ) );
} }
} }
@ -622,7 +625,6 @@ public class DlgDelegate {
.setPositiveButton( R.string.button_enable, lstnr ) .setPositiveButton( R.string.button_enable, lstnr )
.setNegativeButton( android.R.string.cancel, null ) .setNegativeButton( android.R.string.cancel, null )
.create(); .create();
Utils.setRemoveOnDismiss( m_activity, dialog, dlgID );
return dialog; return dialog;
} }

View file

@ -160,183 +160,121 @@ public class GameConfigDelegate extends DelegateBase
} }
} }
protected Dialog onCreateDialog( int id )
{
Dialog dialog = super.onCreateDialog( id );
if ( null == dialog ) {
DialogInterface.OnClickListener dlpos;
AlertDialog.Builder ab;
final DlgID dlgID = DlgID.values()[id];
switch (dlgID) {
case PLAYER_EDIT:
View playerEditView = inflate( R.layout.player_edit );
dialog = makeAlertBuilder()
.setTitle(R.string.player_edit_title)
.setView(playerEditView)
.setPositiveButton( android.R.string.ok,
new DialogInterface.OnClickListener() {
public void
onClick( DialogInterface dlg,
int button ) {
GameConfigDelegate self = curThis();
self.getPlayerSettings( dlg );
self.loadPlayersList();
}
})
.setNegativeButton( android.R.string.cancel, null )
.create();
break;
// case ROLE_EDIT_RELAY:
// case ROLE_EDIT_SMS:
// case ROLE_EDIT_BT:
// dialog = new AlertDialog.Builder( this )
// .setTitle(titleForDlg(id))
// .setView( LayoutInflater.from(this)
// .inflate( layoutForDlg(id), null ))
// .setPositiveButton( android.R.string.ok,
// new DialogInterface.OnClickListener() {
// public void onClick( DialogInterface dlg,
// int whichButton ) {
// getRoleSettings();
// }
// })
// .setNegativeButton( android.R.string.cancel, null )
// .create();
// break;
case FORCE_REMOTE:
dlpos = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int whichButton ) {
curThis().loadPlayersList();
}
};
dialog = makeAlertBuilder()
.setTitle( R.string.force_title )
.setView( inflate( layoutForDlg(dlgID) ) )
.setPositiveButton( android.R.string.ok, dlpos )
.create();
DialogInterface.OnDismissListener dismiss =
new DialogInterface.OnDismissListener() {
@Override
public void onDismiss( DialogInterface di )
{
GameConfigDelegate self = curThis();
if ( null != self
&& self.m_gi.forceRemoteConsistent() ) {
self.showToast( R.string.forced_consistent );
self.loadPlayersList();
} else {
DbgUtils.logw( TAG, "onDismiss(): "
+ "no visible self" );
}
}
};
dialog.setOnDismissListener( dismiss );
break;
case CONFIRM_CHANGE_PLAY:
case CONFIRM_CHANGE:
dlpos = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int whichButton ) {
GameConfigDelegate self = curThis();
self.applyChanges( true );
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
self.launchGame( true );
}
}
};
ab = makeAlertBuilder()
.setTitle( R.string.confirm_save_title )
.setMessage( R.string.confirm_save )
.setPositiveButton( R.string.button_save, dlpos );
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
dlpos = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int whichButton ) {
curThis().finishAndLaunch();
}
};
} else {
dlpos = null;
}
ab.setNegativeButton( R.string.button_discard_changes, dlpos );
dialog = ab.create();
dialog.setOnDismissListener( new DialogInterface.
OnDismissListener() {
public void onDismiss( DialogInterface di ) {
curThis().closeNoSave();
}
});
break;
case NO_NAME_FOUND:
String langName = DictLangCache.getLangName( m_activity,
m_gi.dictLang );
String msg = getString( R.string.no_name_found_fmt,
m_gi.nPlayers, xlateLang( langName ) );
dialog = makeAlertBuilder()
.setPositiveButton( android.R.string.ok, null )
// message added below since varies with language etc.
.setMessage( msg )
.create();
break;
case CHANGE_CONN:
LinearLayout layout = (LinearLayout)inflate( R.layout.conn_types_display );
final ConnViaViewLayout items = (ConnViaViewLayout)
layout.findViewById( R.id.conn_types );
items.setActivity( m_activity );
final CheckBox cb = (CheckBox)layout
.findViewById(R.id.default_check);
cb.setVisibility( View.VISIBLE );
final DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
GameConfigDelegate self = curThis();
self.m_conTypes = items.getTypes();
if ( cb.isChecked()) {
XWPrefs.setAddrTypes( self.m_activity, self.m_conTypes );
}
self.m_car.populate( self.m_activity, self.m_conTypes );
self.setConnLabel();
self.setupRelayStuffIf( false );
self.showHideRelayStuff();
}
};
dialog = makeAlertBuilder()
.setTitle( R.string.title_addrs_pref )
.setView( layout )
.setPositiveButton( android.R.string.ok, lstnr )
.setNegativeButton( android.R.string.cancel, null )
.create();
break;
}
}
return dialog;
} // onCreateDialog
@Override @Override
protected void prepareDialog( DlgID dlgID, Dialog dialog ) protected Dialog makeDialog( DBAlert alert, Object[] params )
{ {
Dialog dialog = null;
final DlgID dlgID = alert.getDlgID();
DbgUtils.logd( TAG, "makeDialog(%s)", dlgID.toString() );
DialogInterface.OnClickListener dlpos;
AlertDialog.Builder ab;
switch ( dlgID ) { switch ( dlgID ) {
case PLAYER_EDIT: case PLAYER_EDIT: {
setPlayerSettings( dialog ); View playerEditView = inflate( R.layout.player_edit );
break; setPlayerSettings( playerEditView );
case FORCE_REMOTE:
ListView listview = (ListView)dialog.findViewById( R.id.players ); dialog = makeAlertBuilder()
listview.setAdapter( new RemoteChoices() ); .setTitle( R.string.player_edit_title )
.setView( playerEditView )
.setPositiveButton( android.R.string.ok,
new DialogInterface.OnClickListener() {
public void
onClick( DialogInterface dlg,
int button ) {
getPlayerSettings( dlg );
loadPlayersList();
}
})
.setNegativeButton( android.R.string.cancel, null )
.create();
}
break; break;
case CHANGE_CONN: case FORCE_REMOTE: {
ConnViaViewLayout items = (ConnViaViewLayout) dlpos = new DialogInterface.OnClickListener() {
dialog.findViewById( R.id.conn_types ); public void onClick( DialogInterface dlg,
int whichButton ) {
loadPlayersList();
}
};
View view = inflate( layoutForDlg(dlgID) );
ListView listview = (ListView)view.findViewById( R.id.players );
listview.setAdapter( new RemoteChoices() );
dialog = makeAlertBuilder()
.setTitle( R.string.force_title )
.setView( view )
.setPositiveButton( android.R.string.ok, dlpos )
.create();
alert.setOnDismissListener( new DBAlert.OnDismissListener() {
@Override
public void onDismissed() {
if ( m_gi.forceRemoteConsistent() ) {
showToast( R.string.forced_consistent );
loadPlayersList();
}
}
});
}
break;
case CONFIRM_CHANGE_PLAY:
case CONFIRM_CHANGE: {
dlpos = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int whichButton ) {
applyChanges( true );
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
launchGame( true );
}
}
};
ab = makeAlertBuilder()
.setTitle( R.string.confirm_save_title )
.setMessage( R.string.confirm_save )
.setPositiveButton( R.string.button_save, dlpos );
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
dlpos = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int whichButton ) {
finishAndLaunch();
}
};
} else {
dlpos = null;
}
ab.setNegativeButton( R.string.button_discard_changes, dlpos );
dialog = ab.create();
alert.setOnDismissListener( new DBAlert.OnDismissListener() {
@Override
public void onDismissed() {
closeNoSave();
}
} );
}
break;
case NO_NAME_FOUND: {
String langName = DictLangCache.getLangName( m_activity,
m_gi.dictLang );
String msg = getString( R.string.no_name_found_fmt,
m_gi.nPlayers, xlateLang( langName ) );
dialog = makeAlertBuilder()
.setPositiveButton( android.R.string.ok, null )
// message added below since varies with language etc.
.setMessage( msg )
.create();
}
break;
case CHANGE_CONN: {
LinearLayout layout = (LinearLayout)inflate( R.layout.conn_types_display );
final ConnViaViewLayout items = (ConnViaViewLayout)
layout.findViewById( R.id.conn_types );
items.setActivity( m_activity );
items.configure( m_conTypes, items.configure( m_conTypes,
new ConnViaViewLayout.CheckEnabledWarner() { new ConnViaViewLayout.CheckEnabledWarner() {
public void warnDisabled( CommsConnType typ ) { public void warnDisabled( CommsConnType typ ) {
@ -368,28 +306,65 @@ public class GameConfigDelegate extends DelegateBase
} }
} }
}, null, this ); }, null, this );
final CheckBox cb = (CheckBox)layout
.findViewById( R.id.default_check );
cb.setVisibility( View.VISIBLE ); // "gone" in .xml file
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
m_conTypes = items.getTypes();
if ( cb.isChecked()) {
XWPrefs.setAddrTypes( m_activity, m_conTypes );
}
m_car.populate( m_activity, m_conTypes );
setConnLabel();
setupRelayStuffIf( false );
showHideRelayStuff();
}
};
dialog = makeAlertBuilder()
.setTitle( R.string.title_addrs_pref )
.setView( layout )
.setPositiveButton( android.R.string.ok, lstnr )
.setNegativeButton( android.R.string.cancel, null )
.create();
}
break;
default:
dialog = super.makeDialog( alert, params );
break; break;
} }
}
private void setPlayerSettings( final Dialog dialog ) Assert.assertNotNull( dialog );
return dialog;
} // makeDialog
private void setPlayerSettings( final View playerView )
{ {
DbgUtils.logd( TAG, "setPlayerSettings()" );
boolean isServer = ! localOnlyGame(); boolean isServer = ! localOnlyGame();
// Independent of other hide/show logic, these guys are // Independent of other hide/show logic, these guys are
// information-only if the game's locked. (Except that in a // information-only if the game's locked. (Except that in a
// local game you can always toggle a player's robot state.) // local game you can always toggle a player's robot state.)
Utils.setEnabled( dialog, R.id.remote_check, !m_isLocked ); Utils.setEnabled( playerView, R.id.remote_check, !m_isLocked );
Utils.setEnabled( dialog, R.id.player_name_edit, !m_isLocked ); Utils.setEnabled( playerView, R.id.player_name_edit, !m_isLocked );
Utils.setEnabled( dialog, R.id.robot_check, !m_isLocked || !isServer ); Utils.setEnabled( playerView, R.id.robot_check,
!m_isLocked || !isServer );
// Hide remote option if in standalone mode... // Hide remote option if in standalone mode...
LocalPlayer lp = m_gi.players[m_whichPlayer]; LocalPlayer lp = m_gi.players[m_whichPlayer];
Utils.setText( dialog, R.id.player_name_edit, lp.name ); Utils.setText( playerView, R.id.player_name_edit, lp.name );
Utils.setText( dialog, R.id.password_edit, lp.password ); Utils.setText( playerView, R.id.password_edit, lp.password );
// Dicts spinner with label // Dicts spinner with label
TextView dictLabel = (TextView)dialog.findViewById( R.id.dict_label ); TextView dictLabel = (TextView)playerView
.findViewById( R.id.dict_label );
if ( localOnlyGame() ) { if ( localOnlyGame() ) {
String langName = DictLangCache.getLangName( m_activity, m_gi.dictLang ); String langName = DictLangCache.getLangName( m_activity, m_gi.dictLang );
String label = getString( R.string.dict_lang_label_fmt, langName ); String label = getString( R.string.dict_lang_label_fmt, langName );
@ -397,7 +372,8 @@ public class GameConfigDelegate extends DelegateBase
} else { } else {
dictLabel.setVisibility( View.GONE ); dictLabel.setVisibility( View.GONE );
} }
m_playerDictSpinner = (Spinner)dialog.findViewById( R.id.dict_spinner ); m_playerDictSpinner = (Spinner)
playerView.findViewById( R.id.dict_spinner );
if ( localOnlyGame() ) { if ( localOnlyGame() ) {
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, m_gi.dictName(lp) ); configDictSpinner( m_playerDictSpinner, m_gi.dictLang, m_gi.dictName(lp) );
} else { } else {
@ -405,10 +381,9 @@ public class GameConfigDelegate extends DelegateBase
m_playerDictSpinner = null; m_playerDictSpinner = null;
} }
final View localSet = dialog.findViewById( R.id.local_player_set ); final View localSet = playerView.findViewById( R.id.local_player_set );
CheckBox check = (CheckBox) CheckBox check = (CheckBox)playerView.findViewById( R.id.remote_check );
dialog.findViewById( R.id.remote_check );
if ( isServer ) { if ( isServer ) {
OnCheckedChangeListener lstnr = OnCheckedChangeListener lstnr =
new OnCheckedChangeListener() { new OnCheckedChangeListener() {
@ -425,19 +400,20 @@ public class GameConfigDelegate extends DelegateBase
localSet.setVisibility( View.VISIBLE ); localSet.setVisibility( View.VISIBLE );
} }
check = (CheckBox)dialog.findViewById( R.id.robot_check ); check = (CheckBox)playerView.findViewById( R.id.robot_check );
OnCheckedChangeListener lstnr = OnCheckedChangeListener lstnr =
new OnCheckedChangeListener() { new OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView, public void onCheckedChanged( CompoundButton buttonView,
boolean checked ) { boolean checked ) {
View view = dialog.findViewById( R.id.password_set ); View view = playerView.findViewById( R.id.password_set );
view.setVisibility( checked ? View.GONE : View.VISIBLE ); view.setVisibility( checked ? View.GONE : View.VISIBLE );
} }
}; };
check.setOnCheckedChangeListener( lstnr ); check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( dialog, R.id.robot_check, lp.isRobot() ); Utils.setChecked( playerView, R.id.robot_check, lp.isRobot() );
Utils.setChecked( dialog, R.id.remote_check, ! lp.isLocal ); Utils.setChecked( playerView, R.id.remote_check, ! lp.isLocal );
DbgUtils.logd( TAG, "setPlayerSettings() DONE" );
} }
private void getPlayerSettings( DialogInterface di ) private void getPlayerSettings( DialogInterface di )
@ -676,7 +652,7 @@ public class GameConfigDelegate extends DelegateBase
// NoNameFound interface // NoNameFound interface
public void NoNameFound() public void NoNameFound()
{ {
showDialog( DlgID.NO_NAME_FOUND ); showDialogFragment( DlgID.NO_NAME_FOUND );
} }
@Override @Override
@ -704,7 +680,7 @@ public class GameConfigDelegate extends DelegateBase
break; break;
case ASKED_PHONE_STATE: case ASKED_PHONE_STATE:
showDialog( DlgID.CHANGE_CONN ); showDialogFragment( DlgID.CHANGE_CONN );
break; break;
default: default:
@ -722,7 +698,7 @@ public class GameConfigDelegate extends DelegateBase
showConnAfterCheck(); showConnAfterCheck();
break; break;
case ASKED_PHONE_STATE: case ASKED_PHONE_STATE:
showDialog( DlgID.CHANGE_CONN ); showDialogFragment( DlgID.CHANGE_CONN );
break; break;
default: default:
handled = super.onNegButton( action, params ); handled = super.onNegButton( action, params );
@ -780,7 +756,7 @@ public class GameConfigDelegate extends DelegateBase
saveAndClose( true ); saveAndClose( true );
} else if ( m_giOrig.changesMatter(m_gi) } else if ( m_giOrig.changesMatter(m_gi)
|| m_carOrig.changesMatter(m_car) ) { || m_carOrig.changesMatter(m_car) ) {
showDialog( DlgID.CONFIRM_CHANGE_PLAY ); showDialogFragment( DlgID.CONFIRM_CHANGE_PLAY );
} else { } else {
finishAndLaunch(); finishAndLaunch();
} }
@ -799,7 +775,7 @@ public class GameConfigDelegate extends DelegateBase
R.string.phone_state_rationale, R.string.phone_state_rationale,
Action.ASKED_PHONE_STATE, this ); Action.ASKED_PHONE_STATE, this );
} else { } else {
showDialog( DlgID.CHANGE_CONN ); showDialogFragment( DlgID.CHANGE_CONN );
} }
} }
@ -844,7 +820,7 @@ public class GameConfigDelegate extends DelegateBase
applyChanges( true ); applyChanges( true );
} else if ( m_giOrig.changesMatter(m_gi) } else if ( m_giOrig.changesMatter(m_gi)
|| m_carOrig.changesMatter(m_car) ) { || m_carOrig.changesMatter(m_car) ) {
showDialog( DlgID.CONFIRM_CHANGE ); showDialogFragment( DlgID.CONFIRM_CHANGE );
consumed = true; // don't dismiss activity yet! consumed = true; // don't dismiss activity yet!
} else { } else {
applyChanges( false ); applyChanges( false );
@ -879,7 +855,7 @@ public class GameConfigDelegate extends DelegateBase
@Override @Override
public void onClick( View view ) { public void onClick( View view ) {
m_whichPlayer = ((XWListItem)view).getPosition(); m_whichPlayer = ((XWListItem)view).getPosition();
showDialog( DlgID.PLAYER_EDIT ); showDialogFragment( DlgID.PLAYER_EDIT );
} }
}; };
@ -917,7 +893,7 @@ public class GameConfigDelegate extends DelegateBase
if ( ! localOnlyGame() if ( ! localOnlyGame()
&& ((0 == m_gi.remoteCount() ) && ((0 == m_gi.remoteCount() )
|| (m_gi.nPlayers == m_gi.remoteCount()) ) ) { || (m_gi.nPlayers == m_gi.remoteCount()) ) ) {
showDialog( DlgID.FORCE_REMOTE ); showDialogFragment( DlgID.FORCE_REMOTE );
} }
adjustPlayersLabel(); adjustPlayersLabel();
} }
@ -1255,7 +1231,7 @@ public class GameConfigDelegate extends DelegateBase
private boolean localOnlyGame() private boolean localOnlyGame()
{ {
return DeviceRole.SERVER_STANDALONE == m_giOrig.serverRole; return DeviceRole.SERVER_STANDALONE == m_gi.serverRole; // m_giOrig is null...
} }
public static void editForResult( Delegator delegator, public static void editForResult( Delegator delegator,

View file

@ -825,7 +825,7 @@ public class GamesListDelegate extends ListDelegateBase
(EditText)layout.findViewById( R.id.name_edit ); (EditText)layout.findViewById( R.id.name_edit );
etext.setText( CommonPrefs.getDefaultPlayerName( m_activity, etext.setText( CommonPrefs.getDefaultPlayerName( m_activity,
0, true ) ); 0, true ) );
alert.setOnDismiss( new DBAlert.OnDismissListener() { alert.setOnDismissListener( new DBAlert.OnDismissListener() {
@Override @Override
public void onDismissed() { public void onDismissed() {
String name = etext.getText().toString(); String name = etext.getText().toString();
@ -2369,7 +2369,6 @@ public class GamesListDelegate extends ListDelegateBase
.setNegativeButton( android.R.string.cancel, lstnr2 ) .setNegativeButton( android.R.string.cancel, lstnr2 )
.setView( namer ) .setView( namer )
.create(); .create();
setRemoveOnDismiss( dialog, dlgID );
return dialog; return dialog;
} }

View file

@ -106,7 +106,7 @@ public class SMSInviteDelegate extends InviteDelegate {
startActivityForResult( intent, RequestCode.GET_CONTACT ); startActivityForResult( intent, RequestCode.GET_CONTACT );
break; break;
case R.id.manual_add_button: case R.id.manual_add_button:
showDialog( DlgID.GET_NUMBER ); showDialogFragment( DlgID.GET_NUMBER );
break; break;
case R.id.button_clear: case R.id.button_clear:
int count = getChecked().size(); int count = getChecked().size();
@ -131,38 +131,37 @@ public class SMSInviteDelegate extends InviteDelegate {
} }
@Override @Override
protected Dialog onCreateDialog( int id ) protected Dialog makeDialog( DBAlert alert, Object[] params )
{ {
Dialog dialog = super.onCreateDialog( id ); Dialog dialog;
if ( null == dialog ) { DialogInterface.OnClickListener lstnr;
DialogInterface.OnClickListener lstnr; switch( alert.getDlgID() ) {
DlgID dlgID = DlgID.values()[id]; case GET_NUMBER: {
switch( dlgID ) { final GameNamer namerView =
case GET_NUMBER: (GameNamer)inflate( R.layout.rename_game );
final GameNamer namerView = namerView.setLabel( R.string.get_sms_number );
(GameNamer)inflate( R.layout.rename_game ); namerView.setKeyListener(DialerKeyListener.getInstance());
namerView.setLabel( R.string.get_sms_number ); lstnr = new DialogInterface.OnClickListener() {
namerView.setKeyListener(DialerKeyListener.getInstance()); public void onClick( DialogInterface dlg, int item ) {
lstnr = new DialogInterface.OnClickListener() { String number = namerView.getName();
public void onClick( DialogInterface dlg, int item ) { PhoneRec rec = new PhoneRec( number );
SMSInviteDelegate self = (SMSInviteDelegate)curThis(); makeConfirmThenBuilder( R.string.warn_unlimited,
String number = namerView.getName(); Action.POST_WARNING_ACTION )
PhoneRec rec = new PhoneRec( number ); .setPosButton( R.string.button_yes )
self.makeConfirmThenBuilder( R.string.warn_unlimited, .setParams( number, null )
Action.POST_WARNING_ACTION ) .show();
.setPosButton( R.string.button_yes ) }
.setParams( number, null ) };
.show(); dialog = makeAlertBuilder()
} .setPositiveButton( android.R.string.ok, lstnr )
}; .setNegativeButton( android.R.string.cancel, null )
dialog = makeAlertBuilder() .setView( namerView )
.setNegativeButton( android.R.string.cancel, null ) .create();
.setPositiveButton( android.R.string.ok, lstnr ) }
.setView( namerView ) break;
.create(); default:
break; dialog = super.makeDialog( alert, params );
} break;
setRemoveOnDismiss( dialog, dlgID );
} }
return dialog; return dialog;
} }

View file

@ -163,17 +163,6 @@ public class Utils {
showToast( context, msg ); showToast( context, msg );
} }
public static void setRemoveOnDismiss( final Activity activity,
Dialog dialog, DlgID dlgID )
{
final int id = dlgID.ordinal();
dialog.setOnDismissListener( new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
activity.removeDialog( id );
}
} );
}
public static void launchSettings( Context context ) public static void launchSettings( Context context )
{ {
Intent intent = new Intent( context, PrefsActivity.class ); Intent intent = new Intent( context, PrefsActivity.class );
@ -326,30 +315,30 @@ public class Utils {
return str; return str;
} }
public static void setChecked( Dialog dialog, int id, boolean value ) public static void setChecked( View parent, int id, boolean value )
{ {
CheckBox cbx = (CheckBox)dialog.findViewById( id ); CheckBox cbx = (CheckBox)parent.findViewById( id );
cbx.setChecked( value ); cbx.setChecked( value );
} }
public static void setText( Dialog dialog, int id, String value ) public static void setText( View parent, int id, String value )
{ {
EditText editText = (EditText)dialog.findViewById( id ); EditText editText = (EditText)parent.findViewById( id );
if ( null != editText ) { if ( null != editText ) {
editText.setText( value, TextView.BufferType.EDITABLE ); editText.setText( value, TextView.BufferType.EDITABLE );
} }
} }
public static void setInt( Dialog dialog, int id, int value ) public static void setInt( View parent, int id, int value )
{ {
String str = Integer.toString(value); String str = Integer.toString(value);
setText( dialog, id, str ); setText( parent, id, str );
} }
public static void setEnabled( Dialog dialog, int id, boolean enabled ) public static void setEnabled( View parent, int id, boolean enabled )
{ {
View view = dialog.findViewById( id ); View view = parent.findViewById( id );
view.setEnabled( enabled ); parent.setEnabled( enabled );
} }
public static boolean getChecked( Dialog dialog, int id ) public static boolean getChecked( Dialog dialog, int id )

View file

@ -23,6 +23,8 @@ package org.eehouse.android.xw4.jni;
import android.content.Context; import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
import java.io.Serializable;
import junit.framework.Assert; import junit.framework.Assert;
import org.eehouse.android.xw4.DBUtils; import org.eehouse.android.xw4.DBUtils;
@ -39,7 +41,7 @@ import org.json.JSONObject;
/** Info we want to access when the game's closed that's not available /** Info we want to access when the game's closed that's not available
* in CurGameInfo * in CurGameInfo
*/ */
public class GameSummary { public class GameSummary implements Serializable {
private static final String TAG = GameSummary.class.getSimpleName(); private static final String TAG = GameSummary.class.getSimpleName();
public static final String EXTRA_REMATCH_BTADDR = "rm_btaddr"; public static final String EXTRA_REMATCH_BTADDR = "rm_btaddr";
public static final String EXTRA_REMATCH_PHONE = "rm_phone"; public static final String EXTRA_REMATCH_PHONE = "rm_phone";