Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Energy unit converter ([#192])
- Pressure unit converter ([#191])
- Speed unit converter ([#190])

### Fixed
- Fixed issue that occurs after doing a percent operation ([#160])
Expand Down Expand Up @@ -64,6 +68,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#44]: https://github.com/FossifyOrg/Calculator/issues/44
[#64]: https://github.com/FossifyOrg/Calculator/issues/64
[#160]: https://github.com/FossifyOrg/Calculator/issues/160
[#190]: https://github.com/FossifyOrg/Calculator/issues/190
[#191]: https://github.com/FossifyOrg/Calculator/issues/191
[#192]: https://github.com/FossifyOrg/Calculator/issues/192

[Unreleased]: https://github.com/FossifyOrg/Calculator/compare/1.2.0...HEAD
[1.2.0]: https://github.com/FossifyOrg/Calculator/compare/1.1.0...1.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ interface Converter {
VolumeConverter,
MassConverter,
TemperatureConverter,
TimeConverter
TimeConverter,
SpeedConverter,
PressureConverter,
EnergyConverter
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package org.fossify.math.helpers.converters

import org.fossify.math.R
import java.math.BigDecimal

/***
* Base unit: joule.
*
* References:
* - https://en.wikipedia.org/wiki/Joule
* - https://en.wikipedia.org/wiki/Calorie
* - https://en.wikipedia.org/wiki/Kilowatt-hour
* - https://en.wikipedia.org/wiki/Electronvolt
* - https://en.wikipedia.org/wiki/British_thermal_unit
* - https://en.wikipedia.org/wiki/Foot-pound_(energy)
* - https://en.wikipedia.org/wiki/Erg
* - https://en.wikipedia.org/wiki/Therm
*/
object EnergyConverter : Converter {
override val nameResId: Int = R.string.unit_energy
override val imageResId: Int = R.drawable.ic_energy_vector
override val key: String = "EnergyConverter"

sealed class Unit(nameResId: Int, symbolResId: Int, factor: BigDecimal, key: String) :
Converter.Unit(nameResId, symbolResId, factor, key) {
data object Joule : Unit(
nameResId = R.string.unit_energy_joule,
symbolResId = R.string.unit_energy_joule_symbol,
factor = BigDecimal.ONE,
key = "Joule"
)

data object Kilojoule : Unit(
nameResId = R.string.unit_energy_kilojoule,
symbolResId = R.string.unit_energy_kilojoule_symbol,
factor = BigDecimal("1000"),
key = "Kilojoule"
)

data object Megajoule : Unit(
nameResId = R.string.unit_energy_megajoule,
symbolResId = R.string.unit_energy_megajoule_symbol,
factor = BigDecimal("1000000"),
key = "Megajoule"
)

data object Gigajoule : Unit(
nameResId = R.string.unit_energy_gigajoule,
symbolResId = R.string.unit_energy_gigajoule_symbol,
factor = BigDecimal("1000000000"),
key = "Gigajoule"
)

data object Calorie : Unit(
nameResId = R.string.unit_energy_calorie,
symbolResId = R.string.unit_energy_calorie_symbol,
factor = BigDecimal("4.184"),
key = "Calorie"
)

data object Kilocalorie : Unit(
nameResId = R.string.unit_energy_kilocalorie,
symbolResId = R.string.unit_energy_kilocalorie_symbol,
factor = BigDecimal("4184"),
key = "Kilocalorie"
)

data object WattHour : Unit(
nameResId = R.string.unit_energy_watt_hour,
symbolResId = R.string.unit_energy_watt_hour_symbol,
factor = BigDecimal("3600"),
key = "WattHour"
)

data object KilowattHour : Unit(
nameResId = R.string.unit_energy_kilowatt_hour,
symbolResId = R.string.unit_energy_kilowatt_hour_symbol,
factor = BigDecimal("3600000"),
key = "KilowattHour"
)

data object MegawattHour : Unit(
nameResId = R.string.unit_energy_megawatt_hour,
symbolResId = R.string.unit_energy_megawatt_hour_symbol,
factor = BigDecimal("3600000000"),
key = "MegawattHour"
)

data object Electronvolt : Unit(
nameResId = R.string.unit_energy_electronvolt,
symbolResId = R.string.unit_energy_electronvolt_symbol,
factor = BigDecimal("1.602176634E-19"),
key = "Electronvolt"
)

data object BritishThermalUnit : Unit(
nameResId = R.string.unit_energy_btu,
symbolResId = R.string.unit_energy_btu_symbol,
factor = BigDecimal("1055.05585262"),
key = "BritishThermalUnit"
)

data object Therm : Unit(
nameResId = R.string.unit_energy_therm,
symbolResId = R.string.unit_energy_therm_symbol,
factor = BigDecimal("105505585.262"),
key = "Therm"
)

data object FootPound : Unit(
nameResId = R.string.unit_energy_foot_pound,
symbolResId = R.string.unit_energy_foot_pound_symbol,
factor = BigDecimal("1.3558179483314004"),
key = "FootPound"
)

data object Erg : Unit(
nameResId = R.string.unit_energy_erg,
symbolResId = R.string.unit_energy_erg_symbol,
factor = BigDecimal("0.0000001"),
key = "Erg"
)
}

override val units: List<Unit> = listOf(
Unit.Joule,
Unit.Kilojoule,
Unit.Megajoule,
Unit.Gigajoule,
Unit.Calorie,
Unit.Kilocalorie,
Unit.WattHour,
Unit.KilowattHour,
Unit.MegawattHour,
Unit.Electronvolt,
Unit.BritishThermalUnit,
Unit.Therm,
Unit.FootPound,
Unit.Erg,
)

override val defaultTopUnit: Unit = Unit.Kilocalorie
override val defaultBottomUnit: Unit = Unit.Kilojoule
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.fossify.math.helpers.converters

import org.fossify.math.R
import java.math.BigDecimal

/**
* Base unit: pascal.
*
* Main references:
* - https://en.wikipedia.org/wiki/Pascal_(unit)
* - https://en.wikipedia.org/wiki/Bar_(unit)
* - https://en.wikipedia.org/wiki/Atmosphere_(unit)
* - https://en.wikipedia.org/wiki/Pounds_per_square_inch
* - https://en.wikipedia.org/wiki/Torr
* - https://en.wikipedia.org/wiki/Millimetre_of_mercury
*/
object PressureConverter : Converter {
override val nameResId: Int = R.string.unit_pressure
override val imageResId: Int = R.drawable.ic_pressure_vector
override val key: String = "PressureConverter"

sealed class Unit(nameResId: Int, symbolResId: Int, factor: BigDecimal, key: String) :
Converter.Unit(nameResId, symbolResId, factor, key) {
data object Pascal : Unit(
nameResId = R.string.unit_pressure_pascal,
symbolResId = R.string.unit_pressure_pascal_symbol,
factor = BigDecimal.ONE,
key = "Pascal"
)

data object Kilopascal : Unit(
nameResId = R.string.unit_pressure_kilopascal,
symbolResId = R.string.unit_pressure_kilopascal_symbol,
factor = BigDecimal("1000"),
key = "Kilopascal"
)

data object Megapascal : Unit(
nameResId = R.string.unit_pressure_megapascal,
symbolResId = R.string.unit_pressure_megapascal_symbol,
factor = BigDecimal("1000000"),
key = "Megapascal"
)

data object Bar : Unit(
nameResId = R.string.unit_pressure_bar,
symbolResId = R.string.unit_pressure_bar_symbol,
factor = BigDecimal("100000"),
key = "Bar"
)

data object Millibar : Unit(
nameResId = R.string.unit_pressure_millibar,
symbolResId = R.string.unit_pressure_millibar_symbol,
factor = BigDecimal("100"),
key = "Millibar"
)

data object Atmosphere : Unit(
nameResId = R.string.unit_pressure_atmosphere,
symbolResId = R.string.unit_pressure_atmosphere_symbol,
factor = BigDecimal("101325"),
key = "Atmosphere"
)

data object Psi : Unit(
nameResId = R.string.unit_pressure_psi,
symbolResId = R.string.unit_pressure_psi_symbol,
factor = BigDecimal("6894.757293168"),
key = "Psi"
)

data object Torr : Unit(
nameResId = R.string.unit_pressure_torr,
symbolResId = R.string.unit_pressure_torr_symbol,
factor = BigDecimal("133.32236842105"),
key = "Torr"
)

data object MillimeterOfMercury : Unit(
nameResId = R.string.unit_pressure_mmhg,
symbolResId = R.string.unit_pressure_mmhg_symbol,
factor = BigDecimal("133.322387415"),
key = "MillimeterOfMercury"
)

data object InchOfMercury : Unit(
nameResId = R.string.unit_pressure_inhg,
symbolResId = R.string.unit_pressure_inhg_symbol,
factor = BigDecimal("3386.389"),
key = "InchOfMercury"
)
}

override val units: List<Unit> = listOf(
Unit.Pascal,
Unit.Kilopascal,
Unit.Megapascal,
Unit.Bar,
Unit.Millibar,
Unit.Atmosphere,
Unit.Psi,
Unit.Torr,
Unit.MillimeterOfMercury,
Unit.InchOfMercury
)
override val defaultTopUnit: Unit = Unit.Bar
override val defaultBottomUnit: Unit = Unit.Psi
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.fossify.math.helpers.converters

import org.fossify.commons.helpers.HOUR_SECONDS
import org.fossify.math.R
import org.fossify.math.helpers.MATH_CONTEXT
import java.math.BigDecimal

/**
* Base unit: meter per second.
*
* Main references:
* - https://en.wikipedia.org/wiki/Metre_per_second
* - https://en.wikipedia.org/wiki/Kilometres_per_hour
* - https://en.wikipedia.org/wiki/Miles_per_hour
* - https://en.wikipedia.org/wiki/Knot_(unit)
* - https://en.wikipedia.org/wiki/Mach_number
* - https://en.wikipedia.org/wiki/Speed_of_light
*/
object SpeedConverter : Converter {
override val nameResId: Int = R.string.unit_speed
override val imageResId: Int = R.drawable.ic_speed_vector
override val key: String = "SpeedConverter"

sealed class Unit(nameResId: Int, symbolResId: Int, factor: BigDecimal, key: String) :
Converter.Unit(nameResId, symbolResId, factor, key) {
data object MeterPerSecond : Unit(
nameResId = R.string.unit_speed_meter_per_second,
symbolResId = R.string.unit_speed_meter_per_second_symbol,
factor = BigDecimal.ONE,
key = "MeterPerSecond"
)

data object KilometerPerSecond : Unit(
nameResId = R.string.unit_speed_kilometer_per_second,
symbolResId = R.string.unit_speed_kilometer_per_second_symbol,
factor = BigDecimal("1000"),
key = "KilometerPerSecond"
)

data object KilometerPerHour : Unit(
nameResId = R.string.unit_speed_kilometer_per_hour,
symbolResId = R.string.unit_speed_kilometer_per_hour_symbol,
factor = BigDecimal("1000").divide(BigDecimal("3600"), MATH_CONTEXT),
key = "KilometerPerHour"
)

data object MilePerHour : Unit(
nameResId = R.string.unit_speed_mile_per_hour,
symbolResId = R.string.unit_speed_mile_per_hour_symbol,
factor = BigDecimal("0.44704"),
key = "MilePerHour"
)

data object Knot : Unit(
nameResId = R.string.unit_speed_knot,
symbolResId = R.string.unit_speed_knot_symbol,
factor = BigDecimal("1852").divide(BigDecimal("3600"), MATH_CONTEXT),
key = "Knot"
)

data object FootPerSecond : Unit(
nameResId = R.string.unit_speed_foot_per_second,
symbolResId = R.string.unit_speed_foot_per_second_symbol,
factor = BigDecimal("0.3048"),
key = "FootPerSecond"
)

data object Mach : Unit(
nameResId = R.string.unit_speed_mach,
symbolResId = R.string.unit_speed_mach_symbol,
factor = BigDecimal("340.27"), // ISA: dry air, 15 °C, sea level
key = "Mach"
)

data object SpeedOfLight : Unit(
nameResId = R.string.unit_speed_speed_of_light,
symbolResId = R.string.unit_speed_speed_of_light_symbol,
factor = BigDecimal("299792458"),
key = "SpeedOfLight"
)
}

override val units: List<Unit> = listOf(
Unit.MeterPerSecond,
Unit.KilometerPerSecond,
Unit.KilometerPerHour,
Unit.MilePerHour,
Unit.Knot,
Unit.FootPerSecond,
Unit.Mach,
Unit.SpeedOfLight
)
override val defaultTopUnit: Unit = Unit.KilometerPerHour
override val defaultBottomUnit: Unit = Unit.MilePerHour
}
3 changes: 3 additions & 0 deletions app/src/main/res/drawable/ic_energy_vector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="960" android:viewportHeight="960">
<path android:pathData="M422 728l207-248H469l29-227-185 267h139l-30 208zm-62-128H236q-24 0-35.5-21.5T203 537l299-430q10-14 26-19.5t33 0.5q17 6 25 21t6 32l-32 259h155q26 0 36.5 23t-6.5 43L416 860q-11 13-27 17t-31-3q-15-7-23.5-21.5T328 821l32-221zm111-110z" android:fillColor="#FFFFFF"/>
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/drawable/ic_pressure_vector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="960" android:viewportHeight="960">
<path android:pathData="M732 308q-5-5-8.5-12.5T720 280q0-11 6-19.5t15-15.5q14-11 31-17t34-11q4-1 8-1t7 3q4 4 2 15-5 17-11 34t-17 31q-7 9-15.5 15t-19.5 6q-8 0-15.5-3.5T732 308zM160 840q-33 0-56.5-23.5T80 760V200q0-33 23.5-56.5T160 120h240q33 0 56.5 23.5T480 200v327q9-3 19-5t21-2q50 0 85 35t35 85v80q0 17 11.5 28.5T680 760q17 0 28.5-11.5T720 720V520h-40v-57q-54-23-87-72t-33-111q0-83 58.5-141.5T760 80q83 0 141.5 58.5T960 280q0 62-33 111t-87 72v57h-40v200q0 50-35 85t-85 35q-50 0-85-35t-35-85v-80q0-17-11.5-28.5T520 600q-17 0-28.5 11.5T480 640v120q0 33-23.5 56.5T400 840H160zm600-440q50 0 85-35t35-85q0-50-35-85t-85-35q-50 0-85 35t-35 85q0 50 35 85t85 35zM160 760h240v-80l-32 32q-14 14-29.5 12.5T312 712q-11-11-12.5-27t12.5-30l88-88v-87l-32 32q-14 14-29.5 12.5T312 512q-11-11-12.5-27t12.5-30l88-88v-87l-32 32q-14 14-29.5 12.5T312 312q-11-11-12.5-27t12.5-30l55-55H193l55 55q14 14 12.5 29.5T248 311q-11 11-26.5 13T192 312l-32-32v87l88 88q14 14 12.5 29.5T248 511q-11 11-26.5 13T192 512l-32-32v87l88 88q14 14 12.5 29.5T248 711q-11 11-26.5 13T192 712l-32-32v80zm120-280z" android:fillColor="#FFFFFF"/>
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/drawable/ic_speed_vector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="960" android:viewportHeight="960">
<path android:pathData="M418 620q24 24 62 23.5t56-27.5l169-253q9-14-2.5-25.5T677 335L424 504q-27 18-28.5 55t22.5 61zm62-460q36 0 71 6t68 19q16 6 34 22.5t10 31.5q-8 15-36 20t-45-1q-25-9-50.5-13.5T480 240q-133 0-226.5 93.5T160 560q0 42 11.5 83t32.5 77h552q23-38 33.5-79t10.5-85q0-26-4.5-51T782 456q-6-17-2-33t18-27q13-10 28.5-6t21.5 18q15 35 23 71.5t9 74.5q1 57-13 109t-41 99q-11 18-30 28t-40 10H204q-21 0-40-10t-30-28q-26-45-40-95.5T80 560q0-83 31.5-155.5t86-127Q252 223 325 191.5T480 160zm7 313z" android:fillColor="#FFFFFF"/>
</vector>
Loading
Loading