Speed up load / start fixing poi current location bugs

This commit is contained in:
Victor Shcherb 2015-04-15 18:05:26 +02:00
parent db41c59938
commit e83021c57f
10 changed files with 130 additions and 130 deletions

View file

@ -209,18 +209,25 @@ public class MapPoiTypes {
sortList(categories);
}
public void init() {
init(null);
}
public void init(){
public void init(String resourceName) {
InputStream is;
long time = System.currentTimeMillis();
List<PoiType> referenceTypes = new ArrayList<PoiType>();
final Map<String, PoiType> allTypes = new LinkedHashMap<String, PoiType>();
if(resourceName != null) {
this.resourceName = resourceName;
}
try {
if(resourceName == null){
is = MapRenderingTypes.class.getResourceAsStream("poi_types.xml"); //$NON-NLS-1$
if (this.resourceName == null) {
is = MapPoiTypes.class.getResourceAsStream("poi_types.xml"); //$NON-NLS-1$
} else {
is = new FileInputStream(resourceName);
is = new FileInputStream(this.resourceName);
}
long time = System.currentTimeMillis();
time = System.currentTimeMillis();
XmlPullParser parser = PlatformUtil.newXMLPullParser();
int tok;
parser.setInput(is, "UTF-8");
@ -230,62 +237,58 @@ public class MapPoiTypes {
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) {
String name = parser.getName();
if (name.equals("poi_category")) {
lastCategory = new PoiCategory(this, parser.getAttributeValue("","name"), categories.size());
lastCategory.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("","top")));
if (name.equals("poi_category")) {
lastCategory = new PoiCategory(this, parser.getAttributeValue("", "name"), categories.size());
lastCategory.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
categories.add(lastCategory);
} else if (name.equals("poi_filter")) {
PoiFilter tp = new PoiFilter(this, lastCategory,
parser.getAttributeValue("", "name"));
tp.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("","top")));
PoiFilter tp = new PoiFilter(this, lastCategory, parser.getAttributeValue("", "name"));
tp.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
lastFilter = tp;
lastCategory.addPoiType(tp);
} else if(name.equals("poi_reference")){
PoiType tp = new PoiType(this,
lastCategory, parser.getAttributeValue("","name"));
} else if (name.equals("poi_reference")) {
PoiType tp = new PoiType(this, lastCategory, parser.getAttributeValue("", "name"));
referenceTypes.add(tp);
tp.setReferenceType(tp);
if(lastFilter != null) {
if (lastFilter != null) {
lastFilter.addPoiType(tp);
}
lastCategory.addPoiType(tp);
} else if(name.equals("poi_additional")){
PoiType tp = new PoiType(this,
lastCategory, parser.getAttributeValue("","name"));
tp.setOsmTag(parser.getAttributeValue("","tag"));
tp.setOsmValue(parser.getAttributeValue("","value"));
tp.setOsmTag2(parser.getAttributeValue("","tag2"));
tp.setOsmValue2(parser.getAttributeValue("","value2"));
if(lastType != null) {
} else if (name.equals("poi_additional")) {
PoiType tp = new PoiType(this, lastCategory, parser.getAttributeValue("", "name"));
tp.setOsmTag(parser.getAttributeValue("", "tag"));
tp.setOsmValue(parser.getAttributeValue("", "value"));
tp.setOsmTag2(parser.getAttributeValue("", "tag2"));
tp.setOsmValue2(parser.getAttributeValue("", "value2"));
if (lastType != null) {
lastType.addPoiAdditional(tp);
} else if(lastFilter != null) {
} else if (lastFilter != null) {
lastFilter.addPoiAdditional(tp);
} else if(lastCategory != null) {
} else if (lastCategory != null) {
lastCategory.addPoiAdditional(tp);
}
} else if(name.equals("poi_type")){
PoiType tp = new PoiType(this,
lastCategory, parser.getAttributeValue("","name"));
tp.setOsmTag(parser.getAttributeValue("","tag"));
tp.setOsmValue(parser.getAttributeValue("","value"));
tp.setOsmTag2(parser.getAttributeValue("","tag2"));
tp.setOsmValue2(parser.getAttributeValue("","value2"));
} else if (name.equals("poi_type")) {
PoiType tp = new PoiType(this, lastCategory, parser.getAttributeValue("", "name"));
tp.setOsmTag(parser.getAttributeValue("", "tag"));
tp.setOsmValue(parser.getAttributeValue("", "value"));
tp.setOsmTag2(parser.getAttributeValue("", "tag2"));
tp.setOsmValue2(parser.getAttributeValue("", "value2"));
lastType = tp;
if(lastFilter != null) {
if (lastFilter != null) {
lastFilter.addPoiType(tp);
}
allTypes.put(tp.getKeyName(), tp);
lastCategory.addPoiType(tp);
}
} else if (tok == XmlPullParser.END_TAG) {
String name = parser.getName();
if (name.equals("poi_filter")) {
if (name.equals("poi_filter")) {
lastFilter = null;
} else if (name.equals("poi_type")) {
} else if (name.equals("poi_type")) {
lastType = null;
}
}
}
}
log.info("Time to init poi types" + (System.currentTimeMillis() - time)); //$NON-NLS-1$
is.close();
} catch (IOException e) {
log.error("Unexpected error", e); //$NON-NLS-1$
@ -301,7 +304,7 @@ public class MapPoiTypes {
throw new RuntimeException(e);
}
for (PoiType gt : referenceTypes) {
PoiType pt = getPoiTypeByKey(gt.keyName);
PoiType pt = allTypes.get(gt.getKeyName());
if (pt == null || pt.getOsmTag() == null) {
throw new IllegalStateException("Can't find poi type for poi reference '" + gt.keyName + "'");
} else {
@ -310,6 +313,7 @@ public class MapPoiTypes {
}
findDefaultOtherCategory();
init = true;
log.info("Time to init poi types " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
}
private void findDefaultOtherCategory() {

View file

@ -1,14 +1,14 @@
package net.osmand.plus;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
@ -39,16 +39,15 @@ import net.osmand.util.Algorithms;
import org.xmlpull.v1.XmlPullParserException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import btools.routingapp.BRouterServiceConnection;
/**
@ -245,7 +244,11 @@ public class AppInitializer implements IProgress {
private void initPoiTypes() {
app.poiTypes.init();
if(app.getAppPath("poi_types.xml").exists()) {
app.poiTypes.init(app.getAppPath("poi_types.xml").getAbsolutePath());
} else {
app.poiTypes.init();
}
app.poiTypes.setPoiTranslator(new MapPoiTypes.PoiTranslator() {
@Override
@ -374,7 +377,7 @@ public class AppInitializer implements IProgress {
notifyEvent(InitEvents.FAVORITES_INITIALIZED);
// init poi types before indexes and before POI
initPoiTypes();
notifyEvent(InitEvents.POI_TYPES_INITIALIZED);
app.resourceManager.reloadIndexesOnStart(this, warnings);
app.resourceManager.initRenderers(this);
@ -473,6 +476,7 @@ public class AppInitializer implements IProgress {
LOG.info("Native library could not be loaded!");
}
}
app.getResourceManager().initMapBoundariesCacheNative();
}
}

View file

@ -4,10 +4,25 @@
package net.osmand.plus.activities;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiLegacyFilter;
import net.osmand.util.Algorithms;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.view.LayoutInflater;
@ -23,26 +38,6 @@ import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import net.osmand.data.LatLon;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.activities.search.SearchPOIActivity;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiLegacyFilter;
import net.osmand.util.Algorithms;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
*
*/
@ -50,8 +45,6 @@ public class EditPOIFilterActivity extends OsmandListActivity {
public static final String AMENITY_FILTER = "net.osmand.amenity_filter"; //$NON-NLS-1$
private PoiLegacyFilter filter;
private PoiFiltersHelper helper;
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; //$NON-NLS-1$
public static final String SEARCH_LON = SearchActivity.SEARCH_LON; //$NON-NLS-1$
private static final int FILTER = 2;
public static final int EDIT_ACTIVITY_RESULT_OK = 20;
@ -113,34 +106,6 @@ public class EditPOIFilterActivity extends OsmandListActivity {
return super.onCreateOptionsMenu(menu);
}
private void filterPOI() {
Bundle extras = getIntent().getExtras();
boolean searchNearBy = true;
LatLon lastKnownMapLocation = ((OsmandApplication) getApplication()).getSettings().getLastKnownMapLocation();
double latitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLatitude() : 0;
double longitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLongitude() : 0;
final Intent newIntent = new Intent(EditPOIFilterActivity.this, SearchPOIActivity.class);
if(extras != null && extras.containsKey(SEARCH_LAT) && extras.containsKey(SEARCH_LON)){
latitude = extras.getDouble(SEARCH_LAT);
longitude = extras.getDouble(SEARCH_LON);
searchNearBy = false;
}
final double lat = latitude;
final double lon = longitude;
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
if (searchNearBy) {
startActivity(newIntent);
} else {
newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, lat);
newIntent.putExtra(SearchPOIActivity.SEARCH_LON, lon);
startActivity(newIntent);
}
}
private void showDialog(final PoiCategory poiCategory) {
ListView lv = EditPOIFilterActivity.this.getListView();

View file

@ -588,6 +588,9 @@ public class MapActivity extends AccessibleActivity {
LatLon loc = getMapLocation();
newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
if(mapViewTrackingUtilities.isMapLinkedToLocation()) {
newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true);
}
startActivity(newIntent);
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return true;

View file

@ -577,6 +577,9 @@ public class MapActivityActions implements DialogProvider {
LatLon loc = mapActivity.getMapLocation();
newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
if(mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true);
}
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mapActivity.startActivity(newIntent);
return true;

View file

@ -51,6 +51,7 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
private static final int REQUEST_FAVORITE_SELECT = 1;
private static final int REQUEST_ADDRESS_SELECT = 2;
public static final String SEARCH_NEARBY = "net.osmand.search_nearby"; //$NON-NLS-1$
public static final String SEARCH_LAT = "net.osmand.search_lat"; //$NON-NLS-1$
public static final String SEARCH_LON = "net.osmand.search_lon"; //$NON-NLS-1$
public static final String SHOW_ONLY_ONE_TAB = "SHOW_ONLY_ONE_TAB"; //$NON-NLS-1$

View file

@ -86,9 +86,10 @@ import android.widget.Toast;
public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompassListener, OsmAndLocationListener {
public static final String AMENITY_FILTER = "net.osmand.amenity_filter"; //$NON-NLS-1$
public static final String SEARCH_NEARBY = SearchActivity.SEARCH_NEARBY; //$NON-NLS-1$
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; //$NON-NLS-1$
public static final String SEARCH_LON = SearchActivity.SEARCH_LON; //$NON-NLS-1$
private static final float MIN_DISTANCE_TO_RESEARCH = 20;
private static final float MIN_DISTANCE_TO_RESEARCH = 100;
private static final float MIN_DISTANCE_TO_REFRESH = 5;
private static final int SEARCH_MORE = 0;
private static final int SHOW_ON_MAP = 1;
@ -257,11 +258,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
location = new net.osmand.Location("internal"); //$NON-NLS-1$
location.setLatitude(bundle.getDouble(SEARCH_LAT));
location.setLongitude(bundle.getDouble(SEARCH_LON));
searchNearBy = false;
} else {
location = null;
searchNearBy = true;
}
searchNearBy = bundle.containsKey(SEARCH_NEARBY);
String filterId = bundle.getString(AMENITY_FILTER);
this.filter = app.getPoiFilters().getFilterById(filterId);
@ -379,10 +377,13 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
Intent newIntent = new Intent(this, EditPOIFilterActivity.class);
// folder selected
newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, poi.getFilterId());
if(location != null && !searchNearBy) {
if(location != null) {
newIntent.putExtra(SearchActivity.SEARCH_LAT, location.getLatitude());
newIntent.putExtra(SearchActivity.SEARCH_LON, location.getLongitude());
}
if(searchNearBy) {
newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true);
}
startActivityForResult(newIntent, RESULT_REQUEST_CODE);
}

View file

@ -17,7 +17,6 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.EditPOIFilterActivity;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.poi.NominatimPoiFilter;
import net.osmand.plus.poi.PoiFiltersHelper;
@ -154,13 +153,16 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
loc = ((SearchActivity) parent).getSearchPoint();
searchAround = ((SearchActivity) parent).isSearchAroundCurrentLocation();
}
if (loc == null && !searchAround) {
if (loc == null) {
loc = getApp().getSettings().getLastKnownMapLocation();
}
if(loc != null && !searchAround) {
if(loc != null) {
intentToLaunch.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
intentToLaunch.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
}
if(searchAround) {
intentToLaunch.putExtra(SearchActivity.SEARCH_NEARBY, true);
}
}
@Override

View file

@ -246,12 +246,16 @@ public class MapRenderRepositories {
// check that everything is initialized
for (String mapName : files.keySet()) {
if (!nativeFiles.contains(mapName)) {
nativeFiles.add(mapName);
if (!library.initMapFile(mapName)) {
continue;
BinaryMapIndexReader fr = files.get(mapName);
if (fr != null && fr.containsMapData(leftX, topY, rightX, bottomY, zoom)) {
if (!nativeFiles.contains(mapName)) {
long time = System.currentTimeMillis();
nativeFiles.add(mapName);
if (!library.initMapFile(mapName)) {
continue;
}
log.debug("Native resource " + mapName + " initialized " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$
}
log.debug("Native resource " + mapName + " initialized"); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -34,6 +34,7 @@ import net.osmand.map.ITileSource;
import net.osmand.map.MapTileDownloader;
import net.osmand.map.MapTileDownloader.DownloadRequest;
import net.osmand.map.OsmandRegions;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.InitEvents;
@ -451,18 +452,19 @@ public class ResourceManager {
}
private List<String> checkAssets(IProgress progress) {
if (!Version.getFullVersion(context)
.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get())) {
String fv = Version.getFullVersion(context);
if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get())) {
File applicationDataDir = context.getAppPath(null);
applicationDataDir.mkdirs();
if(applicationDataDir.canWrite()){
if (applicationDataDir.canWrite()) {
try {
progress.startTask(context.getString(R.string.installing_new_resources), -1);
AssetManager assetManager = context.getAssets();
boolean isFirstInstall = context.getSettings().PREVIOUS_INSTALLED_VERSION.get().equals("");
unpackBundledAssets(assetManager, applicationDataDir, progress, isFirstInstall);
context.getSettings().PREVIOUS_INSTALLED_VERSION.set(Version.getFullVersion(context));
context.getSettings().PREVIOUS_INSTALLED_VERSION.set(fv);
copyRegionsBoundaries();
copyPoiTypes();
} catch (SQLiteException e) {
log.error(e.getMessage(), e);
} catch (IOException e) {
@ -486,6 +488,18 @@ public class ResourceManager {
log.error(e.getMessage(), e);
}
}
private void copyPoiTypes() {
try {
File file = context.getAppPath("poi_types.xml");
if (file != null) {
Algorithms.streamCopy(MapPoiTypes.class.getResourceAsStream("poi_types.xml"), new FileOutputStream(
file));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
private final static String ASSET_INSTALL_MODE__alwaysCopyOnFirstInstall = "alwaysCopyOnFirstInstall";
private final static String ASSET_COPY_MODE__overwriteOnlyIfExists = "overwriteOnlyIfExists";
@ -691,7 +705,6 @@ public class ResourceManager {
log.error("Index file could not be written", e);
}
}
initMapBoundariesCacheNative();
return warnings;
}