forked from thijooree/android
redesign pin and pattern UI, add settings for changing lock and enable/disable biometrics and add button to lock app from any screen
This commit is contained in:
@@ -21,6 +21,13 @@ class SecuritySetupFragment : Fragment() {
|
||||
fun onSecuritySetupComplete()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ARG_CHANGE_MODE = "change_mode"
|
||||
fun newInstance(changeMode: Boolean = false) = SecuritySetupFragment().apply {
|
||||
arguments = android.os.Bundle().also { it.putBoolean(ARG_CHANGE_MODE, changeMode) }
|
||||
}
|
||||
}
|
||||
|
||||
private var _b: FragmentSecuritySetupBinding? = null
|
||||
private val b get() = _b!!
|
||||
|
||||
@@ -38,7 +45,8 @@ class SecuritySetupFragment : Fragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
val prefs = requireContext().getSharedPreferences("prefs", Context.MODE_PRIVATE)
|
||||
if (prefs.getString("security_method", null) != null) {
|
||||
val changeMode = arguments?.getBoolean(ARG_CHANGE_MODE, false) ?: false
|
||||
if (!changeMode && prefs.getString("security_method", null) != null) {
|
||||
(activity as? Callback)?.onSecuritySetupComplete()
|
||||
}
|
||||
|
||||
@@ -69,6 +77,10 @@ class SecuritySetupFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun buildNumpad() {
|
||||
val dp = resources.displayMetrics.density
|
||||
val btnSize = (68 * dp).toInt()
|
||||
val btnMarginH = (10 * dp).toInt()
|
||||
val rowMarginV = (6 * dp).toInt()
|
||||
val rows = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
@@ -78,9 +90,11 @@ class SecuritySetupFragment : Fragment() {
|
||||
rows.forEach { keys ->
|
||||
val row = LinearLayout(requireContext()).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
gravity = android.view.Gravity.CENTER
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f
|
||||
)
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
).also { it.setMargins(0, rowMarginV, 0, rowMarginV) }
|
||||
}
|
||||
keys.forEach { key ->
|
||||
val style = if (key == "✓")
|
||||
@@ -89,11 +103,12 @@ class SecuritySetupFragment : Fragment() {
|
||||
com.google.android.material.R.attr.materialButtonOutlinedStyle
|
||||
val btn = MaterialButton(requireContext(), null, style).apply {
|
||||
text = key
|
||||
textSize = 20f
|
||||
insetTop = 0
|
||||
insetBottom = 0
|
||||
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)
|
||||
.also { it.setMargins(4, 4, 4, 4) }
|
||||
textSize = 24f
|
||||
insetTop = 0; insetBottom = 0
|
||||
minimumWidth = 0; minimumHeight = 0
|
||||
cornerRadius = btnSize / 2
|
||||
layoutParams = LinearLayout.LayoutParams(btnSize, btnSize)
|
||||
.also { it.setMargins(btnMarginH, 0, btnMarginH, 0) }
|
||||
}
|
||||
btn.setOnClickListener { handleKey(key) }
|
||||
row.addView(btn)
|
||||
@@ -223,7 +238,12 @@ class SecuritySetupFragment : Fragment() {
|
||||
.digest(input.toByteArray()).joinToString("") { "%02x".format(it) }
|
||||
|
||||
private fun finishSetup() {
|
||||
(activity as? Callback)?.onSecuritySetupComplete()
|
||||
val cb = activity as? Callback
|
||||
if (cb != null) {
|
||||
cb.onSecuritySetupComplete()
|
||||
} else {
|
||||
parentFragmentManager.popBackStack()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
Reference in New Issue
Block a user