๐ PinLock is a light library to display Pin Lock screen in Jetpack Compose. The library handles saving pin in encrypted file. Integration is very easy and fast.
Add the maven library bucket to the dependencyResolutionManagement.repositories
block in settings.gradle.kts
file as follows:
dependencyResolutionManagement {
...
repositories {
...
maven("https://jitpack.io")
}
}
Install the library to the project in desired module's build.gradle.kts
file. Replace <current_version>
with the actual version:
implementation("com.github.raheemadamboev:pin-lock-compose:<current_version>")
Firstly, initialize the library on your onCreate
of Application class:
PinManager.initialize(this)
To add Pin Lock screen, add the PinLock
composable to your compose area:
PinLock(
title = { pinExists ->
Text(text = if (pinExists) "Enter your pin" else "Create pin")
},
color = MaterialTheme.colorScheme.primary,
onPinCorrect = {
// pin is correct, navigate or hide pin lock
},
onPinIncorrect = {
// pin is incorrect, show error
},
onPinCreated = {
// pin created for the first time, navigate or hide pin lock
}
)
If there is no saved pin yet, it promtps the user to create pin. If there is saved pin, it promts the user to enter its pin:
It is also possible to change pin. Just add ChangePinLock
composable to your compose area:
ChangePinLock(
title = { authenticated ->
Text(text = if (authenticated) "Enter new pin" else "Enter your pin")
},
color = MaterialTheme.colorScheme.primary,
onPinIncorrect = {
// pin is incorrect, show error
},
onPinChanged = {
// pin changed, navigate or hide pin lock
}
)
Use this only if there is already saved pin. If there is no saved pin, use simple PinLock
instead for creating pin for the first time. When using ChangePinLock
, firstly it prompts the user to enter original pin. After user succesfully authenticates using his original pin, it prompts the user to creat a new pin:
To check if saved pin exists:
val pinExists = PinManager.pinExists()
To clear saved pin so user can create brand new pin:
PinManager.clearPin()
- pin lock screen very easily
- handles encryption and saving pin internally
- change pin lock screen
- customizable background color
- robust to configuration changes
- backspace to remove last entered pin number
- incorrect indicator animation
You can install and try demo app. All the features are implemented in the demo from creating pin to changing pin.
Notepad: 100 000+ downloads.
Designed and developed by raheemadamboev (Raheem) 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.