Added double back press to exit
This commit is contained in:
parent
c24d38c753
commit
a71f0eb8e9
2 changed files with 35 additions and 0 deletions
|
@ -6,6 +6,7 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
|
@ -26,6 +27,7 @@ class InitUserInfoActivity : AppCompatActivity() {
|
|||
private var wakeupTime: Long = 0
|
||||
private var sleepingTime: Long = 0
|
||||
private lateinit var sharedPref: SharedPreferences
|
||||
private var doubleBackToExitPressedOnce = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -151,4 +153,20 @@ class InitUserInfoActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (doubleBackToExitPressedOnce) {
|
||||
super.onBackPressed()
|
||||
return
|
||||
}
|
||||
|
||||
this.doubleBackToExitPressedOnce = true
|
||||
Snackbar.make(
|
||||
this.window.decorView.findViewById(android.R.id.content),
|
||||
"Please click BACK again to exit",
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 1000)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.github.z3r0c00l_2k.aquadroid
|
|||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.TypedValue
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.daimajia.androidanimations.library.Techniques
|
||||
|
@ -26,6 +27,7 @@ class MainActivity : AppCompatActivity() {
|
|||
private var selectedOption: Int? = null
|
||||
private var selectedOptionName: String? = null
|
||||
private var snackbar: Snackbar? = null
|
||||
private var doubleBackToExitPressedOnce = false
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -235,5 +237,20 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (doubleBackToExitPressedOnce) {
|
||||
super.onBackPressed()
|
||||
return
|
||||
}
|
||||
|
||||
this.doubleBackToExitPressedOnce = true
|
||||
Snackbar.make(
|
||||
this.window.decorView.findViewById(android.R.id.content),
|
||||
"Please click BACK again to exit",
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 1000)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue