Using a single Canvas of Jetpack Compose to interact with pointerInput
It calculates a square at the center of Canvas thus it supports Horizontally or Vertically.
vertical.mp4
horizontal.mp4
Demonstrating a pattern lock functionality with the use of Android Compose. This activity allows the user to create a pattern by dragging on the screen across multiple dots. Each selected dot will be a part of the pattern, represented by a number.
It's all in the @Composable fun PatternLock()
Here is a brief overview of the main components:
-
PatternLockActivity: This is the main activity. It sets the content to be PatternLockScreen.
-
PatternLockScreen: This composable function provides the main UI for the activity. It displays the pattern the user has drawn on the screen as a sequence of numbers.
-
SelectedNumbersDisplay: This composable function displays the sequence of numbers corresponding to the pattern the user has drawn on the screen.
-
PatternLock: This composable function enables the pattern lock functionality. It takes a callback onUpdates which is called when the pattern changes.
-
vibrate: This function triggers the device to vibrate, giving tactile feedback to the user.
-
PatternLockPreview and PatternLockPreviewForAutomotive1024p: These are preview functions that allow you to see how the PatternLockScreen looks without needing to run it on a device or emulator.
The user interacts with the application by touching and dragging their finger across the screen, forming a pattern. The current pattern will be displayed at the top of the screen as a sequence of numbers.
The pattern lock is a simple and intuitive way for users to interact with your application. It can be used for any situation where you want to ask the user to input a simple sequence, like a gesture-based login, simple game control, or any other type of user interaction that can be mapped to a pattern of dots.