Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions api/android-sdk-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ final class com.mapconductor.core.circle.CircleState$Values {
public int hashCode();
public boolean equals(java.lang.Object);
}
public interface com.mapconductor.core.circle.CircleTileFileStorage$RecordAction {
public abstract void record(int, java.nio.ByteBuffer, int, com.mapconductor.core.circle.TileCircle);
}
public final class com.mapconductor.core.circle.CircleTileSet {
public static final com.mapconductor.core.circle.CircleTileSet$Companion Companion;
public com.mapconductor.core.circle.CircleTileSet(com.mapconductor.core.tileserver.LocalTileServer, kotlinx.coroutines.CoroutineScope);
Expand Down Expand Up @@ -3213,11 +3216,67 @@ public final class com.mapconductor.core.raster.TileScheme extends java.lang.Enu
public static com.mapconductor.core.raster.TileScheme valueOf(java.lang.String);
public static kotlin.enums.EnumEntries<com.mapconductor.core.raster.TileScheme> getEntries();
}
final class com.mapconductor.core.shapetile.GlShapeRasterizer$Context {
public static final com.mapconductor.core.shapetile.GlShapeRasterizer$Context$Companion Companion;
public static final int FILL;
public static final int STROKE;
public static final int FILL_COVERS;
public static final int STROKE_COVERS;
public static final int CIRCLES;
public static final int LINES;
public static final int CORNERS;
public static final int LINE_COLORS;
public final boolean makeCurrent();
public final void releaseCurrent();
public final void destroyContext();
public final java.nio.ByteBuffer draw(com.mapconductor.core.shapetile.GlShapeScene);
}
public final class com.mapconductor.core.shapetile.GlShapeRasterizer$Context$Companion {
public final com.mapconductor.core.shapetile.GlShapeRasterizer$Context create();
}
final class com.mapconductor.core.shapetile.GlShapeRasterizer$Context$Targets {
public final int getMsaa();
public final int getResolve();
}
public final class com.mapconductor.core.shapetile.GlShapeScene$Batch {
public final kotlin.ranges.IntRange getFill();
public final kotlin.ranges.IntRange getFillCovers();
public final kotlin.ranges.IntRange getCircles();
public final kotlin.ranges.IntRange getStroke();
public final kotlin.ranges.IntRange getStrokeCovers();
}
public final class com.mapconductor.core.shapetile.GlShapeScene$Floats {
public final float[] getData();
public final int getSize();
public final void add(float);
public final void clear();
public final void add2(float, float);
}
public final class com.mapconductor.core.shapetile.GlShapeScene$NeedsBatches extends java.lang.RuntimeException {
}
public final class com.mapconductor.core.shapetile.GlShapeSceneKt {
public static final float[] toTilePixels(double[], double, double, float);
}
abstract class com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu {
}
public final class com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu$Drawn extends com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu {
public final java.nio.ByteBuffer getPixels();
public final int getSize();
}
public final class com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu$Empty extends com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu {
public static final com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu$Empty INSTANCE;
}
public final class com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu$Unavailable extends com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu {
public static final com.mapconductor.core.shapetile.ShapeTileRenderer$Gpu$Unavailable INSTANCE;
}
public final class com.mapconductor.core.shapetile.ShapeTileRenderer$Painter$DefaultImpls {
public static <T> boolean getCacheSimplifiedShapes(com.mapconductor.core.shapetile.ShapeTileRenderer$Painter<T>);
public static <T> boolean getThinSubpixelOverlaps(com.mapconductor.core.shapetile.ShapeTileRenderer$Painter<T>);
public static <T> boolean isVisible(com.mapconductor.core.shapetile.ShapeTileRenderer$Painter<T>, T);
public static <T> int subpixelSlot(com.mapconductor.core.shapetile.ShapeTileRenderer$Painter<T>, T, double, double, double, int);
public static <T> boolean getDrawsOnGpu(com.mapconductor.core.shapetile.ShapeTileRenderer$Painter<T>);
public static <T> boolean record(com.mapconductor.core.shapetile.ShapeTileRenderer$Painter<T>, com.mapconductor.core.shapetile.GlShapeScene, T, java.lang.Object, double, double, float);
public static <T> boolean recordAll(com.mapconductor.core.shapetile.ShapeTileRenderer$Painter<T>, com.mapconductor.core.shapetile.GlShapeScene, com.mapconductor.core.shapetile.ShapeTileStorage<T>, int[], java.util.BitSet, double, double, double, int, float, kotlin.jvm.functions.Function0<kotlin.Unit>);
}
public final class com.mapconductor.core.spherical.CalculateMetersPerPixelKt {
public static final double calculateMetersPerPixel(double, double, double);
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/com/mapconductor/core/OverlayAddedTracker.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapconductor.core

import android.util.Log
import java.util.concurrent.CopyOnWriteArrayList
import kotlinx.coroutines.yield

/**
Expand Down Expand Up @@ -62,14 +63,15 @@ internal class OverlayAddedTracker<T : ComponentState>(
var missing: MutableSet<String>? = null
var added: MutableList<T>? = null
var checked = 0
val listening = OverlayAddedListeners.active
for (state in data) {
if (++checked % CHECKS_PER_YIELD == 0) yield()
val id = state.id
if (id in previous) {
next?.add(id)
} else if (isOnMap(state)) {
next?.add(id)
if (onAddedOf(state) != null) (added ?: ArrayList<T>().also { added = it }).add(state)
if (listening || onAddedOf(state) != null) (added ?: ArrayList<T>().also { added = it }).add(state)
} else if (sourceIds != null) {
(missing ?: HashSet<String>().also { missing = it }).add(id)
}
Expand All @@ -81,6 +83,7 @@ internal class OverlayAddedTracker<T : ComponentState>(
}

private fun notify(states: List<T>) {
OverlayAddedListeners.notify(states)
for (state in states) {
val callback = onAddedOf(state) ?: continue
try {
Expand All @@ -97,3 +100,32 @@ internal class OverlayAddedTracker<T : ComponentState>(
const val CHECKS_PER_YIELD = 4096
}
}

/**
* Hears every batch of states [OverlayAddedTracker] finds on the map, before
* their `onAdded` calls, on the main thread. For the framework layer (the
* Compose collections count their own states with it), not for apps.
*/
@InternalMapConductorApi
object OverlayAddedListeners {
private val listeners = CopyOnWriteArrayList<(List<ComponentState>) -> Unit>()

internal val active: Boolean
get() = listeners.isNotEmpty()

/** Adds [listener]; call the returned function to remove it. */
fun add(listener: (List<ComponentState>) -> Unit): () -> Unit {
listeners.add(listener)
return { listeners.remove(listener) }
}

internal fun notify(states: List<ComponentState>) {
for (listener in listeners) {
try {
listener(states)
} catch (e: Exception) {
runCatching { Log.e("MapConductor", "an overlay-added listener threw", e) }
}
}
}
}
21 changes: 21 additions & 0 deletions src/test/java/com/mapconductor/core/OverlayOnAddedTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ class OverlayOnAddedTest {
assertEquals(listOf("onAdded:p0", "onAdded:p1"), events.filter { it.startsWith("onAdded") })
}

@Test
fun `a listener hears the states that reached the map, with or without onAdded, before their onAdded`() {
val map = map()
val overlay = overlay()
val remove = OverlayAddedListeners.add { states -> events += "heard:" + states.joinToString(",") { it.id } }
try {
val states = listOf(square(0, recorder), square(1))
overlay.show(map, states)
overlay.show(map, states) // nothing new
remove()
overlay.show(map, states + square(2))
} finally {
remove()
}

assertEquals(
listOf("heard:p0,p1", "onAdded:p0"),
events.filter { it.startsWith("heard") || it.startsWith("onAdded") },
)
}

// ── the other overlay types use the same tracker; check each is wired ──

private class RecordingMap :
Expand Down
Loading