add prefs & compatible button (ver.1.0-Beta)

master
wlt233 2 years ago
parent 41ffd2cc97
commit 9cca7126ff

@ -11,8 +11,8 @@ android {
applicationId "moe.tqlwsl.aicemu" applicationId "moe.tqlwsl.aicemu"
minSdk 24 minSdk 24
targetSdk 33 targetSdk 33
versionCode 1 versionCode 2
versionName "0.1" versionName "1.0-Beta"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

@ -12,6 +12,7 @@ import android.widget.*
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import androidx.core.content.edit
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.gson.Gson import com.google.gson.Gson
@ -31,6 +32,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var readCardBroadcastReceiver: ReadCardBroadcastReceiver private lateinit var readCardBroadcastReceiver: ReadCardBroadcastReceiver
private lateinit var nfcFComponentName: ComponentName private lateinit var nfcFComponentName: ComponentName
private lateinit var jsonFile: File private lateinit var jsonFile: File
private lateinit var prefs: SharedPreferences
private var nfcAdapter: NfcAdapter? = null private var nfcAdapter: NfcAdapter? = null
private var nfcFCardEmulation: NfcFCardEmulation? = null private var nfcFCardEmulation: NfcFCardEmulation? = null
private var nfcPendingIntent: PendingIntent? = null private var nfcPendingIntent: PendingIntent? = null
@ -95,7 +97,20 @@ class MainActivity : AppCompatActivity() {
"moe.tqlwsl.aicemu.EmuCard" "moe.tqlwsl.aicemu.EmuCard"
) )
emuCurrentCard() // setting prefs
prefs = applicationContext.getSharedPreferences("AICEmu", MODE_PRIVATE)
currentCardId = prefs.getInt("currentCardId", -1)
compatibleID = prefs.getBoolean("compatibleID", false)
val compatibleButton: Button = findViewById(R.id.button_compatible)
compatibleButton.text = (if (compatibleID) {
getString(R.string.mode_compatible)
}
else {
getString(R.string.mode_commmon)
})
compatibleButton.setOnClickListener {
switchCompatible()
}
} }
override fun onResume() { override fun onResume() {
@ -124,7 +139,19 @@ class MainActivity : AppCompatActivity() {
override fun onCreateOptionsMenu(menu: Menu?): Boolean { override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.toolbar_menu, menu) menuInflater.inflate(R.menu.toolbar_menu, menu)
return true return super.onCreateOptionsMenu(menu)
}
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
if (menu != null) {
menu.findItem(R.id.toolbar_menu_compatible).setTitle(if (compatibleID) {
R.string.compatible_off
}
else {
R.string.compatible_on
})
}
return super.onPrepareOptionsMenu(menu)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -141,18 +168,12 @@ class MainActivity : AppCompatActivity() {
true true
} }
R.id.toolbar_menu_compatible -> { R.id.toolbar_menu_compatible -> {
compatibleID = !compatibleID switchCompatible()
item.setTitle(if (compatibleID) {
R.string.compatible_off
}
else {
R.string.compatible_on
})
emuCurrentCard()
true true
} }
R.id.toolbar_menu_settings -> { R.id.toolbar_menu_settings -> {
Toast.makeText(applicationContext, "还没做\nUnder constuction...", Toast.LENGTH_LONG).show() Toast.makeText(applicationContext, "还没做完()\nUnder constuction...", Toast.LENGTH_LONG).show()
val settingIntent = Intent(this, SettingActivity::class.java) val settingIntent = Intent(this, SettingActivity::class.java)
startActivity(settingIntent) startActivity(settingIntent)
true true
@ -161,20 +182,35 @@ class MainActivity : AppCompatActivity() {
} }
} }
private fun switchCompatible() {
compatibleID = !compatibleID
val compatibleButton: Button = findViewById(R.id.button_compatible)
compatibleButton.text = (if (compatibleID) {
getString(R.string.mode_compatible)
}
else {
getString(R.string.mode_commmon)
})
val editor = prefs.edit()
editor.putBoolean("compatibleID", compatibleID)
editor.apply()
emuCurrentCard()
}
private fun checkCardIDShadow() { private fun checkCardIDShadow() {
val cardsLayout: ViewGroup = findViewById(R.id.mainList) val cardsLayout: ViewGroup = findViewById(R.id.mainList)
for (i in 0 until cardsLayout.childCount) { for (i in 0 until cardsLayout.childCount) {
val child = cardsLayout.getChildAt(i) val child = cardsLayout.getChildAt(i)
if (child is CardView) { if (child is CardView) {
val idView = child.findViewById<TextView>(R.id.card_id) val idView = child.findViewById<TextView>(R.id.card_id)
val idShadowView = child.findViewById<TextView>(R.id.card_id_shadow) // val idShadowView = child.findViewById<TextView>(R.id.card_id_shadow)
if (showCardID) { if (showCardID) {
idView.visibility = View.VISIBLE idView.visibility = View.VISIBLE
idShadowView.visibility = View.GONE // idShadowView.visibility = View.GONE
} }
else { else {
idView.visibility = View.GONE idView.visibility = View.GONE
idShadowView.visibility = View.VISIBLE // idShadowView.visibility = View.VISIBLE
} }
} }
} }
@ -233,7 +269,15 @@ class MainActivity : AppCompatActivity() {
if (currentCardId != -1) { if (currentCardId != -1) {
val cardsLayout: ViewGroup = findViewById(R.id.mainList) val cardsLayout: ViewGroup = findViewById(R.id.mainList)
val currentCard = cardsLayout.getChildAt(currentCardId) val currentCard = cardsLayout.getChildAt(currentCardId)
emuCardview(currentCard) if (currentCard != null) {
emuCardview(currentCard)
}
else {
currentCardId = -1
val editor = prefs.edit()
editor.putInt("currentCardId", currentCardId)
editor.apply()
}
} }
} }
@ -250,6 +294,9 @@ class MainActivity : AppCompatActivity() {
emuMark.visibility = View.GONE emuMark.visibility = View.GONE
if (child == cardView) { if (child == cardView) {
currentCardId = i currentCardId = i
val editor = prefs.edit()
editor.putInt("currentCardId", currentCardId)
editor.apply()
} }
} }
} }
@ -279,7 +326,12 @@ 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() if (compatibleID) {
Toast.makeText(applicationContext, getString(R.string.Emulating_compatible, cardName), Toast.LENGTH_LONG).show()
}
else {
Toast.makeText(applicationContext, getString(R.string.Emulating_common, cardName), Toast.LENGTH_LONG).show()
}
} }
} }

@ -30,7 +30,17 @@
android:minHeight="?attr/actionBarSize" android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" android:theme="?attr/actionBarTheme"
app:title="AICEmu" app:title="AICEmu"
app:titleTextColor="#FFFFFF" /> app:titleTextColor="#FFFFFF">
<Button
android:id="@+id/button_compatible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/white"
android:text="@string/mode_commmon" />
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton

@ -54,7 +54,8 @@
android:layout_marginTop="80dp" android:layout_marginTop="80dp"
android:text="@string/dummy_card_id" android:text="@string/dummy_card_id"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="30sp"/> android:textSize="30sp"
android:visibility="gone" />
<ImageButton <ImageButton

@ -20,4 +20,8 @@
<string name="Pmmtool_work_true">Pmmtool 运行中!</string> <string name="Pmmtool_work_true">Pmmtool 运行中!</string>
<string name="Pmmtool_work_false">Pmmtool 炸了...</string> <string name="Pmmtool_work_false">Pmmtool 炸了...</string>
<string name="Pmmtool_work_hook_failed">Hook 失败了...</string> <string name="Pmmtool_work_hook_failed">Hook 失败了...</string>
<string name="Emulating_common">正在模拟 %1$s...(正常)</string>
<string name="Emulating_compatible">正在模拟 %1$s...(兼容)</string>
<string name="mode_compatible">兼容模式</string>
<string name="mode_commmon">正常模式</string>
</resources> </resources>

@ -26,4 +26,8 @@
<string name="Pmmtool_work_true">Pmmtool is working!</string> <string name="Pmmtool_work_true">Pmmtool is working!</string>
<string name="Pmmtool_work_false">Pmmtool not working...</string> <string name="Pmmtool_work_false">Pmmtool not working...</string>
<string name="Pmmtool_work_hook_failed">Hook failed...</string> <string name="Pmmtool_work_hook_failed">Hook failed...</string>
<string name="Emulating_common">Emulating %1$s...(common)</string>
<string name="Emulating_compatible">Emulating %1$s...(compatible)</string>
<string name="mode_commmon">Common</string>
<string name="mode_compatible">Compatible</string>
</resources> </resources>
Loading…
Cancel
Save