-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: android speed limit view * feat: android speed limit view * feat: android speed limit view
- Loading branch information
Showing
38 changed files
with
641 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
.../composeui/src/main/java/com/stadiamaps/ferrostar/composeui/measurement/LocalizedSpeed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package com.stadiamaps.ferrostar.composeui.measurement | ||
|
||
import android.content.res.Resources | ||
import android.content.Context | ||
import com.stadiamaps.ferrostar.composeui.R | ||
import com.stadiamaps.ferrostar.core.measurement.SpeedUnit | ||
import com.stadiamaps.ferrostar.core.measurement.MeasurementSpeedUnit | ||
|
||
fun SpeedUnit.localizedString(): String { | ||
fun MeasurementSpeedUnit.localizedString(context: Context): String { | ||
return when (this) { | ||
SpeedUnit.MetersPerSecond -> Resources.getSystem().getString(R.string.unit_short_mps) | ||
SpeedUnit.MilesPerHour -> Resources.getSystem().getString(R.string.unit_short_kph) | ||
SpeedUnit.KilometersPerHour -> Resources.getSystem().getString(R.string.unit_short_mph) | ||
MeasurementSpeedUnit.MetersPerSecond -> context.getString(R.string.unit_short_mps) | ||
MeasurementSpeedUnit.MilesPerHour -> context.getString(R.string.unit_short_mph) | ||
MeasurementSpeedUnit.KilometersPerHour -> context.getString(R.string.unit_short_kph) | ||
MeasurementSpeedUnit.Knots -> context.getString(R.string.unit_short_knot) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../composeui/src/main/java/com/stadiamaps/ferrostar/composeui/support/GreenScreenPreview.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.stadiamaps.ferrostar.composeui.support | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
@Preview( | ||
name = "Dark Mode", | ||
showBackground = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES, | ||
backgroundColor = 0xFF93C97C) | ||
@Preview( | ||
name = "Light Mode", | ||
showBackground = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_NO, | ||
backgroundColor = 0xFF93C97C) | ||
internal annotation class GreenScreenPreview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ain/java/com/stadiamaps/ferrostar/composeui/views/components/speedlimit/SpeedLimitView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.stadiamaps.ferrostar.composeui.views.components.speedlimit | ||
|
||
import android.content.Context | ||
import android.icu.util.ULocale | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.stadiamaps.ferrostar.composeui.formatting.MeasurementSpeedFormatter | ||
import com.stadiamaps.ferrostar.core.measurement.MeasurementSpeed | ||
import com.stadiamaps.ferrostar.core.measurement.MeasurementSpeedUnit | ||
|
||
enum class SignageStyle { | ||
MUTCD, | ||
ViennaConvention | ||
} | ||
|
||
@Composable | ||
fun SpeedLimitView( | ||
modifier: Modifier = Modifier, | ||
speedLimit: MeasurementSpeed, | ||
signageStyle: SignageStyle, | ||
context: Context = LocalContext.current, | ||
formatter: MeasurementSpeedFormatter = MeasurementSpeedFormatter(context, speedLimit), | ||
locale: ULocale = ULocale.getDefault() | ||
) { | ||
when (signageStyle) { | ||
SignageStyle.MUTCD -> | ||
USStyleSpeedLimitView( | ||
modifier, speedLimit, MeasurementSpeedUnit.MilesPerHour, context, formatter, locale) | ||
SignageStyle.ViennaConvention -> | ||
ViennaConventionStyleSpeedLimitView( | ||
modifier, | ||
speedLimit, | ||
MeasurementSpeedUnit.KilometersPerHour, | ||
context, | ||
formatter, | ||
locale) | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
...a/com/stadiamaps/ferrostar/composeui/views/components/speedlimit/USStyleSpeedLimitView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.stadiamaps.ferrostar.composeui.views.components.speedlimit | ||
|
||
import android.content.Context | ||
import android.icu.util.ULocale | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.shadow | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.stadiamaps.ferrostar.composeui.R | ||
import com.stadiamaps.ferrostar.composeui.formatting.MeasurementSpeedFormatter | ||
import com.stadiamaps.ferrostar.composeui.measurement.localizedString | ||
import com.stadiamaps.ferrostar.composeui.support.GreenScreenPreview | ||
import com.stadiamaps.ferrostar.core.measurement.MeasurementSpeed | ||
import com.stadiamaps.ferrostar.core.measurement.MeasurementSpeedUnit | ||
|
||
@Composable | ||
fun USStyleSpeedLimitView( | ||
modifier: Modifier = Modifier, | ||
speedLimit: MeasurementSpeed, | ||
units: MeasurementSpeedUnit = MeasurementSpeedUnit.MilesPerHour, | ||
context: Context = LocalContext.current, | ||
formatter: MeasurementSpeedFormatter = MeasurementSpeedFormatter(context, speedLimit), | ||
locale: ULocale = ULocale.getDefault() | ||
) { | ||
val formattedSpeed = formatter.formattedValue(locale, units) | ||
|
||
Box( | ||
modifier = | ||
modifier | ||
.height(84.dp) | ||
.width(60.dp) | ||
.background(color = Color.White, shape = RoundedCornerShape(8.dp)) | ||
.padding(2.dp)) { | ||
Box( | ||
modifier = | ||
Modifier.height(80.dp) | ||
.width(56.dp) | ||
.background(color = Color.Black, shape = RoundedCornerShape(6.dp)) | ||
.padding(2.dp)) { | ||
Box( | ||
modifier = | ||
Modifier.height(76.dp) | ||
.width(52.dp) | ||
.background(color = Color.White, shape = RoundedCornerShape(4.dp)) | ||
.padding(4.dp)) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center) { | ||
Text( | ||
text = stringResource(R.string.speed).uppercase(), | ||
fontSize = 9.sp, | ||
lineHeight = 10.sp, | ||
fontWeight = FontWeight.Bold, | ||
color = Color.Black) | ||
|
||
Text( | ||
text = stringResource(R.string.limit).uppercase(), | ||
fontSize = 9.sp, | ||
lineHeight = 10.sp, | ||
fontWeight = FontWeight.Bold, | ||
color = Color.Black) | ||
|
||
Spacer(modifier = Modifier.height(6.dp)) | ||
|
||
Text( | ||
text = formattedSpeed, | ||
fontSize = if (formattedSpeed.length > 3) 18.sp else 24.sp, | ||
lineHeight = if (formattedSpeed.length > 3) 20.sp else 26.sp, | ||
fontWeight = FontWeight.ExtraBold, | ||
color = Color.Black, | ||
textAlign = TextAlign.Center) | ||
|
||
Text( | ||
text = units.localizedString(context), | ||
fontSize = 9.sp, | ||
lineHeight = 10.sp, | ||
fontWeight = FontWeight.Bold, | ||
color = Color.Gray) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@GreenScreenPreview | ||
@Composable | ||
fun USStyleSpeedLimitViewLowSpeedPreview() { | ||
USStyleSpeedLimitView( | ||
modifier = Modifier.padding(16.dp).shadow(4.dp), | ||
speedLimit = MeasurementSpeed(55.0, MeasurementSpeedUnit.MilesPerHour)) | ||
} | ||
|
||
@GreenScreenPreview | ||
@Composable | ||
fun USStyleSpeedLimitViewModerateSpeedPreview() { | ||
USStyleSpeedLimitView( | ||
modifier = Modifier.padding(16.dp).shadow(4.dp), | ||
speedLimit = MeasurementSpeed(100.0, MeasurementSpeedUnit.MilesPerHour)) | ||
} | ||
|
||
@GreenScreenPreview | ||
@Composable | ||
fun USStyleSpeedLimitViewHighSpeedPreview() { | ||
USStyleSpeedLimitView( | ||
modifier = Modifier.padding(16.dp).shadow(4.dp), | ||
speedLimit = MeasurementSpeed(1000.0, MeasurementSpeedUnit.MilesPerHour)) | ||
} |
Oops, something went wrong.