small modifications to issue 154

This commit is contained in:
Victor Shcherb 2011-04-19 00:54:42 +02:00
parent a541591a5f
commit 86966c85ca
5 changed files with 19 additions and 18 deletions

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="specified_dir_doesnt_exist">Can not find specified directory.</string>
<string name="application_dir">Storage directory</string>
<string name="application_dir_change_warning">Changing storage directory will not move or delete the data. You must do it yourself! Do it at your own risk! Continue anyway?</string>
<string name="gps_status_app_not_found">GPS status application not installed. Search in Market?</string>

View file

@ -45,7 +45,6 @@
<PreferenceScreen android:title="@string/general_settings" android:summary="@string/general_settings_descr">
<CheckBoxPreference android:key="use_internet_to_download_tiles" android:title="@string/use_internet" android:summary="@string/use_internet_to_download_tile"></CheckBoxPreference>
<EditTextPreference android:title="@string/application_dir" android:key="external_storage_dir"></EditTextPreference>
<ListPreference android:title="@string/max_level_download_tile" android:summary="@string/max_level_download_tile_descr"
android:key="max_level_download_tile"></ListPreference>
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>
@ -53,6 +52,7 @@
<ListPreference android:key="rotate_map" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></ListPreference>
<ListPreference android:key="map_screen_orientation" android:title="@string/map_screen_orientation" android:summary="@string/map_screen_orientation_descr"></ListPreference>
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
<EditTextPreference android:title="@string/application_dir" android:key="external_storage_dir"></EditTextPreference>
<CheckBoxPreference android:key="use_trackball_for_movements" android:title="@string/use_trackball" android:summary="@string/use_trackball_descr"></CheckBoxPreference>
</PreferenceScreen>

View file

@ -461,13 +461,11 @@ public class OsmandSettings {
return getExternalStorageDirectory(getPrefs(ctx));
}
public static File extendOsmandPath(SharedPreferences prefs, String path)
{
public static File extendOsmandPath(SharedPreferences prefs, String path) {
return new File(getExternalStorageDirectory(prefs), path);
}
public static File extendOsmandPath(Context ctx, String path)
{
public static File extendOsmandPath(Context ctx, String path) {
return new File(getExternalStorageDirectory(ctx), path);
}

View file

@ -101,20 +101,10 @@ public class ResourceManager {
this.context = context;
this.renderer = new MapRenderRepositories(context);
asyncLoadingTiles.start();
OsmandSettings.getSharedPreferences(context).registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
if (key == OsmandSettings.EXTERNAL_STORAGE_DIR) {
resetStoreDirectory();
}
}
});
resetStoreDirectory();
}
private void resetStoreDirectory()
{
public void resetStoreDirectory() {
dirWithTiles = OsmandSettings.extendOsmandPath(context, TILES_PATH);
dirWithTiles.mkdirs();
}

View file

@ -150,7 +150,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
userPassword.setOnPreferenceChangeListener(this);
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
applicationDir.setOnPreferenceChangeListener(this);
updateApplicationDirSummary();
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
applicationMode.setOnPreferenceChangeListener(this);
@ -365,6 +364,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
}
tileSourcePreference.setSummary(summary + mapName);
updateApplicationDirSummary();
}
private void fill(ListPreference component, String[] list, String[] values, String selected) {
@ -456,6 +457,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
edit.commit();
} else if(preference == applicationDir){
warnAboutChangingStorage(edit, (String) newValue);
return false;
} else if(preference == positionOnMap){
edit.putInt(OsmandSettings.POSITION_ON_MAP, positionOnMap.findIndexOfValue((String) newValue));
edit.commit();
@ -539,6 +541,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
private void warnAboutChangingStorage(final Editor edit, final String newValue) {
File path = new File(newValue);
path.mkdirs();
if(!path.canRead() || !path.exists()){
Toast.makeText(this, R.string.specified_dir_doesnt_exist, Toast.LENGTH_LONG).show() ;
return;
}
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.application_dir_change_warning));
builder.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
@ -547,8 +556,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
//edit the preference
edit.putString(OsmandSettings.EXTERNAL_STORAGE_DIR, newValue);
edit.commit();
updateApplicationDirSummary();
((OsmandApplication)getApplication()).getResourceManager().resetStoreDirectory();
reloadIndexes();
updateApplicationDirSummary();
}
});
builder.setNegativeButton(R.string.default_buttons_cancel, null);
@ -562,6 +572,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
@Override
public void run() {
try {
showWarnings(((OsmandApplication)getApplication()).getResourceManager().reloadIndexes(impl));
} finally {
if(progressDlg !=null){