From 824dc02459aaa2914d08bd892c345564ae02b11b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 27 Jan 2013 01:38:11 +0100 Subject: [PATCH] API Refactoring (moving to interfaces) --- OsmAnd/src/net/osmand/LogUtil.java | 31 ++++++++++++++++++- .../plus/RegionAddressRepositoryBinary.java | 24 +++++++------- .../search/SearchByNameAbstractActivity.java | 7 ++--- .../search/SearchCityByNameActivity.java | 11 +++---- .../plus/render/NativeOsmandLibrary.java | 5 +++ 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/LogUtil.java b/OsmAnd/src/net/osmand/LogUtil.java index a3130b80fa..ba170d3d61 100644 --- a/OsmAnd/src/net/osmand/LogUtil.java +++ b/OsmAnd/src/net/osmand/LogUtil.java @@ -1,5 +1,7 @@ package net.osmand; +import java.text.Collator; + import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -157,5 +159,32 @@ public class LogUtil { public static XmlPullParser newXMLPullParser() throws XmlPullParserException { return XmlPullParserFactory.newInstance().newPullParser(); - } + } + + public static net.osmand.Collator primaryCollator(){ + final Collator instance = Collator.getInstance(); + instance.setStrength(Collator.PRIMARY); + return new net.osmand.Collator() { + + @Override + public int compare(Object o1, Object o2) { + return instance.compare(o1, o2); + } + + @Override + public boolean equals(Object obj) { + return instance.equals(obj); + } + + @Override + public boolean equals(String source, String target) { + return instance.equals(source, target); + } + + @Override + public int compare(String source, String target) { + return instance.compare(source, target); + } + }; + } } diff --git a/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java index 5731432f6d..a9f8bf16a5 100644 --- a/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java @@ -2,15 +2,14 @@ package net.osmand.plus; import java.io.IOException; -import java.text.Collator; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.TreeMap; +import net.osmand.Collator; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.LogUtil; @@ -41,11 +40,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { public RegionAddressRepositoryBinary(BinaryMapIndexReader file, String name) { this.file = file; this.region = name; - this.collator = Collator.getInstance(Locale.US); - this.collator.setStrength(Collator.PRIMARY); //ignores also case - Collator sortcollator = Collator.getInstance(); - sortcollator.setStrength(Collator.PRIMARY); //ignores also case - this.postCodes = new TreeMap(sortcollator); + this.collator = LogUtil.primaryCollator(); + this.postCodes = new TreeMap(LogUtil.primaryCollator()); } @Override @@ -140,9 +136,10 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { if (/*name.length() >= 2 && Algoritms.containsDigit(name) && */searchVillages) { // also try to identify postcodes String uName = name.toUpperCase(); - for (City code : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), - new CollatorStringMatcher(collator, uName, StringMatcherMode.CHECK_CONTAINS), false, - BinaryMapAddressReaderAdapter.POSTCODES_TYPE)) { + List foundCities = file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), + new CollatorStringMatcher(uName, StringMatcherMode.CHECK_CONTAINS), false, + BinaryMapAddressReaderAdapter.POSTCODES_TYPE); + for (City code : foundCities) { citiesToFill.add(code); if (resultMatcher.isCancelled()) { return citiesToFill; @@ -165,9 +162,10 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { int initialsize = citiesToFill.size(); if (/*name.length() >= 3 && */searchVillages) { - for (City c : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), - new CollatorStringMatcher(collator, name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), useEnglishNames, - BinaryMapAddressReaderAdapter.VILLAGES_TYPE)) { + List foundCities = file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), + new CollatorStringMatcher(name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), useEnglishNames, + BinaryMapAddressReaderAdapter.VILLAGES_TYPE); + for (City c : foundCities) { citiesToFill.add(c); if (resultMatcher.isCancelled()) { return citiesToFill; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java index 527207f429..af0b8968ee 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java @@ -1,15 +1,15 @@ package net.osmand.plus.activities.search; -import java.text.Collator; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; +import net.osmand.Collator; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.LogUtil; @@ -87,8 +87,7 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity final NamesAdapter namesAdapter = new NamesAdapter(new ArrayList(), createComparator()); //$NON-NLS-1$ setListAdapter(namesAdapter); - collator = Collator.getInstance(Locale.US); - collator.setStrength(Collator.PRIMARY); //ignores also case + collator = LogUtil.primaryCollator(); progress = (ProgressBar) findViewById(R.id.ProgressBar); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java index c8983566ae..e1524cf625 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java @@ -1,12 +1,12 @@ package net.osmand.plus.activities.search; -import java.text.Collator; import java.util.Collection; import java.util.Comparator; import java.util.List; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; +import net.osmand.LogUtil; import net.osmand.ResultMatcher; import net.osmand.data.City; import net.osmand.data.City.CityType; @@ -54,10 +54,9 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity @Override protected Comparator createComparator() { - final Collator cs = Collator.getInstance(); final boolean en = getMyApplication().getSettings().usingEnglishNames(); final StringMatcherMode startsWith = CollatorStringMatcher.StringMatcherMode.CHECK_ONLY_STARTS_WITH; - return new CityComparator(startsWith, cs, en); + return new CityComparator(startsWith, en); } @Override @@ -175,13 +174,13 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity private final class CityComparator implements Comparator { private final StringMatcherMode startsWith; - private final Collator cs; + private final net.osmand.Collator cs; private final boolean en; - private CityComparator(StringMatcherMode startsWith, Collator cs, + private CityComparator(StringMatcherMode startsWith, boolean en) { this.startsWith = startsWith; - this.cs = cs; + this.cs = LogUtil.primaryCollator(); this.en = en; } diff --git a/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java b/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java index afcb211e4d..ceaf76c74a 100644 --- a/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java +++ b/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java @@ -6,6 +6,7 @@ import net.osmand.NativeLibrary; import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.render.RenderingRuleSearchRequest; import net.osmand.render.RenderingRulesStorage; +import net.osmand.router.RouteSegmentResult; import org.apache.commons.logging.Log; @@ -32,6 +33,9 @@ public class NativeOsmandLibrary extends NativeLibrary { System.loadLibrary("gnustl_shared"); log.debug("Loading native cpufeatures_proxy..."); //$NON-NLS-1$ System.loadLibrary("cpufeatures_proxy"); +// log.debug("Loading load routing test..."); //$NON-NLS-1$ +// System.loadLibrary("routing_test_jar"); +// testRoutingPing(); if(android.os.Build.VERSION.SDK_INT >= 8) { log.debug("Loading jnigraphics, since Android >= 2.2 ..."); //$NON-NLS-1$ System.loadLibrary("jnigraphics"); @@ -100,4 +104,5 @@ public class NativeOsmandLibrary extends NativeLibrary { public static native int getCpuCount(); public static native boolean cpuHasNeonSupport(); + }