Migrated SVG generation to apk-build
This commit is contained in:
@@ -19,7 +19,7 @@ import net.helcel.beendroid.R
|
||||
import net.helcel.beendroid.activity.fragment.SettingsFragment
|
||||
|
||||
import net.helcel.beendroid.svg.CSSWrapper
|
||||
import net.helcel.beendroid.svg.PSVGWrapper
|
||||
import net.helcel.beendroid.svg.SVGWrapper
|
||||
import net.helcel.beendroid.helper.*
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var photoView : PhotoView
|
||||
|
||||
private lateinit var psvg : PSVGWrapper
|
||||
private lateinit var psvg : SVGWrapper
|
||||
private lateinit var css : CSSWrapper
|
||||
|
||||
override fun onRestart() {
|
||||
@@ -80,11 +80,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
photoView = findViewById(R.id.photo_view)
|
||||
photoView.minimumScale = 1f
|
||||
photoView.maximumScale = 30f
|
||||
photoView.maximumScale = 50f
|
||||
|
||||
loadData(this, Int.MIN_VALUE)
|
||||
|
||||
psvg = PSVGWrapper(this)
|
||||
psvg = SVGWrapper(this)
|
||||
css = CSSWrapper(this)
|
||||
|
||||
refreshMap()
|
||||
@@ -92,10 +91,8 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun refreshMap() {
|
||||
val opt : RenderOptions = RenderOptions.create()
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
opt.css(css.get())
|
||||
}
|
||||
photoView.setImageDrawable(PictureDrawable(psvg.get().renderToPicture(opt)))
|
||||
opt.css(css.get())
|
||||
photoView.setImageDrawable(PictureDrawable(psvg.get()?.renderToPicture(opt)))
|
||||
}
|
||||
|
||||
}
|
@@ -9,20 +9,24 @@ import net.helcel.beendroid.helper.visits
|
||||
|
||||
class CSSWrapper(ctx: Context) {
|
||||
|
||||
private val colorForeground: String = colorToHex6(colorWrapper(ctx, android.R.attr.panelColorBackground))
|
||||
private val colorBackground: String = colorToHex6(colorWrapper(ctx, android.R.attr.colorBackground))
|
||||
|
||||
|
||||
fun get() : String {
|
||||
return listOf(World.WWW.children
|
||||
.filter { visits!!.getVisited(it)!=0}
|
||||
.map { ".${it.code}{fill:${colorToHex6(groups!!.getGroupFromKey(visits!!.getVisited(it))!!.color)};}"}
|
||||
.map { "#${it.code}{fill:${colorToHex6(groups!!.getGroupFromKey(visits!!.getVisited(it))!!.color)};}"}
|
||||
.fold(""){acc, s-> acc + s},
|
||||
World.WWW.children
|
||||
.filter { visits!!.getVisited(it)==0 }
|
||||
.map { cg -> cg.children
|
||||
.filter { visits!!.getVisited(it)!=0 }
|
||||
.map { ".${it.code}{fill:${colorToHex6(groups!!.getGroupFromKey(visits!!.getVisited(it))!!.color)};}"}
|
||||
.map { "#${it.code}{fill:${colorToHex6(groups!!.getGroupFromKey(visits!!.getVisited(it))!!.color)};}"}
|
||||
.fold(""){acc, s-> acc + s}
|
||||
}.fold(""){acc,s->acc+s},
|
||||
).fold(""){acc,s-> acc+s}
|
||||
).fold(""){acc,s-> acc+s}+
|
||||
"svg{fill:$colorForeground;stroke:$colorBackground;stroke-width:0.1;}"
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package net.helcel.beendroid.svg
|
||||
|
||||
enum class Level(val id: Int) {
|
||||
ZERO(0), ONE(1);
|
||||
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package net.helcel.beendroid.svg
|
||||
|
||||
import android.content.Context
|
||||
import net.helcel.beendroid.countries.Country
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
|
||||
class PSVGLoader(private val c: Context, private val country: Country, private var level: Level) {
|
||||
var data = ""
|
||||
|
||||
fun load(): PSVGLoader {
|
||||
data = try {
|
||||
String(
|
||||
c.assets.open("${country.code}_${level.id}.psvg").readBytes(),
|
||||
StandardCharsets.UTF_8
|
||||
)
|
||||
}catch(e: Exception){
|
||||
""
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun changeLevel(level: Level): PSVGLoader {
|
||||
this.level = level
|
||||
this.load()
|
||||
return this
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package net.helcel.beendroid.svg
|
||||
|
||||
import android.content.Context
|
||||
import com.caverock.androidsvg.SVG
|
||||
import net.helcel.beendroid.countries.Country
|
||||
import net.helcel.beendroid.countries.GeoLoc
|
||||
import net.helcel.beendroid.countries.World
|
||||
import net.helcel.beendroid.helper.colorToHex6
|
||||
import net.helcel.beendroid.helper.colorWrapper
|
||||
|
||||
class PSVGWrapper(ctx: Context) {
|
||||
|
||||
private val cm = HashMap<GeoLoc, PSVGLoader>()
|
||||
private var fm = ""
|
||||
|
||||
private val colorForeground: String = colorToHex6(colorWrapper(ctx, android.R.attr.panelColorBackground))
|
||||
private val colorBackground: String = colorToHex6(colorWrapper(ctx, android.R.attr.colorBackground))
|
||||
|
||||
init {
|
||||
Country.entries.forEach {
|
||||
cm[it] = PSVGLoader(ctx, it, Level.ZERO).load()
|
||||
}
|
||||
build()
|
||||
}
|
||||
|
||||
private 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 {
|
||||
return SVG.getFromString("<svg id=\"map\" xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"1200\" x=\"0\" y=\"0\" fill=\"$colorForeground\" stroke=\"$colorBackground\" stroke-width=\"0.25px\">$fm</svg>")
|
||||
}
|
||||
|
||||
}
|
14
app/src/main/java/net/helcel/beendroid/svg/SVGWrapper.kt
Normal file
14
app/src/main/java/net/helcel/beendroid/svg/SVGWrapper.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package net.helcel.beendroid.svg
|
||||
|
||||
import android.content.Context
|
||||
import com.caverock.androidsvg.SVG
|
||||
|
||||
class SVGWrapper(ctx: Context) {
|
||||
|
||||
private var svg: SVG?= SVG.getFromAsset(ctx.assets,"mercator0.svg")
|
||||
|
||||
fun get(): SVG? {
|
||||
return svg
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user