[M] CSS for map
This commit is contained in:
parent
72a0b73b3f
commit
3add5c2318
@ -38,6 +38,7 @@ class FoldingListAdapter(
|
|||||||
val el = cg.toList()[position]
|
val el = cg.toList()[position]
|
||||||
holder.bind(el) {
|
holder.bind(el) {
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
|
parentLambda()
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.addListeners( {
|
holder.addListeners( {
|
||||||
@ -50,8 +51,6 @@ class FoldingListAdapter(
|
|||||||
visited.setVisited(el.first, it)
|
visited.setVisited(el.first, it)
|
||||||
parentLambda()
|
parentLambda()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
|
@ -6,10 +6,12 @@ import android.os.Bundle
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.caverock.androidsvg.RenderOptions
|
||||||
import com.caverock.androidsvg.SVGImageView
|
import com.caverock.androidsvg.SVGImageView
|
||||||
import net.helcel.beendroid.R
|
import net.helcel.beendroid.R
|
||||||
import net.helcel.beendroid.countries.Visited
|
import net.helcel.beendroid.countries.Visited
|
||||||
import net.helcel.beendroid.countries.World
|
import net.helcel.beendroid.countries.World
|
||||||
|
import net.helcel.beendroid.svg.CSSWrapper
|
||||||
import net.helcel.beendroid.svg.PSVGWrapper
|
import net.helcel.beendroid.svg.PSVGWrapper
|
||||||
|
|
||||||
|
|
||||||
@ -20,27 +22,34 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private lateinit var visited : Visited
|
private lateinit var visited : Visited
|
||||||
private lateinit var psvg : PSVGWrapper
|
private lateinit var psvg : PSVGWrapper
|
||||||
|
private lateinit var css : CSSWrapper
|
||||||
|
|
||||||
|
private val bitmap: Bitmap = Bitmap.createBitmap(1200,900, Bitmap.Config.ARGB_8888)
|
||||||
|
private val canvas = Canvas(bitmap)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
canvas.drawRGB(255, 255, 255)
|
||||||
|
|
||||||
visited = Visited(this)
|
visited = Visited(this)
|
||||||
visited.load()
|
visited.load()
|
||||||
|
|
||||||
psvg = PSVGWrapper(this)
|
psvg = PSVGWrapper(this)
|
||||||
|
css = CSSWrapper(visited)
|
||||||
|
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
map = findViewById(R.id.map)
|
map = findViewById(R.id.map)
|
||||||
|
|
||||||
val bitmap = Bitmap.createBitmap(1200,900, Bitmap.Config.ARGB_8888)
|
|
||||||
val canvas = Canvas(bitmap)
|
|
||||||
canvas.drawRGB(255, 255, 255)
|
|
||||||
|
|
||||||
psvg.get().renderToCanvas(canvas)
|
|
||||||
map.setImageBitmap(bitmap)
|
map.setImageBitmap(bitmap)
|
||||||
|
|
||||||
|
refreshMap()
|
||||||
|
|
||||||
list = findViewById(R.id.list)
|
list = findViewById(R.id.list)
|
||||||
list.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
|
list.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
|
||||||
list.adapter = FoldingListAdapter(this, World.WWW.children, visited) { }
|
list.adapter = FoldingListAdapter(this, World.WWW.children, visited) { refreshMap() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun refreshMap(){
|
||||||
|
psvg.get().renderToCanvas(canvas,RenderOptions.create().css(css.get()))
|
||||||
}
|
}
|
||||||
}
|
}
|
23
app/src/main/java/net/helcel/beendroid/svg/CSSWrapper.kt
Normal file
23
app/src/main/java/net/helcel/beendroid/svg/CSSWrapper.kt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package net.helcel.beendroid.svg
|
||||||
|
|
||||||
|
import net.helcel.beendroid.countries.Visited
|
||||||
|
import net.helcel.beendroid.countries.World
|
||||||
|
|
||||||
|
class CSSWrapper(private val visited: Visited) {
|
||||||
|
|
||||||
|
fun get() : String {
|
||||||
|
return listOf(World.WWW.children
|
||||||
|
.filter { visited.visited(it)}
|
||||||
|
.map { ".${it.code}{fill:blue;}"}
|
||||||
|
.fold(""){acc, s-> acc + s},
|
||||||
|
World.WWW.children
|
||||||
|
.filter { !visited.visited(it) }
|
||||||
|
.map { cg -> cg.children
|
||||||
|
.filter { visited.visited(it) }
|
||||||
|
.map { ".${it.code}{fill:blue;}"}
|
||||||
|
.fold(""){acc, s-> acc + s}
|
||||||
|
}.fold(""){acc,s->acc+s},
|
||||||
|
).fold(""){acc,s-> acc+s}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,24 +3,35 @@ package net.helcel.beendroid.svg
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.caverock.androidsvg.SVG
|
import com.caverock.androidsvg.SVG
|
||||||
import net.helcel.beendroid.countries.Country
|
import net.helcel.beendroid.countries.Country
|
||||||
|
import net.helcel.beendroid.countries.GeoLoc
|
||||||
|
import net.helcel.beendroid.countries.World
|
||||||
|
|
||||||
class PSVGWrapper(ctx: Context) {
|
class PSVGWrapper(ctx: Context) {
|
||||||
|
|
||||||
|
private val cm = HashMap<GeoLoc, PSVGLoader>()
|
||||||
|
private var fm = ""
|
||||||
private val cm = HashMap<Country, PSVGLoader>()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Country.values().forEach {
|
Country.values().forEach {
|
||||||
cm[it] = PSVGLoader(ctx, it, Level.ZERO).load()
|
cm[it] = PSVGLoader(ctx, it, Level.ZERO).load()
|
||||||
}
|
}
|
||||||
|
build()
|
||||||
}
|
}
|
||||||
fun level(el: Country, level: Level){
|
fun level(el: Country, level: Level){
|
||||||
cm[el]?.changeLevel(level)
|
cm[el]?.changeLevel(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun build(){
|
||||||
|
fm = World.WWW.children.map { gr ->
|
||||||
|
gr.children.map {c ->
|
||||||
|
val cc = cm[c]
|
||||||
|
if (cc!=null) "<g class=\"${c.code} ${gr.code}\">${cc.data}</g>"
|
||||||
|
else ""
|
||||||
|
}.fold("") { acc, e -> acc + e }
|
||||||
|
}.fold("") { acc, e -> acc + e }
|
||||||
|
}
|
||||||
|
|
||||||
fun get(): SVG {
|
fun get(): SVG {
|
||||||
val fm = cm.values.fold("") { acc, e -> acc + e.data }
|
|
||||||
return SVG.getFromString("<svg id=\"map\" xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"1200\" x=\"0\" y=\"0\" >$fm</svg>")
|
return SVG.getFromString("<svg id=\"map\" xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"1200\" x=\"0\" y=\"0\" >$fm</svg>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user