Add image support with drawable overload (#13793)

* [android] - add addImage support that takes a Drawable as parameter
This commit is contained in:
Tobrun
2019-01-28 15:06:54 +01:00
committed by GitHub
parent 2a821db754
commit 50018b7574
4 changed files with 121 additions and 2 deletions

View File

@@ -1,11 +1,14 @@
package com.mapbox.mapboxsdk.maps
import android.graphics.Bitmap
import android.graphics.drawable.ShapeDrawable
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
import com.mapbox.mapboxsdk.utils.BitmapUtils
import io.mockk.mockk
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@@ -95,6 +98,21 @@ class StyleBuilderTest {
assertEquals(true, builder.images[0].sdf)
}
@Test
fun testWithImageDrawable() {
val drawable = ShapeDrawable()
drawable.intrinsicWidth = 1
drawable.intrinsicHeight = 1
val builder = Style.Builder()
builder.withImage("id", drawable, true)
assertTrue(BitmapUtils.equals(
BitmapUtils.getBitmapFromDrawable(drawable)!!,
builder.images[0].bitmap)
)
assertEquals("id", builder.images[0].id)
assertEquals(true, builder.images[0].sdf)
}
@Test
fun testWithTransitionOptions() {
val transitionOptions = TransitionOptions(100, 200)

View File

@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.maps
import android.graphics.Bitmap
import android.graphics.drawable.ShapeDrawable
import com.mapbox.mapboxsdk.constants.MapboxConstants
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
@@ -14,7 +15,6 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import java.lang.IllegalStateException
@RunWith(RobolectricTestRunner::class)
class StyleTest {
@@ -277,4 +277,27 @@ class StyleTest {
style!!.addLayer(mockk<SymbolLayer>())
}
}
@Test
fun testAddImage() {
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", bitmap)
mapboxMap.setStyle(builder)
verify(exactly = 1) { nativeMapView.styleUrl = Style.SATELLITE }
verify(exactly = 0) { nativeMapView.addImages(any()) }
mapboxMap.notifyStyleLoaded()
verify(exactly = 1) { nativeMapView.addImages(any()) }
}
@Test
fun testAddDrawable() {
val drawable = ShapeDrawable()
drawable.intrinsicHeight = 10
drawable.intrinsicWidth = 10
val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", drawable)
mapboxMap.setStyle(builder)
verify(exactly = 1) { nativeMapView.styleUrl = Style.SATELLITE }
verify(exactly = 0) { nativeMapView.addImages(any()) }
mapboxMap.notifyStyleLoaded()
verify(exactly = 1) { nativeMapView.addImages(any()) }
}
}