create fully functional osmand application object
git-svn-id: https://osmand.googlecode.com/svn/trunk@488 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
d791fd2a5a
commit
8c9fecb434
35 changed files with 498 additions and 382 deletions
|
@ -37,7 +37,7 @@ public class ToDoConstants {
|
|||
|
||||
// TODO Check
|
||||
// 1. check postal_code if the building was registered by relation!
|
||||
|
||||
// 2. TEST after refactoring : poi custom filters
|
||||
|
||||
// 8. Download with wget
|
||||
// 9. progress while map is loading
|
||||
|
|
BIN
OsmAnd/res/drawable/h_traffic_light.png
Normal file
BIN
OsmAnd/res/drawable/h_traffic_light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -7,6 +7,7 @@ import java.net.URLEncoder;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.osm.MapUtils;
|
||||
|
@ -24,19 +25,11 @@ public class NameFinderPoiFilter extends PoiFilter {
|
|||
|
||||
List<Amenity> searchedAmenities = new ArrayList<Amenity>();
|
||||
|
||||
private static NameFinderPoiFilter INSTANCE;
|
||||
|
||||
private String query = ""; //$NON-NLS-1$
|
||||
|
||||
public static NameFinderPoiFilter getInstance(){
|
||||
if(INSTANCE == null){
|
||||
INSTANCE = new NameFinderPoiFilter();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public NameFinderPoiFilter() {
|
||||
super(null);
|
||||
public NameFinderPoiFilter(OsmandApplication application) {
|
||||
super(null, application);
|
||||
this.name = Messages.getMessage("poi_filter_namefinder"); //$NON-NLS-1$
|
||||
this.filterId = FILTER_ID;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand;
|
||||
|
||||
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.activities.RoutingHelper;
|
||||
import net.osmand.activities.SavingTrackHelper;
|
||||
import android.app.Notification;
|
||||
|
@ -75,7 +76,7 @@ public class NavigationService extends Service implements LocationListener {
|
|||
serviceError = OsmandSettings.getServiceOffWaitInterval(this);
|
||||
savingTrackHelper = new SavingTrackHelper(this);
|
||||
delayedAction(true, 500);
|
||||
routingHelper = RoutingHelper.getInstance(this);
|
||||
routingHelper = ((OsmandApplication)getApplication()).getRoutingHelper();
|
||||
OsmandSettings.setServiceOffEnabled(this, true);
|
||||
|
||||
registerReceiver(new BroadcastReceiver(){
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.io.InputStreamReader;
|
|||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.activities.RouteProvider.RouteService;
|
||||
import net.osmand.activities.search.SearchHistoryHelper;
|
||||
import net.osmand.map.ITileSource;
|
||||
|
@ -585,14 +586,14 @@ public class OsmandSettings {
|
|||
return prefs.edit().putString(SELECTED_POI_FILTER_FOR_MAP, filterId).commit();
|
||||
}
|
||||
|
||||
public static PoiFilter getPoiFilterForMap(Context ctx) {
|
||||
public static PoiFilter getPoiFilterForMap(Context ctx, OsmandApplication application) {
|
||||
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||
String filterId = prefs.getString(SELECTED_POI_FILTER_FOR_MAP, null);
|
||||
PoiFilter filter = PoiFiltersHelper.getFilterById(ctx, filterId);
|
||||
PoiFilter filter = application.getPoiFilters().getFilterById(filterId);
|
||||
if (filter != null) {
|
||||
return filter;
|
||||
}
|
||||
return new PoiFilter(null);
|
||||
return new PoiFilter(null, application);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.data.index.IndexConstants.IndexPoiTable;
|
||||
|
@ -28,10 +29,12 @@ public class PoiFilter {
|
|||
private final static int initialZoom = 13;
|
||||
private final static int maxInitialCount = 200;
|
||||
private int zoom = initialZoom;
|
||||
private final OsmandApplication application;
|
||||
|
||||
|
||||
// constructor for standard filters
|
||||
public PoiFilter(AmenityType type){
|
||||
public PoiFilter(AmenityType type, OsmandApplication application){
|
||||
this.application = application;
|
||||
isStandardFilter = true;
|
||||
filterId = STD_PREFIX + type;
|
||||
name = type == null ? Messages.getMessage("poi_filter_closest_poi") : AmenityType.toPublicString(type); //$NON-NLS-1$
|
||||
|
@ -43,7 +46,8 @@ public class PoiFilter {
|
|||
}
|
||||
|
||||
// constructor for standard filters
|
||||
public PoiFilter(String name, String filterId, Map<AmenityType, List<String>> acceptedTypes){
|
||||
public PoiFilter(String name, String filterId, Map<AmenityType, List<String>> acceptedTypes, OsmandApplication app){
|
||||
application = app;
|
||||
isStandardFilter = false;
|
||||
if(filterId == null){
|
||||
filterId = USER_PREFIX + name.replace(' ', '_').toLowerCase();
|
||||
|
@ -70,7 +74,7 @@ public class PoiFilter {
|
|||
|
||||
public List<Amenity> searchFurther(double latitude, double longitude){
|
||||
zoom --;
|
||||
List<Amenity> amenityList = ResourceManager.getResourceManager().searchAmenities(this, latitude, longitude, zoom, -1);
|
||||
List<Amenity> amenityList = application.getResourceManager().searchAmenities(this, latitude, longitude, zoom, -1);
|
||||
MapUtils.sortListOfMapObject(amenityList, latitude, longitude);
|
||||
|
||||
return amenityList;
|
||||
|
@ -99,7 +103,7 @@ public class PoiFilter {
|
|||
|
||||
public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit){
|
||||
zoom = getInitialZoom();
|
||||
List<Amenity> amenityList = ResourceManager.getResourceManager().searchAmenities(this, lat, lon, zoom, maxInitialCount);
|
||||
List<Amenity> amenityList = application.getResourceManager().searchAmenities(this, lat, lon, zoom, maxInitialCount);
|
||||
MapUtils.sortListOfMapObject(amenityList, lat, lon);
|
||||
while (amenityList.size() > firstTimeLimit) {
|
||||
amenityList.remove(amenityList.size() - 1);
|
||||
|
@ -113,7 +117,7 @@ public class PoiFilter {
|
|||
if(zoom == getInitialZoom()){
|
||||
limit = maxInitialCount;
|
||||
}
|
||||
List<Amenity> amenityList = ResourceManager.getResourceManager().searchAmenities(this, lat, lon, zoom, limit);
|
||||
List<Amenity> amenityList = application.getResourceManager().searchAmenities(this, lat, lon, zoom, limit);
|
||||
MapUtils.sortListOfMapObject(amenityList, lat, lon);
|
||||
return amenityList;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.AmenityType;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
@ -14,23 +15,39 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
import android.database.sqlite.SQLiteStatement;
|
||||
|
||||
public class PoiFiltersHelper {
|
||||
|
||||
public static PoiFilter getFilterById(Context ctx, String filterId){
|
||||
private final OsmandApplication application;
|
||||
|
||||
private NameFinderPoiFilter nameFinderPOIFilter;
|
||||
private List<PoiFilter> cacheUserDefinedFilters;
|
||||
private List<PoiFilter> cacheOsmDefinedFilters;
|
||||
|
||||
public PoiFiltersHelper(OsmandApplication application){
|
||||
this.application = application;
|
||||
}
|
||||
public NameFinderPoiFilter getNameFinderPOIFilter() {
|
||||
if(nameFinderPOIFilter == null){
|
||||
nameFinderPOIFilter = new NameFinderPoiFilter(application);
|
||||
}
|
||||
return nameFinderPOIFilter;
|
||||
}
|
||||
|
||||
|
||||
public PoiFilter getFilterById(String filterId){
|
||||
if(filterId == null){
|
||||
return null;
|
||||
}
|
||||
if(filterId.equals(NameFinderPoiFilter.FILTER_ID)){
|
||||
return NameFinderPoiFilter.getInstance();
|
||||
return getNameFinderPOIFilter();
|
||||
}
|
||||
if(filterId.startsWith(PoiFilter.USER_PREFIX)){
|
||||
List<PoiFilter> filters = getUserDefinedPoiFilters(ctx);
|
||||
List<PoiFilter> filters = getUserDefinedPoiFilters();
|
||||
for(PoiFilter f : filters){
|
||||
if(f.getFilterId().equals(filterId)){
|
||||
return f;
|
||||
}
|
||||
}
|
||||
} else if(filterId.startsWith(PoiFilter.STD_PREFIX)){
|
||||
List<PoiFilter> filters = getOsmDefinedPoiFilters(ctx);
|
||||
List<PoiFilter> filters = getOsmDefinedPoiFilters();
|
||||
for(PoiFilter f : filters){
|
||||
if(f.getFilterId().equals(filterId)){
|
||||
return f;
|
||||
|
@ -40,7 +57,7 @@ public class PoiFiltersHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static List<PoiFilter> getUserDefinedDefaultFilters(){
|
||||
private List<PoiFilter> getUserDefinedDefaultFilters(){
|
||||
List<PoiFilter> filters = new ArrayList<PoiFilter>();
|
||||
Map<AmenityType, List<String>> types = new LinkedHashMap<AmenityType, List<String>>();
|
||||
|
||||
|
@ -53,7 +70,7 @@ public class PoiFiltersHelper {
|
|||
list.add("car"); //$NON-NLS-1$
|
||||
list.add("car_repair"); //$NON-NLS-1$
|
||||
types.put(AmenityType.SHOP, list);
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_car_aid"), null, types)); //$NON-NLS-1$
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_car_aid"), null, types, application)); //$NON-NLS-1$
|
||||
types.clear();
|
||||
|
||||
|
||||
|
@ -73,13 +90,13 @@ public class PoiFiltersHelper {
|
|||
list.add("waste_basket"); //$NON-NLS-1$
|
||||
list.add("waste_disposal"); //$NON-NLS-1$
|
||||
types.put(AmenityType.OTHER, list);
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_for_tourists"), null, types)); //$NON-NLS-1$
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_for_tourists"), null, types, application)); //$NON-NLS-1$
|
||||
types.clear();
|
||||
|
||||
list = new ArrayList<String>();
|
||||
list.add("fuel"); //$NON-NLS-1$
|
||||
types.put(AmenityType.TRANSPORTATION, list);
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_fuel"), null, types)); //$NON-NLS-1$
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_fuel"), null, types, application)); //$NON-NLS-1$
|
||||
types.clear();
|
||||
|
||||
list = new ArrayList<String>();
|
||||
|
@ -97,21 +114,20 @@ public class PoiFiltersHelper {
|
|||
list.add("supermarket"); //$NON-NLS-1$
|
||||
list.add("variety_store"); //$NON-NLS-1$
|
||||
types.put(AmenityType.SHOP, list);
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_food_shop"), null, types)); //$NON-NLS-1$
|
||||
filters.add(new PoiFilter(Messages.getMessage("poi_filter_food_shop"), null, types, application)); //$NON-NLS-1$
|
||||
types.clear();
|
||||
|
||||
return filters;
|
||||
}
|
||||
|
||||
private static List<PoiFilter> cacheUserDefinedFilters;
|
||||
public static List<PoiFilter> getUserDefinedPoiFilters(Context ctx){
|
||||
public List<PoiFilter> getUserDefinedPoiFilters(){
|
||||
if(cacheUserDefinedFilters == null){
|
||||
////ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME);
|
||||
|
||||
cacheUserDefinedFilters = new ArrayList<PoiFilter>();
|
||||
PoiFilter filter = new PoiFilter(Messages.getMessage("poi_filter_custom_filter"), PoiFilter.CUSTOM_FILTER_ID, new LinkedHashMap<AmenityType, List<String>>()); //$NON-NLS-1$
|
||||
PoiFilter filter = new PoiFilter(Messages.getMessage("poi_filter_custom_filter"), PoiFilter.CUSTOM_FILTER_ID, new LinkedHashMap<AmenityType, List<String>>(), application); //$NON-NLS-1$
|
||||
cacheUserDefinedFilters.add(filter);
|
||||
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
|
||||
PoiFilterDbHelper helper = openDbHelper();
|
||||
cacheUserDefinedFilters.addAll(helper.getFilters());
|
||||
helper.close();
|
||||
}
|
||||
|
@ -122,52 +138,68 @@ public class PoiFiltersHelper {
|
|||
return PoiFilter.STD_PREFIX + t;
|
||||
}
|
||||
|
||||
private static List<PoiFilter> cacheOsmDefinedFilters;
|
||||
public static List<PoiFilter> getOsmDefinedPoiFilters(Context ctx){
|
||||
|
||||
public List<PoiFilter> getOsmDefinedPoiFilters(){
|
||||
if(cacheOsmDefinedFilters == null){
|
||||
cacheOsmDefinedFilters = new ArrayList<PoiFilter>();
|
||||
cacheOsmDefinedFilters.add(new PoiFilter(null));
|
||||
cacheOsmDefinedFilters.add(new PoiFilter(null, application));
|
||||
for(AmenityType t : AmenityType.values()){
|
||||
cacheOsmDefinedFilters.add(new PoiFilter(t));
|
||||
cacheOsmDefinedFilters.add(new PoiFilter(t, application));
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(cacheOsmDefinedFilters);
|
||||
}
|
||||
|
||||
public static PoiFilterDbHelper getPoiDbHelper(Context ctx){
|
||||
return new PoiFilterDbHelper(ctx);
|
||||
private PoiFilterDbHelper openDbHelper(){
|
||||
return new PoiFilterDbHelper(application.getApplicationContext());
|
||||
}
|
||||
|
||||
|
||||
public static boolean removePoiFilter(PoiFilterDbHelper helper, PoiFilter filter){
|
||||
public boolean removePoiFilter(PoiFilter filter){
|
||||
if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
|
||||
return false;
|
||||
}
|
||||
PoiFilterDbHelper helper = openDbHelper();
|
||||
if(helper == null){
|
||||
return false;
|
||||
}
|
||||
boolean res = helper.deleteFilter(filter);
|
||||
if(res){
|
||||
cacheUserDefinedFilters.remove(filter);
|
||||
}
|
||||
helper.close();
|
||||
return res;
|
||||
}
|
||||
|
||||
public static boolean createPoiFilter(PoiFilterDbHelper helper, PoiFilter filter){
|
||||
public boolean createPoiFilter(PoiFilter filter){
|
||||
PoiFilterDbHelper helper = openDbHelper();
|
||||
if(helper == null){
|
||||
return false;
|
||||
}
|
||||
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false);
|
||||
if(res){
|
||||
cacheUserDefinedFilters.add(filter);
|
||||
}
|
||||
helper.close();
|
||||
return res;
|
||||
}
|
||||
|
||||
public static boolean editPoiFilter(PoiFilterDbHelper helper, PoiFilter filter){
|
||||
if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
|
||||
|
||||
|
||||
public boolean editPoiFilter(PoiFilter filter) {
|
||||
if (filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)) {
|
||||
return false;
|
||||
}
|
||||
boolean res = helper.editFilter(filter);
|
||||
return res;
|
||||
PoiFilterDbHelper helper = openDbHelper();
|
||||
if (helper != null) {
|
||||
boolean res = helper.editFilter(filter);
|
||||
helper.close();
|
||||
return res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static class PoiFilterDbHelper extends SQLiteOpenHelper {
|
||||
public class PoiFilterDbHelper extends SQLiteOpenHelper {
|
||||
|
||||
public static final String DATABASE_NAME = "poi_filters"; //$NON-NLS-1$
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
@ -266,7 +298,7 @@ public class PoiFiltersHelper {
|
|||
do {
|
||||
String filterId = query.getString(0);
|
||||
if(map.containsKey(filterId)){
|
||||
PoiFilter filter = new PoiFilter(query.getString(1), filterId, map.get(filterId));
|
||||
PoiFilter filter = new PoiFilter(query.getString(1), filterId, map.get(filterId), application);
|
||||
filter.setFilterByName(query.getString(2));
|
||||
list.add(filter);
|
||||
}
|
||||
|
|
|
@ -19,33 +19,53 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
private Handler mViewUpdateHandler;
|
||||
private Thread run;
|
||||
private Context context;
|
||||
private ProgressDialog dialog = null;
|
||||
private final boolean cancelable;
|
||||
|
||||
|
||||
public ProgressDialogImplementation(final ProgressDialog dlg, boolean cancelable){
|
||||
context = dlg.getContext();
|
||||
if(cancelable){
|
||||
dlg.setOnCancelListener(new OnCancelListener(){
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if(run != null){
|
||||
run.stop();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
public ProgressDialogImplementation(Context ctx, ProgressDialog dlg, boolean cancelable){
|
||||
this.cancelable = cancelable;
|
||||
context = ctx;
|
||||
setDialog(dlg);
|
||||
|
||||
mViewUpdateHandler = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
dlg.setMessage(message);
|
||||
if(dialog != null){
|
||||
dialog.setMessage(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public ProgressDialogImplementation(ProgressDialog dlg, boolean cancelable){
|
||||
this(dlg.getContext(), dlg, cancelable);
|
||||
}
|
||||
|
||||
|
||||
public ProgressDialogImplementation(final ProgressDialog dlg){
|
||||
this(dlg, false);
|
||||
}
|
||||
|
||||
public void setDialog(ProgressDialog dlg){
|
||||
if(dlg != null){
|
||||
if(cancelable){
|
||||
dlg.setOnCancelListener(new OnCancelListener(){
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if(run != null){
|
||||
run.stop();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
this.dialog = dlg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setRunnable(String threadName, Runnable run){
|
||||
this.run = new Thread(run, threadName);
|
||||
}
|
||||
|
|
|
@ -54,12 +54,12 @@ public class ResourceManager {
|
|||
|
||||
protected static ResourceManager manager = null;
|
||||
|
||||
public static ResourceManager getResourceManager(){
|
||||
if(manager == null){
|
||||
manager = new ResourceManager();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
// public static ResourceManager getResourceManager(){
|
||||
// if(manager == null){
|
||||
// manager = new ResourceManager();
|
||||
// }
|
||||
// return manager;
|
||||
// }
|
||||
|
||||
// it is not good investigated but no more than 64 (satellite images)
|
||||
// Only 8 MB (from 16 Mb whole mem) available for images : image 64K * 128 = 8 MB (8 bit), 64 - 16 bit, 32 - 32 bit
|
||||
|
@ -71,7 +71,6 @@ public class ResourceManager {
|
|||
protected File dirWithTiles ;
|
||||
|
||||
private MapTileDownloader downloader = MapTileDownloader.getInstance();
|
||||
|
||||
// Indexes
|
||||
private Map<String, RegionAddressRepository> addressMap = new TreeMap<String, RegionAddressRepository>(Collator.getInstance());
|
||||
|
||||
|
|
|
@ -233,12 +233,13 @@ public class DownloadIndexActivity extends ListActivity {
|
|||
}
|
||||
|
||||
ArrayList<String> warnings = new ArrayList<String>();
|
||||
ResourceManager manager = ((OsmandApplication)getApplication()).getResourceManager();
|
||||
if(toIndex.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)){
|
||||
ResourceManager.getResourceManager().indexingAddress(impl, warnings, toIndex);
|
||||
manager.indexingAddress(impl, warnings, toIndex);
|
||||
} else if(toIndex.getName().endsWith(IndexConstants.POI_INDEX_EXT)){
|
||||
ResourceManager.getResourceManager().indexingPoi(impl, warnings, toIndex);
|
||||
manager.indexingPoi(impl, warnings, toIndex);
|
||||
} else if(toIndex.getName().endsWith(IndexConstants.TRANSPORT_INDEX_EXT)){
|
||||
ResourceManager.getResourceManager().indexingTransport(impl, warnings, toIndex);
|
||||
manager.indexingTransport(impl, warnings, toIndex);
|
||||
}
|
||||
if(warnings.isEmpty()){
|
||||
showWarning(getString(R.string.download_index_success));
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.osmand.OsmandSettings;
|
|||
import net.osmand.PoiFilter;
|
||||
import net.osmand.PoiFiltersHelper;
|
||||
import net.osmand.R;
|
||||
import net.osmand.PoiFiltersHelper.PoiFilterDbHelper;
|
||||
import net.osmand.activities.search.SearchPOIActivity;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.osm.LatLon;
|
||||
|
@ -46,7 +45,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
public static final String AMENITY_FILTER = "net.osmand.amenity_filter"; //$NON-NLS-1$
|
||||
private Button filterLevel;
|
||||
private PoiFilter filter;
|
||||
private PoiFilterDbHelper helper;
|
||||
private PoiFiltersHelper helper;
|
||||
public static final String SEARCH_LAT = "SEARCH_LAT"; //$NON-NLS-1$
|
||||
public static final String SEARCH_LON = "SEARCH_LON"; //$NON-NLS-1$
|
||||
|
||||
|
@ -99,22 +98,13 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
|
||||
Bundle bundle = this.getIntent().getExtras();
|
||||
String filterId = bundle.getString(AMENITY_FILTER);
|
||||
filter = PoiFiltersHelper.getFilterById(this, filterId);
|
||||
|
||||
helper = ((OsmandApplication)getApplication()).getPoiFilters();
|
||||
filter = helper.getFilterById(filterId);
|
||||
|
||||
setListAdapter(new AmenityAdapter(AmenityType.getCategories()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
helper = PoiFiltersHelper.getPoiDbHelper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
helper.close();
|
||||
}
|
||||
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
|
@ -132,7 +122,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (PoiFiltersHelper.removePoiFilter(helper, filter)) {
|
||||
if (helper.removePoiFilter(filter)) {
|
||||
Toast.makeText(
|
||||
EditPOIFilterActivity.this,
|
||||
MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_delete_message).toString(),
|
||||
|
@ -152,8 +142,8 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PoiFilter nFilter = new PoiFilter(editText.getText().toString(), null, filter.getAcceptedTypes());
|
||||
if (PoiFiltersHelper.createPoiFilter(helper, nFilter)) {
|
||||
PoiFilter nFilter = new PoiFilter(editText.getText().toString(), null, filter.getAcceptedTypes(), (OsmandApplication) getApplication());
|
||||
if (helper.createPoiFilter(nFilter)) {
|
||||
Toast.makeText(
|
||||
EditPOIFilterActivity.this,
|
||||
MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_create_message).toString(),
|
||||
|
@ -214,7 +204,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
} else {
|
||||
filter.selectSubTypesToAccept(amenity, accepted);
|
||||
}
|
||||
PoiFiltersHelper.editPoiFilter(helper, filter);
|
||||
helper.editPoiFilter(filter);
|
||||
((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated();
|
||||
}
|
||||
});
|
||||
|
@ -223,7 +213,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
filter.selectSubTypesToAccept(amenity, null);
|
||||
PoiFiltersHelper.editPoiFilter(helper, filter);
|
||||
helper.editPoiFilter(filter);
|
||||
((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated();
|
||||
}
|
||||
});
|
||||
|
@ -288,7 +278,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
showDialog(model);
|
||||
} else {
|
||||
filter.setTypeToAccept(model, false);
|
||||
PoiFiltersHelper.editPoiFilter(helper, filter);
|
||||
helper.editPoiFilter(filter);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -23,7 +23,6 @@ import net.osmand.Base64;
|
|||
import net.osmand.LogUtil;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.Version;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.AmenityType;
|
||||
|
@ -85,6 +84,7 @@ public class EditingPOIActivity {
|
|||
private Dialog dlg;
|
||||
private final Context ctx;
|
||||
private final OsmandMapTileView view;
|
||||
private final OsmandApplication app;
|
||||
private AutoCompleteTextView typeText;
|
||||
private EditText nameText;
|
||||
private Button typeButton;
|
||||
|
@ -95,9 +95,12 @@ public class EditingPOIActivity {
|
|||
|
||||
private final static Log log = LogUtil.getLog(EditingPOIActivity.class);
|
||||
|
||||
|
||||
|
||||
public EditingPOIActivity(final Context ctx, OsmandMapTileView view){
|
||||
this.ctx = ctx;
|
||||
|
||||
public EditingPOIActivity(Context uiContext, OsmandApplication app, OsmandMapTileView view){
|
||||
this.app = app;
|
||||
this.ctx = uiContext;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
|
@ -539,7 +542,7 @@ public class EditingPOIActivity {
|
|||
}
|
||||
|
||||
private void updateNodeInIndexes(String action, Node n){
|
||||
List<AmenityIndexRepository> repos = ResourceManager.getResourceManager().searchAmenityRepositories(n.getLatitude(), n.getLongitude());
|
||||
List<AmenityIndexRepository> repos = app.getResourceManager().searchAmenityRepositories(n.getLatitude(), n.getLongitude());
|
||||
if(DELETE_ACTION.equals(action)){
|
||||
for(AmenityIndexRepository r: repos){
|
||||
r.deleteAmenity(n.getId());
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
package net.osmand.activities;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.ProgressDialogImplementation;
|
||||
import net.osmand.R;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.Version;
|
||||
import net.osmand.activities.search.SearchActivity;
|
||||
import net.osmand.voice.CommandPlayer;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
@ -29,112 +18,68 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class MainMenuActivity extends Activity {
|
||||
|
||||
private static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
|
||||
private static boolean applicationAlreadyStarted = false;
|
||||
private static final String EXCEPTION_PATH = "/osmand/exception.log"; //$NON-NLS-1$
|
||||
private static final String EXCEPTION_FILE_SIZE = "/osmand/exception.log"; //$NON-NLS-1$
|
||||
|
||||
|
||||
private Button showMap;
|
||||
private Button settingsButton;
|
||||
private Button searchButton;
|
||||
private Button favouritesButton;
|
||||
private ProgressDialog progressDlg;
|
||||
|
||||
|
||||
|
||||
|
||||
public void startApplication(){
|
||||
if(!applicationAlreadyStarted){
|
||||
// Algoritms.removeAllFiles(new File(Environment.getExternalStorageDirectory(), "/osmand/tiles/Mapnik/18"));
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
|
||||
impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// initializing voice prolog subsystem
|
||||
|
||||
List<String> warnings = ResourceManager.getResourceManager().reloadIndexes(impl);
|
||||
impl.startTask(getString(R.string.voice_data_initializing), -1);
|
||||
String w = CommandPlayer.init(MainMenuActivity.this);
|
||||
if(w != null){
|
||||
warnings.add(w);
|
||||
}
|
||||
SavingTrackHelper helper = new SavingTrackHelper(MainMenuActivity.this);
|
||||
if (helper.hasDataToSave()) {
|
||||
impl.startTask(getString(R.string.saving_gpx_tracks), -1);
|
||||
warnings.addAll(helper.saveDataToGpx());
|
||||
}
|
||||
helper.close();
|
||||
showWarnings(warnings);
|
||||
} finally {
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
impl.run();
|
||||
applicationAlreadyStarted = true;
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
|
||||
|
||||
long size = getPreferences(MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0);
|
||||
final File file = new File(Environment.getExternalStorageDirectory(), EXCEPTION_PATH);
|
||||
if(file.exists() && file.length() > 0){
|
||||
if(size != file.length()){
|
||||
String msg = MessageFormat.format(getString(R.string.previous_run_crashed),
|
||||
EXCEPTION_PATH);
|
||||
Builder builder = new AlertDialog.Builder(MainMenuActivity.this);
|
||||
builder.setMessage(msg).setNeutralButton(getString(R.string.close), null);
|
||||
builder.setPositiveButton(R.string.send_report, new DialogInterface.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"osmand.app@gmail.com"}); //$NON-NLS-1$
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
||||
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append("\nDevice : ").append(Build.DEVICE); //$NON-NLS-1$
|
||||
text.append("\nBrand : ").append(Build.BRAND); //$NON-NLS-1$
|
||||
text.append("\nModel : ").append(Build.MODEL); //$NON-NLS-1$
|
||||
text.append("\nProduct : ").append(Build.PRODUCT); //$NON-NLS-1$
|
||||
text.append("\nBuild : ").append(Build.DISPLAY); //$NON-NLS-1$
|
||||
text.append("\nVersion : ").append(Build.VERSION.RELEASE); //$NON-NLS-1$
|
||||
text.append("\nApp Version : ").append(Version.APP_NAME_VERSION); //$NON-NLS-1$
|
||||
try {
|
||||
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
if (info != null) {
|
||||
text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
public void checkPreviousRunsForExceptions() {
|
||||
long size = getPreferences(MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0);
|
||||
final File file = new File(Environment.getExternalStorageDirectory(), OsmandApplication.EXCEPTION_PATH);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
if (size != file.length()) {
|
||||
String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH);
|
||||
Builder builder = new AlertDialog.Builder(MainMenuActivity.this);
|
||||
builder.setMessage(msg).setNeutralButton(getString(R.string.close), null);
|
||||
builder.setPositiveButton(R.string.send_report, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "osmand.app@gmail.com" }); //$NON-NLS-1$
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
||||
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append("\nDevice : ").append(Build.DEVICE); //$NON-NLS-1$
|
||||
text.append("\nBrand : ").append(Build.BRAND); //$NON-NLS-1$
|
||||
text.append("\nModel : ").append(Build.MODEL); //$NON-NLS-1$
|
||||
text.append("\nProduct : ").append(Build.PRODUCT); //$NON-NLS-1$
|
||||
text.append("\nBuild : ").append(Build.DISPLAY); //$NON-NLS-1$
|
||||
text.append("\nVersion : ").append(Build.VERSION.RELEASE); //$NON-NLS-1$
|
||||
text.append("\nApp Version : ").append(Version.APP_NAME_VERSION); //$NON-NLS-1$
|
||||
try {
|
||||
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
if (info != null) {
|
||||
text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
|
||||
} catch (NameNotFoundException e) {
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
|
||||
}
|
||||
|
||||
} else {
|
||||
if(size > 0){
|
||||
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit();
|
||||
}
|
||||
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (size > 0) {
|
||||
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,16 +127,8 @@ public class MainMenuActivity extends Activity {
|
|||
});
|
||||
|
||||
|
||||
// exitButton = (Button) findViewById(R.id.ExitButton);
|
||||
// exitButton.setVisibility(View.INVISIBLE);
|
||||
// exitButton.setOnClickListener(new OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// finishApplication();
|
||||
// }
|
||||
// });
|
||||
|
||||
startApplication();
|
||||
((OsmandApplication)getApplication()).checkApplicationIsBeingInitialized(this);
|
||||
checkPreviousRunsForExceptions();
|
||||
|
||||
SharedPreferences pref = getPreferences(MODE_WORLD_WRITEABLE);
|
||||
if(!pref.contains(FIRST_TIME_APP_RUN)){
|
||||
|
@ -212,43 +149,7 @@ public class MainMenuActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
protected void showWarnings(List<String> warnings) {
|
||||
if (!warnings.isEmpty()) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String w : warnings) {
|
||||
if(f){
|
||||
f = false;
|
||||
} else {
|
||||
b.append('\n');
|
||||
}
|
||||
b.append(w);
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(MainMenuActivity.this, b.toString(), Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected void finishApplication(){
|
||||
ResourceManager.getResourceManager().close();
|
||||
applicationAlreadyStarted = false;
|
||||
MainMenuActivity.this.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_SEARCH
|
||||
|
@ -260,38 +161,5 @@ public class MainMenuActivity extends Activity {
|
|||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
private class DefaultExceptionHandler implements UncaughtExceptionHandler {
|
||||
|
||||
private UncaughtExceptionHandler defaultHandler;
|
||||
|
||||
public DefaultExceptionHandler(){
|
||||
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable ex) {
|
||||
File file = new File(Environment.getExternalStorageDirectory(), EXCEPTION_PATH);
|
||||
try {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(out);
|
||||
ex.printStackTrace(printStream);
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Exception occured in thread " + thread.toString() + " : "). //$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()));
|
||||
|
||||
if(Environment.getExternalStorageDirectory().canRead()){
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
|
||||
writer.write(msg.toString());
|
||||
writer.close();
|
||||
}
|
||||
defaultHandler.uncaughtException(thread, ex);
|
||||
} catch (Exception e) {
|
||||
// swallow all exceptions
|
||||
Log.e(LogUtil.TAG, "Exception while handle other exception", e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -178,6 +178,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
setContentView(R.layout.main);
|
||||
((OsmandApplication)getApplication()).checkApplicationIsBeingInitialized(this);
|
||||
|
||||
mapView = (OsmandMapTileView) findViewById(R.id.MapView);
|
||||
mapView.setTrackBallDelegate(new OsmandMapTileView.OnTrackBallListener(){
|
||||
|
@ -192,7 +193,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
@Override
|
||||
public void tileDownloaded(DownloadRequest request) {
|
||||
if(request != null && !request.error && request.fileToSave != null){
|
||||
ResourceManager mgr = ResourceManager.getResourceManager();
|
||||
ResourceManager mgr = ((OsmandApplication)getApplication()).getResourceManager();
|
||||
mgr.tileDownloaded(request);
|
||||
}
|
||||
mapView.tileDownloaded(request);
|
||||
|
@ -201,7 +202,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
});
|
||||
|
||||
mapView.setMapLocationListener(this);
|
||||
routingHelper = RoutingHelper.getInstance(this);
|
||||
routingHelper = ((OsmandApplication) getApplication()).getRoutingHelper();
|
||||
|
||||
// 1. route layer
|
||||
routeLayer = new RouteLayer(routingHelper);
|
||||
|
@ -646,6 +647,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
sensorMgr.unregisterListener(this);
|
||||
sensorRegistered = false;
|
||||
currentLocationProvider = null;
|
||||
routingHelper.setUiActivity(null);
|
||||
|
||||
OsmandSettings.setLastKnownMapLocation(this, (float) mapView.getLatitude(), (float) mapView.getLongitude());
|
||||
OsmandSettings.setLastKnownMapZoom(this, mapView.getZoom());
|
||||
|
@ -709,7 +711,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
if(mapView.getMap() instanceof SQLiteTileSource){
|
||||
((SQLiteTileSource)mapView.getMap()).closeDB();
|
||||
}
|
||||
ResourceManager.getResourceManager().setMapSource(newSource);
|
||||
((OsmandApplication)getApplication()).getResourceManager().setMapSource(newSource);
|
||||
mapView.setMap(newSource);
|
||||
}
|
||||
|
||||
|
@ -717,15 +719,13 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
// TODO not commit it
|
||||
rendererLayer.setVisible(true);
|
||||
// rendererLayer.setVisible(true);
|
||||
|
||||
if(OsmandSettings.getMapOrientation(this) != getRequestedOrientation()){
|
||||
setRequestedOrientation(OsmandSettings.getMapOrientation(this));
|
||||
}
|
||||
currentScreenOrientation = getWindow().getWindowManager().getDefaultDisplay().getOrientation();
|
||||
|
||||
// routing helper with current activity
|
||||
routingHelper = RoutingHelper.getInstance(this);
|
||||
ITileSource source = OsmandSettings.getMapTileSource(this);
|
||||
if(!Algoritms.objectEquals(mapView.getMap(), source)){
|
||||
updateMapSource(source);
|
||||
|
@ -734,10 +734,10 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
updateApplicationModeSettings();
|
||||
|
||||
favoritesLayer.reloadFavorites(this);
|
||||
poiMapLayer.setFilter(OsmandSettings.getPoiFilterForMap(this));
|
||||
poiMapLayer.setFilter(OsmandSettings.getPoiFilterForMap(this, (OsmandApplication) getApplication()));
|
||||
backToLocation.setVisibility(View.INVISIBLE);
|
||||
|
||||
|
||||
routingHelper.setUiActivity(this);
|
||||
|
||||
|
||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
|
@ -821,12 +821,6 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
ResourceManager.getResourceManager().onLowMemory();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void locationChanged(double newLatitude, double newLongitude, Object source) {
|
||||
|
@ -1105,7 +1099,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
int height = (int) (FloatMath.ceil(tilesRect.bottom) - top);
|
||||
for (int i = 0; i <width; i++) {
|
||||
for (int j = 0; j< height; j++) {
|
||||
ResourceManager.getResourceManager().clearTileImageForMap(null, mapView.getMap(), i + left, j + top, zoom);
|
||||
((OsmandApplication)getApplication()).getResourceManager().
|
||||
clearTileImageForMap(null, mapView.getMap(), i + left, j + top, zoom);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1132,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
Toast.makeText(this, getString(R.string.update_poi_is_not_available_for_zoom), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
final List<AmenityIndexRepository> repos = ResourceManager.getResourceManager().searchAmenityRepositories(latitude, longitude);
|
||||
final List<AmenityIndexRepository> repos = ((OsmandApplication) getApplication()).
|
||||
getResourceManager().searchAmenityRepositories(latitude, longitude);
|
||||
if(repos.isEmpty()){
|
||||
Toast.makeText(this, getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
@ -1250,7 +1246,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
final List<PoiFilter> userDefined = new ArrayList<PoiFilter>();
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(getString(R.string.any_poi));
|
||||
for(PoiFilter f : PoiFiltersHelper.getUserDefinedPoiFilters(this)){
|
||||
|
||||
final PoiFiltersHelper poiFilters = ((OsmandApplication)getApplication()).getPoiFilters();
|
||||
for(PoiFilter f : poiFilters.getUserDefinedPoiFilters()){
|
||||
if (!f.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)) {
|
||||
userDefined.add(f);
|
||||
list.add(f.getName());
|
||||
|
@ -1273,7 +1271,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
filterId = PoiFiltersHelper.getOsmDefinedFilterId(AmenityType.values()[which - userDefined.size() - 1]);
|
||||
}
|
||||
OsmandSettings.setPoiFilterForMap(MapActivity.this, filterId);
|
||||
poiMapLayer.setFilter(PoiFiltersHelper.getFilterById(MapActivity.this, filterId));
|
||||
poiMapLayer.setFilter(poiFilters.getFilterById(filterId));
|
||||
mapView.refreshMap();
|
||||
}
|
||||
|
||||
|
@ -1342,7 +1340,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
} else if(which == 3){
|
||||
addFavouritePoint(latitude, longitude);
|
||||
} else if(which == 4){
|
||||
EditingPOIActivity activity = new EditingPOIActivity(MapActivity.this, mapView);
|
||||
EditingPOIActivity activity = new EditingPOIActivity(MapActivity.this, (OsmandApplication) getApplication(), mapView);
|
||||
activity.showCreateDialog(latitude, longitude);
|
||||
} else if(which == 5){
|
||||
osmBugsLayer.openBug(MapActivity.this, getLayoutInflater(), mapView, latitude, longitude);
|
||||
|
|
|
@ -1,14 +1,200 @@
|
|||
package net.osmand.activities;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.PoiFiltersHelper;
|
||||
import net.osmand.ProgressDialogImplementation;
|
||||
import net.osmand.R;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.voice.CommandPlayer;
|
||||
import android.app.Application;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class OsmandApplication extends Application {
|
||||
public static final String EXCEPTION_PATH = "/osmand/exception.log"; //$NON-NLS-1$
|
||||
|
||||
ResourceManager manager = null;
|
||||
PoiFiltersHelper poiFilters = null;
|
||||
RoutingHelper routingHelper = null;
|
||||
CommandPlayer player;
|
||||
|
||||
|
||||
// start variables
|
||||
private ProgressDialogImplementation startDialog;
|
||||
private List<String> startingWarnings;
|
||||
private ProgressDialog progressDlg;
|
||||
private Handler uiHandler;
|
||||
|
||||
|
||||
|
||||
|
||||
public void onCreate(){
|
||||
super.onCreate();
|
||||
manager = new ResourceManager();
|
||||
uiHandler = new Handler();
|
||||
startApplication();
|
||||
}
|
||||
|
||||
public PoiFiltersHelper getPoiFilters() {
|
||||
if(poiFilters == null){
|
||||
poiFilters = new PoiFiltersHelper(this);
|
||||
}
|
||||
return poiFilters;
|
||||
}
|
||||
|
||||
public ResourceManager getResourceManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
manager.onLowMemory();
|
||||
}
|
||||
|
||||
public void checkApplicationIsBeingInitialized(Context uiContext){
|
||||
synchronized (OsmandApplication.this) {
|
||||
if(startDialog != null){
|
||||
progressDlg = ProgressDialog.show(uiContext, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
startDialog.setDialog(progressDlg);
|
||||
} else if(startingWarnings != null){
|
||||
showWarnings(startingWarnings, uiContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RoutingHelper getRoutingHelper() {
|
||||
return routingHelper;
|
||||
}
|
||||
|
||||
public CommandPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String initCommandPlayer(){
|
||||
if(player == null){
|
||||
player = new CommandPlayer(OsmandApplication.this);
|
||||
}
|
||||
return player.init();
|
||||
}
|
||||
|
||||
public void startApplication() {
|
||||
startDialog = new ProgressDialogImplementation(this, null, false);
|
||||
|
||||
startDialog.setRunnable("Initializing app", new Runnable() { //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<String> warnings = null;
|
||||
try {
|
||||
warnings = manager.reloadIndexes(startDialog);
|
||||
String voice = OsmandSettings.getVoiceProvider(OsmandApplication.this);
|
||||
player = null;
|
||||
if(voice != null){
|
||||
startDialog.startTask(getString(R.string.voice_data_initializing), -1);
|
||||
String w = initCommandPlayer();
|
||||
if (w != null) {
|
||||
warnings.add(w);
|
||||
}
|
||||
}
|
||||
routingHelper = new RoutingHelper(OsmandSettings.getApplicationMode(OsmandApplication.this), OsmandApplication.this, player);
|
||||
SavingTrackHelper helper = new SavingTrackHelper(OsmandApplication.this);
|
||||
if (helper.hasDataToSave()) {
|
||||
startDialog.startTask(getString(R.string.saving_gpx_tracks), -1);
|
||||
warnings.addAll(helper.saveDataToGpx());
|
||||
}
|
||||
helper.close();
|
||||
|
||||
} finally {
|
||||
synchronized (OsmandApplication.this) {
|
||||
startDialog = null;
|
||||
if (progressDlg != null) {
|
||||
progressDlg.dismiss();
|
||||
showWarnings(warnings, progressDlg.getContext());
|
||||
progressDlg = null;
|
||||
} else {
|
||||
startingWarnings = warnings;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
startDialog.run();
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
|
||||
|
||||
}
|
||||
|
||||
protected void showWarnings(List<String> warnings, final Context uiContext) {
|
||||
if (warnings != null && !warnings.isEmpty()) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String w : warnings) {
|
||||
if(f){
|
||||
f = false;
|
||||
} else {
|
||||
b.append('\n');
|
||||
}
|
||||
b.append(w);
|
||||
}
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(uiContext, b.toString(), Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class DefaultExceptionHandler implements UncaughtExceptionHandler {
|
||||
|
||||
private UncaughtExceptionHandler defaultHandler;
|
||||
|
||||
public DefaultExceptionHandler() {
|
||||
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable ex) {
|
||||
File file = new File(Environment.getExternalStorageDirectory(), EXCEPTION_PATH);
|
||||
try {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(out);
|
||||
ex.printStackTrace(printStream);
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Exception occured in thread " + thread.toString() + " : "). //$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()));
|
||||
|
||||
if (Environment.getExternalStorageDirectory().canRead()) {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
|
||||
writer.write(msg.toString());
|
||||
writer.close();
|
||||
}
|
||||
defaultHandler.uncaughtException(thread, ex);
|
||||
} catch (Exception e) {
|
||||
// swallow all exceptions
|
||||
Log.e(LogUtil.TAG, "Exception while handle other exception", e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.osmand.activities.RouteProvider.RouteCalculationResult;
|
|||
import net.osmand.activities.RouteProvider.RouteService;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.voice.CommandPlayer;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
|
@ -32,9 +33,11 @@ public class RoutingHelper {
|
|||
|
||||
private List<IRouteInformationListener> listeners = new ArrayList<IRouteInformationListener>();
|
||||
|
||||
// activity to show messages & refresh map when route is calculated
|
||||
private Context context;
|
||||
|
||||
// activity to show messages & refresh map when route is calculated
|
||||
private Activity uiActivity;
|
||||
|
||||
private boolean isFollowingMode = false;
|
||||
|
||||
// instead of this properties RouteCalculationResult could be used
|
||||
|
@ -76,19 +79,12 @@ public class RoutingHelper {
|
|||
// END TEST CODE
|
||||
|
||||
|
||||
private RoutingHelper(){
|
||||
voiceRouter = new VoiceRouter(this);
|
||||
public RoutingHelper(ApplicationMode mode, Context context, CommandPlayer player){
|
||||
this.mode = mode;
|
||||
this.context = context;
|
||||
voiceRouter = new VoiceRouter(this, player);
|
||||
}
|
||||
|
||||
private static RoutingHelper INSTANCE = new RoutingHelper();
|
||||
public static RoutingHelper getInstance(Context ctx){
|
||||
INSTANCE.context = ctx;
|
||||
INSTANCE.voiceRouter.init(ctx);
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isFollowingMode() {
|
||||
return isFollowingMode;
|
||||
}
|
||||
|
@ -159,6 +155,10 @@ public class RoutingHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setUiActivity(Activity uiActivity) {
|
||||
this.uiActivity = uiActivity;
|
||||
}
|
||||
|
||||
public Location getCurrentLocation() {
|
||||
return lastFixedLocation;
|
||||
}
|
||||
|
@ -450,9 +450,9 @@ public class RoutingHelper {
|
|||
int[] dist = res.getListDistance();
|
||||
int l = dist != null && dist.length > 0 ? dist[0] : 0;
|
||||
showMessage(context.getString(R.string.new_route_calculated_dist) +" : "+ MapUtils.getFormattedDistance(l)); //$NON-NLS-1$
|
||||
if (context instanceof MapActivity) {
|
||||
if (uiActivity instanceof MapActivity) {
|
||||
// be aware that is non ui thread
|
||||
((MapActivity) context).getMapView().refreshMap();
|
||||
((MapActivity) uiActivity).getMapView().refreshMap();
|
||||
}
|
||||
} else {
|
||||
if (res.getErrorMessage() != null) {
|
||||
|
@ -473,11 +473,11 @@ public class RoutingHelper {
|
|||
}
|
||||
|
||||
private void showMessage(final String msg){
|
||||
if (context instanceof Activity) {
|
||||
((Activity)context).runOnUiThread(new Runnable() {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(uiActivity, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -438,7 +438,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
edit.putString(OsmandSettings.VOICE_PROVIDER, (String) newValue);
|
||||
}
|
||||
edit.commit();
|
||||
CommandPlayer.init(this);
|
||||
((OsmandApplication)getApplication()).initCommandPlayer();
|
||||
} else if (preference == tileSourcePreference) {
|
||||
edit.putString(OsmandSettings.MAP_TILE_SOURCES, (String) newValue);
|
||||
edit.commit();
|
||||
|
@ -460,7 +460,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
showWarnings(ResourceManager.getResourceManager().reloadIndexes(impl));
|
||||
showWarnings(((OsmandApplication)getApplication()).getResourceManager().reloadIndexes(impl));
|
||||
} finally {
|
||||
if(progressDlg !=null){
|
||||
progressDlg.dismiss();
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ShowRouteInfoActivity extends ListActivity {
|
|||
ListView lv = new ListView(this);
|
||||
lv.setId(android.R.id.list);
|
||||
header = new TextView(this);
|
||||
helper = RoutingHelper.getInstance(this);
|
||||
helper = ((OsmandApplication)getApplication()).getRoutingHelper();
|
||||
|
||||
lv.addHeaderView(header);
|
||||
setContentView(lv);
|
||||
|
@ -71,7 +71,7 @@ public class ShowRouteInfoActivity extends ListActivity {
|
|||
// large screen
|
||||
header.setTextSize(dm.scaledDensity * 23);
|
||||
}
|
||||
setListAdapter(new RouteInfoAdapter(RoutingHelper.getInstance(this).getRouteDirections()));
|
||||
setListAdapter(new RouteInfoAdapter(((OsmandApplication)getApplication()).getRoutingHelper().getRouteDirections()));
|
||||
}
|
||||
|
||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import net.osmand.activities.RoutingHelper.RouteDirectionInfo;
|
|||
import net.osmand.activities.RoutingHelper.TurnType;
|
||||
import net.osmand.voice.CommandPlayer;
|
||||
import net.osmand.voice.CommandPlayer.CommandBuilder;
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
public class VoiceRouter {
|
||||
|
@ -26,13 +25,14 @@ public class VoiceRouter {
|
|||
private int currentStatus = STATUS_UNKNOWN;
|
||||
|
||||
|
||||
public VoiceRouter(RoutingHelper router){
|
||||
public VoiceRouter(RoutingHelper router, CommandPlayer player){
|
||||
this.router = router;
|
||||
this.player = player;
|
||||
updateAppMode();
|
||||
}
|
||||
|
||||
protected void init(Context ctx){
|
||||
player = CommandPlayer.getInstance(ctx);
|
||||
public void setPlayer(CommandPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void setMute(boolean mute) {
|
||||
|
|
|
@ -6,8 +6,8 @@ import java.text.MessageFormat;
|
|||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.RegionAddressRepository;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.activities.MapActivity;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
|
@ -352,7 +352,7 @@ public class SearchAddressActivity extends Activity {
|
|||
|
||||
region = null;
|
||||
String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(SearchAddressActivity.this);
|
||||
region = ResourceManager.getResourceManager().getRegionRepository(lastSearchedRegion);
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(lastSearchedRegion);
|
||||
String progressMsg = null;
|
||||
// try to determine whether progress dialog & new thread needed
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.RegionAddressRepository;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.PostCode;
|
||||
|
@ -22,7 +22,7 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
if(region != null){
|
||||
postcode = region.getPostcode(OsmandSettings.getLastSearchedPostcode(this));
|
||||
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.RegionAddressRepository;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.data.PostCode;
|
||||
|
@ -21,7 +21,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
location = OsmandSettings.getLastKnownMapLocation(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city);
|
||||
|
|
|
@ -12,9 +12,9 @@ import net.osmand.LogUtil;
|
|||
import net.osmand.NameFinderPoiFilter;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.PoiFilter;
|
||||
import net.osmand.PoiFiltersHelper;
|
||||
import net.osmand.R;
|
||||
import net.osmand.activities.MapActivity;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
|
@ -101,7 +101,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
|
|||
setContentView(R.layout.searchpoi);
|
||||
Bundle bundle = this.getIntent().getExtras();
|
||||
String filterId = bundle.getString(AMENITY_FILTER);
|
||||
filter = PoiFiltersHelper.getFilterById(this, filterId);
|
||||
filter = ((OsmandApplication)getApplication()).getPoiFilters().getFilterById(filterId);
|
||||
|
||||
uiHandler = new Handler();
|
||||
searchPOILevel = (Button) findViewById(R.id.SearchPOILevelButton);
|
||||
|
|
|
@ -6,12 +6,12 @@ package net.osmand.activities.search;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.NameFinderPoiFilter;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.PoiFilter;
|
||||
import net.osmand.PoiFiltersHelper;
|
||||
import net.osmand.R;
|
||||
import net.osmand.activities.EditPOIFilterActivity;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.osm.LatLon;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
|
@ -78,9 +78,10 @@ public class SearchPoiFilterActivity extends ListActivity {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
List<PoiFilter> filters = new ArrayList<PoiFilter>(PoiFiltersHelper.getUserDefinedPoiFilters(this)) ;
|
||||
filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this));
|
||||
filters.add(NameFinderPoiFilter.getInstance());
|
||||
PoiFiltersHelper poiFilters = ((OsmandApplication)getApplication()).getPoiFilters();
|
||||
List<PoiFilter> filters = new ArrayList<PoiFilter>(poiFilters.getUserDefinedPoiFilters()) ;
|
||||
filters.addAll(poiFilters.getOsmDefinedPoiFilters());
|
||||
filters.add(poiFilters.getNameFinderPOIFilter());
|
||||
setListAdapter(new AmenityAdapter(filters));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.RegionAddressRepository;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -18,14 +18,14 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<Reg
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
((TextView)findViewById(R.id.Label)).setText(R.string.choose_available_region);
|
||||
if(ResourceManager.getResourceManager().getAddressRepositories().isEmpty()){
|
||||
if(((OsmandApplication)getApplication()).getResourceManager().getAddressRepositories().isEmpty()){
|
||||
Toast.makeText(this, R.string.none_region_found, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RegionAddressRepository> getObjects(String filter) {
|
||||
return new ArrayList<RegionAddressRepository>(ResourceManager.getResourceManager().getAddressRepositories());
|
||||
return new ArrayList<RegionAddressRepository>(((OsmandApplication)getApplication()).getResourceManager().getAddressRepositories());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.RegionAddressRepository;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
|
@ -24,7 +24,7 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
|||
private ProgressDialog progressDlg;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
if(region != null){
|
||||
postcode = region.getPostcode(OsmandSettings.getLastSearchedPostcode(this));
|
||||
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.RegionAddressRepository;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
|
@ -19,7 +19,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
|
|||
private PostCode postcode;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
if(region != null){
|
||||
postcode = region.getPostcode(OsmandSettings.getLastSearchedPostcode(this));
|
||||
if (postcode == null) {
|
||||
|
|
|
@ -11,9 +11,9 @@ import net.osmand.Algoritms;
|
|||
import net.osmand.Messages;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.TransportIndexRepository;
|
||||
import net.osmand.TransportIndexRepository.RouteInfoLocation;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.activities.TransportRouteHelper;
|
||||
import net.osmand.data.TransportRoute;
|
||||
import net.osmand.data.TransportStop;
|
||||
|
@ -144,7 +144,7 @@ public class SearchTransportActivity extends ListActivity {
|
|||
if (!routeCalculated && getLocationToStart() != null) {
|
||||
final LatLon locationToStart = getLocationToStart();
|
||||
final LatLon locationToGo = getLocationToGo();
|
||||
List<TransportIndexRepository> rs = ResourceManager.getResourceManager().searchTransportRepositories(locationToStart.getLatitude(),
|
||||
List<TransportIndexRepository> rs = ((OsmandApplication)getApplication()).getResourceManager().searchTransportRepositories(locationToStart.getLatitude(),
|
||||
locationToStart.getLongitude());
|
||||
if(!rs.isEmpty()){
|
||||
repo = rs.get(0);
|
||||
|
|
|
@ -5,13 +5,16 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.R;
|
||||
import net.osmand.osm.MapRenderObject;
|
||||
import net.osmand.osm.MapRenderingTypes;
|
||||
import net.osmand.osm.MapUtils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.DashPathEffect;
|
||||
|
@ -32,6 +35,7 @@ public class OsmandRenderer implements Comparator<MapRenderObject> {
|
|||
private Paint paintFill;
|
||||
private Paint paintFillWhite;
|
||||
|
||||
private Resources resources = null;
|
||||
|
||||
/// Colors
|
||||
private int clFillScreen = Color.rgb(241, 238, 232);
|
||||
|
@ -164,12 +168,37 @@ public class OsmandRenderer implements Comparator<MapRenderObject> {
|
|||
if (zoom > 15) {
|
||||
float x = (float) ((MapUtils.getTileNumberX(zoom, obj.getPointLongitude(0)) - leftTileX) * 256f);
|
||||
float y = (float) ((MapUtils.getTileNumberY(zoom, obj.getPointLatitude(0)) - topTileY) * 256f);
|
||||
paintFill.setColor(clPoint);
|
||||
canvas.drawCircle(x, y, 6, paintFill);
|
||||
int subType = MapRenderingTypes.getPointSubType(obj.getType());
|
||||
int type = MapRenderingTypes.getObjectType(obj.getType());
|
||||
if(type == MapRenderingTypes.HIGHWAY && subType == 38){
|
||||
if (zoom > 16) {
|
||||
drawBitmap(canvas, x, y, R.drawable.h_traffic_light);
|
||||
}
|
||||
} else {
|
||||
paintFill.setColor(clPoint);
|
||||
canvas.drawCircle(x, y, 6, paintFill);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Resources getResources() {
|
||||
|
||||
return resources;
|
||||
}
|
||||
public void setResources(Resources resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
private void drawBitmap(Canvas canvas, float x, float y, int resId){
|
||||
if(resources != null){
|
||||
Bitmap bmp = BitmapFactory.decodeResource(resources, resId);
|
||||
if(bmp != null){
|
||||
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHighway(MapRenderObject obj, Canvas canvas, double leftTileX, double topTileY, int zoom, float rotate) {
|
||||
if(obj.getPointsLength() == 0){
|
||||
return;
|
||||
|
|
|
@ -16,6 +16,7 @@ import net.osmand.osm.MapRenderObject;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.RectF;
|
||||
|
||||
|
@ -181,6 +182,10 @@ public class RenderMapsRepositories {
|
|||
|
||||
}
|
||||
|
||||
public void setResources(Resources resources){
|
||||
renderer.setResources(resources);
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
return bmp;
|
||||
}
|
||||
|
|
|
@ -35,8 +35,9 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
resourceManager = ResourceManager.getResourceManager();
|
||||
resourceManager = view.getApplication().getResourceManager();
|
||||
paintImg = new Paint();
|
||||
paintImg.setFilterBitmap(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +52,7 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
double rightLongitude = MapUtils.getLongitudeFromTile(view.getFloatZoom(), tileRect.right);
|
||||
resourceManager.updateRendererIfNeeded(topLatitude, leftLongitude, bottomLatitude, rightLongitude, view.getZoom());
|
||||
RenderMapsRepositories renderer = resourceManager.getRenderer();
|
||||
renderer.setResources(view.getResources());
|
||||
if (renderer != null && renderer.getBitmap() != null) {
|
||||
RectF newLoc = renderer.getCachedWaysLoc();
|
||||
double leftX1 = MapUtils.getTileNumberX(view.getFloatZoom(), newLoc.left);
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Map;
|
|||
import net.osmand.LogUtil;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.data.preparation.MapTileDownloader;
|
||||
import net.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||
import net.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
|
||||
|
@ -115,16 +116,20 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
Paint paintBitmap;
|
||||
|
||||
private DisplayMetrics dm;
|
||||
|
||||
private final OsmandApplication application;
|
||||
|
||||
|
||||
public OsmandMapTileView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initView();
|
||||
application = (OsmandApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
public OsmandMapTileView(Context context) {
|
||||
super(context);
|
||||
initView();
|
||||
application = (OsmandApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
/////////////////////////////// INITIALIZING UI PART ///////////////////////////////////
|
||||
|
@ -206,6 +211,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
public List<OsmandMapLayer> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
public OsmandApplication getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////// NON UI PART (could be extracted in common) /////////////////////////////
|
||||
|
@ -444,7 +453,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
canvas.rotate(rotate, w , h);
|
||||
try {
|
||||
if (showMapTiles) {
|
||||
ResourceManager mgr = ResourceManager.getResourceManager();
|
||||
ResourceManager mgr = getApplication().getResourceManager();
|
||||
boolean useInternet = OsmandSettings.isUsingInternetToDownloadTiles(getContext())
|
||||
&& map.couldBeDownloadedFromInternet();
|
||||
int maxLevel = Math.min(OsmandSettings.getMaximumLevelToDownloadTile(getContext()), map.getMaximumZoomSupported());
|
||||
|
@ -578,7 +587,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
|
||||
try {
|
||||
if (showMapTiles) {
|
||||
ResourceManager mgr = ResourceManager.getResourceManager();
|
||||
ResourceManager mgr = getApplication().getResourceManager();
|
||||
Bitmap bmp = mgr.getTileImageForMapSync(null, map, request.xTile, request.yTile, request.zoom, false);
|
||||
float x = (request.xTile - tileX) * getTileSize() + w;
|
||||
float y = (request.yTile - tileY) * getTileSize() + h;
|
||||
|
|
|
@ -101,7 +101,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen
|
|||
pointAltUI.setColor(Color.rgb(255, 128, 0));
|
||||
pointAltUI.setAlpha(200);
|
||||
pointAltUI.setAntiAlias(true);
|
||||
resourceManager = ResourceManager.getResourceManager();
|
||||
resourceManager = view.getApplication().getResourceManager();
|
||||
pixRect.set(0, 0, view.getWidth(), view.getHeight());
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen
|
|||
final Amenity a = (Amenity) o;
|
||||
actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_modify));
|
||||
actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_delete));
|
||||
final EditingPOIActivity edit = new EditingPOIActivity(view.getContext(), view);
|
||||
final EditingPOIActivity edit = new EditingPOIActivity(view.getContext(), view.getApplication(), view);
|
||||
return new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.TransportIndexRepository;
|
||||
import net.osmand.activities.search.SearchTransportActivity;
|
||||
import net.osmand.data.TransportStop;
|
||||
|
@ -89,7 +88,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo
|
|||
StringBuilder text = new StringBuilder(250);
|
||||
text.append(view.getContext().getString(R.string.transport_Stop)).append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getContext()))); //$NON-NLS-1$
|
||||
text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
List<TransportIndexRepository> reps = ResourceManager.getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude());
|
||||
List<TransportIndexRepository> reps = view.getApplication().getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude());
|
||||
if(!reps.isEmpty()){
|
||||
List<String> l;
|
||||
if(!useName){
|
||||
|
@ -135,7 +134,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo
|
|||
double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right);
|
||||
|
||||
objects.clear();
|
||||
ResourceManager.getResourceManager().searchTransportAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, view.getZoom(), objects);
|
||||
view.getApplication().getResourceManager().searchTransportAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, view.getZoom(), objects);
|
||||
int r = 3 * getRadiusPoi(view.getZoom()) / 4;
|
||||
for (TransportStop o : objects) {
|
||||
int x = view.getMapXForPoint(o.getLocation().getLongitude());
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
|
@ -39,7 +38,6 @@ public class CommandPlayer {
|
|||
public static final int VOICE_VERSION = 0;
|
||||
private static final Log log = LogUtil.getLog(CommandPlayer.class);
|
||||
|
||||
private static CommandPlayer instance = null;
|
||||
|
||||
protected Context ctx;
|
||||
// or zip file
|
||||
|
@ -55,36 +53,9 @@ public class CommandPlayer {
|
|||
private boolean playNext = true;
|
||||
private List<String> filesToPlay = Collections.synchronizedList(new ArrayList<String>());
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @return null could be returned it means there is no available voice config
|
||||
*/
|
||||
public static CommandPlayer getInstance(Context ctx) {
|
||||
init(ctx);
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public static String init(Context ctx){
|
||||
if(OsmandSettings.getVoiceProvider(ctx) == null && instance == null){
|
||||
return null;
|
||||
}
|
||||
if(instance == null){
|
||||
long time = System.currentTimeMillis();
|
||||
instance = new CommandPlayer(ctx);
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Initializing prolog system : " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
instance.ctx = ctx;
|
||||
if(!Algoritms.objectEquals(OsmandSettings.getVoiceProvider(ctx), instance.getCurrentVoice())){
|
||||
return instance.init();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CommandPlayer(Context ctx){
|
||||
public CommandPlayer(Context ctx){
|
||||
long time = System.currentTimeMillis();
|
||||
try {
|
||||
this.ctx = ctx;
|
||||
prologSystem = new Prolog(new String[]{"alice.tuprolog.lib.BasicLibrary"}); //$NON-NLS-1$
|
||||
|
@ -93,8 +64,12 @@ public class CommandPlayer {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
mediaPlayer = new MediaPlayer();
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Initializing prolog system : " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getCurrentVoice(){
|
||||
if(voiceDir == null){
|
||||
return null;
|
||||
|
@ -102,7 +77,7 @@ public class CommandPlayer {
|
|||
return voiceDir.getName();
|
||||
}
|
||||
|
||||
protected String init(){
|
||||
public String init(){
|
||||
String voiceProvider = OsmandSettings.getVoiceProvider(ctx);
|
||||
prologSystem.clearTheory();
|
||||
voiceDir = null;
|
||||
|
|
Loading…
Reference in a new issue