Skip to content

Commit

Permalink
✨ 包名检测,信息
Browse files Browse the repository at this point in the history
  • Loading branch information
Szzrain committed May 24, 2023
1 parent aa5a100 commit 13e73bb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/sealdice/dice/DebugActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ class DebugActivity : AppCompatActivity() {
findViewById<Button>(R.id.DEBUG_crash).setOnClickListener {
throw Exception("DEBUG:Crash")
}
findViewById<Button>(R.id.DEBUG_button_info).setOnClickListener {
val alertDialogBuilder = androidx.appcompat.app.AlertDialog.Builder(
this, R.style.Theme_Mshell_DialogOverlay
)
alertDialogBuilder.setTitle("DEBUG:Info")
alertDialogBuilder.setMessage("Version:"+BuildConfig.VERSION_NAME+"\nBuild:"+BuildConfig.VERSION_CODE+"\nPackage:"+packageName)
alertDialogBuilder.setPositiveButton("确定") { _: android.content.DialogInterface, _: Int ->
}
alertDialogBuilder.create().show()
}
findViewById<ImageView>(R.id.DEBUG_app_icon).setOnClickListener {
it.animate().scaleX(1.2f).scaleY(1.2f).setDuration(100).withEndAction {
it.animate().scaleX(1f).scaleY(1f).setDuration(100).start()
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/sealdice/dice/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.*
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
Expand Down Expand Up @@ -73,6 +74,24 @@ class MainActivity : AppCompatActivity() {
return true
}

override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onPostCreate(savedInstanceState, persistentState)
if (this.packageName != "com.sealdice.dice") {
val alertDialogBuilder = AlertDialog.Builder(this,R.style.Theme_Mshell_DialogOverlay)
alertDialogBuilder.setTitle("提示")
alertDialogBuilder.setMessage("检测到您正在使用非官方版本或多开软件,可能会导致一些问题,建议您使用官方版本")
alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int -> }
alertDialogBuilder.setNegativeButton("前往官网") { _: DialogInterface, _: Int ->
val uri = Uri.parse("https://dice.weizaima.com")
val intent = Intent()
intent.action = "android.intent.action.VIEW"
intent.data = uri
startActivity(intent)
}
alertDialogBuilder.create().show()
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
android:gravity="center"
android:text="RUNNING SERVICES"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/DEBUG_button_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="400dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center"
android:text="INFO"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/DEBUG_app_icon"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit 13e73bb

Please sign in to comment.