From a7851f3c55b539c247397fee7b9e80b47ed84ac9 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 10 Jun 2011 18:58:49 -0700 Subject: [PATCH] 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. --- .../android/XWords4/res/values/strings.xml | 10 ++++-- .../org/eehouse/android/xw4/GamesList.java | 35 +++++++++++++++++++ .../eehouse/android/xw4/jni/CommonPrefs.java | 30 ++++++++++++++-- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 3c9c3d811..c00403a2e 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -273,9 +273,9 @@ Restore all Restore colors Are you sure you want to - restore all color preferences to their default values? + restore all color preferences to their original values? Are you sure you want to restore - all preferences to their default values? + all preferences to their original values? New game defaults Default settings for new @@ -571,4 +571,10 @@ Unable to download. Do you have a web browser installed? + New player welcome + 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.) + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 072d41c42..f32baf986 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -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 ); + } + } + } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java index 487bef2e4..6b75edd49 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java @@ -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(); + } + }