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
File diff suppressed because it is too large
Load diff
|
@ -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 );
|
||||
|
||||
@Override
|
||||
public void onDismiss( DialogInterface dif )
|
||||
{
|
||||
if ( null != m_onDismiss ) {
|
||||
m_onDismiss.onDismissed();
|
||||
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 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,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
|
||||
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 ) {
|
||||
case PLAYER_EDIT:
|
||||
setPlayerSettings( dialog );
|
||||
break;
|
||||
case FORCE_REMOTE:
|
||||
ListView listview = (ListView)dialog.findViewById( R.id.players );
|
||||
listview.setAdapter( new RemoteChoices() );
|
||||
case PLAYER_EDIT: {
|
||||
View playerEditView = inflate( R.layout.player_edit );
|
||||
setPlayerSettings( playerEditView );
|
||||
|
||||
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 ) {
|
||||
getPlayerSettings( dlg );
|
||||
loadPlayersList();
|
||||
}
|
||||
})
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.create();
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case CHANGE_CONN:
|
||||
ConnViaViewLayout items = (ConnViaViewLayout)
|
||||
dialog.findViewById( R.id.conn_types );
|
||||
case FORCE_REMOTE: {
|
||||
dlpos = new DialogInterface.OnClickListener() {
|
||||
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,
|
||||
new ConnViaViewLayout.CheckEnabledWarner() {
|
||||
public void warnDisabled( CommsConnType typ ) {
|
||||
|
@ -368,28 +306,65 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
}, 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;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// 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,38 +131,37 @@ 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 ) {
|
||||
DialogInterface.OnClickListener lstnr;
|
||||
DlgID dlgID = DlgID.values()[id];
|
||||
switch( dlgID ) {
|
||||
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,
|
||||
Action.POST_WARNING_ACTION )
|
||||
.setPosButton( R.string.button_yes )
|
||||
.setParams( number, null )
|
||||
.show();
|
||||
}
|
||||
};
|
||||
dialog = makeAlertBuilder()
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.setPositiveButton( android.R.string.ok, lstnr )
|
||||
.setView( namerView )
|
||||
.create();
|
||||
break;
|
||||
}
|
||||
setRemoveOnDismiss( dialog, dlgID );
|
||||
Dialog dialog;
|
||||
DialogInterface.OnClickListener lstnr;
|
||||
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 ) {
|
||||
String number = namerView.getName();
|
||||
PhoneRec rec = new PhoneRec( number );
|
||||
makeConfirmThenBuilder( R.string.warn_unlimited,
|
||||
Action.POST_WARNING_ACTION )
|
||||
.setPosButton( R.string.button_yes )
|
||||
.setParams( number, null )
|
||||
.show();
|
||||
}
|
||||
};
|
||||
dialog = makeAlertBuilder()
|
||||
.setPositiveButton( android.R.string.ok, lstnr )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.setView( namerView )
|
||||
.create();
|
||||
}
|
||||
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