From 41ffd2cc975105b6c8ce5d627ab018ba0e69c429 Mon Sep 17 00:00:00 2001 From: wlt233 <1486185683@qq.com> Date: Sun, 30 Apr 2023 01:45:54 +0800 Subject: [PATCH] add emulate card button --- .../java/moe/tqlwsl/aicemu/MainActivity.kt | 49 +++++++++++++++---- app/src/main/res/layout/activity_main.xml | 3 +- app/src/main/res/layout/card.xml | 27 ++++++++++ app/src/main/res/values-night/themes.xml | 4 +- app/src/main/res/values/colors.xml | 3 ++ app/src/main/res/values/themes.xml | 4 +- 6 files changed, 76 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/moe/tqlwsl/aicemu/MainActivity.kt b/app/src/main/java/moe/tqlwsl/aicemu/MainActivity.kt index a7c2178..b4ec3dd 100644 --- a/app/src/main/java/moe/tqlwsl/aicemu/MainActivity.kt +++ b/app/src/main/java/moe/tqlwsl/aicemu/MainActivity.kt @@ -40,6 +40,7 @@ class MainActivity : AppCompatActivity() { private val TAG = "AICEmu" private var showCardID: Boolean = false private var compatibleID: Boolean = false + private var currentCardId: Int = -1 override fun onCreate(savedInstanceState: Bundle?) { @@ -93,6 +94,8 @@ class MainActivity : AppCompatActivity() { "moe.tqlwsl.aicemu", "moe.tqlwsl.aicemu.EmuCard" ) + + emuCurrentCard() } override fun onResume() { @@ -101,6 +104,7 @@ class MainActivity : AppCompatActivity() { nfcAdapter?.enableForegroundDispatch(this, nfcPendingIntent, null, null) } nfcFCardEmulation?.enableService(this, nfcFComponentName) + emuCurrentCard() } override fun onPause() { @@ -144,6 +148,7 @@ class MainActivity : AppCompatActivity() { else { R.string.compatible_on }) + emuCurrentCard() true } R.id.toolbar_menu_settings -> { @@ -210,8 +215,6 @@ class MainActivity : AppCompatActivity() { } - - private fun setIDm(idm: String): Boolean { nfcFCardEmulation?.disableService(this) val resultIdm = nfcFCardEmulation?.setNfcid2ForService(nfcFComponentName, idm) @@ -226,10 +229,37 @@ class MainActivity : AppCompatActivity() { return resultSys == true } - private fun emuCard(cardView: View) { - val globalVar = this.applicationContext as GlobalVar + private fun emuCurrentCard() { + if (currentCardId != -1) { + val cardsLayout: ViewGroup = findViewById(R.id.mainList) + val currentCard = cardsLayout.getChildAt(currentCardId) + emuCardview(currentCard) + } + } + + private fun emuCardview(cardView: View) { val cardIDmTextView = cardView.findViewById(R.id.card_id) - globalVar.IDm = cardIDmTextView.text.toString() + val cardNameTextView = cardView.findViewById(R.id.card_name) + emuCard(cardIDmTextView.text.toString(), cardNameTextView.text.toString()) + + val mainLayout: ViewGroup = findViewById(R.id.mainList) + for (i in 0 until mainLayout.childCount) { + val child = mainLayout.getChildAt(i) + if (child is CardView) { + val emuMark: ImageButton = child.findViewById(R.id.card_emu_mark_on) + emuMark.visibility = View.GONE + if (child == cardView) { + currentCardId = i + } + } + } + val emuMark: ImageButton = cardView.findViewById(R.id.card_emu_mark_on) + emuMark.visibility = View.VISIBLE + } + + private fun emuCard(cardId: String, cardName: String) { + val globalVar = this.applicationContext as GlobalVar + globalVar.IDm = cardId var resultIdm = if (compatibleID) { // hardcoded idm for specific model e.g. Samsung S8 // idm needs to start with 02, or syscode won't be added to polling ack @@ -242,8 +272,6 @@ class MainActivity : AppCompatActivity() { val resultSys = setSys("88B4") // hardcoded syscode for sbga globalVar.isHCEFUnlocked = resultSys - val cardNameTextView = cardView.findViewById(R.id.card_name) - val cardName = cardNameTextView.text if (!resultIdm) { Toast.makeText(applicationContext, "Error IDm", Toast.LENGTH_LONG).show() } @@ -251,7 +279,7 @@ class MainActivity : AppCompatActivity() { Toast.makeText(applicationContext, "Error Sys", Toast.LENGTH_LONG).show() } if (resultIdm && resultSys) { - Toast.makeText(applicationContext, "正在模拟$cardName...", Toast.LENGTH_LONG).show() + Toast.makeText(applicationContext, "正在模拟 $cardName...", Toast.LENGTH_LONG).show() } } @@ -270,10 +298,13 @@ class MainActivity : AppCompatActivity() { menuButton.setOnClickListener { showCardMenu(it, cardView) } + val emuButton: ImageButton = cardView.findViewById(R.id.card_emu_mark) + emuButton.setOnClickListener { + emuCardview(cardView) + } cardView.setOnTouchListener { v, _ -> val editText = v.findViewById(R.id.card_name_edit) editText.clearFocus() - emuCard(v) v.performClick() true } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index fff896a..bf481e9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,7 +17,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:paddingTop="80dp"> + android:paddingTop="80dp" + android:paddingBottom="70dp"> diff --git a/app/src/main/res/layout/card.xml b/app/src/main/res/layout/card.xml index cfc6216..1fa2e88 100644 --- a/app/src/main/res/layout/card.xml +++ b/app/src/main/res/layout/card.xml @@ -2,6 +2,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 70ccec6..d159f56 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,7 +1,7 @@