Merge pull request #1014 from osmandapp/gradle

Gradle
This commit is contained in:
vshcherb 2014-12-19 11:20:18 +01:00
commit 0ff3e4b585
21 changed files with 308 additions and 90 deletions

View file

@ -166,7 +166,7 @@ public class RenderingRuleProperty {
try {
return parseColor(value);
} catch (RuntimeException e) {
log.error("Rendering parse " + e.getMessage());
log.error("Rendering parse " + e.getMessage() + " in " + attrName);
}
return -1;
} else if(type == FLOAT_TYPE){
@ -178,7 +178,7 @@ public class RenderingRuleProperty {
}
return 0;
} catch (NumberFormatException e) {
log.error("Rendering parse " + value);
log.error("Rendering parse " + value + " in " + attrName);
}
return -1;
} else {
@ -198,7 +198,7 @@ public class RenderingRuleProperty {
}
return Float.parseFloat(value);
} catch (NumberFormatException e) {
log.error("Rendering parse " + value);
log.error("Rendering parse " + value + " in " + attrName);
}
return -1;
} else {

5
OsmAnd/.gitignore vendored
View file

@ -31,3 +31,8 @@ assets/OsmAndCore_ResourcesBundle/
# Output
/build
# Project-specific
/helpAssets
/voiceAssets
/resourcesSrc

0
OsmAnd/assets/bundled_assets.xml Executable file → Normal file
View file

View file

@ -5,4 +5,3 @@
li { text-align:justify;"}
img { max-width: 75%; width: auto; height: auto; }
p.img {text-align: center}

View file

@ -5,4 +5,3 @@
li { text-align:justify;"}
img { max-width: 75%; width: auto; height: auto; }
p.img {text-align: center}

View file

@ -1,16 +1,50 @@
apply plugin: 'com.android.application'
//<target name="fix_apostrophe_issues">
//<replace token="version='1.0'" value="version=&quot;1.0&quot;" encoding="UTF-8">
//<fileset dir="res" includes="**/strings.xml" />
//</replace>
// <replace token="encoding='utf-8'" value="encoding=&quot;utf-8&quot;" encoding="UTF-8">
// <fileset dir="res" includes="**/strings.xml" />
//</replace>
//
// <replaceregexp match="([^\\])'" replace="\1\\\\'" flags="-g" byline="off" encoding="UTF-8">
// <fileset dir="res" includes="**/strings.xml" />
//</replaceregexp>
// </target>
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
signingConfigs {
development {
storeFile file("../keystores/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
publishing {
storeFile file("osmand_key")
storePassword System.getenv("PWD")
keyAlias "androiddebugkey"
keyPassword System.getenv("PWD")
}
}
defaultConfig {
minSdkVersion 7
minSdkVersion 9
targetSdkVersion 21
versionCode System.getenv("APK_NUMBER_VERSION") ?: versionCode
versionName System.getenv("APK_VERSION") ?: versionName
}
lintOptions {
lintConfig file("lint.xml")
abortOnError false
warningsAsErrors false
}
// This is from OsmAndCore_android.aar - for some reason it's not inherited
@ -25,64 +59,196 @@ android {
sourceSets {
main {
manifest {
srcFile "AndroidManifest.xml"
}
jni {
srcDirs = []
}
jniLibs {
srcDirs = ["libs"]
}
aidl {
srcDirs = ["src"]
}
java {
srcDirs = [
manifest.srcFile "AndroidManifest.xml"
jni.srcDirs = []
jniLibs.srcDirs = ["libs"]
aidl.srcDirs = ["src"]
java.srcDirs = [
"src",
fileTree(dir: "../OsmAnd-java/src", exclude: "**/PlatformUtil.java")]
}
resources {
srcDirs = ["src", "../OsmAnd-java/src"]
}
renderscript {
srcDirs = ["src"]
}
res {
srcDirs = ["res"]
}
assets {
srcDirs = ["assets"]
}
fileTree(dir: "../OsmAnd-java/src", exclude: "**/PlatformUtil.java"),
"resourcesSrc"
]
resources.srcDirs = [
"src",
"../OsmAnd-java/src",
"resourcesSrc"
]
renderscript.srcDirs = ["src"]
res.srcDirs = [
"res",
"../../resources/rendering_styles/style-icons/"
]
assets.srcDirs = [
"assets",
"voiceAssets",
"helpAssets"
]
}
}
flavorDimensions "version", "distribution", "abi"
productFlavors {
// ABI
x86 {
flavorDimension "abi"
ndk {
abiFilter "x86"
}
}
mips {
flavorDimension "abi"
ndk {
abiFilter "mips"
}
}
armv7 {
flavorDimension "abi"
ndk {
abiFilter "armeabi-v7a"
}
}
armv5 {
flavorDimension "abi"
ndk {
abiFilter "armeabi"
}
}
fat
fat {
flavorDimension "abi"
}
// Version
free {
flavorDimension "version"
applicationId "net.osmand"
}
paid {
flavorDimension "version"
applicationId "net.osmand.plus"
}
/*
sherpafy {
flavorDimension "version"
applicationId "net.osmand.sherpafy"
}
*/
// Distribution
googleplay {
flavorDimension "distribution"
}
/*
amazon {
flavorDimension "distribution"
}
*/
}
buildTypes {
debug {
signingConfig signingConfigs.development
}
nativeDebug {
signingConfig signingConfigs.development
}
release {
signingConfig signingConfigs.publishing
}
}
}
task collectVoiceAssets(type: Sync) {
from "../../resources"
into "voiceAssets"
include "specialphrases/**"
include "voice/**/*.p"
}
task collectRoutingResources(type: Sync) {
from "../../resources/routing"
into "resourcesSrc/net/osmand/router"
include "*.xml"
}
task collectRenderingStyles(type: Sync) {
from "../../resources/rendering_styles"
into "resourcesSrc/net/osmand/render"
include "*.xml"
}
task collectRegionsInfo(type: Copy) {
from "../../resources/countries-info"
into "resourcesSrc/net/osmand/map"
include "regions.ocbf"
}
task collectHelpContents(type: Sync) {
from "../../help"
into "helpAssets/help"
include "*.html"
include "images/**/*.png"
}
task collectMiscResources(type: Copy) {
from("../../../resources/obf_creation") {
include "rendering_types.xml"
}
from("../../../resources/poi") {
include "poi_types.xml"
}
into "resourcesSrc/net/osmand/osm"
}
task collectExternalResources << {}
collectExternalResources.dependsOn collectVoiceAssets,
collectRoutingResources,
collectRenderingStyles,
collectRegionsInfo,
collectHelpContents,
collectMiscResources
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn << collectExternalResources
}
// Legacy core build
import org.apache.tools.ant.taskdefs.condition.Os
task buildOsmAndCore(type: Exec) {
description "Build Legacy OsmAndCore"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "bash", file("./old-ndk-build.sh").getAbsolutePath()
} else {
commandLine "cmd", "/c", "echo", "Not supported"
}
}
task cleanupDuplicatesInCore(type: Delete) {
dependsOn buildOsmAndCore
delete "libs/armeabi/libgnustl_shared.so"
delete "libs/armeabi-v7a/libgnustl_shared.so"
delete "libs/mips/libgnustl_shared.so"
delete "libs/x86/libgnustl_shared.so"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn << [buildOsmAndCore, cleanupDuplicatesInCore]
}
repositories {
ivy {
name = "OsmAndBinariesIvy"
url = "http://builder.osmand.net:81"
layout "pattern" , {
artifact "ivy/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"], exclude: ["QtAndroid-bundled.jar", "QtAndroidAccessibility-bundled.jar"])
compile "com.actionbarsherlock:actionbarsherlock:4.4.0@aar"
compile fileTree(dir: "libs", include: ["*.jar"])
compile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar"
debugCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar"
nativeDebugCompile "net.osmand:OsmAndCore_androidNativeDebug:0.1-SNAPSHOT@aar"
releaseCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar"
}

Binary file not shown.

0
OsmAnd/res/drawable-hdpi/map_layers_black.png Executable file → Normal file
View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

0
OsmAnd/res/drawable-large/map_layers_black.png Executable file → Normal file
View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

0
OsmAnd/res/drawable-large/widget_layer.png Executable file → Normal file
View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

0
OsmAnd/res/drawable-xhdpi/map_layers_black.png Executable file → Normal file
View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -217,7 +217,6 @@
</LinearLayout>
<TextView
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/net.osmand.plus"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/net.osmand.plus"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
@ -47,11 +47,9 @@
</TableRow>
<TableRow
android:id="@+id/TableRow"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/TextView"
android:text="@string/search_address_city" />
<Button
@ -71,11 +69,9 @@
</TableRow>
<TableRow
android:id="@+id/TableRow"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/TextView"
android:text="@string/search_address_street" />
<Button
@ -95,7 +91,6 @@
</TableRow>
<TableRow
android:id="@+id/TableRow"
android:layout_marginLeft="5dp">
<TextView

View file

@ -34,7 +34,6 @@
<TableRow android:layout_width="fill_parent">
<TextView
android:id="@+id/TextView"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/gpx_tags_txt" />
@ -51,7 +50,6 @@
<TableRow android:layout_width="fill_parent">
<TextView
android:id="@+id/TextView"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/gpx_visibility_txt" />

View file

@ -1,7 +1,11 @@
package net.osmand.core.android;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import net.osmand.core.jni.IMapTiledSymbolsProvider;
@ -17,6 +21,7 @@ import net.osmand.core.jni.MapStylesCollection;
import net.osmand.core.jni.ObfMapObjectsProvider;
import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.ResolvedMapStyle;
import net.osmand.core.jni.SwigUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
@ -30,7 +35,8 @@ import net.osmand.util.Algorithms;
* @author Alexey Pelykh
*
*/
public class MapRendererContext {
public class MapRendererContext implements RendererRegistry.IRendererLoadedEventListener {
private static final String TAG = "MapRendererContext";
private static final int OBF_RASTER_LAYER = 0;
private OsmandApplication app;
@ -101,7 +107,7 @@ public class MapRendererContext {
}
protected float getDisplayDensityFactor() {
return (float) (app.getSettings().MAP_DENSITY.get()) * Math.max(1, density);
return app.getSettings().MAP_DENSITY.get() * Math.max(1, density);
}
protected int getRasterTileSize() {
@ -126,7 +132,28 @@ public class MapRendererContext {
rendName = "default";
}
if (!mapStyles.containsKey(rendName)) {
mapStyles.put(rendName, mapStylesCollection.getResolvedStyleByName(rendName));
Log.d(TAG, "Style '" + rendName + "' not in cache");
if (mapStylesCollection.getStyleByName(rendName) == null) {
Log.d(TAG, "Unknown '" + rendName + "' style, need to load");
// Ensure parents are loaded (this may also trigger load)
app.getRendererRegistry().getRenderer(rendName);
if (mapStylesCollection.getStyleByName(rendName) == null) {
try {
loadStyleFromStream(rendName, app.getRendererRegistry().getInputStream(rendName));
} catch (IOException e) {
Log.e(TAG, "Failed to load '" + rendName + "'", e);
}
}
}
ResolvedMapStyle mapStyle = mapStylesCollection.getResolvedStyleByName(rendName);
if (mapStyle != null) {
mapStyles.put(rendName, mapStyle);
} else {
Log.d(TAG, "Failed to resolve '" + rendName + "', will use 'default'");
rendName = "default";
}
}
ResolvedMapStyle mapStyle = mapStyles.get(rendName);
CachedMapPresentation pres = new CachedMapPresentation(langId, langPref, mapStyle, displayDensityFactor);
@ -163,10 +190,9 @@ public class MapRendererContext {
}
QStringStringHash convertedStyleSettings = new QStringStringHash();
for (Iterator<Map.Entry<String, String>> itSetting = props.entrySet().iterator(); itSetting.hasNext();) {
Map.Entry<String, String> setting = itSetting.next();
convertedStyleSettings.set(setting.getKey(), setting.getValue());
}
for (Map.Entry<String, String> setting : props.entrySet()) {
convertedStyleSettings.set(setting.getKey(), setting.getValue());
}
if (nightMode) {
convertedStyleSettings.set("nightMode", "true");
}
@ -200,7 +226,7 @@ public class MapRendererContext {
}
// Create new OBF map symbols provider
obfMapSymbolsProvider = new MapObjectsSymbolsProvider(mapPrimitivesProvider, getReferenceTileSize(),
app.getSettings().TEXT_SCALE.get() / Math.max(1, density) );
app.getSettings().TEXT_SCALE.get());
// If there's bound view, add new provider
if (mapRendererView != null) {
mapRendererView.addSymbolsProvider(obfMapSymbolsProvider);
@ -221,8 +247,7 @@ public class MapRendererContext {
mapRendererView.addSymbolsProvider(obfMapSymbolsProvider);
}
}
private class CachedMapPresentation {
String langId ;
LanguagePreference langPref;
@ -257,7 +282,45 @@ public class MapRendererContext {
return false;
return true;
}
}
public void onRendererLoaded(String name, RenderingRulesStorage rules, InputStream source) {
loadStyleFromStream(name, source);
}
private void loadStyleFromStream(String name, InputStream source) {
if (RendererRegistry.DEFAULT_RENDER.equals(name)) {
if (source != null) {
try {
source.close();
} catch(IOException e) {}
}
return;
}
Log.d(TAG, "Going to pass '" + name + "' style content to native");
byte[] content;
try {
ByteArrayOutputStream intermediateBuffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = source.read(data, 0, data.length)) != -1) {
intermediateBuffer.write(data, 0, nRead);
}
intermediateBuffer.flush();
content = intermediateBuffer.toByteArray();
} catch(IOException e) {
Log.e(TAG, "Failed to read style content", e);
return;
} finally {
try {
source.close();
} catch(IOException e) {}
}
if (!mapStylesCollection.addStyleFromByteArray(
SwigUtilities.createQByteArrayAsCopyOf(content), name)) {
Log.w(TAG, "Failed to add style from byte array");
}
}
}

View file

@ -141,7 +141,7 @@ public class MapActivityActions implements DialogProvider {
builder.setTitle(R.string.add_waypoint_dialog_title);
FrameLayout parent = new FrameLayout(mapActivity);
final EditText editText = new EditText(mapActivity);
editText.setId(R.id.TextView);
editText.setId(android.R.id.edit);
parent.setPadding(15, 0, 15, 0);
parent.addView(editText);
builder.setView(parent);
@ -540,7 +540,7 @@ public class MapActivityActions implements DialogProvider {
args.getDouble(KEY_LATITUDE), args.getDouble(KEY_LONGITUDE),args.getString(KEY_NAME));
break;
case DIALOG_ADD_WAYPOINT:
EditText v = (EditText) dialog.getWindow().findViewById(R.id.TextView);
EditText v = (EditText) dialog.getWindow().findViewById(android.R.id.edit);
v.setPadding(5, 0, 5, 0);
if(args.getString(KEY_NAME) != null) {
v.setText(args.getString(KEY_NAME));

0
OsmAnd/src/net/osmand/plus/helpers/WakeLockHelper.java Executable file → Normal file
View file

View file

@ -32,6 +32,12 @@ public class RendererRegistry {
private Map<String, String> internalRenderers = new LinkedHashMap<String, String>();
private Map<String, RenderingRulesStorage> renderers = new LinkedHashMap<String, RenderingRulesStorage>();
public interface IRendererLoadedEventListener {
void onRendererLoaded(String name, RenderingRulesStorage rules, InputStream source);
}
private IRendererLoadedEventListener rendererLoadedEventListener;
public RendererRegistry(){
internalRenderers.put(DEFAULT_RENDER, "default.render.xml");
@ -126,12 +132,16 @@ public class RendererRegistry {
} finally {
is.close();
}
if (rendererLoadedEventListener != null)
rendererLoadedEventListener.onRendererLoaded(name, main, getInputStream(name));
return main;
}
@SuppressWarnings("resource")
private InputStream getInputStream(String name) throws FileNotFoundException {
InputStream is = null;
public InputStream getInputStream(String name) throws FileNotFoundException {
InputStream is;
if("default".equalsIgnoreCase(name)) {
name = DEFAULT_RENDER;
}
@ -169,5 +179,11 @@ public class RendererRegistry {
this.currentSelectedRender = currentSelectedRender;
}
public void setRendererLoadedEventListener(IRendererLoadedEventListener listener) {
rendererLoadedEventListener = listener;
}
public IRendererLoadedEventListener getRendererLoadedEventListener() {
return rendererLoadedEventListener;
}
}

View file

@ -58,37 +58,15 @@ public class NativeCoreContext {
ObfsCollection obfsCollection = new ObfsCollection();
obfsCollection.addDirectory(directory.getAbsolutePath(), false);
MapStylesCollection mapStylesCollection = setupMapStyleCollection(app);
mapRendererContext = new MapRendererContext(app, dm.density);
mapRendererContext.setupObfMap(mapStylesCollection, obfsCollection);
mapRendererContext = new MapRendererContext(app, dm.density);
mapRendererContext.setupObfMap(new MapStylesCollection(), obfsCollection);
app.getRendererRegistry().setRendererLoadedEventListener(mapRendererContext);
init = true;
}
}
}
private static MapStylesCollection setupMapStyleCollection(
OsmandApplication app) {
MapStylesCollection mapStylesCollection = new MapStylesCollection();
// Alexey TODO
// internalRenderers.put("Touring-view_(more-contrast-and-details)", "Touring-view_(more-contrast-and-details)" +".render.xml");
// internalRenderers.put("UniRS", "UniRS" + ".render.xml");
// internalRenderers.put("LightRS", "LightRS" + ".render.xml");
// internalRenderers.put("High-contrast-roads", "High-contrast-roads" + ".render.xml");
// internalRenderers.put("Winter-and-ski", "Winter-and-ski" + ".render.xml");
File renderers = app.getAppPath(IndexConstants.RENDERERS_DIR);
File[] lf = renderers.listFiles();
if(lf != null) {
for(File f : lf) {
if(f.getName().endsWith(IndexConstants.RENDERER_INDEX_EXT)) {
mapStylesCollection.addStyleFromFile(f.getAbsolutePath());
}
}
}
return mapStylesCollection;
}
public static MapRendererContext getMapRendererContext() {
return mapRendererContext;
}