Created PatternSecurityLockDialog, which will be in charge of creating and confirming a new Pattern of validating the existing one, with a logic similar to PINSecurityLockDialog's. Created basic PatternSecurityLockDialog with a UI that resembles Android's.
This commit is contained in:
parent
e8e1259314
commit
e44f4ea6e2
5 changed files with 192 additions and 11 deletions
|
@ -0,0 +1,75 @@
|
|||
package cy.agorise.bitsybitshareswallet.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import cy.agorise.bitsybitshareswallet.R
|
||||
import kotlinx.android.synthetic.main.dialog_pattern_security_lock.*
|
||||
import com.andrognito.patternlockview.PatternLockView
|
||||
import com.andrognito.patternlockview.listener.PatternLockViewListener
|
||||
import cy.agorise.bitsybitshareswallet.utils.toast
|
||||
|
||||
|
||||
/**
|
||||
* Contains all the specific logic to create and confirm a new Pattern or verifying the validity of the current one.
|
||||
*/
|
||||
class PatternSecurityLockDialog : BaseSecurityLockDialog() {
|
||||
|
||||
companion object {
|
||||
const val TAG = "PatternSecurityLockDialog"
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
|
||||
return inflater.inflate(R.layout.dialog_pattern_security_lock, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupScreen()
|
||||
|
||||
patternLockView.addPatternLockListener(mPatternLockViewListener)
|
||||
}
|
||||
|
||||
private val mPatternLockViewListener = object : PatternLockViewListener {
|
||||
override fun onStarted() {
|
||||
context?.toast("Pattern started")
|
||||
}
|
||||
|
||||
override fun onProgress(progressPattern: List<PatternLockView.Dot>) {
|
||||
tvMessage.text = getString(R.string.msg__release_finger)
|
||||
}
|
||||
|
||||
override fun onComplete(pattern: List<PatternLockView.Dot>) {
|
||||
if (pattern.size < 4) {
|
||||
patternLockView.setViewMode(PatternLockView.PatternViewMode.WRONG)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
context?.toast("Pattern has been cleared")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupScreen() {
|
||||
when (currentStep) {
|
||||
STEP_SECURITY_LOCK_VERIFY -> {
|
||||
tvTitle.text = getString(R.string.title__re_enter_your_pattern)
|
||||
tvSubTitle.text = getString(R.string.msg__enter_your_pattern)
|
||||
btnClear.visibility = View.INVISIBLE
|
||||
}
|
||||
STEP_SECURITY_LOCK_CREATE -> {
|
||||
tvTitle.text = getString(R.string.title__set_bitsy_screen_lock)
|
||||
tvSubTitle.text = getString(R.string.msg__set_bitsy_pattern)
|
||||
btnClear.visibility = View.INVISIBLE
|
||||
}
|
||||
STEP_SECURITY_LOCK_CONFIRM -> {
|
||||
tvTitle.text = getString(R.string.title__re_enter_your_pin)
|
||||
tvSubTitle.text = ""
|
||||
tvSubTitle.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -233,19 +233,23 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O
|
|||
* @return true if the action was handled, false otherwise
|
||||
*/
|
||||
private fun verifySecurityLock(securityLockSelected: Int, actionIdentifier: Int): Boolean {
|
||||
return when (securityLockSelected) {
|
||||
0 -> { /* PIN */
|
||||
val pinFrag = PINSecurityLockDialog()
|
||||
// Args used for both PIN and Pattern options
|
||||
val args = Bundle()
|
||||
args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK,
|
||||
BaseSecurityLockDialog.STEP_SECURITY_LOCK_VERIFY)
|
||||
args.putInt(BaseSecurityLockDialog.KEY_ACTION_IDENTIFIER, actionIdentifier)
|
||||
|
||||
return when (securityLockSelected) {
|
||||
0 -> { /* PIN */
|
||||
val pinFrag = PINSecurityLockDialog()
|
||||
pinFrag.arguments = args
|
||||
pinFrag.show(childFragmentManager, "pin_security_lock_tag")
|
||||
true
|
||||
}
|
||||
1 -> { /* Pattern */
|
||||
|
||||
val patternFrag = PatternSecurityLockDialog()
|
||||
patternFrag.arguments = args
|
||||
patternFrag.show(childFragmentManager, "pattern_security_lock_tag")
|
||||
true
|
||||
}
|
||||
else -> { /* None */
|
||||
|
@ -281,19 +285,23 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O
|
|||
context?.let {
|
||||
MaterialDialog(it).show {
|
||||
title(R.string.title__security_dialog)
|
||||
listItems(R.array.security_lock_options) {dialog, index, text ->
|
||||
when (index) {
|
||||
0 -> { /* PIN */
|
||||
val pinFrag = PINSecurityLockDialog()
|
||||
listItems(R.array.security_lock_options) {_, index, _ ->
|
||||
// Args used for both PIN and Pattern options
|
||||
val args = Bundle()
|
||||
args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK,
|
||||
BaseSecurityLockDialog.STEP_SECURITY_LOCK_CREATE)
|
||||
args.putInt(BaseSecurityLockDialog.KEY_ACTION_IDENTIFIER, -1)
|
||||
|
||||
when (index) {
|
||||
0 -> { /* PIN */
|
||||
val pinFrag = PINSecurityLockDialog()
|
||||
pinFrag.arguments = args
|
||||
pinFrag.show(childFragmentManager, "pin_security_lock_tag")
|
||||
}
|
||||
1 -> { /* Pattern */
|
||||
|
||||
val patternFrag = PatternSecurityLockDialog()
|
||||
patternFrag.arguments = args
|
||||
patternFrag.show(childFragmentManager, "pattern_security_lock_tag")
|
||||
}
|
||||
else -> { /* None */
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||
|
|
86
app/src/main/res/layout/dialog_pattern_security_lock.xml
Normal file
86
app/src/main/res/layout/dialog_pattern_security_lock.xml
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingStart="@dimen/activity_horizontal_margin"
|
||||
android:paddingEnd="@dimen/activity_horizontal_margin"
|
||||
android:orientation="vertical"
|
||||
tools:context=".fragments.PINSecurityLockDialog">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivLock"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginTop="@dimen/spacing_same_topic"
|
||||
android:src="@drawable/ic_lock"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:contentDescription="@string/title__re_enter_your_pin" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_same_topic"
|
||||
tools:text="Enter your pattern"
|
||||
android:textAppearance="@style/TextAppearance.Bitsy.Headline5"
|
||||
app:layout_constraintTop_toBottomOf="@id/ivLock" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSubTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
tools:text="Enter your BiTSy pattern to continue"
|
||||
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvTitle"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMessage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Draw an unlock pattern"
|
||||
android:textAlignment="center"
|
||||
app:layout_constraintBottom_toTopOf="@id/patternLockView"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSubTitle"
|
||||
app:layout_constraintVertical_chainStyle="spread"
|
||||
tools:layout_editor_absoluteX="16dp" />
|
||||
|
||||
<com.andrognito.patternlockview.PatternLockView
|
||||
android:id="@+id/patternLockView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="@dimen/spacing_different_topic"
|
||||
app:normalStateColor="?android:textColorSecondary"
|
||||
app:correctStateColor="@color/colorPrimary"
|
||||
app:wrongStateColor="@color/colorSend"
|
||||
app:layout_constraintDimensionRatio="h,1:1"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvMessage"
|
||||
app:layout_constraintBottom_toTopOf="@id/btnClear"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnClear"
|
||||
style="@style/Widget.Bitsy.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/btn__clear"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnNext"
|
||||
style="@style/Widget.Bitsy.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/btn__next"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -151,5 +151,11 @@
|
|||
<string name="msg__set_bitsy_pin">Por seguridad, crea un PIN para BiTSy</string>
|
||||
<string name="msg__min_pin_length">El PIN debe tener al menos 6 dígitos</string>
|
||||
<string name="title__pins_dont_match">El PIN no concuerda</string>
|
||||
<string name="title__re_enter_your_pattern">Reingresa tu patrón</string>
|
||||
<string name="msg__enter_your_pattern">Ingresa tu patrón de BiTSy para continuar</string>
|
||||
<string name="msg__set_bitsy_pattern">Por seguridad, crea un patrón para BiTSy</string>
|
||||
<string name="msg__release_finger">Suelta tu dedo al terminar</string>
|
||||
<string name="btn__clear">Limpiar</string>
|
||||
<string name="btn__next">Siguiente</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -152,5 +152,11 @@
|
|||
<string name="msg__set_bitsy_pin">For security, set BiTSy PIN</string>
|
||||
<string name="msg__min_pin_length">PIN must be at least 6 digits</string>
|
||||
<string name="title__pins_dont_match">PINs don\'t match</string>
|
||||
<string name="title__re_enter_your_pattern">Re-enter your pattern</string>
|
||||
<string name="msg__enter_your_pattern">Enter your BiTSy pattern to continue</string>
|
||||
<string name="msg__set_bitsy_pattern">For security, set BiTSy pattern</string>
|
||||
<string name="msg__release_finger">Release finger when done</string>
|
||||
<string name="btn__clear">Clear</string>
|
||||
<string name="btn__next">Next</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue