Permalink
Browse files

Android 9 compatibility, fix #1066

  • Loading branch information...
devemux86 committed Jun 10, 2018
1 parent 38746f6 commit b7b07619a6389886734acd5bcb8ae9b14dfce8c2
@@ -46,6 +46,7 @@ subprojects {
repositories {
google()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
tasks.withType(JavaCompile) {
@@ -12,6 +12,7 @@
- Tile sources with api keys [#1028](https://github.com/mapsforge/mapsforge/issues/1028)
- Render theme fallback internal resources [#1026](https://github.com/mapsforge/mapsforge/issues/1026)
- MapViewPosition interface [#1044](https://github.com/mapsforge/mapsforge/pull/1044)
- Android 9 compatibility [#1066](https://github.com/mapsforge/mapsforge/issues/1066)
- JTS (LocationTech) [#1027](https://github.com/mapsforge/mapsforge/issues/1027)
- Many other minor improvements and bug fixes
- [Solved issues](https://github.com/mapsforge/mapsforge/issues?q=is%3Aclosed+milestone%3A0.10.0)
@@ -19,8 +19,12 @@ implementation 'net.sf.kxml:kxml2:2.3.0'
#### Android
```groovy
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
implementation 'org.mapsforge:mapsforge-map-android:[CURRENT-VERSION]'
implementation 'com.caverock:androidsvg:1.2.2-beta-1'
implementation 'com.caverock:androidsvg:1.3-SNAPSHOT'
```
#### Desktop
@@ -1,4 +1,4 @@
dependencies {
api project(":mapsforge-map-reader")
api 'com.caverock:androidsvg:1.2.2-beta-1'
api 'com.caverock:androidsvg:1.3-SNAPSHOT'
}
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2014-2017 devemux86
* Copyright 2014-2018 devemux86
* Copyright 2017 usrusr
*
* This program is free software: you can redistribute it and/or modify it under the
@@ -23,6 +23,7 @@
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Build;
import org.mapsforge.core.graphics.Bitmap;
import org.mapsforge.core.graphics.Canvas;
@@ -213,7 +214,13 @@ public int getWidth() {
@Override
public void resetClip() {
this.canvas.clipRect(0, 0, getWidth(), getHeight(), Region.Op.REPLACE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.canvas.save();
this.canvas.clipRect(0, 0, getWidth(), getHeight());
this.canvas.restore();
} else {
this.canvas.clipRect(0, 0, getWidth(), getHeight(), Region.Op.REPLACE);
}
}
@Override
@@ -223,7 +230,13 @@ public void setBitmap(Bitmap bitmap) {
@Override
public void setClip(int left, int top, int width, int height) {
this.setClipInternal(left, top, width, height, Region.Op.REPLACE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.canvas.save();
this.canvas.clipRect(left, top, left + width, top + height);
this.canvas.restore();
} else {
this.setClipInternal(left, top, width, height, Region.Op.REPLACE);
}
}
@Override
@@ -237,24 +250,29 @@ public void setClipInternal(int left, int top, int width, int height, Region.Op
@Override
public void shadeBitmap(Bitmap bitmap, Rectangle hillRect, Rectangle tileRect, float magnitude) {
canvas.save();
this.canvas.save();
final HilshadingTemps temps;
if (this.hillshadingTemps == null) {
this.hillshadingTemps = new HilshadingTemps();
}
temps = this.hillshadingTemps;
android.graphics.Paint shadePaint = hillshadingTemps.useAlphaPaint((int) (255 * magnitude));
;
if (bitmap == null) {
if (tileRect != null) {
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom, Region.Op.REPLACE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.canvas.save();
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom);
this.canvas.restore();
} else {
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom, Region.Op.REPLACE);
}
}
// scale a dummy pixel over the canvas - just drawing a paint would probably be faster, but the resulting colors can be inconsistent with the bitmap draw (maybe only on some devices?)
this.canvas.drawBitmap(hillshadingTemps.useNeutralShadingPixel(), hillshadingTemps.useAsr(0, 0, 1, 1), hillshadingTemps.useAdr(0, 0, canvas.getWidth(), canvas.getHeight()), shadePaint);
canvas.restore();
this.canvas.restore();
return;
}
@@ -264,7 +282,13 @@ public void shadeBitmap(Bitmap bitmap, Rectangle hillRect, Rectangle tileRect, f
if (horizontalScale < 1 && verticalScale < 1) {
// fast path for wide zoom (downscaling)
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom, Region.Op.REPLACE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.canvas.save();
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom);
this.canvas.restore();
} else {
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom, Region.Op.REPLACE);
}
android.graphics.Matrix transform = temps.useMatrix();
transform.preTranslate((float) tileRect.left, (float) tileRect.top);
transform.preScale((float) horizontalScale, (float) verticalScale);
@@ -1,6 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2018 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -20,7 +21,6 @@
import org.junit.Test;
import org.mapsforge.core.model.Tile;
import org.mapsforge.map.TestUtils;
import org.mapsforge.map.layer.download.tilesource.OpenCycleMap;
import org.mapsforge.map.layer.download.tilesource.OpenStreetMapMapnik;
import org.mapsforge.map.layer.download.tilesource.TileSource;
import org.mapsforge.map.layer.renderer.RendererJob;
@@ -60,12 +60,9 @@ public void equalsTest() {
Tile tile = new Tile(0, 0, (byte) 0, TILE_SIZE);
DownloadJob downloadJob1 = new DownloadJob(tile, OpenStreetMapMapnik.INSTANCE);
DownloadJob downloadJob2 = new DownloadJob(tile, OpenStreetMapMapnik.INSTANCE);
DownloadJob downloadJob3 = new DownloadJob(tile, OpenCycleMap.INSTANCE);
TestUtils.equalsTest(downloadJob1, downloadJob2);
Assert.assertNotEquals(downloadJob1, downloadJob3);
Assert.assertNotEquals(downloadJob3, downloadJob1);
Assert.assertNotEquals(downloadJob1, new Object());
MapFile mapFile = MapFile.TEST_MAP_FILE;
@@ -1,6 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2018 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -56,12 +57,9 @@ public void constructorTest() {
public void equalsTest() {
AbstractTileSource abstractTileSource1 = OpenStreetMapMapnik.INSTANCE;
AbstractTileSource abstractTileSource2 = OpenStreetMapMapnik.INSTANCE;
AbstractTileSource abstractTileSource3 = OpenCycleMap.INSTANCE;
TestUtils.equalsTest(abstractTileSource1, abstractTileSource2);
Assert.assertNotEquals(abstractTileSource1, abstractTileSource3);
Assert.assertNotEquals(abstractTileSource3, abstractTileSource1);
Assert.assertNotEquals(abstractTileSource1, new Object());
}
}

This file was deleted.

Oops, something went wrong.
@@ -1,6 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2018 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -34,7 +35,7 @@ public void getTileUrlTest() throws MalformedURLException {
TileSource tileSource = OpenStreetMapMapnik.INSTANCE;
URL tileUrl = tileSource.getTileUrl(new Tile(0, 1, (byte) 2, 256));
Assert.assertTrue(tileUrl.toExternalForm().endsWith(".tile.openstreetmap.org:80/2/0/1.png"));
Assert.assertTrue(tileUrl.toExternalForm().endsWith(".tile.openstreetmap.org:443/2/0/1.png"));
}
@Test

This file was deleted.

Oops, something went wrong.
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2014 devemux86
* Copyright 2014-2018 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -32,9 +32,9 @@
*/
public class OpenStreetMapMapnik extends AbstractTileSource {
public static final OpenStreetMapMapnik INSTANCE = new OpenStreetMapMapnik(new String[]{
"a.tile.openstreetmap.org", "b.tile.openstreetmap.org", "c.tile.openstreetmap.org"}, 80);
"a.tile.openstreetmap.org", "b.tile.openstreetmap.org", "c.tile.openstreetmap.org"}, 443);
private static final int PARALLEL_REQUESTS_LIMIT = 8;
private static final String PROTOCOL = "http";
private static final String PROTOCOL = "https";
private static final int ZOOM_LEVEL_MAX = 18;
private static final int ZOOM_LEVEL_MIN = 0;
@@ -15,7 +15,8 @@
android:name=".SamplesApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Mapsforge Samples">
android:label="Mapsforge Samples"
android:usesCleartextTraffic="true">
<activity
android:name=".Samples"
android:configChanges="keyboardHidden|orientation|screenSize">
@@ -26,10 +26,10 @@
protected void createLayers() {
OnlineTileSource onlineTileSource = new OnlineTileSource(new String[]{
"a.tile.openstreetmap.fr", "b.tile.openstreetmap.fr", "c.tile.openstreetmap.fr"},
80);
443);
onlineTileSource.setName("Humanitarian").setAlpha(false)
.setBaseUrl("/hot/")
.setParallelRequestsLimit(8).setProtocol("http").setTileSize(256)
.setParallelRequestsLimit(8).setProtocol("https").setTileSize(256)
.setZoomLevelMax((byte) 18).setZoomLevelMin((byte) 0);
onlineTileSource.setUserAgent("Mapsforge Samples");
this.downloadLayer = new TileDownloadLayer(this.tileCaches.get(0),

0 comments on commit b7b0761

Please sign in to comment.