forked from andras-adam/virtualtag
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bc7098
commit d0b78a6
Showing
11 changed files
with
232 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/virtualtag/app/ui/components/DataRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.virtualtag.app.ui.components | ||
|
||
import android.widget.Toast | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.combinedClickable | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.platform.ClipboardManager | ||
import androidx.compose.ui.platform.LocalClipboardManager | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import com.virtualtag.app.R | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
fun DataRow(title: String, content: String, icon: ImageVector) { | ||
val context = LocalContext.current | ||
val clipboardManager: ClipboardManager = LocalClipboardManager.current | ||
Column(modifier = Modifier | ||
.fillMaxWidth() | ||
.combinedClickable( | ||
onLongClick = { | ||
clipboardManager.setText(AnnotatedString(content)) | ||
Toast | ||
.makeText(context, context.getString(R.string.clipboard), Toast.LENGTH_SHORT) | ||
.show() | ||
}, | ||
onClick = { /* do nothing */ })) { | ||
Row(modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 8.dp)) { | ||
Icon(icon, contentDescription = null, modifier = Modifier | ||
.size(48.dp) | ||
.padding(horizontal = 4.dp)) | ||
Column(modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 2.dp, end = 16.dp)) { | ||
Text(title, fontWeight = FontWeight.Bold, modifier = Modifier.padding(bottom = 4.dp)) | ||
Text(content, modifier = Modifier.padding(bottom = 8.dp)) | ||
} | ||
} | ||
Divider(color = Color.LightGray) | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/virtualtag/app/ui/components/MifareClassicView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.virtualtag.app.ui.components | ||
|
||
import android.nfc.tech.MifareClassic | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.virtualtag.app.db.Card | ||
import com.virtualtag.app.utils.formatHex | ||
|
||
@Composable | ||
fun MifareClassicView(card: Card) { | ||
val id = formatHex(card.id) | ||
val techList = card.techList | ||
.replace("android.nfc.tech.", "") | ||
.replace(",", ", ") | ||
val type = when (card.mifareClassicType ?: MifareClassic.TYPE_UNKNOWN) { | ||
MifareClassic.TYPE_CLASSIC -> "Classic" | ||
MifareClassic.TYPE_PLUS -> "Plus" | ||
MifareClassic.TYPE_PRO -> "Pro" | ||
else -> "Unknown" | ||
} | ||
val sectorCount = card.mifareClassicSectorCount ?: 0 | ||
val blockCount = card.mifareClassicBlockCount ?: 0 | ||
val size = (card.mifareClassicSize ?: 0) * MifareClassic.BLOCK_SIZE | ||
val timeout = card.mifareClassicTimeout ?: 0 | ||
val maxTranscieveLength = card.mifareClassicMaxTransceiveLength ?: 0 | ||
val atqa = card.mifareClassicAtqa ?: "" | ||
val sak = card.mifareClassicSak ?: 0 | ||
val data = card.mifareClassicData ?: "" | ||
|
||
LazyColumn(modifier = Modifier.fillMaxWidth()) { | ||
item { | ||
DataRow(title = "Serial number", content = id, icon = Icons.Filled.Key) | ||
} | ||
item { | ||
DataRow(title = "NFC technologies", content = techList, icon = Icons.Filled.Style) | ||
} | ||
item { | ||
DataRow(title = "MifareClassic type", content = type, icon = Icons.Filled.Category) | ||
} | ||
item { | ||
DataRow(title = "Memory size", content = "$size bytes", icon = Icons.Filled.Save) | ||
} | ||
item { | ||
DataRow(title = "Memory sector count", content = "$sectorCount", icon = Icons.Filled.Save) | ||
} | ||
item { | ||
DataRow(title = "Memory block count", content = "$blockCount", icon = Icons.Filled.Save) | ||
} | ||
item { | ||
DataRow(title = "Transcieve timeout", content = "$timeout ms", icon = Icons.Filled.Sensors) | ||
} | ||
item { | ||
DataRow(title = "Transcieve max length", content = "$maxTranscieveLength bytes", icon = Icons.Filled.Sensors) | ||
} | ||
item { | ||
DataRow(title = "ATQA", content = atqa, icon = Icons.Filled.Code) | ||
} | ||
item { | ||
DataRow(title = "SAK", content = "$sak", icon = Icons.Filled.Code) | ||
} | ||
if (data.isNotEmpty()) { | ||
items(blockCount) { index -> | ||
DataRow( | ||
title = "Memory block ${index + 1}", | ||
content = formatHex(data.substring(index * 32, index * 32 + 32)), | ||
icon = Icons.Filled.Memory | ||
) | ||
} | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/virtualtag/app/ui/components/MifareUltralightView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.virtualtag.app.ui.components | ||
|
||
import android.nfc.tech.MifareUltralight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.virtualtag.app.db.Card | ||
import com.virtualtag.app.utils.formatHex | ||
|
||
@Composable | ||
fun MifareUltralightView(card: Card) { | ||
val id = formatHex(card.id) | ||
val techList = card.techList | ||
.replace("android.nfc.tech.", "") | ||
.replace(",", ", ") | ||
val type = when (card.mifareUltralightType ?: MifareUltralight.TYPE_UNKNOWN) { | ||
MifareUltralight.TYPE_ULTRALIGHT -> "Ultralight" | ||
MifareUltralight.TYPE_ULTRALIGHT_C -> "Ultralight C" | ||
else -> "Unknown" | ||
} | ||
val size = when (card.mifareUltralightType ?: MifareUltralight.TYPE_UNKNOWN) { | ||
MifareUltralight.TYPE_ULTRALIGHT -> 16 * MifareUltralight.PAGE_SIZE | ||
MifareUltralight.TYPE_ULTRALIGHT_C -> 48 * MifareUltralight.PAGE_SIZE | ||
else -> 0 | ||
} | ||
val timeout = card.mifareUltralightTimeout ?: 0 | ||
val maxTranscieveLength = card.mifareUltralightMaxTransceiveLength ?: 0 | ||
val atqa = card.mifareUltralightAtqa ?: "" | ||
val sak = card.mifareUltralightSak ?: 0 | ||
val data = card.mifareUltralightData ?: "" | ||
|
||
LazyColumn(modifier = Modifier.fillMaxWidth()) { | ||
item { | ||
DataRow(title = "Serial number", content = id, icon = Icons.Filled.Key) | ||
} | ||
item { | ||
DataRow(title = "NFC technologies", content = techList, icon = Icons.Filled.Style) | ||
} | ||
item { | ||
DataRow(title = "MifareUltralight type", content = type, icon = Icons.Filled.Category) | ||
} | ||
item { | ||
DataRow(title = "Memory size", content = "$size bytes", icon = Icons.Filled.Save) | ||
} | ||
item { | ||
DataRow(title = "Transcieve timeout", content = "$timeout ms", icon = Icons.Filled.Sensors) | ||
} | ||
item { | ||
DataRow(title = "Transcieve max length", content = "$maxTranscieveLength bytes", icon = Icons.Filled.Sensors) | ||
} | ||
item { | ||
DataRow(title = "ATQA", content = atqa, icon = Icons.Filled.Code) | ||
} | ||
item { | ||
DataRow(title = "SAK", content = "$sak", icon = Icons.Filled.Code) | ||
} | ||
// if (data.isNotEmpty()) { | ||
// items(blockCount) { index -> | ||
// DataRow( | ||
// title = "Memory block ${index + 1}", | ||
// content = formatHex(data.substring(index * 32, index * 32 + 32)), | ||
// icon = Icons.Filled.Memory | ||
// ) | ||
// } | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.virtualtag.app.utils | ||
|
||
// Byte array to HEX helper | ||
fun ByteArray.toHex(): String = joinToString(separator = "") { "%02x".format(it) } | ||
|
||
// Format HEX strings into colon (:) delimited HEX strings | ||
// E.g.: BF55 -> BF:55 | ||
fun formatHex(content: String): String { | ||
val result = arrayListOf<String>() | ||
for (i in content.indices step 2) { | ||
result.add(content.substring(i, i + 2)) | ||
} | ||
return result.joinToString(":") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters