Skip to content

Commit 0d164fe

Browse files
author
Ramesh M Nair
committed
added full customisation option for the views
1 parent e51781a commit 0d164fe

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

SpeedometerComposeLibrary/src/main/java/com/ramzmania/speedometercomposeview/SpeedometerComposeView.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ fun SpeedometerComposeView(
6868
glowMulticolor:Boolean=true,
6969
glowSingleColor: Color = Color(0xFF388E3C),
7070
glowRadius:Float=28f,
71-
glowSpeedPoints:Boolean=false
71+
glowSpeedPoints:Boolean=false,
72+
baseArcColorConstant:Color?=null,
73+
needleCircleColor:Color?=null,
74+
needleIndicatorColor:Color?=null,
75+
needleSemiIndicatorColor:Color=Color.White,
76+
movingSpeedTextExtraPadding:Float=14f
7277
) {
7378

7479
// Constants for drawing the speedometer
@@ -126,7 +131,7 @@ fun SpeedometerComposeView(
126131

127132
// Draw the background arc
128133
drawArc(
129-
secondaryColor,
134+
baseArcColorConstant ?: secondaryColor,
130135
startArcAngle,
131136
arcDegrees.toFloat(),
132137
false,
@@ -247,8 +252,8 @@ fun SpeedometerComposeView(
247252

248253

249254
// Draw circles for the center and needle
250-
drawCircle(mainColor, 50f, centerOffset)
251-
drawCircle(Color.White, 25f, centerOffset)
255+
drawCircle(needleCircleColor ?: mainColor, 50f, centerOffset)
256+
drawCircle(needleSemiIndicatorColor, 25f, centerOffset)
252257
drawCircle(needleColor, 20f, centerOffset)
253258
//
254259
// // Draw markers and their text the 55 marker points
@@ -257,7 +262,7 @@ fun SpeedometerComposeView(
257262
val lineEndX = 100f
258263
val lineEndY =
259264
h / 2f // Since line is horizontal, lineEndY is the same as the center of the canvas vertically
260-
paint.color = mainColor
265+
paint.color = needleIndicatorColor ?: mainColor
261266

262267
val lineStartX = if (counter % 5 == 0) {
263268
paint.strokeWidth = 3f
@@ -340,7 +345,7 @@ fun SpeedometerComposeView(
340345
var textY = lineEndY + 10f
341346
if(text>99)
342347
{
343-
textY += 14f
348+
textY += movingSpeedTextExtraPadding
344349
}
345350
/*Rotate canvas so that the point perfectly pad with the circle*/
346351
when {

app/src/main/java/com/ramzmania/speedometerview/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.runtime.Composable
1313
import androidx.compose.runtime.SideEffect
1414
import androidx.compose.ui.Modifier
1515
import androidx.compose.ui.graphics.Color
16+
import androidx.compose.ui.platform.LocalContext
1617
import androidx.compose.ui.res.colorResource
1718
import androidx.compose.ui.tooling.preview.Preview
1819
import androidx.compose.ui.unit.dp

app/src/main/java/com/ramzmania/speedometerview/SpeedometerTypes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fun SpeedometerUiViewCompose() {
256256
Column {
257257
Spacer(modifier = Modifier.height(16.dp)) // Adjust the height as needed for the top margin
258258
SpeedometerComposeView(
259-
speedMeterMaxRange = 220,
259+
speedMeterMaxRange = 80,
260260
currentSpeedValue = speedOver.value.toInt(),
261261
needleColor = Color.Red,
262262
speedTextColor = colorResource(

0 commit comments

Comments
 (0)