mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
on initial startup check if the default name's been set for Player 1.
If not, give a chance to set it and a welcome message. Whatever happens, wind up with some sort of default name so the query isn't repeated unless user clears all defaults.
This commit is contained in:
parent
1d5cfd49fa
commit
a7851f3c55
3 changed files with 71 additions and 4 deletions
|
@ -273,9 +273,9 @@
|
|||
<string name="menu_revert_all">Restore all</string>
|
||||
<string name="menu_revert_colors">Restore colors</string>
|
||||
<string name="confirm_revert_colors">Are you sure you want to
|
||||
restore all color preferences to their default values?</string>
|
||||
restore all color preferences to their original values?</string>
|
||||
<string name="confirm_revert_all">Are you sure you want to restore
|
||||
all preferences to their default values?</string>
|
||||
all preferences to their original values?</string>
|
||||
|
||||
<string name="prefs_defaults">New game defaults</string>
|
||||
<string name="prefs_defaults_summary">Default settings for new
|
||||
|
@ -571,4 +571,10 @@
|
|||
<string name="no_download_warning">Unable to download. Do you have
|
||||
a web browser installed?</string>
|
||||
|
||||
<string name="default_name_title">New player welcome</string>
|
||||
<string name="default_name_message">Thanks for installing
|
||||
Crosswords! Feel free to enter your name here. It will be used
|
||||
when creating new games. (You can change it later in the \"New
|
||||
game default\" section of Settings.)</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -37,6 +37,7 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Button;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -56,6 +57,7 @@ public class GamesList extends XWListActivity
|
|||
private static final int WARN_NODICT = DlgDelegate.DIALOG_LAST + 1;
|
||||
private static final int WARN_NODICT_SUBST = WARN_NODICT + 1;
|
||||
private static final int SHOW_SUBST = WARN_NODICT + 2;
|
||||
private static final int GET_NAME = WARN_NODICT + 3;
|
||||
|
||||
private GameListAdapter m_adapter;
|
||||
private String m_missingDict;
|
||||
|
@ -158,6 +160,30 @@ public class GamesList extends XWListActivity
|
|||
}
|
||||
});
|
||||
break;
|
||||
case GET_NAME:
|
||||
final EditText etext = new EditText( this );
|
||||
etext.setText( CommonPrefs.getDefaultPlayerName( this, 0,
|
||||
true ) );
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setTitle( R.string.default_name_title )
|
||||
.setMessage( R.string.default_name_message )
|
||||
.setPositiveButton( R.string.button_ok, null )
|
||||
.setView( etext )
|
||||
.create();
|
||||
dialog.setOnDismissListener(new DialogInterface.
|
||||
OnDismissListener() {
|
||||
public void onDismiss( DialogInterface dlg ) {
|
||||
String name = etext.getText().toString();
|
||||
if ( 0 == name.length() ) {
|
||||
name = CommonPrefs.
|
||||
getDefaultPlayerName( GamesList.this,
|
||||
0, true );
|
||||
}
|
||||
CommonPrefs.setDefaultPlayerName( GamesList.this,
|
||||
name );
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
// just drop it; super.onCreateDialog likely failed
|
||||
break;
|
||||
|
@ -201,6 +227,7 @@ public class GamesList extends XWListActivity
|
|||
Intent intent = getIntent();
|
||||
startFirstHasDict( intent );
|
||||
startNewNetGameIf( intent );
|
||||
askDefaultNameIf();
|
||||
|
||||
DBUtils.setDBChangeListener( this );
|
||||
} // onCreate
|
||||
|
@ -587,4 +614,12 @@ public class GamesList extends XWListActivity
|
|||
}
|
||||
}
|
||||
} // startNewNetGameIf
|
||||
|
||||
private void askDefaultNameIf()
|
||||
{
|
||||
if ( null == CommonPrefs.getDefaultPlayerName( this, 0, false ) ) {
|
||||
showDialog( GET_NAME );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -219,7 +219,8 @@ public class CommonPrefs {
|
|||
return value;
|
||||
}
|
||||
|
||||
public static String getDefaultPlayerName( Context context, int num )
|
||||
public static String getDefaultPlayerName( Context context, int num,
|
||||
boolean force )
|
||||
{
|
||||
int id = 0;
|
||||
switch( num ) {
|
||||
|
@ -229,13 +230,26 @@ public class CommonPrefs {
|
|||
case 3: id = R.string.key_player4_name; break;
|
||||
}
|
||||
String result = getString( context, id );
|
||||
if ( null == result || 0 == result.length() ) {
|
||||
if ( null != result && 0 == result.length() ) {
|
||||
result = null; // be consistent
|
||||
}
|
||||
if ( force && null == result ) {
|
||||
String fmt = context.getString( R.string.playerf );
|
||||
result = String.format( fmt, num + 1 );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getDefaultPlayerName( Context context, int num )
|
||||
{
|
||||
return getDefaultPlayerName( context, num, true );
|
||||
}
|
||||
|
||||
public static void setDefaultPlayerName( Context context, String value )
|
||||
{
|
||||
setPrefsString( context, R.string.key_player1_name, value );
|
||||
}
|
||||
|
||||
public static CurGameInfo.XWPhoniesChoice
|
||||
getDefaultPhonies( Context context )
|
||||
{
|
||||
|
@ -314,4 +328,16 @@ public class CommonPrefs {
|
|||
.getDefaultSharedPreferences( context );
|
||||
return sp.getString( key, "" );
|
||||
}
|
||||
|
||||
private static void setPrefsString( Context context, int keyID,
|
||||
String newValue )
|
||||
{
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences( context );
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
String key = context.getString( keyID );
|
||||
editor.putString( key, newValue );
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue