mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
remember last-used radio and start with it next time
Saves a step if you generally create games the same way most of the time. Required reordering alert init.
This commit is contained in:
parent
357897661e
commit
ddd5f7b978
2 changed files with 41 additions and 15 deletions
|
@ -919,7 +919,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
// String[] names = XwJNI.kplr_getPlayers();
|
||||
final NewWithKnowns view = (NewWithKnowns)
|
||||
LocUtils.inflate( m_activity, R.layout.new_game_with_knowns );
|
||||
view.configure( standalone, GameUtils.makeDefaultName( m_activity ) );
|
||||
AlertDialog.Builder ab = makeAlertBuilder()
|
||||
.setView( view )
|
||||
.setTitle( standalone ? R.string.new_game : R.string.new_game_networked )
|
||||
|
@ -964,17 +963,24 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
final AlertDialog dialog = ab.create();
|
||||
view.setCallback( new NewWithKnowns.ButtonChangeListener() {
|
||||
@Override
|
||||
public void onNewButtonText( String txt ) {
|
||||
Button button = dialog.getButton( DialogInterface.BUTTON_POSITIVE );
|
||||
if ( null != button ) {
|
||||
button.setText( txt );
|
||||
} else {
|
||||
Log.e( TAG, "Button still null" );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow( DialogInterface diface ) {
|
||||
view.setCallback( new NewWithKnowns.ButtonChangeListener() {
|
||||
@Override
|
||||
public void onNewButtonText( String txt ) {
|
||||
Button button = dialog.getButton( DialogInterface.BUTTON_POSITIVE );
|
||||
if ( null != button ) {
|
||||
button.setText( txt );
|
||||
} else {
|
||||
Assert.failDbg();
|
||||
}
|
||||
}
|
||||
} );
|
||||
view.configure( standalone, GameUtils.makeDefaultName( m_activity ) );
|
||||
}
|
||||
});
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
|||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
@ -39,6 +40,8 @@ public class NewWithKnowns extends LinearLayout
|
|||
{
|
||||
private static final String TAG = NewWithKnowns.class.getSimpleName();
|
||||
private static final String KP_NAME_KEY = TAG + "/kp_last_name";
|
||||
private static final String KP_PREVSOLO_KEY = TAG + "/kp_prev_solo";
|
||||
private static final String KP_PREVNET_KEY = TAG + "/kp_prev_net";
|
||||
|
||||
public interface ButtonChangeListener {
|
||||
void onNewButtonText( String txt );
|
||||
|
@ -68,15 +71,16 @@ public class NewWithKnowns extends LinearLayout
|
|||
|
||||
void configure( boolean standalone, String gameName )
|
||||
{
|
||||
Context context = getContext();
|
||||
mStandalone = standalone;
|
||||
boolean hasKnowns = !standalone && XwJNI.hasKnownPlayers();
|
||||
int[] toHide;
|
||||
if ( hasKnowns ) {
|
||||
String[] knowns = XwJNI.kplr_getPlayers();
|
||||
mCurKnown = DBUtils.getStringFor( getContext(), KP_NAME_KEY,
|
||||
mCurKnown = DBUtils.getStringFor( context, KP_NAME_KEY,
|
||||
knowns[0] );
|
||||
ArrayAdapter<String> adapter = new
|
||||
ArrayAdapter<String>( getContext(),
|
||||
ArrayAdapter<String>( context,
|
||||
android.R.layout.simple_spinner_item,
|
||||
knowns );
|
||||
adapter.setDropDownViewResource( android.R.layout
|
||||
|
@ -108,14 +112,27 @@ public class NewWithKnowns extends LinearLayout
|
|||
|
||||
RadioGroup group = (RadioGroup)findViewById( R.id.group );
|
||||
group.setOnCheckedChangeListener( this );
|
||||
|
||||
String key = standalone ? KP_PREVSOLO_KEY : KP_PREVNET_KEY;
|
||||
int lastSet = DBUtils.getIntFor( context, key, 0 );
|
||||
if ( lastSet != 0 ) {
|
||||
// Let's made sure it's still a RadioButton. Ids are generated by
|
||||
// the build system and can change. Passing a non-radiobutton id
|
||||
// to check() still calls onCheckedChanged() etc.
|
||||
View view = findViewById( lastSet );
|
||||
if ( null != view && view instanceof RadioButton ) {
|
||||
group.check( lastSet );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onButtonPressed( ButtonCallbacks procs )
|
||||
{
|
||||
Context context = getContext();
|
||||
String gameName = gameName();
|
||||
switch ( mCurRadio ) {
|
||||
case R.id.radio_known:
|
||||
DBUtils.setStringFor( getContext(), KP_NAME_KEY, mCurKnown );
|
||||
DBUtils.setStringFor( context, KP_NAME_KEY, mCurKnown );
|
||||
procs.onUseKnown( mCurKnown, gameName );
|
||||
break;
|
||||
case R.id.radio_unknown:
|
||||
|
@ -129,6 +146,9 @@ public class NewWithKnowns extends LinearLayout
|
|||
Assert.failDbg();
|
||||
break;
|
||||
}
|
||||
|
||||
String key = mStandalone ? KP_PREVSOLO_KEY : KP_PREVNET_KEY;
|
||||
DBUtils.setIntFor( context, key, mCurRadio );
|
||||
}
|
||||
|
||||
private String gameName()
|
||||
|
|
Loading…
Reference in a new issue