From 8c9fecb434be33d90085eb9652cfaaaff9c1b4e6 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 5 Sep 2010 18:23:51 +0000 Subject: [PATCH] create fully functional osmand application object git-svn-id: https://osmand.googlecode.com/svn/trunk@488 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/net/osmand/ToDoConstants.java | 2 +- OsmAnd/res/drawable/h_traffic_light.png | Bin 0 -> 1169 bytes .../src/net/osmand/NameFinderPoiFilter.java | 13 +- OsmAnd/src/net/osmand/NavigationService.java | 3 +- OsmAnd/src/net/osmand/OsmandSettings.java | 7 +- OsmAnd/src/net/osmand/PoiFilter.java | 14 +- OsmAnd/src/net/osmand/PoiFiltersHelper.java | 90 ++++--- .../osmand/ProgressDialogImplementation.java | 48 ++-- OsmAnd/src/net/osmand/ResourceManager.java | 13 +- .../activities/DownloadIndexActivity.java | 7 +- .../activities/EditPOIFilterActivity.java | 30 +-- .../osmand/activities/EditingPOIActivity.java | 11 +- .../osmand/activities/MainMenuActivity.java | 222 ++++-------------- .../net/osmand/activities/MapActivity.java | 36 ++- .../osmand/activities/OsmandApplication.java | 188 ++++++++++++++- .../net/osmand/activities/RoutingHelper.java | 34 +-- .../osmand/activities/SettingsActivity.java | 4 +- .../activities/ShowRouteInfoActivity.java | 4 +- .../net/osmand/activities/VoiceRouter.java | 8 +- .../search/SearchAddressActivity.java | 4 +- .../search/SearchBuildingByNameActivity.java | 4 +- .../search/SearchCityByNameActivity.java | 4 +- .../activities/search/SearchPOIActivity.java | 4 +- .../search/SearchPoiFilterActivity.java | 9 +- .../search/SearchRegionByNameActivity.java | 6 +- .../search/SearchStreet2ByNameActivity.java | 4 +- .../search/SearchStreetByNameActivity.java | 4 +- .../search/SearchTransportActivity.java | 4 +- .../src/net/osmand/render/OsmandRenderer.java | 33 ++- .../osmand/render/RenderMapsRepositories.java | 5 + .../src/net/osmand/render/RendererLayer.java | 4 +- .../net/osmand/views/OsmandMapTileView.java | 13 +- OsmAnd/src/net/osmand/views/POIMapLayer.java | 4 +- .../net/osmand/views/TransportStopsLayer.java | 5 +- .../src/net/osmand/voice/CommandPlayer.java | 39 +-- 35 files changed, 498 insertions(+), 382 deletions(-) create mode 100644 OsmAnd/res/drawable/h_traffic_light.png diff --git a/DataExtractionOSM/src/net/osmand/ToDoConstants.java b/DataExtractionOSM/src/net/osmand/ToDoConstants.java index fe502154aa..4db495e508 100644 --- a/DataExtractionOSM/src/net/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/net/osmand/ToDoConstants.java @@ -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 diff --git a/OsmAnd/res/drawable/h_traffic_light.png b/OsmAnd/res/drawable/h_traffic_light.png new file mode 100644 index 0000000000000000000000000000000000000000..1c2b3ca7b809175517a59d5f7e0d424c47223abe GIT binary patch literal 1169 zcmV;C1aA9@P)KLZ*U+lnSp_Ufq@}0xwybFAi#%#fq@|}KQEO56)-X|e7nZL z$iTqBa9P*U#mSX{G{Bl%P*lRez;J+pfx##xwK$o9f#C}S14DXwNkIt%17i#W1A|CX zc0maP17iUL1A|C*NRTrF17iyV0~1e4YDEbH0|SF|enDkXW_m`6f}y3QrGjHhep0GJ zaAk2xYHqQDXI^rCQ9*uDVo7QW0|Nup4h9AW240u^5(W3f%sd4{Q&k2kgNVo|1qcff zJ_s=cNG>fZg9jx8g8+jTgC9dB!zzXcjM9uzjPn?uG8r;8FkNESU~Xi-%VNVakCmA< zoAoN26WbJk(nbKDkms+R=!8UN0C?Yg3=V_C>14@ z*Q#698rA(YWHsJu?$es6ovLH4E2R5M?}+|ghuuQb_ zv9_>LwH2{rvHNQO+~Kz41*c=qdtJ7=u6JAMzSLup=R&Uq-V1#e`!4fa<-a~)YvA6X zW5MS`ZiPMz`x3zvDHx>`Z5-nk8x@xq-;yvpadXny#c{8Bv*4S+lbD&|w7H};LTeNub$E6O-CMYHnI*EOxbxzS)#$L0rHt+q|w{$Z!@u2p+D_NMPUen9P!e)1|n}r>^TY4rKi~dU{r?XDE({%upgajN0000WV@Og>004R=004l4 z008;_004mL004C`008P>0026e000+nl3&F}0002+Nklv0a#PAvIZ~$!7RS=JzE- zg1>FSL$fdozPIo+D0!%bI@H#}577hmUG<=Gth(mS(*%blpHd))k^&!|QczaXTYTdy zy`u|HgAVQ|>l0y{4BRh*#@<1)DK)5(y;zA#ni-lnK^a%(H7W_ffuQym;}OqPqgplz zBf@8Hjyh_IZF2LEB)jwpIr4POE-pDo9p|`2)fAovAEg*)SYw4#l;RO1Ep$ySE&LcC j7I searchedAmenities = new ArrayList(); - 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; } diff --git a/OsmAnd/src/net/osmand/NavigationService.java b/OsmAnd/src/net/osmand/NavigationService.java index 828bd2d919..dc299b99ee 100644 --- a/OsmAnd/src/net/osmand/NavigationService.java +++ b/OsmAnd/src/net/osmand/NavigationService.java @@ -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(){ diff --git a/OsmAnd/src/net/osmand/OsmandSettings.java b/OsmAnd/src/net/osmand/OsmandSettings.java index 14a0760e20..6ad5e25ad7 100644 --- a/OsmAnd/src/net/osmand/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/OsmandSettings.java @@ -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); } diff --git a/OsmAnd/src/net/osmand/PoiFilter.java b/OsmAnd/src/net/osmand/PoiFilter.java index 4a8d2ffa78..e45bba7694 100644 --- a/OsmAnd/src/net/osmand/PoiFilter.java +++ b/OsmAnd/src/net/osmand/PoiFilter.java @@ -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> acceptedTypes){ + public PoiFilter(String name, String filterId, Map> 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 searchFurther(double latitude, double longitude){ zoom --; - List amenityList = ResourceManager.getResourceManager().searchAmenities(this, latitude, longitude, zoom, -1); + List 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 initializeNewSearch(double lat, double lon, int firstTimeLimit){ zoom = getInitialZoom(); - List amenityList = ResourceManager.getResourceManager().searchAmenities(this, lat, lon, zoom, maxInitialCount); + List 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 amenityList = ResourceManager.getResourceManager().searchAmenities(this, lat, lon, zoom, limit); + List amenityList = application.getResourceManager().searchAmenities(this, lat, lon, zoom, limit); MapUtils.sortListOfMapObject(amenityList, lat, lon); return amenityList; } diff --git a/OsmAnd/src/net/osmand/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/PoiFiltersHelper.java index 589b9a311b..b8091174a3 100644 --- a/OsmAnd/src/net/osmand/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/PoiFiltersHelper.java @@ -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 cacheUserDefinedFilters; + private List 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 filters = getUserDefinedPoiFilters(ctx); + List filters = getUserDefinedPoiFilters(); for(PoiFilter f : filters){ if(f.getFilterId().equals(filterId)){ return f; } } } else if(filterId.startsWith(PoiFilter.STD_PREFIX)){ - List filters = getOsmDefinedPoiFilters(ctx); + List 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 getUserDefinedDefaultFilters(){ + private List getUserDefinedDefaultFilters(){ List filters = new ArrayList(); Map> types = new LinkedHashMap>(); @@ -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(); 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(); @@ -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 cacheUserDefinedFilters; - public static List getUserDefinedPoiFilters(Context ctx){ + public List getUserDefinedPoiFilters(){ if(cacheUserDefinedFilters == null){ ////ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME); cacheUserDefinedFilters = new ArrayList(); - PoiFilter filter = new PoiFilter(Messages.getMessage("poi_filter_custom_filter"), PoiFilter.CUSTOM_FILTER_ID, new LinkedHashMap>()); //$NON-NLS-1$ + PoiFilter filter = new PoiFilter(Messages.getMessage("poi_filter_custom_filter"), PoiFilter.CUSTOM_FILTER_ID, new LinkedHashMap>(), 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 cacheOsmDefinedFilters; - public static List getOsmDefinedPoiFilters(Context ctx){ + + public List getOsmDefinedPoiFilters(){ if(cacheOsmDefinedFilters == null){ cacheOsmDefinedFilters = new ArrayList(); - 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); } diff --git a/OsmAnd/src/net/osmand/ProgressDialogImplementation.java b/OsmAnd/src/net/osmand/ProgressDialogImplementation.java index f218cd5f42..7a2457f765 100644 --- a/OsmAnd/src/net/osmand/ProgressDialogImplementation.java +++ b/OsmAnd/src/net/osmand/ProgressDialogImplementation.java @@ -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); } diff --git a/OsmAnd/src/net/osmand/ResourceManager.java b/OsmAnd/src/net/osmand/ResourceManager.java index 34a8987845..48388ab59f 100644 --- a/OsmAnd/src/net/osmand/ResourceManager.java +++ b/OsmAnd/src/net/osmand/ResourceManager.java @@ -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 addressMap = new TreeMap(Collator.getInstance()); diff --git a/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java index 0e4a73557a..d34ef14ef8 100644 --- a/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java @@ -233,12 +233,13 @@ public class DownloadIndexActivity extends ListActivity { } ArrayList warnings = new ArrayList(); + 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)); diff --git a/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java b/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java index bf91c9e9ed..507d607f42 100644 --- a/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java +++ b/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java @@ -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); } } }); diff --git a/OsmAnd/src/net/osmand/activities/EditingPOIActivity.java b/OsmAnd/src/net/osmand/activities/EditingPOIActivity.java index 2135c49d3f..c7aac47dfb 100644 --- a/OsmAnd/src/net/osmand/activities/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/activities/EditingPOIActivity.java @@ -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 repos = ResourceManager.getResourceManager().searchAmenityRepositories(n.getLatitude(), n.getLongitude()); + List repos = app.getResourceManager().searchAmenityRepositories(n.getLatitude(), n.getLongitude()); if(DELETE_ACTION.equals(action)){ for(AmenityIndexRepository r: repos){ r.deleteAmenity(n.getId()); diff --git a/OsmAnd/src/net/osmand/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/activities/MainMenuActivity.java index 937fae4022..9116620c23 100644 --- a/OsmAnd/src/net/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/activities/MainMenuActivity.java @@ -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 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 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$ - } - - } - } - + } diff --git a/OsmAnd/src/net/osmand/activities/MapActivity.java b/OsmAnd/src/net/osmand/activities/MapActivity.java index f9693d7dce..f825108dfe 100644 --- a/OsmAnd/src/net/osmand/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/activities/MapActivity.java @@ -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 repos = ResourceManager.getResourceManager().searchAmenityRepositories(latitude, longitude); + final List 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 userDefined = new ArrayList(); List list = new ArrayList(); 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); diff --git a/OsmAnd/src/net/osmand/activities/OsmandApplication.java b/OsmAnd/src/net/osmand/activities/OsmandApplication.java index dc9e663764..a0e1c217bd 100644 --- a/OsmAnd/src/net/osmand/activities/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/activities/OsmandApplication.java @@ -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 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 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 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$ + } + + } } - } diff --git a/OsmAnd/src/net/osmand/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/activities/RoutingHelper.java index 49db7f03f9..82bc030d93 100644 --- a/OsmAnd/src/net/osmand/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/activities/RoutingHelper.java @@ -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 listeners = new ArrayList(); - // 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(); } }); } diff --git a/OsmAnd/src/net/osmand/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/activities/SettingsActivity.java index 507fa5f0a3..d5fdcae141 100644 --- a/OsmAnd/src/net/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/activities/SettingsActivity.java @@ -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(); diff --git a/OsmAnd/src/net/osmand/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/activities/ShowRouteInfoActivity.java index 120006fc6b..5cfc0dd467 100644 --- a/OsmAnd/src/net/osmand/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/activities/ShowRouteInfoActivity.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/activities/VoiceRouter.java b/OsmAnd/src/net/osmand/activities/VoiceRouter.java index e7080de158..1af2e8dc3d 100644 --- a/OsmAnd/src/net/osmand/activities/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/activities/VoiceRouter.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java index 63e8fdd4ce..0cd3861afa 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java @@ -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 diff --git a/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java index 775afe4666..ec70c1c57a 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java @@ -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 filters = new ArrayList(PoiFiltersHelper.getUserDefinedPoiFilters(this)) ; - filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this)); - filters.add(NameFinderPoiFilter.getInstance()); + PoiFiltersHelper poiFilters = ((OsmandApplication)getApplication()).getPoiFilters(); + List filters = new ArrayList(poiFilters.getUserDefinedPoiFilters()) ; + filters.addAll(poiFilters.getOsmDefinedPoiFilters()); + filters.add(poiFilters.getNameFinderPOIFilter()); setListAdapter(new AmenityAdapter(filters)); } diff --git a/OsmAnd/src/net/osmand/activities/search/SearchRegionByNameActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchRegionByNameActivity.java index 12af3c8168..ca7ced3aeb 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchRegionByNameActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchRegionByNameActivity.java @@ -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 getObjects(String filter) { - return new ArrayList(ResourceManager.getResourceManager().getAddressRepositories()); + return new ArrayList(((OsmandApplication)getApplication()).getResourceManager().getAddressRepositories()); } @Override diff --git a/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java index b8da8c927c..a879514f76 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java @@ -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 rs = ResourceManager.getResourceManager().searchTransportRepositories(locationToStart.getLatitude(), + List rs = ((OsmandApplication)getApplication()).getResourceManager().searchTransportRepositories(locationToStart.getLatitude(), locationToStart.getLongitude()); if(!rs.isEmpty()){ repo = rs.get(0); diff --git a/OsmAnd/src/net/osmand/render/OsmandRenderer.java b/OsmAnd/src/net/osmand/render/OsmandRenderer.java index 19fd345175..63ee76d9a7 100644 --- a/OsmAnd/src/net/osmand/render/OsmandRenderer.java +++ b/OsmAnd/src/net/osmand/render/OsmandRenderer.java @@ -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 { 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 { 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; diff --git a/OsmAnd/src/net/osmand/render/RenderMapsRepositories.java b/OsmAnd/src/net/osmand/render/RenderMapsRepositories.java index cd7e0616cb..dd7e8b8ce6 100644 --- a/OsmAnd/src/net/osmand/render/RenderMapsRepositories.java +++ b/OsmAnd/src/net/osmand/render/RenderMapsRepositories.java @@ -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; } diff --git a/OsmAnd/src/net/osmand/render/RendererLayer.java b/OsmAnd/src/net/osmand/render/RendererLayer.java index 31d59605f9..42663a1d44 100644 --- a/OsmAnd/src/net/osmand/render/RendererLayer.java +++ b/OsmAnd/src/net/osmand/render/RendererLayer.java @@ -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); diff --git a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java index 8729840311..053c4cca57 100644 --- a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java @@ -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 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; diff --git a/OsmAnd/src/net/osmand/views/POIMapLayer.java b/OsmAnd/src/net/osmand/views/POIMapLayer.java index b6ae35cb14..dc999fa328 100644 --- a/OsmAnd/src/net/osmand/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/views/POIMapLayer.java @@ -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 diff --git a/OsmAnd/src/net/osmand/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/views/TransportStopsLayer.java index bfad635640..b3277e4032 100644 --- a/OsmAnd/src/net/osmand/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/views/TransportStopsLayer.java @@ -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 reps = ResourceManager.getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude()); + List reps = view.getApplication().getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude()); if(!reps.isEmpty()){ List 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()); diff --git a/OsmAnd/src/net/osmand/voice/CommandPlayer.java b/OsmAnd/src/net/osmand/voice/CommandPlayer.java index fe4c4041d0..052bac4f83 100644 --- a/OsmAnd/src/net/osmand/voice/CommandPlayer.java +++ b/OsmAnd/src/net/osmand/voice/CommandPlayer.java @@ -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 filesToPlay = Collections.synchronizedList(new ArrayList()); - /** - * @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;