AnalogClock: add option to show tick marks (#1334)
* AnalogClock: add option to show tick marks * Refactor as data class with settings in WatchFaceSelector.kt
This commit is contained in:
@@ -24,6 +24,7 @@ import androidx.compose.material.icons.rounded.AlignVerticalBottom
|
||||
import androidx.compose.material.icons.rounded.AlignVerticalCenter
|
||||
import androidx.compose.material.icons.rounded.AlignVerticalTop
|
||||
import androidx.compose.material.icons.rounded.AutoAwesome
|
||||
import androidx.compose.material.icons.rounded.AvTimer
|
||||
import androidx.compose.material.icons.rounded.BatteryFull
|
||||
import androidx.compose.material.icons.rounded.ColorLens
|
||||
import androidx.compose.material.icons.rounded.DarkMode
|
||||
@@ -312,7 +313,8 @@ fun Clock(
|
||||
compact,
|
||||
showSeconds,
|
||||
useThemeColor,
|
||||
darkColors
|
||||
darkColors,
|
||||
style
|
||||
)
|
||||
|
||||
is ClockWidgetStyle.Orbit -> OrbitClock(
|
||||
|
||||
+18
-1
@@ -147,7 +147,9 @@ fun WatchFaceSelector(
|
||||
|
||||
Box {
|
||||
androidx.compose.animation.AnimatedVisibility(
|
||||
selected is ClockWidgetStyle.Digital1 || (selected is ClockWidgetStyle.Custom && selected.widgetId != null),
|
||||
selected is ClockWidgetStyle.Digital1 ||
|
||||
selected is ClockWidgetStyle.Analog ||
|
||||
(selected is ClockWidgetStyle.Custom && selected.widgetId != null),
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.zIndex(1f),
|
||||
@@ -179,6 +181,21 @@ fun WatchFaceSelector(
|
||||
}
|
||||
)
|
||||
}
|
||||
if (selected is ClockWidgetStyle.Analog) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.clock_variant_analog_ticks)) },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
if (selected.showTicks) Icons.Rounded.CheckCircle
|
||||
else Icons.Rounded.RadioButtonUnchecked,
|
||||
null
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
onSelect(selected.copy(showTicks = !selected.showTicks))
|
||||
}
|
||||
)
|
||||
}
|
||||
if (selected is ClockWidgetStyle.Custom) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.widget_pick_widget)) },
|
||||
|
||||
+15
@@ -13,6 +13,7 @@ import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.graphics.drawscope.Fill
|
||||
import androidx.compose.ui.graphics.drawscope.rotate
|
||||
import androidx.compose.ui.unit.dp
|
||||
import de.mm20.launcher2.preferences.ClockWidgetStyle
|
||||
import de.mm20.launcher2.ui.locals.LocalDarkTheme
|
||||
import java.util.Calendar
|
||||
|
||||
@@ -23,6 +24,7 @@ fun AnalogClock(
|
||||
showSeconds: Boolean,
|
||||
useThemeColor: Boolean,
|
||||
darkColors: Boolean,
|
||||
style: ClockWidgetStyle.Analog,
|
||||
) {
|
||||
val verticalLayout = !compact
|
||||
val date = Calendar.getInstance()
|
||||
@@ -66,6 +68,19 @@ fun AnalogClock(
|
||||
.padding(top = if (verticalLayout) 8.dp else 0.dp,
|
||||
bottom = if (verticalLayout) 8.dp else 0.dp)
|
||||
.size(size)) {
|
||||
if (style.showTicks) {
|
||||
for (hour in 0.. 11) {
|
||||
rotate(hour.toFloat() / 12f * 360f, this.size.center) {
|
||||
drawLine(
|
||||
secondaryColor,
|
||||
this.size.center.copy(y = this.size.height * 0.95f),
|
||||
this.size.center.copy(y = this.size.height),
|
||||
strokeWidth = (strokeWidth * 0.75f).toPx(),
|
||||
cap = StrokeCap.Round
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
rotate(hour.toFloat() / 12f * 360f + ((minute.toFloat() / 60f) * 30f) + (second.toFloat() / 120f), this.size.center) {
|
||||
drawLine(
|
||||
color,
|
||||
|
||||
+2
-2
@@ -21,11 +21,11 @@ class ClockWidgetSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
settings.setCompact(compact)
|
||||
}
|
||||
|
||||
val availableClockStyles = combine(settings.digital1, settings.custom) { digital1, custom ->
|
||||
val availableClockStyles = combine(settings.digital1, settings.analog, settings.custom) { digital1, analog, custom ->
|
||||
listOf(
|
||||
digital1,
|
||||
ClockWidgetStyle.Digital2,
|
||||
ClockWidgetStyle.Analog,
|
||||
analog,
|
||||
ClockWidgetStyle.Orbit,
|
||||
ClockWidgetStyle.Segment,
|
||||
ClockWidgetStyle.Binary,
|
||||
|
||||
Reference in New Issue
Block a user