Implementing map preference folder. (issue 154)
OsmandSettings has now methods for extending the storage folder or getting the storage folder. It should not be taken from Environment directly now, but from the settings. - fixed some warnings
This commit is contained in:
parent
b2bf8fbb46
commit
a541591a5f
16 changed files with 111 additions and 47 deletions
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<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>
|
<string name="gps_status_app_not_found">GPS status application not installed. Search in Market?</string>
|
||||||
|
|
||||||
<string name="voice_is_not_available_msg">Voice guidance is not available. Please go to settings, choose preferrable voice data or download it.</string>
|
<string name="voice_is_not_available_msg">Voice guidance is not available. Please go to settings, choose preferrable voice data or download it.</string>
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
<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>
|
||||||
|
<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"
|
<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>
|
||||||
|
|
|
@ -450,6 +450,27 @@ 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 +481,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)){
|
||||||
|
|
|
@ -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,22 @@ 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);
|
OsmandSettings.getSharedPreferences(context).registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
|
||||||
if(Environment.getExternalStorageDirectory().canRead()){
|
@Override
|
||||||
dirWithTiles.mkdirs();
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||||
|
String key) {
|
||||||
|
if (key == OsmandSettings.EXTERNAL_STORAGE_DIR) {
|
||||||
|
resetStoreDirectory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
resetStoreDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetStoreDirectory()
|
||||||
|
{
|
||||||
|
dirWithTiles = OsmandSettings.extendOsmandPath(context, TILES_PATH);
|
||||||
|
dirWithTiles.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsmandApplication getContext() {
|
public OsmandApplication getContext() {
|
||||||
|
@ -356,10 +368,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 +390,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 +447,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 +487,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 +519,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 +753,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import net.osmand.Version;
|
import net.osmand.Version;
|
||||||
|
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;
|
||||||
import net.osmand.plus.activities.search.SearchActivity;
|
import net.osmand.plus.activities.search.SearchActivity;
|
||||||
|
@ -18,7 +19,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
@ -44,7 +44,7 @@ public class MainMenuActivity extends Activity {
|
||||||
|
|
||||||
public void checkPreviousRunsForExceptions() {
|
public void checkPreviousRunsForExceptions() {
|
||||||
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()) {
|
if (size != file.length()) {
|
||||||
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);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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,9 @@ 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);
|
||||||
|
updateApplicationDirSummary();
|
||||||
|
|
||||||
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
|
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
|
||||||
applicationMode.setOnPreferenceChangeListener(this);
|
applicationMode.setOnPreferenceChangeListener(this);
|
||||||
|
@ -188,6 +195,10 @@ 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() {
|
||||||
|
applicationDir.setSummary(OsmandSettings.getExternalStorageDirectory(getApplicationContext()).getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -207,6 +218,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 +301,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()) {
|
||||||
|
@ -363,7 +375,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>(){
|
||||||
|
@ -442,6 +454,8 @@ 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);
|
||||||
} 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();
|
||||||
|
@ -524,6 +538,23 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void warnAboutChangingStorage(final Editor edit, final String newValue) {
|
||||||
|
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, newValue);
|
||||||
|
edit.commit();
|
||||||
|
updateApplicationDirSummary();
|
||||||
|
reloadIndexes();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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);
|
||||||
|
@ -653,6 +684,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){
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue