add emulate card button

master
wlt233 2 years ago
parent 5442c328be
commit 41ffd2cc97

@ -40,6 +40,7 @@ class MainActivity : AppCompatActivity() {
private val TAG = "AICEmu" private val TAG = "AICEmu"
private var showCardID: Boolean = false private var showCardID: Boolean = false
private var compatibleID: Boolean = false private var compatibleID: Boolean = false
private var currentCardId: Int = -1
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -93,6 +94,8 @@ class MainActivity : AppCompatActivity() {
"moe.tqlwsl.aicemu", "moe.tqlwsl.aicemu",
"moe.tqlwsl.aicemu.EmuCard" "moe.tqlwsl.aicemu.EmuCard"
) )
emuCurrentCard()
} }
override fun onResume() { override fun onResume() {
@ -101,6 +104,7 @@ class MainActivity : AppCompatActivity() {
nfcAdapter?.enableForegroundDispatch(this, nfcPendingIntent, null, null) nfcAdapter?.enableForegroundDispatch(this, nfcPendingIntent, null, null)
} }
nfcFCardEmulation?.enableService(this, nfcFComponentName) nfcFCardEmulation?.enableService(this, nfcFComponentName)
emuCurrentCard()
} }
override fun onPause() { override fun onPause() {
@ -144,6 +148,7 @@ class MainActivity : AppCompatActivity() {
else { else {
R.string.compatible_on R.string.compatible_on
}) })
emuCurrentCard()
true true
} }
R.id.toolbar_menu_settings -> { R.id.toolbar_menu_settings -> {
@ -210,8 +215,6 @@ class MainActivity : AppCompatActivity() {
} }
private fun setIDm(idm: String): Boolean { private fun setIDm(idm: String): Boolean {
nfcFCardEmulation?.disableService(this) nfcFCardEmulation?.disableService(this)
val resultIdm = nfcFCardEmulation?.setNfcid2ForService(nfcFComponentName, idm) val resultIdm = nfcFCardEmulation?.setNfcid2ForService(nfcFComponentName, idm)
@ -226,10 +229,37 @@ class MainActivity : AppCompatActivity() {
return resultSys == true return resultSys == true
} }
private fun emuCard(cardView: View) { private fun emuCurrentCard() {
val globalVar = this.applicationContext as GlobalVar 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<TextView>(R.id.card_id) val cardIDmTextView = cardView.findViewById<TextView>(R.id.card_id)
globalVar.IDm = cardIDmTextView.text.toString() val cardNameTextView = cardView.findViewById<TextView>(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) { var resultIdm = if (compatibleID) {
// hardcoded idm for specific model e.g. Samsung S8 // hardcoded idm for specific model e.g. Samsung S8
// idm needs to start with 02, or syscode won't be added to polling ack // 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 val resultSys = setSys("88B4") // hardcoded syscode for sbga
globalVar.isHCEFUnlocked = resultSys globalVar.isHCEFUnlocked = resultSys
val cardNameTextView = cardView.findViewById<TextView>(R.id.card_name)
val cardName = cardNameTextView.text
if (!resultIdm) { if (!resultIdm) {
Toast.makeText(applicationContext, "Error IDm", Toast.LENGTH_LONG).show() 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() Toast.makeText(applicationContext, "Error Sys", Toast.LENGTH_LONG).show()
} }
if (resultIdm && resultSys) { 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 { menuButton.setOnClickListener {
showCardMenu(it, cardView) showCardMenu(it, cardView)
} }
val emuButton: ImageButton = cardView.findViewById(R.id.card_emu_mark)
emuButton.setOnClickListener {
emuCardview(cardView)
}
cardView.setOnTouchListener { v, _ -> cardView.setOnTouchListener { v, _ ->
val editText = v.findViewById<EditText>(R.id.card_name_edit) val editText = v.findViewById<EditText>(R.id.card_name_edit)
editText.clearFocus() editText.clearFocus()
emuCard(v)
v.performClick() v.performClick()
true true
} }

@ -17,7 +17,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="80dp"> android:paddingTop="80dp"
android:paddingBottom="70dp">
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

@ -2,6 +2,7 @@
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card1" android:id="@+id/card1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="250dp" android:layout_height="250dp"
@ -67,4 +68,30 @@
android:contentDescription="@string/desc_edit_card" android:contentDescription="@string/desc_edit_card"
android:src="@android:drawable/ic_menu_edit" /> android:src="@android:drawable/ic_menu_edit" />
<ImageButton
android:id="@+id/card_emu_mark"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="end|bottom"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="@null"
android:contentDescription="@string/desc_edit_card"
android:scaleType="fitCenter"
android:src="@drawable/aic"
app:tint="?android:attr/textColorSecondary"/>
<ImageButton
android:id="@+id/card_emu_mark_on"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="end|bottom"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="@null"
android:contentDescription="@string/desc_edit_card"
android:scaleType="fitCenter"
android:src="@drawable/aic"
android:visibility="gone" />
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>

@ -1,7 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="Base.Theme.AICEmu" parent="Theme.Material3.DayNight.NoActionBar"> <style name="Base.Theme.AICEmu" parent="Theme.Material3.DayNight.NoActionBar">
<item name="titleTextColor">#E0E0E0</item> <!--<item name="titleTextColor">#E0E0E0</item>
<item name="subtitleTextColor">#B0B0B0</item> <item name="subtitleTextColor">@color/grey_night</item>-->
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimary</item>
<item name="colorSecondary">@color/colorSecondary</item> <item name="colorSecondary">@color/colorSecondary</item>

@ -5,4 +5,7 @@
<color name="colorPrimary">#e83948</color> <color name="colorPrimary">#e83948</color>
<color name="colorPrimaryDark">#98030d</color> <color name="colorPrimaryDark">#98030d</color>
<color name="colorSecondary">#e86871</color> <color name="colorSecondary">#e86871</color>
<color name="grey_light">#505050</color>
<color name="grey_night">#B0B0B0</color>
</resources> </resources>

@ -1,7 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="Base.Theme.AICEmu" parent="Theme.Material3.DayNight.NoActionBar"> <style name="Base.Theme.AICEmu" parent="Theme.Material3.DayNight.NoActionBar">
<item name="titleTextColor">#202020</item> <!--<item name="titleTextColor">#202020</item>
<item name="subtitleTextColor">#505050</item> <item name="subtitleTextColor">@color/grey_light</item>-->
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimary</item>
<item name="colorSecondary">@color/colorSecondary</item> <item name="colorSecondary">@color/colorSecondary</item>

Loading…
Cancel
Save