Skip to content
/ hzone Public

🩸 HZone is a Kotlin library that simplifies the implementation of a dynamic heart rate zone component. Visualize heart rate zones effortlessly based on the BPM (beats per minute) value. The library offers easy integration.

License

Notifications You must be signed in to change notification settings

gastsail/hzone

Repository files navigation

HZone

ezgif com-video-to-gif

HZone is a Kotlin library that demonstrates how to implement a component that draws five different zones based on a BPM (heart rate beats per minute) value provided to it.

The inspiration was taken from the apple watch in which you can see these zones in action doing any activity, the idea of this library is to bring this feature to your Android project.

image

Getting Started

To use HZone in your project, you need to add the following configuration to your settings.gradle file.

Kotlin DSL

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://jitpack.io")
        }
    }
}

Groovy

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

Next, add the library dependency to your app module's build.gradle.

Kotlin DSL

dependencies {
    implementation("com.github.gastsail:hzone:[latest]")
}

Groovy

dependencies {
    implementation 'com.github.gastsail:hzone:[latest]'
}

Usage

The concept of heart zones, as defined by the Zoladz method for heart rate calculation, is explained in detail on Wikipedia.

To use HZone in your application, import the HZone method and provide the necessary parameters.

val averageBpm = 75 // Replace with your actual average BPM

HZone(averageBpm) {
    // Zone clicked
}

You can also specify the onZoneClick parameter to handle zone click events.

HZone(averageBpm = averageBpm, onZoneClick = {
    // Zone clicked
})

The averageBpm parameter is used to calculate the average BPM from the values you provide using the calculateAverageBpm function.

val bpmValues = viewModel.bpmValues.collectAsStateWithLifecycle()
val averageBpm = calculateAverageBpm(bpmValues)

Remember that the bpmValues should be a stream that comes from a data source, this can be modeled in a viewmodel that emits each bpm to the view and the view collect it as state.

Colors can be customized sending your own Custom Zones, take in mind that the max zones are 5 so you will be limited sending the list to the first 5 entries.

val customZones = listOf(
                        Zone(
                            color = Color.Green,
                            text = "Zone 1",
                            zoneType = ZoneType.ZONE_1,
                            zoneEnabled = false
                        ),
                        Zone(
                            color = Color.DarkGray,
                            text = "Zone 2",
                            zoneType = ZoneType.ZONE_2,
                            zoneEnabled = false
                        )
                    )
                    HZone(
                        modifier = Modifier.padding(16.dp),
                        averageBpm = viewModel.averageBpm.collectAsState().value,
                        customZones = customZones,
                        onZoneClick = {})

Feel free to customize and integrate HZone into your project to visualize heart rate zones dynamically.

If you like this repo please don't forget to leave a ⭐️

About

🩸 HZone is a Kotlin library that simplifies the implementation of a dynamic heart rate zone component. Visualize heart rate zones effortlessly based on the BPM (beats per minute) value. The library offers easy integration.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages