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
Modifier.pointerInput(Unit) { | |
var moveSkipped = false | |
forEachGesture { | |
awaitPointerEventScope { | |
while (true) { | |
val event = awaitPointerEvent() | |
val firstChange = event.changes.firstOrNull() ?: continue | |
val position = firstChange.position | |
if(event.type == PointerEventType.Release && moveSkipped) { | |
moveSkipped = false |
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
val context = LocalContext.current | |
val newContext = remember(locale) { | |
val res = context.resources | |
val conf = res.configuration | |
conf.setLocale(locale) | |
context.createConfigurationContext(conf) | |
} | |
val okText = remember(newContext) { | |
newContext.resources.getString(android.R.string.ok) | |
} |
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
//firstDayOfWeek contains when the week starts in the locale. | |
//For example, UK locale will have Monday as first day of week | |
//English locale will have Sunday as first day of week. | |
val firstDayOfWeek = currentMonth.firstDayOfWeek | |
//weekDayList contains a list of week days with size 7 | |
//that starts with the firstDayOfWeek. | |
//For example, the UK locale has MONDAY as first day of week. | |
//The value of Calendar.MONDAY is 2. | |
//So the list contains [2, 3, 4, 5, 6, 7, 1] |
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
Column( | |
modifier = Modifier | |
.fillMaxWidth() | |
) { | |
(1..6).forEach { _ -> | |
Row( | |
modifier = Modifier | |
.fillMaxWidth(), | |
horizontalArrangement = Arrangement.SpaceEvenly, | |
verticalAlignment = Alignment.CenterVertically |
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
(0..6).forEach { weekDay -> | |
val dayIndex = (weekDay + (firstDayOfWeek - 1)) % 7 | |
val currentDay = Calendar.getInstance(locale).apply { | |
set(2023, 0, 1 + dayIndex) | |
} | |
val weekText = remember(weekDay, locale) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val dayOrdinal = if (dayIndex == 0) 7 else dayIndex | |
DayOfWeek.of(dayOrdinal).getDisplayName(java.time.format.TextStyle.NARROW, locale).toString() | |
} else { |
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
val year = currentSelectedDate.get(Calendar.YEAR).getFormattedNumber(locale) | |
val monthText = remember(year, month) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
java.time.YearMonth.of(year, month).month.getDisplayName(java.time.format.TextStyle.FULL, locale) | |
} else { | |
Calendar.getInstance(locale).apply { | |
set(year, month - 1, 1) | |
}.getDisplayName(Calendar.MONTH, Calendar.LONG, locale) ?: "" | |
} | |
} |
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
val startIndex = remember(currentSelectedDate) { | |
val year = currentSelectedDate.get(Calendar.YEAR) | |
val month = currentSelectedDate.get(Calendar.MONTH) | |
((year - startYear) * 12) + month | |
} |
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
val dateFormat = DateFormat.getInstanceForSkeleton("EMMMd", locale) | |
dateFormat.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE) | |
val monthText = dateFormat.format(currentSelectedDate.time) |
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
Column( | |
modifier = Modifier | |
.fillMaxWidth() | |
.background(datePickerColor.datePickerHeaderColor) | |
.padding(16.dp) | |
) { | |
Text( | |
modifier = Modifier.clickable { | |
setMode(DatePickerMode.YEAR) | |
}, |
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
Column( | |
modifier = Modifier | |
.fillMaxSize(), | |
horizontalAlignment = Alignment.CenterHorizontally, | |
verticalArrangement = Arrangement.Center | |
) { | |
val hsv = remember { | |
val hsv = floatArrayOf(0f, 0f, 0f) | |
AndroidColor.colorToHSV(Color.Blue.toArgb(), hsv) | |
mutableStateOf( |
NewerOlder