mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
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:
parent
13adebdc51
commit
e631d57e9b
10 changed files with 697 additions and 697 deletions
|
@ -113,10 +113,7 @@ public class BoardDelegate extends DelegateBase
|
|||
private Perms23.PermCbck m_permCbck;
|
||||
private ArrayList<String> m_pendingChats;
|
||||
|
||||
private String m_dlgBytes = null;
|
||||
private EditText m_passwdEdit;
|
||||
private int m_dlgTitle;
|
||||
private String m_dlgTitleStr;
|
||||
private String[] m_texts;
|
||||
private CommsConnTypeSet m_connTypes = null;
|
||||
private String[] m_missingDevs;
|
||||
|
@ -171,36 +168,47 @@ public class BoardDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
protected Dialog onCreateDialog( int id )
|
||||
private DBAlert.OnDismissListener m_blockingODL =
|
||||
new DBAlert.OnDismissListener() {
|
||||
public void onDismissed() {
|
||||
releaseIfBlocking();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
Dialog dialog = super.onCreateDialog( id );
|
||||
if ( null == dialog ) {
|
||||
final DlgID dlgID = alert.getDlgID();
|
||||
DbgUtils.logd( TAG, "makeDialog(%s)", dlgID.toString() );
|
||||
OnClickListener lstnr;
|
||||
AlertDialog.Builder ab = makeAlertBuilder();
|
||||
|
||||
final DlgID dlgID = DlgID.values()[id];
|
||||
Dialog dialog;
|
||||
switch ( dlgID ) {
|
||||
case DLG_OKONLY:
|
||||
case DLG_RETRY:
|
||||
case GAME_OVER:
|
||||
case DLG_CONNSTAT:
|
||||
ab.setTitle( m_dlgTitle )
|
||||
.setMessage( m_dlgBytes )
|
||||
case DLG_CONNSTAT: {
|
||||
GameSummary summary = (GameSummary)params[0];
|
||||
int title = (Integer)params[1];
|
||||
String msg = (String)params[2];
|
||||
ab.setTitle( title )
|
||||
.setMessage( msg )
|
||||
.setPositiveButton( android.R.string.ok, null );
|
||||
if ( DlgID.DLG_RETRY == dlgID ) {
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
curThis().handleViaThread( JNICmd.CMD_RESET );
|
||||
handleViaThread( JNICmd.CMD_RESET );
|
||||
}
|
||||
};
|
||||
ab.setNegativeButton( R.string.button_retry, lstnr );
|
||||
} else if ( DlgID.GAME_OVER == dlgID
|
||||
&& rematchSupported( true ) ) {
|
||||
&& rematchSupported( m_activity, true, summary ) ) {
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
curThis().doRematchIf();
|
||||
doRematchIf();
|
||||
}
|
||||
};
|
||||
ab.setNegativeButton( R.string.button_rematch, lstnr );
|
||||
|
@ -224,31 +232,32 @@ public class BoardDelegate extends DelegateBase
|
|||
ab.setNegativeButton( R.string.button_reconnect, lstnr );
|
||||
}
|
||||
dialog = ab.create();
|
||||
setRemoveOnDismiss( dialog, dlgID );
|
||||
}
|
||||
break;
|
||||
|
||||
case DLG_USEDICT:
|
||||
case DLG_GETDICT:
|
||||
case DLG_GETDICT: {
|
||||
int title = (Integer)params[0];
|
||||
String msg = (String)params[1];
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
BoardDelegate self = curThis();
|
||||
if ( DlgID.DLG_USEDICT == dlgID ) {
|
||||
self.setGotGameDict( m_getDict );
|
||||
setGotGameDict( m_getDict );
|
||||
} else {
|
||||
DwnldDelegate
|
||||
.downloadDictInBack( self.m_activity,
|
||||
self.m_gi.dictLang,
|
||||
self.m_getDict, self );
|
||||
.downloadDictInBack( m_activity,
|
||||
m_gi.dictLang,
|
||||
m_getDict, BoardDelegate.this );
|
||||
}
|
||||
}
|
||||
};
|
||||
dialog = ab.setTitle( m_dlgTitle )
|
||||
.setMessage( m_dlgBytes )
|
||||
dialog = ab.setTitle( title )
|
||||
.setMessage( msg )
|
||||
.setPositiveButton( R.string.button_yes, lstnr )
|
||||
.setNegativeButton( R.string.button_no, null )
|
||||
.create();
|
||||
setRemoveOnDismiss( dialog, dlgID );
|
||||
}
|
||||
break;
|
||||
|
||||
case DLG_DELETED:
|
||||
|
@ -258,7 +267,7 @@ public class BoardDelegate extends DelegateBase
|
|||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
curThis().deleteAndClose();
|
||||
deleteAndClose();
|
||||
}
|
||||
};
|
||||
ab.setNegativeButton( R.string.button_delete, lstnr );
|
||||
|
@ -267,16 +276,19 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
case QUERY_REQUEST_BLK:
|
||||
case QUERY_INFORM_BLK:
|
||||
case DLG_SCORES:
|
||||
case DLG_BADWORDS_BLK:
|
||||
ab = ab.setMessage( m_dlgBytes );
|
||||
if ( 0 != m_dlgTitle ) {
|
||||
ab.setTitle( m_dlgTitle );
|
||||
checkBlocking();
|
||||
case DLG_SCORES: {
|
||||
int title = (Integer)params[0];
|
||||
String msg = (String)params[1];
|
||||
ab.setMessage( msg );
|
||||
if ( 0 != title ) {
|
||||
ab.setTitle( title );
|
||||
}
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int whichButton ) {
|
||||
curThis().m_resultCode = 1;
|
||||
m_resultCode = 1;
|
||||
}
|
||||
};
|
||||
ab.setPositiveButton( DlgID.QUERY_REQUEST_BLK == dlgID ?
|
||||
|
@ -286,7 +298,7 @@ public class BoardDelegate extends DelegateBase
|
|||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int whichButton ) {
|
||||
curThis().m_resultCode = 0;
|
||||
m_resultCode = 0;
|
||||
}
|
||||
};
|
||||
ab.setNegativeButton( R.string.button_no, lstnr );
|
||||
|
@ -307,7 +319,6 @@ public class BoardDelegate extends DelegateBase
|
|||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int whichButton ) {
|
||||
curThis().
|
||||
makeNotAgainBuilder( R.string.not_again_lookup,
|
||||
R.string.key_na_lookup,
|
||||
Action.LOOKUP_ACTION )
|
||||
|
@ -319,15 +330,17 @@ public class BoardDelegate extends DelegateBase
|
|||
}
|
||||
|
||||
dialog = ab.create();
|
||||
dialog.setOnDismissListener( makeODLforBlocking( id ) );
|
||||
alert.setOnDismissListener( m_blockingODL );
|
||||
}
|
||||
break;
|
||||
|
||||
case PICK_TILE_REQUESTBLANK_BLK:
|
||||
case PICK_TILE_REQUESTTRAY_BLK:
|
||||
checkBlocking();
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
curThis().m_resultCode = item;
|
||||
m_resultCode = item;
|
||||
}
|
||||
};
|
||||
ab.setItems( m_texts, lstnr );
|
||||
|
@ -340,9 +353,8 @@ public class BoardDelegate extends DelegateBase
|
|||
OnClickListener undoClicked = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int whichButton ) {
|
||||
BoardDelegate self = curThis();
|
||||
self.m_resultCode = UtilCtxt.PICKER_BACKUP;
|
||||
self.removeDialog( dlgID );
|
||||
m_resultCode = UtilCtxt.PICKER_BACKUP;
|
||||
removeDialog( dlgID );
|
||||
}
|
||||
};
|
||||
ab.setPositiveButton( R.string.tilepick_undo,
|
||||
|
@ -351,25 +363,25 @@ public class BoardDelegate extends DelegateBase
|
|||
OnClickListener doAllClicked = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int whichButton ) {
|
||||
BoardDelegate self = curThis();
|
||||
self.m_resultCode = UtilCtxt.PICKER_PICKALL;
|
||||
self.removeDialog( dlgID );
|
||||
m_resultCode = UtilCtxt.PICKER_PICKALL;
|
||||
removeDialog( dlgID );
|
||||
}
|
||||
};
|
||||
ab.setNegativeButton( R.string.tilepick_all, doAllClicked );
|
||||
}
|
||||
|
||||
dialog = ab.create();
|
||||
dialog.setOnDismissListener( makeODLforBlocking( id ) );
|
||||
alert.setOnDismissListener( m_blockingODL );
|
||||
break;
|
||||
|
||||
case ASK_PASSWORD_BLK:
|
||||
m_dlgTitleStr = getString( R.string.msg_ask_password_fmt, m_pwdName );
|
||||
checkBlocking();
|
||||
String dlgTitle = getString( R.string.msg_ask_password_fmt, m_pwdName );
|
||||
LinearLayout pwdLayout =
|
||||
(LinearLayout)inflate( R.layout.passwd_view );
|
||||
m_passwdEdit = (EditText)pwdLayout.findViewById( R.id.edit );
|
||||
m_passwdEdit.setText( "", TextView.BufferType.EDITABLE );
|
||||
ab.setTitle( m_dlgTitleStr )
|
||||
ab.setTitle( dlgTitle )
|
||||
.setView( pwdLayout )
|
||||
.setPositiveButton( android.R.string.ok,
|
||||
new OnClickListener() {
|
||||
|
@ -380,7 +392,7 @@ public class BoardDelegate extends DelegateBase
|
|||
}
|
||||
});
|
||||
dialog = ab.create();
|
||||
dialog.setOnDismissListener( makeODLforBlocking( id ) );
|
||||
alert.setOnDismissListener( m_blockingODL );
|
||||
break;
|
||||
|
||||
case QUERY_ENDGAME:
|
||||
|
@ -398,49 +410,7 @@ public class BoardDelegate extends DelegateBase
|
|||
.create();
|
||||
break;
|
||||
case DLG_INVITE:
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog, int item ){
|
||||
BoardDelegate self = curThis();
|
||||
if ( !self.m_relayMissing ||
|
||||
! self.m_connTypes.contains(CommsConnType.COMMS_CONN_RELAY) ) {
|
||||
Assert.assertTrue( 0 < self.m_nMissing );
|
||||
if ( self.m_summary.hasRematchInfo() ) {
|
||||
self.tryRematchInvites( true );
|
||||
} else {
|
||||
self.callInviteChoices( self.m_sentInfo );
|
||||
}
|
||||
} else {
|
||||
self.askDropRelay();
|
||||
}
|
||||
}
|
||||
};
|
||||
OnClickListener lstnrWait = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
curThis().finish();
|
||||
}
|
||||
};
|
||||
OnClickListener lstnrMore = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
BoardDelegate self = curThis();
|
||||
String msg = self.m_sentInfo
|
||||
.getAsText( self.m_activity );
|
||||
self.makeOkOnlyBuilder( msg ).show();
|
||||
}
|
||||
};
|
||||
|
||||
dialog = ab.setTitle( "foo" )
|
||||
.setMessage( "" )
|
||||
.setPositiveButton( "", lstnr )
|
||||
.setNegativeButton( R.string.button_wait, lstnrWait )
|
||||
.setNeutralButton( R.string.newgame_invite_more, lstnrMore )
|
||||
.setOnCancelListener( new OnCancelListener() {
|
||||
public void onCancel( DialogInterface dialog ) {
|
||||
finish();
|
||||
}
|
||||
} )
|
||||
.create();
|
||||
dialog = makeAlertDialog();
|
||||
break;
|
||||
|
||||
case ENABLE_NFC:
|
||||
|
@ -448,29 +418,27 @@ public class BoardDelegate extends DelegateBase
|
|||
break;
|
||||
|
||||
default:
|
||||
// just drop it; super.onCreateDialog likely failed
|
||||
dialog = super.makeDialog( alert, params );
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dialog;
|
||||
} // onCreateDialog
|
||||
|
||||
@Override
|
||||
protected void prepareDialog( DlgID dlgID, Dialog dialog )
|
||||
return dialog;
|
||||
} // makeDialog
|
||||
|
||||
private Dialog makeAlertDialog()
|
||||
{
|
||||
switch( dlgID ) {
|
||||
case DLG_INVITE:
|
||||
AlertDialog ad = (AlertDialog)dialog;
|
||||
String message;
|
||||
int titleID;
|
||||
boolean nukeInviteButton = false;
|
||||
boolean nukeNeutButton = true;
|
||||
boolean showInviteButton = true;
|
||||
boolean showNeutButton = false;
|
||||
|
||||
int buttonTxt = R.string.newgame_invite;
|
||||
|
||||
if ( m_relayMissing ) {
|
||||
titleID = R.string.seeking_relay;
|
||||
// If relay is only means, don't allow at all
|
||||
boolean relayOnly = 1 >= m_connTypes.size();
|
||||
nukeInviteButton = relayOnly;
|
||||
showInviteButton = !relayOnly;
|
||||
message = getString( R.string.no_relay_conn );
|
||||
if ( NetStateCache.netAvail( m_activity )
|
||||
&& NetStateCache.onWifi() ) {
|
||||
|
@ -499,19 +467,19 @@ public class BoardDelegate extends DelegateBase
|
|||
nSent, nSent, m_nMissing );
|
||||
}
|
||||
buttonTxt = R.string.button_reinvite;
|
||||
nukeNeutButton = false;
|
||||
showNeutButton = true;
|
||||
} else if ( DeviceRole.SERVER_ISCLIENT == m_gi.serverRole ) {
|
||||
Assert.assertFalse( m_summary.hasRematchInfo() );
|
||||
message = getString( R.string.invited_msg );
|
||||
titleID = R.string.waiting_title;
|
||||
nukeInviteButton = true;
|
||||
showInviteButton = false;
|
||||
} else {
|
||||
titleID = R.string.waiting_title;
|
||||
message = getQuantityString( R.plurals.invite_msg_fmt,
|
||||
m_nMissing, m_nMissing );
|
||||
}
|
||||
|
||||
if ( ! invitesSent && ! nukeInviteButton ) {
|
||||
if ( ! invitesSent && showInviteButton ) {
|
||||
String ps = null;
|
||||
if ( m_nMissing > 1 ) {
|
||||
ps = getString( R.string.invite_multiple );
|
||||
|
@ -529,22 +497,63 @@ public class BoardDelegate extends DelegateBase
|
|||
message += "\n\n" + getString( R.string.invite_stays );
|
||||
}
|
||||
|
||||
ad.setMessage( message );
|
||||
ad.setTitle( titleID );
|
||||
// Button button = ad.getButton( AlertDialog.BUTTON_POSITIVE );
|
||||
// button.setVisibility( nukeInviteButton ? View.GONE : View.VISIBLE );
|
||||
// if ( !nukeInviteButton ) {
|
||||
// button.setText( buttonTxt );
|
||||
// }
|
||||
// button = ad.getButton( AlertDialog.BUTTON_NEUTRAL );
|
||||
// button.setVisibility( nukeNeutButton ? View.GONE : View.VISIBLE );
|
||||
|
||||
Button button = ad.getButton( AlertDialog.BUTTON_POSITIVE );
|
||||
button.setVisibility( nukeInviteButton ? View.GONE : View.VISIBLE );
|
||||
if ( !nukeInviteButton ) {
|
||||
button.setText( buttonTxt );
|
||||
OnClickListener lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog, int item ){
|
||||
if ( !m_relayMissing ||
|
||||
! m_connTypes.contains(CommsConnType.COMMS_CONN_RELAY) ) {
|
||||
Assert.assertTrue( 0 < m_nMissing );
|
||||
if ( m_summary.hasRematchInfo() ) {
|
||||
tryRematchInvites( true );
|
||||
} else {
|
||||
callInviteChoices( m_sentInfo );
|
||||
}
|
||||
button = ad.getButton( AlertDialog.BUTTON_NEUTRAL );
|
||||
button.setVisibility( nukeNeutButton ? View.GONE : View.VISIBLE );
|
||||
} else {
|
||||
askDropRelay();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
break;
|
||||
default:
|
||||
super.prepareDialog( dlgID, dialog );
|
||||
break;
|
||||
AlertDialog.Builder ab = makeAlertBuilder()
|
||||
.setTitle( titleID )
|
||||
.setMessage( message )
|
||||
.setPositiveButton( buttonTxt, lstnr )
|
||||
.setOnCancelListener( new OnCancelListener() {
|
||||
public void onCancel( DialogInterface dialog ) {
|
||||
finish();
|
||||
}
|
||||
} );
|
||||
|
||||
if ( showNeutButton ) {
|
||||
OnClickListener lstnrMore = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
String msg = m_sentInfo
|
||||
.getAsText( m_activity );
|
||||
makeOkOnlyBuilder( msg ).show();
|
||||
}
|
||||
};
|
||||
ab.setNeutralButton( R.string.newgame_invite_more, lstnrMore );
|
||||
}
|
||||
if ( showInviteButton ) {
|
||||
OnClickListener lstnrWait = new OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
ab.setNegativeButton( R.string.button_wait, lstnrWait );
|
||||
}
|
||||
|
||||
Dialog dialog = ab.create();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public BoardDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
|
@ -645,9 +654,6 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
protected void onSaveInstanceState( Bundle outState )
|
||||
{
|
||||
outState.putInt( DLG_TITLE, m_dlgTitle );
|
||||
outState.putString( DLG_TITLESTR, m_dlgTitleStr );
|
||||
outState.putString( DLG_BYTES, m_dlgBytes );
|
||||
outState.putString( ROOM, m_room );
|
||||
outState.putString( TOASTSTR, m_toastStr );
|
||||
outState.putStringArray( WORDS, m_words );
|
||||
|
@ -658,9 +664,6 @@ public class BoardDelegate extends DelegateBase
|
|||
private void getBundledData( Bundle bundle )
|
||||
{
|
||||
if ( null != bundle ) {
|
||||
m_dlgTitleStr = bundle.getString( DLG_TITLESTR );
|
||||
m_dlgTitle = bundle.getInt( DLG_TITLE );
|
||||
m_dlgBytes = bundle.getString( DLG_BYTES );
|
||||
m_room = bundle.getString( ROOM );
|
||||
m_toastStr = bundle.getString( TOASTSTR );
|
||||
m_words = bundle.getStringArray( WORDS );
|
||||
|
@ -712,7 +715,7 @@ public class BoardDelegate extends DelegateBase
|
|||
setBackgroundColor();
|
||||
setKeepScreenOn();
|
||||
} else if ( 0 < m_nMissing ) {
|
||||
showDialog( DlgID.DLG_INVITE );
|
||||
showDialogFragment( DlgID.DLG_INVITE );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1170,7 +1173,7 @@ public class BoardDelegate extends DelegateBase
|
|||
makeConfirmThenBuilder( R.string.nfc_to_self, Action.NFC_TO_SELF )
|
||||
.show();
|
||||
} else if ( ! NFCUtils.nfcAvail( m_activity )[1] ) {
|
||||
showDialog( DlgID.ENABLE_NFC );
|
||||
showDialogFragment( DlgID.ENABLE_NFC );
|
||||
} else {
|
||||
makeOkOnlyBuilder( R.string.nfc_just_tap ).show();
|
||||
}
|
||||
|
@ -1245,7 +1248,7 @@ public class BoardDelegate extends DelegateBase
|
|||
if ( gameID == m_gi.gameID ) {
|
||||
post( new Runnable() {
|
||||
public void run() {
|
||||
showDialog( DlgID.DLG_DELETED );
|
||||
showDialogFragment( DlgID.DLG_DELETED );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
@ -1358,9 +1361,8 @@ public class BoardDelegate extends DelegateBase
|
|||
final DlgID dlgIDf = dlgID;
|
||||
post( new Runnable() {
|
||||
public void run() {
|
||||
m_dlgBytes = getString( strIDf );
|
||||
m_dlgTitle = R.string.relay_alert;
|
||||
showDialog( dlgIDf );
|
||||
showDialogFragment( dlgIDf, R.string.relay_alert,
|
||||
getString( strIDf ) );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1445,9 +1447,8 @@ public class BoardDelegate extends DelegateBase
|
|||
if ( null == msg ) {
|
||||
askNoAddrsDelete();
|
||||
} else {
|
||||
m_dlgBytes = msg;
|
||||
m_dlgTitle = R.string.info_title;
|
||||
showDialog( DlgID.DLG_CONNSTAT );
|
||||
showDialogFragment( DlgID.DLG_CONNSTAT,
|
||||
R.string.info_title, msg );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
@ -1458,12 +1459,6 @@ public class BoardDelegate extends DelegateBase
|
|||
return m_handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BoardDelegate curThis()
|
||||
{
|
||||
return (BoardDelegate)super.curThis();
|
||||
}
|
||||
|
||||
private void deleteAndClose()
|
||||
{
|
||||
GameUtils.deleteGame( m_activity, m_gameLock, false );
|
||||
|
@ -1556,6 +1551,14 @@ public class BoardDelegate extends DelegateBase
|
|||
// work for as long as this activity lives. Hence
|
||||
// releaseIfBlocking(). This feels really fragile but it does
|
||||
// work.
|
||||
|
||||
private void checkBlocking()
|
||||
{
|
||||
if ( null == m_blockingThread ) {
|
||||
DbgUtils.logd( TAG, "no blocking thread!!!" );
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlockingThread()
|
||||
{
|
||||
synchronized( this ) {
|
||||
|
@ -1618,7 +1621,7 @@ public class BoardDelegate extends DelegateBase
|
|||
} else if ( !m_haveInvited ) {
|
||||
m_haveInvited = true;
|
||||
m_room = room;
|
||||
showDialog( DlgID.DLG_INVITE );
|
||||
showDialogFragment( DlgID.DLG_INVITE );
|
||||
invalidateOptionsMenuIf();
|
||||
skipDismiss = true;
|
||||
} else {
|
||||
|
@ -1849,17 +1852,15 @@ public class BoardDelegate extends DelegateBase
|
|||
// don't block then a second dialog will replace this one.
|
||||
// So block. Yuck.
|
||||
case UtilCtxt.QUERY_ROBOT_TRADE:
|
||||
m_dlgBytes = query;
|
||||
m_dlgTitle = R.string.info_title;
|
||||
waitBlockingDialog( DlgID.QUERY_INFORM_BLK, 0 );
|
||||
waitBlockingDialog( DlgID.QUERY_INFORM_BLK, 0,
|
||||
R.string.info_title, query );
|
||||
result = true;
|
||||
break;
|
||||
|
||||
// These *are* blocking dialogs
|
||||
case UtilCtxt.QUERY_COMMIT_TURN:
|
||||
m_dlgBytes = query;
|
||||
m_dlgTitle = R.string.query_title;
|
||||
result = 0 != waitBlockingDialog( DlgID.QUERY_REQUEST_BLK, 0 );
|
||||
result = 0 != waitBlockingDialog( DlgID.QUERY_REQUEST_BLK, 0,
|
||||
R.string.query_title, query);
|
||||
break;
|
||||
default:
|
||||
Assert.fail();
|
||||
|
@ -1872,11 +1873,11 @@ public class BoardDelegate extends DelegateBase
|
|||
@Override
|
||||
public boolean confirmTrade( String[] tiles )
|
||||
{
|
||||
m_dlgTitle = R.string.info_title;
|
||||
m_dlgBytes =
|
||||
String dlgBytes =
|
||||
getQuantityString( R.plurals.query_trade_fmt, tiles.length,
|
||||
tiles.length, TextUtils.join( ", ", tiles ));
|
||||
return 0 != waitBlockingDialog( DlgID.QUERY_REQUEST_BLK, 0 );
|
||||
return 0 != waitBlockingDialog( DlgID.QUERY_REQUEST_BLK, 0,
|
||||
R.string.info_title, dlgBytes );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1970,7 +1971,7 @@ public class BoardDelegate extends DelegateBase
|
|||
doDismiss = false;
|
||||
post( new Runnable() {
|
||||
public void run() {
|
||||
showDialog( DlgID.DLG_INVITE );
|
||||
showDialogFragment( DlgID.DLG_INVITE );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
@ -2065,13 +2066,13 @@ public class BoardDelegate extends DelegateBase
|
|||
getString( R.string.ids_badwords_fmt, wordsString, dict );
|
||||
|
||||
if ( turnLost ) {
|
||||
m_dlgBytes = message + getString( R.string.badwords_lost );
|
||||
m_dlgTitle = R.string.badwords_title;
|
||||
waitBlockingDialog( DlgID.DLG_BADWORDS_BLK, 0 );
|
||||
waitBlockingDialog( DlgID.DLG_BADWORDS_BLK, 0, R.string.badwords_title,
|
||||
message + getString( R.string.badwords_lost ) );
|
||||
} else {
|
||||
m_dlgBytes = message + getString( R.string.badwords_accept );
|
||||
m_dlgTitle = R.string.query_title;
|
||||
accept = 0 != waitBlockingDialog( DlgID.QUERY_REQUEST_BLK, 0 );
|
||||
String dlgBytes = message + getString( R.string.badwords_accept );
|
||||
accept = 0 != waitBlockingDialog( DlgID.QUERY_REQUEST_BLK, 0,
|
||||
R.string.query_title,
|
||||
dlgBytes );
|
||||
}
|
||||
|
||||
return accept;
|
||||
|
@ -2137,12 +2138,11 @@ public class BoardDelegate extends DelegateBase
|
|||
public void handleMessage( Message msg ) {
|
||||
switch( msg.what ) {
|
||||
case JNIThread.DIALOG:
|
||||
m_dlgBytes = (String)msg.obj;
|
||||
m_dlgTitle = msg.arg1;
|
||||
showDialog( DlgID.DLG_OKONLY );
|
||||
showDialogFragment( DlgID.DLG_OKONLY, msg.arg1,
|
||||
(String)msg.obj );
|
||||
break;
|
||||
case JNIThread.QUERY_ENDGAME:
|
||||
showDialog( DlgID.QUERY_ENDGAME );
|
||||
showDialogFragment( DlgID.QUERY_ENDGAME );
|
||||
break;
|
||||
case JNIThread.TOOLBAR_STATES:
|
||||
if ( null != m_jniThread ) {
|
||||
|
@ -2163,9 +2163,8 @@ public class BoardDelegate extends DelegateBase
|
|||
gi.dictLang );
|
||||
break;
|
||||
case JNIThread.GAME_OVER:
|
||||
m_dlgBytes = (String)msg.obj;
|
||||
m_dlgTitle = msg.arg1;
|
||||
showDialog( DlgID.GAME_OVER );
|
||||
showDialogFragment( DlgID.GAME_OVER, m_summary, msg.arg1,
|
||||
(String)msg.obj );
|
||||
break;
|
||||
case JNIThread.MSGS_SENT:
|
||||
int nSent = (Integer)msg.obj;
|
||||
|
@ -2352,17 +2351,13 @@ public class BoardDelegate extends DelegateBase
|
|||
}
|
||||
} // populateToolbar
|
||||
|
||||
private OnDismissListener makeODLforBlocking( final int id )
|
||||
private int waitBlockingDialog( final DlgID dlgID, int cancelResult )
|
||||
{
|
||||
return new OnDismissListener() {
|
||||
public void onDismiss( DialogInterface di ) {
|
||||
releaseIfBlocking();
|
||||
removeDialog( id );
|
||||
}
|
||||
};
|
||||
return waitBlockingDialog( dlgID, cancelResult, 0, null );
|
||||
}
|
||||
|
||||
private int waitBlockingDialog( final DlgID dlgID, int cancelResult )
|
||||
private int waitBlockingDialog( final DlgID dlgID, int cancelResult,
|
||||
final int title, final String msg )
|
||||
{
|
||||
int result = cancelResult;
|
||||
// this has been true; dunno why
|
||||
|
@ -2376,7 +2371,7 @@ public class BoardDelegate extends DelegateBase
|
|||
if ( post( new Runnable() {
|
||||
public void run() {
|
||||
m_blockingDlgID = dlgID;
|
||||
showDialog( dlgID );
|
||||
showDialogFragment( dlgID, title, msg );
|
||||
}
|
||||
} ) ) {
|
||||
|
||||
|
@ -2401,26 +2396,27 @@ public class BoardDelegate extends DelegateBase
|
|||
return result;
|
||||
}
|
||||
|
||||
private void nonBlockingDialog( final DlgID dlgID, String txt )
|
||||
private void nonBlockingDialog( final DlgID dlgID, final String txt )
|
||||
{
|
||||
int dlgTitle = 0;
|
||||
switch ( dlgID ) {
|
||||
case DLG_OKONLY:
|
||||
case DLG_SCORES:
|
||||
m_dlgTitle = R.string.info_title;
|
||||
dlgTitle = R.string.info_title;
|
||||
break;
|
||||
case DLG_USEDICT:
|
||||
case DLG_GETDICT:
|
||||
m_dlgTitle = R.string.inform_dict_title;
|
||||
dlgTitle = R.string.inform_dict_title;
|
||||
break;
|
||||
|
||||
default:
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
m_dlgBytes = txt;
|
||||
final int fTitle = dlgTitle;
|
||||
runOnUiThread( new Runnable() {
|
||||
public void run() {
|
||||
showDialog( dlgID );
|
||||
showDialogFragment( dlgID, fTitle, txt );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
@ -2704,8 +2700,14 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
private static boolean rematchSupported( Context context,
|
||||
GameSummary summary )
|
||||
|
||||
{
|
||||
return rematchSupported( context, false, summary );
|
||||
}
|
||||
|
||||
private static boolean rematchSupported( Context context, boolean supported,
|
||||
GameSummary summary )
|
||||
{
|
||||
boolean supported = false;
|
||||
// standalone games are easy to rematch
|
||||
supported = summary.serverRole == DeviceRole.SERVER_STANDALONE;
|
||||
|
||||
|
|
|
@ -20,15 +20,21 @@
|
|||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
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 PARMS_KEY = "PARMS_KEY";
|
||||
|
||||
|
@ -44,7 +50,11 @@ public class DBAlert extends DialogFragment {
|
|||
{
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss( DialogInterface dif )
|
||||
{
|
||||
if ( null != m_onDismiss ) {
|
||||
m_onDismiss.onDismissed();
|
||||
}
|
||||
super.onDismiss( dif );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog( Bundle sis )
|
||||
{
|
||||
|
@ -78,19 +97,36 @@ public class DBAlert extends DialogFragment {
|
|||
mParams = (Object[])sis.getSerializable(PARMS_KEY);
|
||||
|
||||
XWActivity activity = (XWActivity)getActivity();
|
||||
return activity.makeDialog( this, mParams );
|
||||
}
|
||||
Dialog dialog = activity.makeDialog( this, mParams );
|
||||
|
||||
if ( null == dialog ) {
|
||||
dialog = LocUtils.makeAlertBuilder( getActivity() )
|
||||
.setTitle( "Stub Alert" )
|
||||
.setMessage( String.format( "Unable to create for %s", mDlgID.toString() ) )
|
||||
.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 onDismiss( DialogInterface dif )
|
||||
{
|
||||
if ( null != m_onDismiss ) {
|
||||
m_onDismiss.onDismissed();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -481,11 +481,6 @@ public class DelegateBase implements DlgClickNotify,
|
|||
return LocUtils.makeAlertBuilder( m_activity );
|
||||
}
|
||||
|
||||
protected void setRemoveOnDismiss( Dialog dialog, DlgID dlgID )
|
||||
{
|
||||
Utils.setRemoveOnDismiss( m_activity, dialog, dlgID );
|
||||
}
|
||||
|
||||
public NotAgainBuilder
|
||||
makeNotAgainBuilder( String msg, int key, Action action )
|
||||
{
|
||||
|
|
|
@ -465,7 +465,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
return dialog;
|
||||
} // onCreateDialog
|
||||
} // makeDialog
|
||||
|
||||
@Override
|
||||
protected void init( Bundle savedInstanceState )
|
||||
|
|
|
@ -450,8 +450,11 @@ public class DlgDelegate {
|
|||
}
|
||||
} else {
|
||||
DlgState state = new DlgState( DlgID.DIALOG_NOTAGAIN )
|
||||
.setMsg( msg).setPrefsKey( prefsKey ).setAction( action )
|
||||
.setActionPair( more ).setParams( params );
|
||||
.setMsg( msg)
|
||||
.setPrefsKey( prefsKey )
|
||||
.setAction( action )
|
||||
.setActionPair( more )
|
||||
.setParams( params );
|
||||
m_dlgt.show( NotAgainAlert.newInstance( state ) );
|
||||
}
|
||||
}
|
||||
|
@ -622,7 +625,6 @@ public class DlgDelegate {
|
|||
.setPositiveButton( R.string.button_enable, lstnr )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.create();
|
||||
Utils.setRemoveOnDismiss( m_activity, dialog, dlgID );
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
|
|
@ -160,18 +160,20 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
protected Dialog onCreateDialog( int id )
|
||||
@Override
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
Dialog dialog = super.onCreateDialog( id );
|
||||
Dialog dialog = null;
|
||||
final DlgID dlgID = alert.getDlgID();
|
||||
DbgUtils.logd( TAG, "makeDialog(%s)", dlgID.toString() );
|
||||
|
||||
if ( null == dialog ) {
|
||||
DialogInterface.OnClickListener dlpos;
|
||||
AlertDialog.Builder ab;
|
||||
|
||||
final DlgID dlgID = DlgID.values()[id];
|
||||
switch ( dlgID ) {
|
||||
case PLAYER_EDIT:
|
||||
case PLAYER_EDIT: {
|
||||
View playerEditView = inflate( R.layout.player_edit );
|
||||
setPlayerSettings( playerEditView );
|
||||
|
||||
dialog = makeAlertBuilder()
|
||||
.setTitle( R.string.player_edit_title )
|
||||
|
@ -181,71 +183,52 @@ public class GameConfigDelegate extends DelegateBase
|
|||
public void
|
||||
onClick( DialogInterface dlg,
|
||||
int button ) {
|
||||
GameConfigDelegate self = curThis();
|
||||
self.getPlayerSettings( dlg );
|
||||
self.loadPlayersList();
|
||||
getPlayerSettings( dlg );
|
||||
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:
|
||||
}
|
||||
break;
|
||||
|
||||
case FORCE_REMOTE: {
|
||||
dlpos = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
curThis().loadPlayersList();
|
||||
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( inflate( layoutForDlg(dlgID) ) )
|
||||
.setView( view )
|
||||
.setPositiveButton( android.R.string.ok, dlpos )
|
||||
.create();
|
||||
DialogInterface.OnDismissListener dismiss =
|
||||
new DialogInterface.OnDismissListener() {
|
||||
alert.setOnDismissListener( new DBAlert.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" );
|
||||
public void onDismissed() {
|
||||
if ( m_gi.forceRemoteConsistent() ) {
|
||||
showToast( R.string.forced_consistent );
|
||||
loadPlayersList();
|
||||
}
|
||||
}
|
||||
};
|
||||
dialog.setOnDismissListener( dismiss );
|
||||
});
|
||||
}
|
||||
break;
|
||||
case CONFIRM_CHANGE_PLAY:
|
||||
case CONFIRM_CHANGE:
|
||||
case CONFIRM_CHANGE: {
|
||||
dlpos = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
GameConfigDelegate self = curThis();
|
||||
self.applyChanges( true );
|
||||
applyChanges( true );
|
||||
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
|
||||
self.launchGame( true );
|
||||
launchGame( true );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -257,7 +240,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
dlpos = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
curThis().finishAndLaunch();
|
||||
finishAndLaunch();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
@ -266,14 +249,15 @@ public class GameConfigDelegate extends DelegateBase
|
|||
ab.setNegativeButton( R.string.button_discard_changes, dlpos );
|
||||
dialog = ab.create();
|
||||
|
||||
dialog.setOnDismissListener( new DialogInterface.
|
||||
OnDismissListener() {
|
||||
public void onDismiss( DialogInterface di ) {
|
||||
curThis().closeNoSave();
|
||||
alert.setOnDismissListener( new DBAlert.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismissed() {
|
||||
closeNoSave();
|
||||
}
|
||||
} );
|
||||
}
|
||||
break;
|
||||
case NO_NAME_FOUND:
|
||||
case NO_NAME_FOUND: {
|
||||
String langName = DictLangCache.getLangName( m_activity,
|
||||
m_gi.dictLang );
|
||||
String msg = getString( R.string.no_name_found_fmt,
|
||||
|
@ -283,60 +267,14 @@ public class GameConfigDelegate extends DelegateBase
|
|||
// message added below since varies with language etc.
|
||||
.setMessage( msg )
|
||||
.create();
|
||||
}
|
||||
break;
|
||||
case CHANGE_CONN:
|
||||
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
|
||||
protected void prepareDialog( DlgID dlgID, Dialog dialog )
|
||||
{
|
||||
switch ( dlgID ) {
|
||||
case PLAYER_EDIT:
|
||||
setPlayerSettings( dialog );
|
||||
break;
|
||||
case FORCE_REMOTE:
|
||||
ListView listview = (ListView)dialog.findViewById( R.id.players );
|
||||
listview.setAdapter( new RemoteChoices() );
|
||||
break;
|
||||
|
||||
case CHANGE_CONN:
|
||||
ConnViaViewLayout items = (ConnViaViewLayout)
|
||||
dialog.findViewById( R.id.conn_types );
|
||||
items.configure( m_conTypes,
|
||||
new ConnViaViewLayout.CheckEnabledWarner() {
|
||||
public void warnDisabled( CommsConnType typ ) {
|
||||
|
@ -368,28 +306,65 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
}, null, this );
|
||||
break;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
private void setPlayerSettings( final Dialog dialog )
|
||||
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;
|
||||
}
|
||||
|
||||
Assert.assertNotNull( dialog );
|
||||
return dialog;
|
||||
} // makeDialog
|
||||
|
||||
private void setPlayerSettings( final View playerView )
|
||||
{
|
||||
DbgUtils.logd( TAG, "setPlayerSettings()" );
|
||||
boolean isServer = ! localOnlyGame();
|
||||
|
||||
// Independent of other hide/show logic, these guys are
|
||||
// information-only if the game's locked. (Except that in a
|
||||
// local game you can always toggle a player's robot state.)
|
||||
Utils.setEnabled( dialog, R.id.remote_check, !m_isLocked );
|
||||
Utils.setEnabled( dialog, R.id.player_name_edit, !m_isLocked );
|
||||
Utils.setEnabled( dialog, R.id.robot_check, !m_isLocked || !isServer );
|
||||
Utils.setEnabled( playerView, R.id.remote_check, !m_isLocked );
|
||||
Utils.setEnabled( playerView, R.id.player_name_edit, !m_isLocked );
|
||||
Utils.setEnabled( playerView, R.id.robot_check,
|
||||
!m_isLocked || !isServer );
|
||||
|
||||
// Hide remote option if in standalone mode...
|
||||
LocalPlayer lp = m_gi.players[m_whichPlayer];
|
||||
Utils.setText( dialog, R.id.player_name_edit, lp.name );
|
||||
Utils.setText( dialog, R.id.password_edit, lp.password );
|
||||
Utils.setText( playerView, R.id.player_name_edit, lp.name );
|
||||
Utils.setText( playerView, R.id.password_edit, lp.password );
|
||||
|
||||
// Dicts spinner with label
|
||||
TextView dictLabel = (TextView)dialog.findViewById( R.id.dict_label );
|
||||
TextView dictLabel = (TextView)playerView
|
||||
.findViewById( R.id.dict_label );
|
||||
if ( localOnlyGame() ) {
|
||||
String langName = DictLangCache.getLangName( m_activity, m_gi.dictLang );
|
||||
String label = getString( R.string.dict_lang_label_fmt, langName );
|
||||
|
@ -397,7 +372,8 @@ public class GameConfigDelegate extends DelegateBase
|
|||
} else {
|
||||
dictLabel.setVisibility( View.GONE );
|
||||
}
|
||||
m_playerDictSpinner = (Spinner)dialog.findViewById( R.id.dict_spinner );
|
||||
m_playerDictSpinner = (Spinner)
|
||||
playerView.findViewById( R.id.dict_spinner );
|
||||
if ( localOnlyGame() ) {
|
||||
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, m_gi.dictName(lp) );
|
||||
} else {
|
||||
|
@ -405,10 +381,9 @@ public class GameConfigDelegate extends DelegateBase
|
|||
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)
|
||||
dialog.findViewById( R.id.remote_check );
|
||||
CheckBox check = (CheckBox)playerView.findViewById( R.id.remote_check );
|
||||
if ( isServer ) {
|
||||
OnCheckedChangeListener lstnr =
|
||||
new OnCheckedChangeListener() {
|
||||
|
@ -425,19 +400,20 @@ public class GameConfigDelegate extends DelegateBase
|
|||
localSet.setVisibility( View.VISIBLE );
|
||||
}
|
||||
|
||||
check = (CheckBox)dialog.findViewById( R.id.robot_check );
|
||||
check = (CheckBox)playerView.findViewById( R.id.robot_check );
|
||||
OnCheckedChangeListener lstnr =
|
||||
new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
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 );
|
||||
}
|
||||
};
|
||||
check.setOnCheckedChangeListener( lstnr );
|
||||
|
||||
Utils.setChecked( dialog, R.id.robot_check, lp.isRobot() );
|
||||
Utils.setChecked( dialog, R.id.remote_check, ! lp.isLocal );
|
||||
Utils.setChecked( playerView, R.id.robot_check, lp.isRobot() );
|
||||
Utils.setChecked( playerView, R.id.remote_check, ! lp.isLocal );
|
||||
DbgUtils.logd( TAG, "setPlayerSettings() DONE" );
|
||||
}
|
||||
|
||||
private void getPlayerSettings( DialogInterface di )
|
||||
|
@ -676,7 +652,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
// NoNameFound interface
|
||||
public void NoNameFound()
|
||||
{
|
||||
showDialog( DlgID.NO_NAME_FOUND );
|
||||
showDialogFragment( DlgID.NO_NAME_FOUND );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -704,7 +680,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
break;
|
||||
|
||||
case ASKED_PHONE_STATE:
|
||||
showDialog( DlgID.CHANGE_CONN );
|
||||
showDialogFragment( DlgID.CHANGE_CONN );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -722,7 +698,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
showConnAfterCheck();
|
||||
break;
|
||||
case ASKED_PHONE_STATE:
|
||||
showDialog( DlgID.CHANGE_CONN );
|
||||
showDialogFragment( DlgID.CHANGE_CONN );
|
||||
break;
|
||||
default:
|
||||
handled = super.onNegButton( action, params );
|
||||
|
@ -780,7 +756,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
saveAndClose( true );
|
||||
} else if ( m_giOrig.changesMatter(m_gi)
|
||||
|| m_carOrig.changesMatter(m_car) ) {
|
||||
showDialog( DlgID.CONFIRM_CHANGE_PLAY );
|
||||
showDialogFragment( DlgID.CONFIRM_CHANGE_PLAY );
|
||||
} else {
|
||||
finishAndLaunch();
|
||||
}
|
||||
|
@ -799,7 +775,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
R.string.phone_state_rationale,
|
||||
Action.ASKED_PHONE_STATE, this );
|
||||
} else {
|
||||
showDialog( DlgID.CHANGE_CONN );
|
||||
showDialogFragment( DlgID.CHANGE_CONN );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -844,7 +820,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
applyChanges( true );
|
||||
} else if ( m_giOrig.changesMatter(m_gi)
|
||||
|| m_carOrig.changesMatter(m_car) ) {
|
||||
showDialog( DlgID.CONFIRM_CHANGE );
|
||||
showDialogFragment( DlgID.CONFIRM_CHANGE );
|
||||
consumed = true; // don't dismiss activity yet!
|
||||
} else {
|
||||
applyChanges( false );
|
||||
|
@ -879,7 +855,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
@Override
|
||||
public void onClick( View view ) {
|
||||
m_whichPlayer = ((XWListItem)view).getPosition();
|
||||
showDialog( DlgID.PLAYER_EDIT );
|
||||
showDialogFragment( DlgID.PLAYER_EDIT );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -917,7 +893,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
if ( ! localOnlyGame()
|
||||
&& ((0 == m_gi.remoteCount() )
|
||||
|| (m_gi.nPlayers == m_gi.remoteCount()) ) ) {
|
||||
showDialog( DlgID.FORCE_REMOTE );
|
||||
showDialogFragment( DlgID.FORCE_REMOTE );
|
||||
}
|
||||
adjustPlayersLabel();
|
||||
}
|
||||
|
@ -1255,7 +1231,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
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,
|
||||
|
|
|
@ -825,7 +825,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
(EditText)layout.findViewById( R.id.name_edit );
|
||||
etext.setText( CommonPrefs.getDefaultPlayerName( m_activity,
|
||||
0, true ) );
|
||||
alert.setOnDismiss( new DBAlert.OnDismissListener() {
|
||||
alert.setOnDismissListener( new DBAlert.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismissed() {
|
||||
String name = etext.getText().toString();
|
||||
|
@ -2369,7 +2369,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
.setNegativeButton( android.R.string.cancel, lstnr2 )
|
||||
.setView( namer )
|
||||
.create();
|
||||
setRemoveOnDismiss( dialog, dlgID );
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ public class SMSInviteDelegate extends InviteDelegate {
|
|||
startActivityForResult( intent, RequestCode.GET_CONTACT );
|
||||
break;
|
||||
case R.id.manual_add_button:
|
||||
showDialog( DlgID.GET_NUMBER );
|
||||
showDialogFragment( DlgID.GET_NUMBER );
|
||||
break;
|
||||
case R.id.button_clear:
|
||||
int count = getChecked().size();
|
||||
|
@ -131,24 +131,21 @@ public class SMSInviteDelegate extends InviteDelegate {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
Dialog dialog = super.onCreateDialog( id );
|
||||
if ( null == dialog ) {
|
||||
Dialog dialog;
|
||||
DialogInterface.OnClickListener lstnr;
|
||||
DlgID dlgID = DlgID.values()[id];
|
||||
switch( dlgID ) {
|
||||
case GET_NUMBER:
|
||||
switch( alert.getDlgID() ) {
|
||||
case GET_NUMBER: {
|
||||
final GameNamer namerView =
|
||||
(GameNamer)inflate( R.layout.rename_game );
|
||||
namerView.setLabel( R.string.get_sms_number );
|
||||
namerView.setKeyListener(DialerKeyListener.getInstance());
|
||||
lstnr = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
SMSInviteDelegate self = (SMSInviteDelegate)curThis();
|
||||
String number = namerView.getName();
|
||||
PhoneRec rec = new PhoneRec( number );
|
||||
self.makeConfirmThenBuilder( R.string.warn_unlimited,
|
||||
makeConfirmThenBuilder( R.string.warn_unlimited,
|
||||
Action.POST_WARNING_ACTION )
|
||||
.setPosButton( R.string.button_yes )
|
||||
.setParams( number, null )
|
||||
|
@ -156,13 +153,15 @@ public class SMSInviteDelegate extends InviteDelegate {
|
|||
}
|
||||
};
|
||||
dialog = makeAlertBuilder()
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.setPositiveButton( android.R.string.ok, lstnr )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.setView( namerView )
|
||||
.create();
|
||||
break;
|
||||
}
|
||||
setRemoveOnDismiss( dialog, dlgID );
|
||||
break;
|
||||
default:
|
||||
dialog = super.makeDialog( alert, params );
|
||||
break;
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
|
|
@ -163,17 +163,6 @@ public class Utils {
|
|||
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 )
|
||||
{
|
||||
Intent intent = new Intent( context, PrefsActivity.class );
|
||||
|
@ -326,30 +315,30 @@ public class Utils {
|
|||
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 );
|
||||
}
|
||||
|
||||
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 ) {
|
||||
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);
|
||||
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.setEnabled( enabled );
|
||||
View view = parent.findViewById( id );
|
||||
parent.setEnabled( enabled );
|
||||
}
|
||||
|
||||
public static boolean getChecked( Dialog dialog, int id )
|
||||
|
|
|
@ -23,6 +23,8 @@ package org.eehouse.android.xw4.jni;
|
|||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
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
|
||||
* in CurGameInfo
|
||||
*/
|
||||
public class GameSummary {
|
||||
public class GameSummary implements Serializable {
|
||||
private static final String TAG = GameSummary.class.getSimpleName();
|
||||
public static final String EXTRA_REMATCH_BTADDR = "rm_btaddr";
|
||||
public static final String EXTRA_REMATCH_PHONE = "rm_phone";
|
||||
|
|
Loading…
Add table
Reference in a new issue