Merge issue154 into master

This commit is contained in:
Victor Shcherb 2011-04-19 21:54:22 +02:00
commit d2182d273b
16 changed files with 122 additions and 51 deletions

View file

@ -5,7 +5,6 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays;
import java.util.zip.Deflater; import java.util.zip.Deflater;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;

View file

@ -29,7 +29,6 @@ import gnu.trove.procedure.TFloatProcedure;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.iterator.TFloatIterator; import gnu.trove.iterator.TFloatIterator;
import gnu.trove.iterator.TFloatObjectIterator; import gnu.trove.iterator.TFloatObjectIterator;
import gnu.trove.iterator.TPrimitiveIterator;
import gnu.trove.function.TObjectFunction; import gnu.trove.function.TObjectFunction;
import gnu.trove.set.TFloatSet; import gnu.trove.set.TFloatSet;
import gnu.trove.TFloatCollection; import gnu.trove.TFloatCollection;

View file

@ -29,7 +29,6 @@ import gnu.trove.procedure.TLongProcedure;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.iterator.TLongIterator; import gnu.trove.iterator.TLongIterator;
import gnu.trove.iterator.TLongObjectIterator; import gnu.trove.iterator.TLongObjectIterator;
import gnu.trove.iterator.TPrimitiveIterator;
import gnu.trove.function.TObjectFunction; import gnu.trove.function.TObjectFunction;
import gnu.trove.set.TLongSet; import gnu.trove.set.TLongSet;
import gnu.trove.TLongCollection; import gnu.trove.TLongCollection;

View file

@ -7,7 +7,6 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Box; import javax.swing.Box;

View file

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources> <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="osmand_net_previously_installed">You have installed previous OsmAnd version. All offline data will be supported by new application. Favorite points should be exported in old application and imported.</string> <string name="osmand_net_previously_installed">You have installed previous OsmAnd version. All offline data will be supported by new application. Favorite points should be exported in old application and imported.</string>
<string name="build_installed">Build {0} successfully installed ({1}).</string> <string name="build_installed">Build {0} successfully installed ({1}).</string>
<string name="downloading_build">Downloading build...</string> <string name="downloading_build">Downloading build...</string>

View file

@ -45,7 +45,6 @@
<PreferenceScreen android:title="@string/general_settings" android:summary="@string/general_settings_descr"> <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> <CheckBoxPreference android:key="use_internet_to_download_tiles" android:title="@string/use_internet" android:summary="@string/use_internet_to_download_tile"></CheckBoxPreference>
<ListPreference android:title="@string/max_level_download_tile" android:summary="@string/max_level_download_tile_descr" <ListPreference android:title="@string/max_level_download_tile" android:summary="@string/max_level_download_tile_descr"
android:key="max_level_download_tile"></ListPreference> 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> <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="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="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> <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> <CheckBoxPreference android:key="use_trackball_for_movements" android:title="@string/use_trackball" android:summary="@string/use_trackball_descr"></CheckBoxPreference>
</PreferenceScreen> </PreferenceScreen>

View file

@ -450,6 +450,25 @@ public class OsmandSettings {
return prefs.getBoolean(MAP_VECTOR_DATA, false); return prefs.getBoolean(MAP_VECTOR_DATA, false);
} }
public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$
// public static final String MAP_TILE_SOURCES = "map_tile_sources"; //$NON-NLS-1$
public static File getExternalStorageDirectory(SharedPreferences prefs) {
return new File(prefs.getString(EXTERNAL_STORAGE_DIR, Environment.getExternalStorageDirectory().getAbsolutePath()));
}
public static File getExternalStorageDirectory(Context ctx) {
return getExternalStorageDirectory(getPrefs(ctx));
}
public static File extendOsmandPath(SharedPreferences prefs, String path) {
return new File(getExternalStorageDirectory(prefs), path);
}
public static File extendOsmandPath(Context ctx, String path) {
return new File(getExternalStorageDirectory(ctx), path);
}
public static ITileSource getMapTileSource(SharedPreferences prefs) { public static ITileSource getMapTileSource(SharedPreferences prefs) {
String tileName = prefs.getString(MAP_TILE_SOURCES, null); String tileName = prefs.getString(MAP_TILE_SOURCES, null);
if (tileName != null) { if (tileName != null) {
@ -460,7 +479,7 @@ public class OsmandSettings {
return l; return l;
} }
} }
File tPath = new File(Environment.getExternalStorageDirectory(), ResourceManager.TILES_PATH); File tPath = OsmandSettings.extendOsmandPath(prefs, ResourceManager.TILES_PATH);
File dir = new File(tPath, tileName); File dir = new File(tPath, tileName);
if(dir.exists()){ if(dir.exists()){
if(tileName.endsWith(SQLiteTileSource.EXT)){ if(tileName.endsWith(SQLiteTileSource.EXT)){

View file

@ -35,10 +35,11 @@ import net.osmand.plus.views.POIMapLayer;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Environment;
/** /**
* Resource manager is responsible to work with all resources * Resource manager is responsible to work with all resources
@ -100,11 +101,12 @@ public class ResourceManager {
this.context = context; this.context = context;
this.renderer = new MapRenderRepositories(context); this.renderer = new MapRenderRepositories(context);
asyncLoadingTiles.start(); asyncLoadingTiles.start();
dirWithTiles = new File(Environment.getExternalStorageDirectory(), TILES_PATH); resetStoreDirectory();
if(Environment.getExternalStorageDirectory().canRead()){ }
dirWithTiles.mkdirs();
}
public void resetStoreDirectory() {
dirWithTiles = OsmandSettings.extendOsmandPath(context, TILES_PATH);
dirWithTiles.mkdirs();
} }
public OsmandApplication getContext() { public OsmandApplication getContext() {
@ -356,10 +358,8 @@ public class ResourceManager {
} }
private void initRenderers(IProgress progress) { private void initRenderers(IProgress progress) {
File file = new File(Environment.getExternalStorageDirectory(), APP_DIR + IndexConstants.RENDERERS_DIR); File file = OsmandSettings.extendOsmandPath(context, APP_DIR + IndexConstants.RENDERERS_DIR);
if(Environment.getExternalStorageDirectory().canRead()){ file.mkdirs();
file.mkdirs();
}
Map<String, File> externalRenderers = new LinkedHashMap<String, File>(); Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
if (file.exists() && file.canRead()) { if (file.exists() && file.canRead()) {
for (File f : file.listFiles()) { for (File f : file.listFiles()) {
@ -380,10 +380,8 @@ public class ResourceManager {
} }
public List<String> indexingMaps(final IProgress progress) { public List<String> indexingMaps(final IProgress progress) {
File file = new File(Environment.getExternalStorageDirectory(), MAPS_PATH); File file = OsmandSettings.extendOsmandPath(context, MAPS_PATH);
if(Environment.getExternalStorageDirectory().canRead()){ file.mkdirs();
file.mkdirs();
}
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
renderer.clearAllResources(); renderer.clearAllResources();
if (file.exists() && file.canRead()) { if (file.exists() && file.canRead()) {
@ -439,10 +437,8 @@ public class ResourceManager {
// POI INDEX // // POI INDEX //
public List<String> indexingPoi(final IProgress progress) { public List<String> indexingPoi(final IProgress progress) {
File file = new File(Environment.getExternalStorageDirectory(), POI_PATH); File file = OsmandSettings.extendOsmandPath(context, POI_PATH);
if(Environment.getExternalStorageDirectory().canRead()){ file.mkdirs();
file.mkdirs();
}
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
closeAmenities(); closeAmenities();
if (file.exists() && file.canRead()) { if (file.exists() && file.canRead()) {
@ -481,7 +477,7 @@ public class ResourceManager {
public List<String> indexingAddresses(final IProgress progress){ public List<String> indexingAddresses(final IProgress progress){
File file = new File(Environment.getExternalStorageDirectory(), ADDRESS_PATH); File file = OsmandSettings.extendOsmandPath(context, ADDRESS_PATH);
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
closeAddresses(); closeAddresses();
if (file.exists() && file.canRead()) { if (file.exists() && file.canRead()) {
@ -513,7 +509,7 @@ public class ResourceManager {
public List<String> indexingTransport(final IProgress progress){ public List<String> indexingTransport(final IProgress progress){
File file = new File(Environment.getExternalStorageDirectory(), TRANSPORT_PATH); File file = OsmandSettings.extendOsmandPath(context, TRANSPORT_PATH);
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
closeTransport(); closeTransport();
if (file.exists() && file.canRead()) { if (file.exists() && file.canRead()) {
@ -747,7 +743,7 @@ public class ResourceManager {
String tileId, ITileSource source, int tileX, int tileY, int zoom) { String tileId, ITileSource source, int tileX, int tileY, int zoom) {
super(url, fileToSave, tileX, tileY, zoom); super(url, fileToSave, tileX, tileY, zoom);
this.dirWithTiles = dirWithTiles; this.dirWithTiles = dirWithTiles;
tileSource = source; this.tileSource = source;
this.tileId = tileId; this.tileId = tileId;
} }
} }

View file

@ -39,8 +39,10 @@ import java.util.zip.ZipInputStream;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.LogUtil; import net.osmand.LogUtil;
import net.osmand.data.index.DownloaderIndexFromGoogleCode;
import net.osmand.data.index.IndexConstants; import net.osmand.data.index.IndexConstants;
import net.osmand.plus.DownloadOsmandIndexesHelper; import net.osmand.plus.DownloadOsmandIndexesHelper;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ProgressDialogImplementation; import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.ResourceManager; import net.osmand.plus.ResourceManager;
@ -55,7 +57,6 @@ import android.app.AlertDialog.Builder;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -315,7 +316,7 @@ public class DownloadIndexActivity extends ListActivity {
private List<String> listAlreadyDownloadedWithAlternatives() private List<String> listAlreadyDownloadedWithAlternatives()
{ {
List<String> files = new ArrayList<String>(); List<String> files = new ArrayList<String>();
File externalStorageDirectory = Environment.getExternalStorageDirectory(); File externalStorageDirectory = OsmandSettings.getExternalStorageDirectory(getApplicationContext());
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.ADDRESS_PATH),ADDRESS_INDEX_EXT,ADDRESS_INDEX_EXT_ZIP,ADDRESS_TABLE_VERSION)); files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.ADDRESS_PATH),ADDRESS_INDEX_EXT,ADDRESS_INDEX_EXT_ZIP,ADDRESS_TABLE_VERSION));
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.POI_PATH),POI_INDEX_EXT,POI_INDEX_EXT_ZIP,POI_TABLE_VERSION)); files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.POI_PATH),POI_INDEX_EXT,POI_INDEX_EXT_ZIP,POI_TABLE_VERSION));
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.TRANSPORT_PATH),TRANSPORT_INDEX_EXT,TRANSPORT_INDEX_EXT_ZIP,TRANSPORT_TABLE_VERSION)); files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.TRANSPORT_PATH),TRANSPORT_INDEX_EXT,TRANSPORT_INDEX_EXT_ZIP,TRANSPORT_TABLE_VERSION));
@ -351,7 +352,8 @@ public class DownloadIndexActivity extends ListActivity {
String toSavePostfix = null; String toSavePostfix = null;
String toCheckPostfix = null; String toCheckPostfix = null;
boolean unzipDir = false; boolean unzipDir = false;
File externalStorageDirectory = Environment.getExternalStorageDirectory();
File externalStorageDirectory = OsmandSettings.getExternalStorageDirectory(getApplicationContext());
if(fileName.endsWith(ADDRESS_INDEX_EXT)){ if(fileName.endsWith(ADDRESS_INDEX_EXT)){
parent = new File(externalStorageDirectory, ResourceManager.ADDRESS_PATH); parent = new File(externalStorageDirectory, ResourceManager.ADDRESS_PATH);
toSavePostfix = ADDRESS_INDEX_EXT; toSavePostfix = ADDRESS_INDEX_EXT;

View file

@ -28,7 +28,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -193,7 +192,7 @@ public class FavouritesActivity extends ListActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == EXPORT_ID){ if(item.getItemId() == EXPORT_ID){
File appDir = new File(Environment.getExternalStorageDirectory(), ResourceManager.APP_DIR); File appDir = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.APP_DIR);
if(favouritesAdapter.isEmpty()){ if(favouritesAdapter.isEmpty()){
Toast.makeText(this, R.string.no_fav_to_save, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.no_fav_to_save, Toast.LENGTH_LONG).show();
} else if(!appDir.exists()){ } else if(!appDir.exists()){
@ -215,7 +214,7 @@ public class FavouritesActivity extends ListActivity {
} }
} }
} else if(item.getItemId() == IMPORT_ID){ } else if(item.getItemId() == IMPORT_ID){
File appDir = new File(Environment.getExternalStorageDirectory(), ResourceManager.APP_DIR); File appDir = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.APP_DIR);
File f = new File(appDir, FILE_TO_SAVE); File f = new File(appDir, FILE_TO_SAVE);
if(!f.exists()){ if(!f.exists()){
Toast.makeText(this, MessageFormat.format(getString(R.string.fav_file_to_load_not_found), f.getAbsolutePath()), Toast.LENGTH_LONG).show(); Toast.makeText(this, MessageFormat.format(getString(R.string.fav_file_to_load_not_found), f.getAbsolutePath()), Toast.LENGTH_LONG).show();

View file

@ -50,7 +50,7 @@ public class MainMenuActivity extends Activity {
public void checkPreviousRunsForExceptions(boolean firstTime) { public void checkPreviousRunsForExceptions(boolean firstTime) {
long size = getPreferences(MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0); long size = getPreferences(MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0);
final File file = new File(Environment.getExternalStorageDirectory(), OsmandApplication.EXCEPTION_PATH); final File file = OsmandSettings.extendOsmandPath(getApplicationContext(), OsmandApplication.EXCEPTION_PATH);
if (file.exists() && file.length() > 0) { if (file.exists() && file.length() > 0) {
if (size != file.length() && !firstTime) { if (size != file.length() && !firstTime) {
String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH); String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH);

View file

@ -1369,7 +1369,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
private void useGPXFileLayer(final boolean useRouting, final LatLon endForRouting) { private void useGPXFileLayer(final boolean useRouting, final LatLon endForRouting) {
final List<String> list = new ArrayList<String>(); final List<String> list = new ArrayList<String>();
final File dir = new File(Environment.getExternalStorageDirectory(), ResourceManager.APP_DIR + SavingTrackHelper.TRACKS_PATH); final File dir = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.APP_DIR + SavingTrackHelper.TRACKS_PATH);
if (dir != null && dir.canRead()) { if (dir != null && dir.canRead()) {
File[] files = dir.listFiles(); File[] files = dir.listFiles();
if (files != null) { if (files != null) {

View file

@ -24,7 +24,6 @@ import android.app.AlertDialog.Builder;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.Log; import android.util.Log;
@ -234,7 +233,7 @@ public class OsmandApplication extends Application {
@Override @Override
public void uncaughtException(final Thread thread, final Throwable ex) { public void uncaughtException(final Thread thread, final Throwable ex) {
File file = new File(Environment.getExternalStorageDirectory(), EXCEPTION_PATH); File file = OsmandSettings.extendOsmandPath(getApplicationContext(), EXCEPTION_PATH);
try { try {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(out); PrintStream printStream = new PrintStream(out);
@ -244,7 +243,7 @@ public class OsmandApplication extends Application {
append(DateFormat.format("MMMM dd, yyyy h:mm:ss", System.currentTimeMillis())).append("\n"). //$NON-NLS-1$//$NON-NLS-2$ append(DateFormat.format("MMMM dd, yyyy h:mm:ss", System.currentTimeMillis())).append("\n"). //$NON-NLS-1$//$NON-NLS-2$
append(new String(out.toByteArray())); append(new String(out.toByteArray()));
if (Environment.getExternalStorageDirectory().canRead()) { if (file.getParentFile().canWrite()) {
BufferedWriter writer = new BufferedWriter(new FileWriter(file, true)); BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
writer.write(msg.toString()); writer.write(msg.toString());
writer.close(); writer.close();

View file

@ -19,7 +19,6 @@ import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.text.format.DateFormat; import android.text.format.DateFormat;
public class SavingTrackHelper extends SQLiteOpenHelper { public class SavingTrackHelper extends SQLiteOpenHelper {
@ -79,7 +78,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public List<String> saveDataToGpx(){ public List<String> saveDataToGpx(){
SQLiteDatabase db = getReadableDatabase(); SQLiteDatabase db = getReadableDatabase();
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
File file = Environment.getExternalStorageDirectory(); File file = OsmandSettings.getExternalStorageDirectory(ctx);
if(db != null && file.canWrite()){ if(db != null && file.canWrite()){
file = new File(file, ResourceManager.APP_DIR + TRACKS_PATH); file = new File(file, ResourceManager.APP_DIR + TRACKS_PATH);
file.mkdirs(); file.mkdirs();

View file

@ -24,19 +24,22 @@ import net.osmand.plus.OsmandSettings.DayNightMode;
import net.osmand.plus.activities.RouteProvider.RouteService; import net.osmand.plus.activities.RouteProvider.RouteService;
import net.osmand.plus.render.BaseOsmandRender; import net.osmand.plus.render.BaseOsmandRender;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.location.LocationManager; import android.location.LocationManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
@ -78,6 +81,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private EditTextPreference userPassword; private EditTextPreference userPassword;
private EditTextPreference userName; private EditTextPreference userName;
private EditTextPreference applicationDir;
private Preference saveCurrentTrack; private Preference saveCurrentTrack;
private Preference reloadIndexes; private Preference reloadIndexes;
@ -144,6 +148,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
userName.setOnPreferenceChangeListener(this); userName.setOnPreferenceChangeListener(this);
userPassword = (EditTextPreference) screen.findPreference(OsmandSettings.USER_PASSWORD); userPassword = (EditTextPreference) screen.findPreference(OsmandSettings.USER_PASSWORD);
userPassword.setOnPreferenceChangeListener(this); userPassword.setOnPreferenceChangeListener(this);
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
applicationDir.setOnPreferenceChangeListener(this);
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE); applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
applicationMode.setOnPreferenceChangeListener(this); applicationMode.setOnPreferenceChangeListener(this);
@ -188,6 +194,12 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.OSMAND_STOP_SERVICE_ACTION)); registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.OSMAND_STOP_SERVICE_ACTION));
} }
private void updateApplicationDirSummary() {
String storageDir = OsmandSettings.getExternalStorageDirectory(getApplicationContext()).getAbsolutePath();
applicationDir.setText(storageDir);
applicationDir.setSummary(storageDir);
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@ -207,6 +219,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} }
userName.setText(OsmandSettings.getUserName(prefs)); userName.setText(OsmandSettings.getUserName(prefs));
userPassword.setText(OsmandSettings.getUserPassword(prefs)); userPassword.setText(OsmandSettings.getUserPassword(prefs));
applicationDir.setText(OsmandSettings.getExternalStorageDirectory(prefs).getAbsolutePath());
useInternetToDownload.setChecked(OsmandSettings.isUsingInternetToDownloadTiles(prefs)); useInternetToDownload.setChecked(OsmandSettings.isUsingInternetToDownloadTiles(prefs));
Resources resources = this.getResources(); Resources resources = this.getResources();
@ -289,7 +302,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
fill(routerPreference, entries, entries, entry); fill(routerPreference, entries, entries, entry);
// read available voice data // read available voice data
File extStorage = new File(Environment.getExternalStorageDirectory(), ResourceManager.VOICE_PATH); File extStorage = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.VOICE_PATH);
Set<String> setFiles = new LinkedHashSet<String>(); Set<String> setFiles = new LinkedHashSet<String>();
if (extStorage.exists()) { if (extStorage.exists()) {
for (File f : extStorage.listFiles()) { for (File f : extStorage.listFiles()) {
@ -353,6 +366,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
summary = summary.substring(0, summary.lastIndexOf(':') + 1); summary = summary.substring(0, summary.lastIndexOf(':') + 1);
} }
tileSourcePreference.setSummary(summary + mapName); tileSourcePreference.setSummary(summary + mapName);
updateApplicationDirSummary();
} }
private void fill(ListPreference component, String[] list, String[] values, String selected) { private void fill(ListPreference component, String[] list, String[] values, String selected) {
@ -363,7 +378,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
public static Map<String, String> getTileSourceEntries(Context ctx){ public static Map<String, String> getTileSourceEntries(Context ctx){
Map<String, String> map = new LinkedHashMap<String, String>(); Map<String, String> map = new LinkedHashMap<String, String>();
File dir = new File(Environment.getExternalStorageDirectory(), ResourceManager.TILES_PATH); File dir = OsmandSettings.extendOsmandPath(ctx, ResourceManager.TILES_PATH);
if (dir != null && dir.canRead()) { if (dir != null && dir.canRead()) {
File[] files = dir.listFiles(); File[] files = dir.listFiles();
Arrays.sort(files, new Comparator<File>(){ Arrays.sort(files, new Comparator<File>(){
@ -420,12 +435,12 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if(preference == applicationMode){ } else if(preference == applicationMode){
ApplicationMode old = OsmandSettings.getApplicationMode(prefs); ApplicationMode old = OsmandSettings.getApplicationMode(prefs);
edit.putString(OsmandSettings.APPLICATION_MODE, (String) newValue); edit.putString(OsmandSettings.APPLICATION_MODE, (String) newValue);
setAppMode(ApplicationMode.valueOf(newValue.toString()), edit, (OsmandApplication) getApplication(), old); setAppMode(ApplicationMode.valueOf(newValue.toString()), edit, getMyApplication(), old);
edit.commit(); edit.commit();
updateAllSettings(); updateAllSettings();
} else if(preference == daynightMode){ } else if(preference == daynightMode){
edit.putString(OsmandSettings.DAYNIGHT_MODE, (String) newValue); edit.putString(OsmandSettings.DAYNIGHT_MODE, (String) newValue);
((OsmandApplication)getApplication()).getDaynightHelper().setDayNightMode(DayNightMode.valueOf(newValue.toString())); getMyApplication().getDaynightHelper().setDayNightMode(DayNightMode.valueOf(newValue.toString()));
edit.commit(); edit.commit();
} else if(preference == mapScreenOrientation){ } else if(preference == mapScreenOrientation){
edit.putInt(OsmandSettings.MAP_SCREEN_ORIENTATION, Integer.parseInt(newValue.toString())); edit.putInt(OsmandSettings.MAP_SCREEN_ORIENTATION, Integer.parseInt(newValue.toString()));
@ -442,6 +457,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if(preference == userName){ } else if(preference == userName){
edit.putString(OsmandSettings.USER_NAME, (String) newValue); edit.putString(OsmandSettings.USER_NAME, (String) newValue);
edit.commit(); edit.commit();
} else if(preference == applicationDir){
warnAboutChangingStorage(edit, (String) newValue);
return false;
} else if(preference == positionOnMap){ } else if(preference == positionOnMap){
edit.putInt(OsmandSettings.POSITION_ON_MAP, positionOnMap.findIndexOfValue((String) newValue)); edit.putInt(OsmandSettings.POSITION_ON_MAP, positionOnMap.findIndexOfValue((String) newValue));
edit.commit(); edit.commit();
@ -492,7 +510,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
RendererRegistry.getRegistry().setCurrentSelectedRender(loaded); RendererRegistry.getRegistry().setCurrentSelectedRender(loaded);
edit.putString(OsmandSettings.RENDERER, (String) newValue); edit.putString(OsmandSettings.RENDERER, (String) newValue);
Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
((OsmandApplication)getApplication()).getResourceManager().getRenderer().clearCache(); getMyApplication().getResourceManager().getRenderer().clearCache();
} }
edit.commit(); edit.commit();
} else if (preference == voicePreference) { } else if (preference == voicePreference) {
@ -503,7 +521,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
edit.putString(OsmandSettings.VOICE_PROVIDER, (String) newValue); edit.putString(OsmandSettings.VOICE_PROVIDER, (String) newValue);
} }
edit.commit(); edit.commit();
((OsmandApplication)getApplication()).initCommandPlayer(); getMyApplication().initCommandPlayer();
} else if (preference == tileSourcePreference) { } else if (preference == tileSourcePreference) {
if(VECTOR_MAP.equals((String) newValue)){ if(VECTOR_MAP.equals((String) newValue)){
edit.putBoolean(OsmandSettings.MAP_VECTOR_DATA, true); edit.putBoolean(OsmandSettings.MAP_VECTOR_DATA, true);
@ -524,6 +542,32 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
return true; return true;
} }
private void warnAboutChangingStorage(final Editor edit, final String newValue) {
final String newDir = newValue != null ? newValue.trim(): newValue;
File path = new File(newDir);
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() {
@Override
public void onClick(DialogInterface dialog, int which) {
//edit the preference
edit.putString(OsmandSettings.EXTERNAL_STORAGE_DIR, newDir);
edit.commit();
getMyApplication().getResourceManager().resetStoreDirectory();
reloadIndexes();
updateApplicationDirSummary();
}
});
builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.show();
}
public void reloadIndexes(){ public void reloadIndexes(){
progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true); progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg); final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
@ -531,7 +575,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
@Override @Override
public void run() { public void run() {
try { try {
showWarnings(((OsmandApplication)getApplication()).getResourceManager().reloadIndexes(impl)); showWarnings(getMyApplication().getResourceManager().reloadIndexes(impl));
} finally { } finally {
if(progressDlg !=null){ if(progressDlg !=null){
progressDlg.dismiss(); progressDlg.dismiss();
@ -543,6 +587,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
impl.run(); impl.run();
} }
private OsmandApplication getMyApplication() {
return (OsmandApplication)getApplication();
}
@Override @Override
protected void onStop() { protected void onStop() {
if(progressDlg !=null){ if(progressDlg !=null){
@ -653,6 +701,15 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} }
} }
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (preference == applicationDir) {
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if(preference == downloadIndexes){ if(preference == downloadIndexes){

View file

@ -13,6 +13,7 @@ import java.util.List;
import net.osmand.LogUtil; import net.osmand.LogUtil;
import net.osmand.data.index.IndexConstants; import net.osmand.data.index.IndexConstants;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.ResourceManager; import net.osmand.plus.ResourceManager;
@ -30,7 +31,6 @@ import alice.tuprolog.Theory;
import alice.tuprolog.Var; import alice.tuprolog.Var;
import android.content.Context; import android.content.Context;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Environment;
/** /**
* That class represents command player. * That class represents command player.
@ -83,7 +83,7 @@ public class CommandPlayer {
prologSystem.clearTheory(); prologSystem.clearTheory();
voiceDir = null; voiceDir = null;
if(voiceProvider != null){ if(voiceProvider != null){
File parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.VOICE_PATH); File parent = OsmandSettings.extendOsmandPath(ctx, ResourceManager.VOICE_PATH);
voiceDir = new File(parent, voiceProvider); voiceDir = new File(parent, voiceProvider);
if(!voiceDir.exists()){ if(!voiceDir.exists()){
voiceDir = null; voiceDir = null;