15
15
package menion .android .whereyougo .maps .mapsforge .preferences ;
16
16
17
17
import menion .android .whereyougo .R ;
18
+ import menion .android .whereyougo .maps .mapsforge .filepicker .FilePicker ;
18
19
20
+ import android .app .AlertDialog ;
21
+ import android .content .SharedPreferences ;
19
22
import android .os .Bundle ;
23
+ import android .preference .Preference ;
20
24
import android .preference .PreferenceActivity ;
21
25
import android .preference .PreferenceManager ;
22
26
import android .view .WindowManager ;
27
+ import android .widget .Toast ;
23
28
24
29
/**
25
30
* Activity to edit the application preferences.
@@ -29,6 +34,37 @@ public class EditPreferences extends PreferenceActivity {
29
34
protected void onCreate (Bundle savedInstanceState ) {
30
35
super .onCreate (savedInstanceState );
31
36
addPreferencesFromResource (R .xml .mapsforge_preferences );
37
+
38
+ Preference resetCurrentDirectoryPrivate = findPreference ("resetCurrentDirectoryPrivate" );
39
+ if (resetCurrentDirectoryPrivate != null ) {
40
+ resetCurrentDirectoryPrivate .setOnPreferenceClickListener (preference -> resetCurrentDirectory (true ));
41
+ }
42
+
43
+ Preference resetCurrentDirectoryRoot = findPreference ("resetCurrentDirectoryRoot" );
44
+ if (resetCurrentDirectoryRoot != null ) {
45
+ resetCurrentDirectoryRoot .setOnPreferenceClickListener (preference -> resetCurrentDirectory (false ));
46
+ }
47
+
48
+ }
49
+
50
+ private boolean resetCurrentDirectory (final boolean toPrivateFolder ) {
51
+ new AlertDialog .Builder (this )
52
+ .setTitle (R .string .reset_map_settings_confirmation_title )
53
+ .setMessage (R .string .reset_map_settings_confirmation_message )
54
+ .setPositiveButton (android .R .string .ok , ((dialogInterface , i ) -> {
55
+ SharedPreferences .Editor editor = getSharedPreferences (FilePicker .PREFERENCES_FILE , MODE_PRIVATE ).edit ();
56
+ editor .putString (FilePicker .CURRENT_DIRECTORY , toPrivateFolder ? getExternalFilesDir (null ).getAbsolutePath () : "/" );
57
+ editor .commit ();
58
+
59
+ SharedPreferences .Editor editor2 = getSharedPreferences ("MapActivity" , MODE_PRIVATE ).edit ();
60
+ editor2 .remove ("mapFile" );
61
+ editor2 .commit ();
62
+
63
+ Toast .makeText (this , R .string .reset_current_directory_info , Toast .LENGTH_SHORT ).show ();
64
+ }))
65
+ .setNegativeButton (android .R .string .cancel , (dialogInterface , i ) -> {})
66
+ .show ();
67
+ return true ;
32
68
}
33
69
34
70
@ Override
0 commit comments