fix idm shadow bug; refactor log

master
wlt233 1 year ago
parent b53c2970ab
commit a480f15152

@ -8,6 +8,7 @@ import android.widget.Toast
class EmuCard : HostNfcFService() {
private lateinit var card: FelicaCard
private var TAG: String = "AICEmu-EmuCard"
// byte utils
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
@ -25,12 +26,12 @@ class EmuCard : HostNfcFService() {
override fun processNfcFPacket(commandPacket: ByteArray, extras: Bundle?): ByteArray? {
val commandHexStr = commandPacket.toHexString()
Log.d("HCEFService", "processNfcFPacket NFCF")
Log.d("HCEFService", "received $commandHexStr")
Log.d(TAG, "processNfcFPacket NFCF")
Log.d(TAG, "received $commandHexStr")
//Toast.makeText(this, "received $commandHexStr", Toast.LENGTH_LONG).show()
if (commandPacket.size < 1 + 1 + 8 || (commandPacket.size.toByte() != commandPacket[0])) {
Log.e("HCEFService", "processNfcFPacket: packet size error")
Log.e(TAG, "processNfcFPacket: packet size error")
return null
}
@ -39,7 +40,7 @@ class EmuCard : HostNfcFService() {
// val myNfcid2 =
// byteArrayOfInts(0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
// if (!Arrays.equals(myNfcid2, nfcid2)) {
// Log.e("HCEFService", "processNfcFPacket: nfcid2 error")
// Log.e(TAG, "processNfcFPacket: nfcid2 error")
// return null
// }
@ -53,7 +54,7 @@ class EmuCard : HostNfcFService() {
}
val resp = packResponse(0x07.toByte(), nfcid2, payload)
val respHexStr = resp.toHexString()
Log.d("HCEFService", "send $respHexStr")
Log.d(TAG, "send $respHexStr")
Toast.makeText(this, "Scanned", Toast.LENGTH_LONG).show()
//Toast.makeText(this, "received $commandHexStr\n\nsend $respHexStr", Toast.LENGTH_LONG).show()
return resp
@ -62,7 +63,7 @@ class EmuCard : HostNfcFService() {
val payload = ByteArray(2)
val resp = packResponse(0x09.toByte(), nfcid2, payload)
val respHexStr = resp.toHexString()
Log.d("HCEFService", "send $respHexStr")
Log.d(TAG, "send $respHexStr")
//Toast.makeText(this, "received $commandHexStr\n\nsend $respHexStr", Toast.LENGTH_LONG).show()
return resp
}
@ -76,7 +77,7 @@ class EmuCard : HostNfcFService() {
override fun onCreate() {
Log.d("HCEFService", "onCreate NFCF")
Log.d(TAG, "onCreate NFCF")
super.onCreate()
val globalVar = this.applicationContext as GlobalVar
card = FelicaCard(this, globalVar.IDm)
@ -84,12 +85,12 @@ class EmuCard : HostNfcFService() {
}
override fun onDestroy() {
Log.d("HCEFService", "onDestroy NFCF")
Log.d(TAG, "onDestroy NFCF")
super.onDestroy()
// Toast.makeText(this, "onDestroy", Toast.LENGTH_LONG).show()
}
override fun onDeactivated(reason: Int) {
Log.d("HCEFService", "onDeactivated NFCF")
Log.d(TAG, "onDeactivated NFCF")
// Toast.makeText(this, "onDeactivated", Toast.LENGTH_LONG).show()
}
}

@ -125,23 +125,8 @@ class MainActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.toolbar_menu_hide_id -> {
val cardsLayout: ViewGroup = findViewById(R.id.mainList)
showCardID = !showCardID
for (i in 0 until cardsLayout.childCount) {
val child = cardsLayout.getChildAt(i)
if (child is CardView) {
val idView = child.findViewById<TextView>(R.id.card_id)
val idShadowView = child.findViewById<TextView>(R.id.card_id_shadow)
if (showCardID) {
idView.visibility = View.VISIBLE
idShadowView.visibility = View.GONE
}
else {
idView.visibility = View.GONE
idShadowView.visibility = View.VISIBLE
}
}
}
checkCardIDShadow()
true
}
R.id.toolbar_menu_settings -> {
@ -153,6 +138,25 @@ class MainActivity : AppCompatActivity() {
}
}
private fun checkCardIDShadow() {
val cardsLayout: ViewGroup = findViewById(R.id.mainList)
for (i in 0 until cardsLayout.childCount) {
val child = cardsLayout.getChildAt(i)
if (child is CardView) {
val idView = child.findViewById<TextView>(R.id.card_id)
val idShadowView = child.findViewById<TextView>(R.id.card_id_shadow)
if (showCardID) {
idView.visibility = View.VISIBLE
idShadowView.visibility = View.GONE
}
else {
idView.visibility = View.GONE
idShadowView.visibility = View.VISIBLE
}
}
}
}
private fun showCardMenu(v: View, cardView: View) {
val popupMenu = PopupMenu(this, v)
popupMenu.inflate(R.menu.card_menu) // 加载菜单资源文件
@ -240,6 +244,7 @@ class MainActivity : AppCompatActivity() {
nameTextView.text = name
val IDmTextView = cardView.findViewById<TextView>(R.id.card_id)
IDmTextView.text = IDm
checkCardIDShadow()
val menuButton: ImageButton = cardView.findViewById(R.id.card_menu_button)
menuButton.setOnClickListener {
showCardMenu(it, cardView)

@ -14,7 +14,7 @@ import android.widget.Toast
class ReadCard : Activity(), NfcAdapter.ReaderCallback{
private var nfcAdapter: NfcAdapter? = null
private val TAG = "AICEmu"
private val TAG = "AICEmu-ReadCard"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -26,9 +26,7 @@ class ReadCard : Activity(), NfcAdapter.ReaderCallback{
override fun onResume() {
super.onResume()
nfcAdapter?.let {
// 设置前台调度系统
val options = Bundle()
options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000)
it.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_F, options)
@ -44,7 +42,7 @@ class ReadCard : Activity(), NfcAdapter.ReaderCallback{
val nfcF = NfcF.get(tag)
nfcF?.let {
val idm = it.tag.id
val idmString = toHexString(idm)
val idmString = idm.toHexString(false)
Log.d(TAG, "IDm: $idmString")
runOnUiThread {
@ -56,12 +54,7 @@ class ReadCard : Activity(), NfcAdapter.ReaderCallback{
finish()
}
}
private fun toHexString(data: ByteArray): String {
val sb = StringBuilder()
for (b in data) {
sb.append(String.format("%02X", b))
}
return sb.toString()
fun ByteArray.toHexString(hasSpace: Boolean = true) = this.joinToString("") {
(it.toInt() and 0xFF).toString(16).padStart(2, '0').uppercase() + if (hasSpace) " " else ""
}
}

Loading…
Cancel
Save