KhmParser start
This commit is contained in:
parent
215807914a
commit
996f9b83ca
3 changed files with 57 additions and 26 deletions
27
app/src/main/java/com/mirenkov/ktheightmap/KhmParser.kt
Normal file
27
app/src/main/java/com/mirenkov/ktheightmap/KhmParser.kt
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package com.mirenkov.ktheightmap
|
||||
|
||||
import android.util.Log
|
||||
import java.io.DataInputStream
|
||||
import java.io.FileInputStream
|
||||
|
||||
class KhmParser {
|
||||
companion object {
|
||||
fun parse(filePath: String) {
|
||||
Log.i(TAG, "start")
|
||||
val dis = DataInputStream(FileInputStream(filePath))
|
||||
with(dis) {
|
||||
Log.i(TAG, "start2")
|
||||
val minLon = readFloat()
|
||||
val minLat = readFloat()
|
||||
val lonPerPixel = readFloat()
|
||||
val latPerPixel = readFloat()
|
||||
val rasterWidth = readInt()
|
||||
val rasterHeight = readInt()
|
||||
Log.i(TAG, "mLon: %.6f, mLat: %.6f, pLon: %.6f, pLat: %.6f, w: %d, h: %d".format(
|
||||
minLon, minLat, lonPerPixel, latPerPixel, rasterWidth, rasterHeight
|
||||
))
|
||||
}
|
||||
Log.i(TAG, "end")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,10 @@ package com.mirenkov.ktheightmap
|
|||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectDragGestures
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableFloatState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ import androidx.compose.foundation.layout.safeDrawingPadding
|
|||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
|
@ -31,7 +35,7 @@ import java.util.zip.ZipInputStream
|
|||
class SettingsActivity : ComponentActivity() {
|
||||
|
||||
companion object {
|
||||
var filePath: String? = null
|
||||
var filePath: MutableState<String?> = mutableStateOf(null)
|
||||
}
|
||||
|
||||
fun filePickerResult(result: FilePickerResult): String? {
|
||||
|
|
@ -41,7 +45,7 @@ class SettingsActivity : ComponentActivity() {
|
|||
} else {
|
||||
val filePath = result.selectedFilePath
|
||||
filePath?.let {
|
||||
if (it.endsWith(".zip"))
|
||||
if (it.endsWith(".zip") || it.endsWith(".khm"))
|
||||
return filePath
|
||||
}
|
||||
return null
|
||||
|
|
@ -50,7 +54,7 @@ class SettingsActivity : ComponentActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val launcher = registerForActivityResult(FilePickerResultContracts.PickDocumentFile())
|
||||
{ result -> filePath = filePickerResult(result) }
|
||||
{ result -> filePath.value = filePickerResult(result) }
|
||||
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
|
|
@ -70,31 +74,34 @@ class SettingsActivity : ComponentActivity() {
|
|||
@Composable
|
||||
fun SettingsMain(vm: TileViewModel, launcher: ActivityResultLauncher<DocumentFilePickerConfig?>) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val filePath by remember { SettingsActivity.filePath }
|
||||
KtHeightMapTheme {
|
||||
Column(Modifier.fillMaxSize()
|
||||
.safeDrawingPadding()) {
|
||||
Button(onClick = {
|
||||
launcher.launch(null)
|
||||
}) { Text(text = "Select database") }
|
||||
Button(onClick = { coroutineScope.launch {
|
||||
processZip(SettingsActivity.filePath).forEach {
|
||||
with(vm.repository) {
|
||||
val t = getTile(it.x, it.y, it.level)
|
||||
if (t == null) {
|
||||
pushTile(it)
|
||||
Log.i(TAG, "pushed to db: %d, %d, %d".format(it.level, it.x, it.y))
|
||||
}
|
||||
else
|
||||
Log.i(TAG, "found in db: %d, %d, %d".format(t.level, t.x, t.y))
|
||||
Button(
|
||||
onClick = { launcher.launch(null) }
|
||||
) { Text(text = "Select database") }
|
||||
Button(
|
||||
onClick = { coroutineScope.launch {
|
||||
processZip(filePath).forEach {
|
||||
with(vm.repository) {
|
||||
val t = getTile(it.x, it.y, it.level)
|
||||
if (t == null) {
|
||||
pushTile(it)
|
||||
Log.i(TAG, "pushed to db: %d, %d, %d".format(it.level, it.x, it.y))
|
||||
}
|
||||
else
|
||||
Log.i(TAG, "found in db: %d, %d, %d".format(t.level, t.x, t.y))
|
||||
}
|
||||
}
|
||||
}
|
||||
}) { Text(text = "Load database") }
|
||||
Button(onClick = {
|
||||
coroutineScope.launch {
|
||||
vm.repository.clearTiles()
|
||||
}
|
||||
}) { Text(text = "Clear database") }
|
||||
} },
|
||||
) { Text(text = "Load .zip") }
|
||||
Button(
|
||||
onClick = { coroutineScope.launch { vm.repository.clearTiles() } },
|
||||
) { Text(text = "Clear database") }
|
||||
Button(
|
||||
onClick = { filePath?.let { KhmParser.parse(it) } },
|
||||
) { Text(text = "Load .khm") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue