Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
79f53d9a5c
8 changed files with 224 additions and 29 deletions
|
@ -34,8 +34,8 @@ import android.util.Log;
|
|||
// This class provides reverse mapping from 'embed-resources.list' to files&folders scheme used by OsmAndCore_android.aar package
|
||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
|
||||
public class CoreResourcesFromAndroidAssetsCustom extends interface_ICoreResourcesProvider {
|
||||
private static final String TAG = "CoreResourcesFromAndroidAssets";
|
||||
private static final String NATIVE_TAG = "CoreResourcesFromAndroidAssets";
|
||||
private static final String TAG = "CoreResFromAndAssets";
|
||||
private static final String NATIVE_TAG = "CoreResFromAndAssets";
|
||||
|
||||
private CoreResourcesFromAndroidAssetsCustom(final Context context) {
|
||||
_context = context;
|
||||
|
@ -84,7 +84,7 @@ public class CoreResourcesFromAndroidAssetsCustom extends interface_ICoreResourc
|
|||
}
|
||||
|
||||
// Get location of this resource
|
||||
final String path = "OsmAndCore_ResourcesBundle/" + resourceInBundle + ".qz";
|
||||
final String path = "OsmAndCore_ResourcesBundle/" + resourceInBundle + (resourceInBundle.endsWith(".png") ? "" : ".qz");
|
||||
final File extractedPath = ((OsmandApplication) _context.getApplicationContext()).getAppPath(path);
|
||||
final ResourceData resourceData = new ResourceData();
|
||||
if (!extractedPath.exists()) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:name=".SampleApplication"
|
||||
android:icon="@mipmap/sample_app"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
|
|
|
@ -18,7 +18,7 @@ android {
|
|||
// This is from OsmAndCore_android.aar - for some reason it's not inherited
|
||||
aaptOptions {
|
||||
// Don't compress any embedded resources
|
||||
noCompress "qz"
|
||||
noCompress "qz", "png"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
@ -27,7 +27,6 @@ android {
|
|||
jni.srcDirs = []
|
||||
jniLibs.srcDirs = ["libs"]
|
||||
java.srcDirs = ["src"]
|
||||
resources.srcDirs = ["src"]
|
||||
renderscript.srcDirs = ["src"]
|
||||
res.srcDirs = ["res"]
|
||||
assets.srcDirs = ["assets"]
|
||||
|
|
BIN
OsmAndCore-sample/libs/simple-logging.jar
Normal file
BIN
OsmAndCore-sample/libs/simple-logging.jar
Normal file
Binary file not shown.
151
OsmAndCore-sample/src/net/osmand/PlatformUtil.java
Normal file
151
OsmAndCore-sample/src/net/osmand/PlatformUtil.java
Normal file
|
@ -0,0 +1,151 @@
|
|||
package net.osmand;
|
||||
|
||||
import android.util.Xml;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
/**
|
||||
* That class is replacing of standard LogFactory due to
|
||||
* problems with Android implementation of LogFactory.
|
||||
*
|
||||
* 1. It is impossible to replace standard LogFactory (that is hidden in android.jar)
|
||||
* 2. Implementation of LogFactory always creates Logger.getLogger(String name)
|
||||
* 3. + It is possible to enable logger level by calling
|
||||
* Logger.getLogger("net.osmand").setLevel(Level.ALL);
|
||||
* 4. Logger goes to low level android.util.Log where android.util.Log#isLoggable(String, int) is checked
|
||||
* String tag -> is string of length 23 (stripped full class name)
|
||||
* 5. It is impossible to set for all tags debug level (info is default) - android.util.Log#isLoggable(String, int).
|
||||
*
|
||||
*/
|
||||
public class PlatformUtil {
|
||||
public static String TAG = "net.osmand"; //$NON-NLS-1$
|
||||
private static class OsmandLogImplementation implements Log {
|
||||
|
||||
private final String fullName;
|
||||
private final String name;
|
||||
|
||||
public OsmandLogImplementation(String name){
|
||||
this.fullName = name;
|
||||
this.name = fullName.substring(fullName.lastIndexOf('.') + 1);
|
||||
}
|
||||
@Override
|
||||
public void debug(Object message) {
|
||||
if(isDebugEnabled()){
|
||||
android.util.Log.d(TAG, name + " " + message); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(Object message, Throwable t) {
|
||||
if(isDebugEnabled()){
|
||||
android.util.Log.d(TAG, name + " " + message, t); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message) {
|
||||
if(isErrorEnabled()){
|
||||
android.util.Log.e(TAG, name + " " + message); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message, Throwable t) {
|
||||
if(isErrorEnabled()){
|
||||
android.util.Log.e(TAG, name + " " + message, t); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(Object message) {
|
||||
if(isFatalEnabled()){
|
||||
android.util.Log.e(TAG, name + " " + message); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(Object message, Throwable t) {
|
||||
if(isFatalEnabled()){
|
||||
android.util.Log.e(TAG, name + " " + message, t); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message) {
|
||||
if(isInfoEnabled()){
|
||||
android.util.Log.i(TAG, name + " " + message); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message, Throwable t) {
|
||||
if(isInfoEnabled()){
|
||||
android.util.Log.i(TAG, name + " " + message, t); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
// For debur purposes always true
|
||||
// return android.util.Log.isLoggable(NATIVE_TAG, android.util.Log.DEBUG);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return android.util.Log.isLoggable(TAG, android.util.Log.ERROR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFatalEnabled() {
|
||||
return android.util.Log.isLoggable(TAG, android.util.Log.ERROR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return android.util.Log.isLoggable(TAG, android.util.Log.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return android.util.Log.isLoggable(TAG, android.util.Log.WARN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message) {
|
||||
if(isWarnEnabled()){
|
||||
android.util.Log.w(TAG, name + " " + message); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message, Throwable t) {
|
||||
if(isWarnEnabled()){
|
||||
android.util.Log.w(TAG, name + " " + message, t); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Log getLog(String name){
|
||||
return new OsmandLogImplementation(name);
|
||||
}
|
||||
|
||||
public static Log getLog(Class<?> cl){
|
||||
return getLog(cl.getName());
|
||||
}
|
||||
|
||||
public static XmlPullParser newXMLPullParser() throws XmlPullParserException {
|
||||
// return XmlPullParserFactory.newInstance().newPullParser();
|
||||
return Xml.newPullParser();
|
||||
}
|
||||
|
||||
public static XmlSerializer newSerializer() {
|
||||
return Xml.newSerializer();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -40,6 +40,8 @@ import net.osmand.core.jni.MapRasterLayerProvider_Software;
|
|||
import net.osmand.core.jni.MapStylesCollection;
|
||||
import net.osmand.core.jni.ObfMapObjectsProvider;
|
||||
import net.osmand.core.jni.ObfsCollection;
|
||||
import net.osmand.core.jni.OsmAndCore;
|
||||
import net.osmand.core.jni.OsmAndCoreJNI;
|
||||
import net.osmand.core.jni.PointI;
|
||||
import net.osmand.core.jni.QIODeviceLogSink;
|
||||
import net.osmand.core.jni.ResolvedMapStyle;
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package net.osmand.core.samples.android.sample1;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Environment;
|
||||
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SampleApplication extends Application
|
||||
{
|
||||
private MapPoiTypes poiTypes;
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
|
||||
//initPoiTypes();
|
||||
}
|
||||
|
||||
public MapPoiTypes getPoiTypes() {
|
||||
return poiTypes;
|
||||
}
|
||||
|
||||
private void initPoiTypes() {
|
||||
poiTypes = MapPoiTypes.getDefaultNoInit();
|
||||
poiTypes.init(new File(Environment.getExternalStorageDirectory(), "poi_types.xml").getAbsolutePath());
|
||||
poiTypes.setPoiTranslator(new MapPoiTypes.PoiTranslator() {
|
||||
|
||||
@Override
|
||||
public String getTranslation(AbstractPoiType type) {
|
||||
if(type.getBaseLangType() != null) {
|
||||
return getTranslation(type.getBaseLangType()) + " (" + getLangTranslation(type.getLang()).toLowerCase() +")";
|
||||
}
|
||||
try {
|
||||
Field f = R.string.class.getField("poi_" + type.getIconKeyName());
|
||||
if (f != null) {
|
||||
Integer in = (Integer) f.get(null);
|
||||
return getString(in);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("No translation for "+ type.getIconKeyName() + " " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getLangTranslation(String l) {
|
||||
try {
|
||||
java.lang.reflect.Field f = R.string.class.getField("lang_"+l);
|
||||
if (f != null) {
|
||||
Integer in = (Integer) f.get(null);
|
||||
return getString(in);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
return l;
|
||||
}
|
||||
}
|
|
@ -7,16 +7,15 @@ import net.osmand.core.jni.Amenity;
|
|||
import net.osmand.core.jni.Amenity.DecodedCategory;
|
||||
import net.osmand.core.jni.AreaI;
|
||||
import net.osmand.core.jni.DecodedCategoryList;
|
||||
import net.osmand.core.jni.IObfsCollection;
|
||||
import net.osmand.core.jni.IQueryController;
|
||||
import net.osmand.core.jni.ISearch;
|
||||
import net.osmand.core.jni.LatLon;
|
||||
import net.osmand.core.jni.NullableAreaI;
|
||||
import net.osmand.core.jni.ObfInfo;
|
||||
import net.osmand.core.jni.ObfsCollection;
|
||||
import net.osmand.core.jni.PointI;
|
||||
import net.osmand.core.jni.QStringStringHash;
|
||||
import net.osmand.core.jni.Utilities;
|
||||
import net.osmand.osm.PoiType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -150,7 +149,7 @@ public class SearchAPI {
|
|||
AmenitiesByNameSearch.Criteria criteria = new AmenitiesByNameSearch.Criteria();
|
||||
criteria.setName(keyword);
|
||||
if (obfAreaFilter != null) {
|
||||
criteria.setObfInfoAreaFilter(new NullableAreaI(new AreaI(obfAreaFilter)));
|
||||
criteria.setObfInfoAreaFilter(new NullableAreaI(obfAreaFilter));
|
||||
}
|
||||
|
||||
ISearch.INewResultEntryCallback newResultEntryCallback = new ISearch.INewResultEntryCallback() {
|
||||
|
@ -160,18 +159,6 @@ public class SearchAPI {
|
|||
searchItems.add(new AmenitySearchItem(amenity));
|
||||
System.out.println("Poi found === " + amenity.getNativeName());
|
||||
resCount++;
|
||||
/*
|
||||
QStringStringHash locNames = amenity.getLocalizedNames();
|
||||
if (locNames.size() > 0) {
|
||||
QStringList keys = locNames.keys();
|
||||
StringBuilder sb = new StringBuilder("=== Localized names: ");
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
String key = keys.get(i);
|
||||
sb.append(key).append("=").append(locNames.get(key)).append(" | ");
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -255,15 +242,6 @@ public class SearchAPI {
|
|||
if (locNames.has_key(MapUtils.LANGUAGE)) {
|
||||
localizedName = locNames.get(MapUtils.LANGUAGE);
|
||||
}
|
||||
/*
|
||||
if (locNames.size() > 0) {
|
||||
QStringList keys = locNames.keys();
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
String key = keys.get(i);
|
||||
localizedNamesMap.put(key, locNames.get(key));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
DecodedCategoryList catList = amenity.getDecodedCategories();
|
||||
if (catList.size() > 0) {
|
||||
|
|
Loading…
Reference in a new issue