From 134116d79a955f3b667520d248897becf6fcb50a Mon Sep 17 00:00:00 2001 From: Timo Date: Thu, 19 Dec 2024 21:54:03 +0100 Subject: [PATCH 1/2] Added Planck units + milli- & nanometer --- core/i18n/src/main/res/values/units.xml | 30 +++++++++++++++++++ .../converters/LengthConverter.kt | 15 ++++++++++ .../unitconverter/converters/MassConverter.kt | 5 ++++ .../converters/TemperatureConverter.kt | 27 ++++++++++++++++- .../unitconverter/converters/TimeConverter.kt | 5 ++++ 5 files changed, 81 insertions(+), 1 deletion(-) diff --git a/core/i18n/src/main/res/values/units.xml b/core/i18n/src/main/res/values/units.xml index d80ac70c8..22a245892 100644 --- a/core/i18n/src/main/res/values/units.xml +++ b/core/i18n/src/main/res/values/units.xml @@ -43,6 +43,16 @@ millimeter millimeters + mm + + nanometer + nanometers + + mm + + picometer + picometers + in inch @@ -68,6 +78,11 @@ nautical mile nautical miles + lP + + Planck + Planck + @@ -145,6 +160,11 @@ year years + tP + + Planck time + Planck time + B @@ -278,6 +298,11 @@ short ton short tons + mP + + Planck mass + Planck mass + °C @@ -294,4 +319,9 @@ kelvin kelvins + TP + + Planck temperature + Planck temperature + \ No newline at end of file diff --git a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/LengthConverter.kt b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/LengthConverter.kt index d25a8cea7..18e28398d 100644 --- a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/LengthConverter.kt +++ b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/LengthConverter.kt @@ -33,6 +33,16 @@ internal class LengthConverter(context: Context) : SimpleFactorConverter() { context.getString(R.string.unit_millimeter_symbol), R.plurals.unit_millimeter ), + MeasureUnitWithFactor( + 1000_000.0, + context.getString(R.string.unit_nanometer_symbol), + R.plurals.unit_nanometer + ), + MeasureUnitWithFactor( + 1_000_000_000.0, + context.getString(R.string.unit_picometer_symbol), + R.plurals.unit_picometer + ), MeasureUnitWithFactor( 100 / 2.54, context.getString(R.string.unit_inch_symbol), @@ -57,6 +67,11 @@ internal class LengthConverter(context: Context) : SimpleFactorConverter() { 1 / 1852.0, context.getString(R.string.unit_nautic_mile_symbol), R.plurals.unit_nautic_mile + ), + MeasureUnitWithFactor( + 1.616255e-35, + context.getString(R.string.unit_planck_distance_symbol), + R.plurals.unit_planck_distance ) ) diff --git a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/MassConverter.kt b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/MassConverter.kt index 8b73fbbf1..1f82ff439 100644 --- a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/MassConverter.kt +++ b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/MassConverter.kt @@ -47,6 +47,11 @@ internal class MassConverter(context: Context): SimpleFactorConverter() { 1000.0 / (453.59237 * 2000.0), context.getString(R.string.unit_short_ton_symbol), R.plurals.unit_short_ton + ), + MeasureUnitWithFactor( + 2.176434e-8, + context.getString(R.string.unit_planck_mass_symbol), + R.plurals.unit_planck_mass ) ) diff --git a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TemperatureConverter.kt b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TemperatureConverter.kt index 3712a0b59..85cce177b 100644 --- a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TemperatureConverter.kt +++ b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TemperatureConverter.kt @@ -23,6 +23,11 @@ internal class TemperatureConverter(context: Context) : Converter { R.plurals.unit_kelvin, TemperatureUnit.Kelvin ), + TemperatureMeasureUnit( + context.getString(R.string.unit_planck_temperature_symbol), + R.plurals.unit_planck_temperature, + TemperatureUnit.Planck + ) ) override suspend fun isValidUnit(symbol: String): Boolean { @@ -91,13 +96,32 @@ internal class TemperatureConverter(context: Context) : Converter { if (from === TemperatureUnit.DegreeFahrenheit && to == TemperatureUnit.DegreeCelsius) { return (value - 32.0) * (5.0 / 9.0) } - if (from === TemperatureUnit.Kelvin && to == TemperatureUnit.DegreeFahrenheit) { return (value - 273.15) * (9.0 / 5.0) + 32.0 } if (from === TemperatureUnit.DegreeFahrenheit && to == TemperatureUnit.Kelvin) { return (value - 32.0) * (5.0 / 9.0) + 273.15 } + if (from === TemperatureUnit.Kelvin && to == TemperatureUnit.Planck) { + return value * 1.416833e32 + } + if (from === TemperatureUnit.Planck && to == TemperatureUnit.Kelvin) { + return value / 1.416833e32 + } + if (from === TemperatureUnit.DegreeCelsius && to == TemperatureUnit.Planck) { + return (value - 273.15) * 1.416833e32 + } + if (from === TemperatureUnit.Planck && to == TemperatureUnit.DegreeCelsius) { + return value / 1.416833e32 + 273.15 + } + if (from === TemperatureUnit.DegreeFahrenheit && to == TemperatureUnit.Planck) { + return ((value - 32.0) * (5.0 / 9.0) + 273.15) * 1.416833e32 + } + if (from === TemperatureUnit.Planck && to == TemperatureUnit.DegreeFahrenheit) { + return ((value / 1.416833e32) - 273.15) * (9.0 / 5.0) + 32.0 + } + + throw IllegalArgumentException() } @@ -120,4 +144,5 @@ enum class TemperatureUnit { DegreeCelsius, DegreeFahrenheit, Kelvin, + Planck, } \ No newline at end of file diff --git a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TimeConverter.kt b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TimeConverter.kt index 2485d3d3e..d763f4a4e 100644 --- a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TimeConverter.kt +++ b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/TimeConverter.kt @@ -37,6 +37,11 @@ internal class TimeConverter(context: Context) : SimpleFactorConverter() { 1.0 / (60 * 60 * 24 * 365), context.getString(R.string.unit_year_symbol), R.plurals.unit_year + ), + MeasureUnitWithFactor( + 5.391247e-44, + context.getString(R.string.unit_planck_time_symbol), + R.plurals.unit_planck_time ) ) From a18f949409a80ab6a085774a20b24c2fc409f729 Mon Sep 17 00:00:00 2001 From: Timo Date: Tue, 24 Dec 2024 12:16:38 +0100 Subject: [PATCH 2/2] Fixed symbols --- core/i18n/src/main/res/values/units.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/i18n/src/main/res/values/units.xml b/core/i18n/src/main/res/values/units.xml index 22a245892..9281e8609 100644 --- a/core/i18n/src/main/res/values/units.xml +++ b/core/i18n/src/main/res/values/units.xml @@ -43,12 +43,12 @@ millimeter millimeters - mm + nm nanometer nanometers - mm + pm picometer picometers @@ -324,4 +324,4 @@ Planck temperature Planck temperature - \ No newline at end of file +