Analog clock: fix hour hand

This commit is contained in:
MM20 2022-02-26 23:37:01 +01:00
parent 3b1ce45ee4
commit 84f35487c1
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 2 additions and 64 deletions

View File

@ -38,7 +38,7 @@ fun AnalogClock(
center = this.size.center,
style = Fill
)
rotate(hour.toFloat() / 12f * 360f + minute.toFloat() / 60f * 5f, this.size.center) {
rotate(hour.toFloat() / 12f * 360f + (minute.toFloat() / 60f) * 30f, this.size.center) {
drawLine(
color,
this.size.center, this.size.center.copy(y = this.size.height * 0.25f),
@ -46,7 +46,7 @@ fun AnalogClock(
cap = StrokeCap.Round
)
}
rotate(minute.toFloat() / 60 * 360, this.size.center) {
rotate(minute.toFloat() / 60f * 360f, this.size.center) {
drawLine(
color,
this.size.center, this.size.center.copy(y = this.size.height * 0.1f),

View File

@ -1,62 +0,0 @@
package de.mm20.launcher2.ui.launcher.widgets.clock.parts
import android.content.ContentUris
import android.content.Intent
import android.provider.CalendarContract
import android.text.format.DateFormat
import android.text.format.DateUtils
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.em
import de.mm20.launcher2.preferences.Settings.ClockWidgetSettings.ClockWidgetLayout
import java.text.SimpleDateFormat
import java.util.*
@Composable
fun DatePart(
time: Long,
layout: ClockWidgetLayout
) {
val verticalLayout = layout == ClockWidgetLayout.Vertical
val context = LocalContext.current
TextButton(onClick = {
val startMillis = System.currentTimeMillis()
val builder = CalendarContract.CONTENT_URI.buildUpon()
builder.appendPath("time")
ContentUris.appendId(builder, startMillis)
val intent = Intent(Intent.ACTION_VIEW)
.setData(builder.build())
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}) {
if (verticalLayout) {
Text(
text = DateUtils.formatDateTime(
context,
time,
DateUtils.FORMAT_SHOW_WEEKDAY or DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR
),
style = MaterialTheme.typography.titleMedium,
color = Color.White
)
} else {
val line1Format = DateFormat.getBestDateTimePattern(Locale.getDefault(), "EEEE")
val line2Format = DateFormat.getBestDateTimePattern(Locale.getDefault(), "MMMM dd yyyy")
val format = SimpleDateFormat("$line1Format\n$line2Format")
Text(
text = format.format(time),
lineHeight = 1.2.em,
style = MaterialTheme.typography.titleLarge.copy(
fontWeight = FontWeight.Medium
),
color = Color.White
)
}
}
}