Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AbstractGauge interface public to allow dynamic instancing #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

penguin86
Copy link

Hello, thank you for your nice lib!
I found useful to make AbstractGauge interface public, so if you'd like, you could merge it to your lib.
The use case is instancing gauges dynamically at runtime, when the type of gauge is not known at compile time and cannot be included in a layout file.

Here an usage example (the gauges are configured remotely through a json):

                val gaugeView: AbstractGauge = when(gaugeJo.getString("type")) {
                    "half" -> HalfGauge(this)
                    "multi" -> MultiGauge(this)
                    "arc" -> ArcGauge(this)
                    else -> FullGauge(this)
                }
                gaugeContainerView.addView(gaugeView)

                // Set max, min, value
                gaugeView.minValue = gaugeJo.getDouble("min")
                gaugeView.maxValue = gaugeJo.getDouble("max")
                gaugeView.value = gaugeJo.getJSONArray("values").getDouble(0)

                // Set ranges
                val range = Range()
                range.color = Color.parseColor("#00ff00")
                range.from = gaugeJo.getDouble("min")
                range.to = gaugeJo.getDouble("warn")
                gaugeView.addRange(range)
    
                // ... and so on...

This is possible only having a supertype (or the interface) common to all gauges.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant