Add DSB Zoom

Minor changes PSE
This commit is contained in:
BuildTools
2024-06-03 16:27:39 +02:00
parent 75302eed36
commit e9ca2d8704
2 changed files with 49 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -12,8 +13,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
@@ -25,13 +25,22 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import com.schoolapp.cleverclass.ui.theme.CleverClassTheme import com.schoolapp.cleverclass.ui.theme.CleverClassTheme
import org.json.JSONObject import org.json.JSONObject
import java.io.File import java.io.File
import java.lang.Float.max
import java.lang.Float.min
private lateinit var folder : File private lateinit var folder : File
private lateinit var information : JSONObject private lateinit var information : JSONObject
@@ -64,6 +73,10 @@ class DSBDayViewActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun DSBDayViewContent(activity: ComponentActivity){ fun DSBDayViewContent(activity: ComponentActivity){
var scale by remember { mutableStateOf(1f) }
var XOffset by remember { mutableStateOf(0f) }
var YOffset by remember { mutableStateOf(0f) }
Column{ Column{
TopAppBar( TopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer), colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
@@ -83,17 +96,35 @@ fun DSBDayViewContent(activity: ComponentActivity){
) )
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier
.fillMaxWidth()
.zIndex(1f)
) )
val imageFiles = folder.listFiles { file -> file.extension == "jpg" }?.toList() val imageFiles = folder.listFiles { file -> file.extension == "jpg" }?.toList()
Column( LazyColumn(
userScrollEnabled = true,
modifier = Modifier modifier = Modifier
.padding(8.dp) .padding(8.dp)
.verticalScroll(rememberScrollState()) .pointerInput(Unit) {
detectTransformGestures { _, move, zoom, _ ->
scale = max(min(zoom * scale, 2f), 1f)
val maxXOffset = 520 * (scale - 1)
val maxYOffset = 992 * (scale - 1)
XOffset = max(min(XOffset + move.x, maxXOffset), -maxXOffset)
YOffset = max(min(YOffset + move.y, maxYOffset), -maxYOffset)
}
}
.graphicsLayer(
scaleX = scale,
scaleY = scale,
translationX = XOffset,
translationY = YOffset
)
) { ) {
imageFiles?.forEach { imageFiles?.forEach {
item {
Image( Image(
bitmap = BitmapFactory.decodeFile(it.absolutePath).asImageBitmap(), bitmap = BitmapFactory.decodeFile(it.absolutePath).asImageBitmap(),
contentDescription = null, contentDescription = null,
@@ -104,4 +135,5 @@ fun DSBDayViewContent(activity: ComponentActivity){
} }
} }
} }
}
} }

View File

@@ -79,6 +79,7 @@ fun PSEContent(activity: ComponentActivity){
} }
} }
private lateinit var rootObj : JSONObject
private val colors = listOf( private val colors = listOf(
Color(0xFFBCA76D), Color(0xFFBCA76D),
@@ -117,7 +118,7 @@ private val elementButtonColors = listOf(
@Composable @Composable
fun PSEMainContent(activity: ComponentActivity) { fun PSEMainContent(activity: ComponentActivity) {
val inputStream = activity.assets.open("elements_data.json") val inputStream = activity.assets.open("elements_data.json")
val rootObj = JSONObject(InputStreamReader(inputStream).readText()) rootObj = JSONObject(InputStreamReader(inputStream).readText())
var showInfo by remember { var showInfo by remember {
mutableStateOf(false) mutableStateOf(false)
@@ -204,7 +205,7 @@ fun PSEMainContent(activity: ComponentActivity) {
modifier = Modifier modifier = Modifier
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
.horizontalScroll(rememberScrollState()), .horizontalScroll(rememberScrollState()),
text = readElementData(rootObj, dcValue), text = readElementData(dcValue),
color = MaterialTheme.colorScheme.onPrimaryContainer, color = MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.labelMedium style = MaterialTheme.typography.labelMedium
) )
@@ -293,8 +294,8 @@ fun InformationBox(text: String, color: Color){
} }
} }
private fun readElementData(jsonObject: JSONObject, int: Int): String { private fun readElementData(int: Int): String {
val elementData = jsonObject.getJSONArray("elements").getJSONObject(int) val elementData = rootObj.getJSONArray("elements").getJSONObject(int)
return "Name:\n${elementData.get("Name")}\n\n" + return "Name:\n${elementData.get("Name")}\n\n" +
"Ordnungszahl:\n${elementData.get("Ordnungszahl")}\n\n" + "Ordnungszahl:\n${elementData.get("Ordnungszahl")}\n\n" +
"Gruppe:\n${elementData.get("Gruppe")}\n\n" + "Gruppe:\n${elementData.get("Gruppe")}\n\n" +