Add two new clock styles: analog clock and empty clock
This commit is contained in:
parent
b533e02ecf
commit
1faac28ce4
@ -48,6 +48,8 @@ message Settings {
|
||||
DigitalClock1 = 0;
|
||||
DigitalClock2 = 1;
|
||||
BinaryClock = 2;
|
||||
AnalogClock = 3;
|
||||
EmptyClock = 4;
|
||||
}
|
||||
ClockStyle clock_style = 2;
|
||||
}
|
||||
|
||||
@ -19,9 +19,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import de.mm20.launcher2.preferences.Settings.ClockWidgetSettings.ClockStyle
|
||||
import de.mm20.launcher2.preferences.Settings.ClockWidgetSettings.ClockWidgetLayout
|
||||
import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidgetVM
|
||||
import de.mm20.launcher2.ui.launcher.widgets.clock.clocks.BinaryClock
|
||||
import de.mm20.launcher2.ui.launcher.widgets.clock.clocks.DigitalClock1
|
||||
import de.mm20.launcher2.ui.launcher.widgets.clock.clocks.DigitalClock2
|
||||
import de.mm20.launcher2.ui.launcher.widgets.clock.clocks.*
|
||||
import de.mm20.launcher2.ui.launcher.widgets.clock.parts.DatePart
|
||||
|
||||
@Composable
|
||||
@ -120,6 +118,8 @@ fun Clock(
|
||||
ClockStyle.DigitalClock1 -> DigitalClock1(time, layout)
|
||||
ClockStyle.DigitalClock2 -> DigitalClock2(time, layout)
|
||||
ClockStyle.BinaryClock -> BinaryClock(time, layout)
|
||||
ClockStyle.AnalogClock -> AnalogClock(time, layout)
|
||||
ClockStyle.EmptyClock -> EmptyClock(time, layout)
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package de.mm20.launcher2.ui.launcher.widgets.clock.clocks
|
||||
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.center
|
||||
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.Settings
|
||||
import java.util.*
|
||||
|
||||
@Composable
|
||||
fun AnalogClock(
|
||||
time: Long,
|
||||
layout: Settings.ClockWidgetSettings.ClockWidgetLayout
|
||||
) {
|
||||
val verticalLayout = layout == Settings.ClockWidgetSettings.ClockWidgetLayout.Vertical
|
||||
val date = Calendar.getInstance()
|
||||
date.timeInMillis = time
|
||||
val minute = date[Calendar.MINUTE]
|
||||
val hour = date[Calendar.HOUR]
|
||||
|
||||
val size = if (verticalLayout) 128.dp else 56.dp
|
||||
val strokeWidth = if (verticalLayout) 4.dp else 2.dp
|
||||
|
||||
val color = LocalContentColor.current
|
||||
Canvas(modifier = Modifier
|
||||
.padding(bottom = if (verticalLayout) 8.dp else 0.dp)
|
||||
.size(size)) {
|
||||
drawCircle(
|
||||
color,
|
||||
radius = strokeWidth.toPx(),
|
||||
center = this.size.center,
|
||||
style = Fill
|
||||
)
|
||||
rotate(hour.toFloat() / 12f * 360f + minute.toFloat() / 60f * 5f, this.size.center) {
|
||||
drawLine(
|
||||
color,
|
||||
this.size.center, this.size.center.copy(y = this.size.height * 0.25f),
|
||||
strokeWidth = strokeWidth.toPx(),
|
||||
cap = StrokeCap.Round
|
||||
)
|
||||
}
|
||||
rotate(minute.toFloat() / 60 * 360, this.size.center) {
|
||||
drawLine(
|
||||
color,
|
||||
this.size.center, this.size.center.copy(y = this.size.height * 0.1f),
|
||||
strokeWidth = strokeWidth.toPx(),
|
||||
cap = StrokeCap.Round,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package de.mm20.launcher2.ui.launcher.widgets.clock.clocks
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
|
||||
@Composable
|
||||
fun EmptyClock(
|
||||
time: Long,
|
||||
layout: Settings.ClockWidgetSettings.ClockWidgetLayout
|
||||
) {
|
||||
// Nothing to see here
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user