added colors list changed the dialog assignment from list to a single var added new data from elements_data.json into the dialog
247 lines
11 KiB
Kotlin
247 lines
11 KiB
Kotlin
package com.schoolapp.cleverclass
|
|
|
|
import android.content.Context
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.horizontalScroll
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.size
|
|
import androidx.compose.foundation.rememberScrollState
|
|
import androidx.compose.foundation.verticalScroll
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
import androidx.compose.material.icons.outlined.Info
|
|
import androidx.compose.material3.AlertDialog
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.IconButton
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TopAppBar
|
|
import androidx.compose.material3.TopAppBarDefaults
|
|
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.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import com.schoolapp.cleverclass.ui.theme.CleverClassTheme
|
|
import org.json.JSONObject
|
|
import java.io.InputStreamReader
|
|
|
|
class PSEActivity : ComponentActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
setContent {
|
|
CleverClassTheme {
|
|
Surface(modifier = Modifier.fillMaxSize(),
|
|
color = MaterialTheme.colorScheme.background) {
|
|
PSEContent(activity = this)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Content of PSE
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
@Composable
|
|
fun PSEContent(activity: ComponentActivity){
|
|
var showInfo by remember {
|
|
mutableStateOf(false)
|
|
}
|
|
var dialogChooser by remember {
|
|
mutableStateOf(-1)
|
|
}
|
|
val elementNameList = listOf(
|
|
"H", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "He",
|
|
"Li", "Be", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "B", "C", "N", "O", "F", "Ne",
|
|
"Na", "Mg", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Al", "Si", "P", "S", "Cl", "Ar",
|
|
"K", "Ca", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",
|
|
"Rb", "Sr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe",
|
|
"Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn",
|
|
"Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og"
|
|
)
|
|
val elementButtonColors = listOf(
|
|
0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0,
|
|
1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1,
|
|
2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2,
|
|
3, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
|
|
4, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
|
|
5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5,
|
|
6, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6
|
|
)
|
|
val colors = listOf(
|
|
Color(0xFFBCA76D),
|
|
Color(0xFFC65253),
|
|
Color(0xFF337733),
|
|
Color(0xFFDC2222),
|
|
Color(0xFF129DC3),
|
|
Color(0xFFDDCC69),
|
|
Color(0xFF7044DD)
|
|
)
|
|
Column {
|
|
TopAppBar(
|
|
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
|
|
title = {
|
|
Text(
|
|
text = "Periodensystem der Elemente",
|
|
style = MaterialTheme.typography.headlineSmall,
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
},
|
|
navigationIcon = {
|
|
IconButton(onClick = { activity.finish() }) {
|
|
Icon(
|
|
imageVector = Icons.Filled.ArrowBack,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(28.dp),
|
|
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
}
|
|
},
|
|
actions = {
|
|
IconButton(onClick = {
|
|
showInfo = true
|
|
}) {
|
|
Icon(
|
|
imageVector = Icons.Outlined.Info,
|
|
contentDescription = "",
|
|
modifier = Modifier.size(28.dp),
|
|
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
}
|
|
},
|
|
modifier = Modifier.fillMaxWidth()
|
|
)
|
|
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxHeight()
|
|
.padding(3.dp)
|
|
.verticalScroll(rememberScrollState())
|
|
.horizontalScroll(rememberScrollState())
|
|
) {
|
|
var dialogCounter = 0
|
|
for (row in 0..6) {
|
|
Row {
|
|
for (element in 0..31) {
|
|
val index = row * 32 + element
|
|
if (elementNameList[index] != "") {
|
|
Box(modifier = Modifier
|
|
.padding(3.dp)
|
|
.size(60.dp)
|
|
.background(color = colors[elementButtonColors[index]])
|
|
.clickable { dialogChooser = ++dialogCounter }
|
|
) {
|
|
Text(
|
|
modifier = Modifier
|
|
.align(Alignment.Center),
|
|
text = elementNameList[index],
|
|
color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton,
|
|
fontSize = 24.sp
|
|
)
|
|
}
|
|
} else {
|
|
Box(
|
|
modifier = Modifier
|
|
.padding(3.dp)
|
|
.size(60.dp)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (dialogChooser != -1) {
|
|
val dcValue = dialogChooser
|
|
AlertDialog(
|
|
onDismissRequest = { dialogChooser = -1 },
|
|
text = {
|
|
Text(
|
|
modifier = Modifier
|
|
.verticalScroll(rememberScrollState())
|
|
.horizontalScroll(rememberScrollState()),
|
|
text = readElementData(activity, dcValue),
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
style = MaterialTheme.typography.labelMedium
|
|
)
|
|
},
|
|
confirmButton = {
|
|
Text(
|
|
text = "Schließen",
|
|
color = MaterialTheme.colorScheme.secondary,
|
|
style = MaterialTheme.typography.labelMedium,
|
|
modifier = Modifier.clickable {
|
|
dialogChooser = -1
|
|
}
|
|
)
|
|
},
|
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
|
modifier = Modifier
|
|
.padding(5.dp)
|
|
)
|
|
}
|
|
if (showInfo) {
|
|
AlertDialog(
|
|
onDismissRequest = { showInfo = false },
|
|
text = {
|
|
Text(
|
|
text = "Verwendung im Querformat empfohlen",
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
style = MaterialTheme.typography.labelMedium
|
|
)
|
|
},
|
|
confirmButton = {
|
|
Text(
|
|
text = "Schließen",
|
|
color = MaterialTheme.colorScheme.secondary,
|
|
style = MaterialTheme.typography.labelMedium,
|
|
modifier = Modifier.clickable {
|
|
showInfo = false
|
|
}
|
|
)
|
|
},
|
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
|
modifier = Modifier
|
|
.padding(5.dp)
|
|
)
|
|
}
|
|
}
|
|
|
|
fun readElementData(context: Context, int: Int): String {
|
|
val inputStream = context.assets.open("elements_data.json")
|
|
val rootObj = JSONObject(InputStreamReader(inputStream).readText())
|
|
val elementData = rootObj.getJSONArray("elements").getJSONObject(int)
|
|
return "Name\n >>> ${elementData.get("Name")}\n\n" +
|
|
"Ordnungszahl\n >>> ${elementData.get("Ordnungszahl")}\n\n" +
|
|
"Gruppe\n >>> ${elementData.get("Gruppe")}\n\n" +
|
|
"Periode/Hauptquantenzahl\n >>> ${elementData.get("Periode/Hauptquantenzahl")}\n\n" +
|
|
"Schale\n >>> ${elementData.get("Schale")}\n\n" +
|
|
"Molare Masse\n >>> ${elementData.get("Molare Masse")}\n\n" +
|
|
"Dichte\n >>> ${elementData.get("Dichte")}\n\n" +
|
|
"Elektronegativität\n >>> ${elementData.get("Elektronegativität")}\n\n" +
|
|
"Schmelztemperatur\n >>> ${elementData.get("Schmelztemperatur")}\n\n" +
|
|
"Siedetemperatur\n >>> ${elementData.get("Siedetemperatur")}\n\n" +
|
|
"radioaktiv\n >>> ${elementData.get("radioaktiv")}\n\n" +
|
|
"Halbwertszeit\n >>> ${elementData.get("Halbwertszeit")}\n\n" +
|
|
"Strahlungsart\n >>> ${elementData.get("Strahlungsart")}\n\n" +
|
|
"künstlich\n >>> ${elementData.get("künstlich")}\n\n" +
|
|
"langlebigstes Isotop\n >>> ${elementData.get("langlebigstes Isotop")}"
|
|
} |