mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
add second prefs menu to restore all prefs
This commit is contained in:
parent
57b74391bc
commit
74c9e9db92
2 changed files with 53 additions and 19 deletions
|
@ -219,9 +219,12 @@
|
||||||
<string name="phonies_disallow">Disallow phonies</string>
|
<string name="phonies_disallow">Disallow phonies</string>
|
||||||
<string name="menu_prefs">Settings</string>
|
<string name="menu_prefs">Settings</string>
|
||||||
<string name="gamel_menu_dicts">Dictionaries</string>
|
<string name="gamel_menu_dicts">Dictionaries</string>
|
||||||
|
<string name="menu_revert_all">Restore all</string>
|
||||||
<string name="menu_revert_colors">Restore colors</string>
|
<string name="menu_revert_colors">Restore colors</string>
|
||||||
<string name="confirm_revert_colors">Are you sure you want to
|
<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 default values?</string>
|
||||||
|
<string name="confirm_revert_all">Are you sure you want to restore
|
||||||
|
all preferences to their default values?</string>
|
||||||
|
|
||||||
<string name="room_label">Room</string>
|
<string name="room_label">Room</string>
|
||||||
<string name="phone_label">Host phone number</string>
|
<string name="phone_label">Host phone number</string>
|
||||||
|
|
|
@ -36,17 +36,20 @@ public class PrefsActivity extends PreferenceActivity
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private static final int REVERT_COLORS = 1;
|
private static final int REVERT_COLORS = 1;
|
||||||
|
private static final int REVERT_ALL = 2;
|
||||||
|
|
||||||
private String[] m_keys;
|
private String[] m_keys;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog( int id )
|
protected Dialog onCreateDialog( int id )
|
||||||
{
|
{
|
||||||
Dialog dialog = null;
|
DialogInterface.OnClickListener lstnr = null;
|
||||||
|
int confirmID = 0;
|
||||||
|
|
||||||
switch( id ) {
|
switch( id ) {
|
||||||
case REVERT_COLORS:
|
case REVERT_COLORS:
|
||||||
DialogInterface.OnClickListener lstnr =
|
confirmID = R.string.confirm_revert_colors;
|
||||||
new DialogInterface.OnClickListener() {
|
lstnr = new DialogInterface.OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
SharedPreferences sp =
|
SharedPreferences sp =
|
||||||
getPreferenceScreen().getSharedPreferences();
|
getPreferenceScreen().getSharedPreferences();
|
||||||
|
@ -68,26 +71,33 @@ public class PrefsActivity extends PreferenceActivity
|
||||||
editor.remove( getString(colorKey) );
|
editor.remove( getString(colorKey) );
|
||||||
}
|
}
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
relaunch();
|
||||||
PreferenceManager.setDefaultValues( PrefsActivity.this,
|
|
||||||
R.xml.xwprefs,
|
|
||||||
false );
|
|
||||||
|
|
||||||
// Now replace this activity with a new copy
|
|
||||||
// so the new values get loaded.
|
|
||||||
startActivity( new Intent( PrefsActivity.this,
|
|
||||||
PrefsActivity.class ) );
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
break;
|
||||||
|
case REVERT_ALL:
|
||||||
|
confirmID = R.string.confirm_revert_all;
|
||||||
|
lstnr = new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
|
SharedPreferences sp =
|
||||||
|
getPreferenceScreen().getSharedPreferences();
|
||||||
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
|
editor.clear();
|
||||||
|
editor.commit();
|
||||||
|
relaunch();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog dialog = null;
|
||||||
|
if ( null != lstnr ) {
|
||||||
dialog = new AlertDialog.Builder( this )
|
dialog = new AlertDialog.Builder( this )
|
||||||
.setTitle( R.string.query_title )
|
.setTitle( R.string.query_title )
|
||||||
.setMessage( R.string.confirm_revert_colors )
|
.setMessage( confirmID )
|
||||||
.setPositiveButton( R.string.button_ok, lstnr )
|
.setPositiveButton( R.string.button_ok, lstnr )
|
||||||
.setNegativeButton( R.string.button_cancel, null )
|
.setNegativeButton( R.string.button_cancel, null )
|
||||||
.create();
|
.create();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
@ -158,10 +168,19 @@ public class PrefsActivity extends PreferenceActivity
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected( MenuItem item )
|
public boolean onOptionsItemSelected( MenuItem item )
|
||||||
{
|
{
|
||||||
boolean handled = false;
|
int dlgID = 0;
|
||||||
if ( R.id.menu_revert_colors == item.getItemId()) {
|
switch ( item.getItemId() ) {
|
||||||
showDialog( REVERT_COLORS );
|
case R.id.menu_revert_all:
|
||||||
handled = true;
|
dlgID = REVERT_ALL;
|
||||||
|
break;
|
||||||
|
case R.id.menu_revert_colors:
|
||||||
|
dlgID = REVERT_COLORS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean handled = 0 != dlgID;
|
||||||
|
if ( handled ) {
|
||||||
|
showDialog( dlgID );
|
||||||
}
|
}
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
@ -175,4 +194,16 @@ public class PrefsActivity extends PreferenceActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void relaunch()
|
||||||
|
{
|
||||||
|
PreferenceManager.setDefaultValues( this, R.xml.xwprefs,
|
||||||
|
false );
|
||||||
|
|
||||||
|
// Now replace this activity with a new copy
|
||||||
|
// so the new values get loaded.
|
||||||
|
startActivity( new Intent( this, PrefsActivity.class ) );
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue