diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1fb6941..d563b37 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ android:theme="@style/Theme.Convertisseur" tools:targetApi="31"> diff --git a/app/src/main/java/fr/univpau/convertisseur/ConvertisseurMainActivity.java b/app/src/main/java/fr/univpau/convertisseur/MainActivity.java similarity index 83% rename from app/src/main/java/fr/univpau/convertisseur/ConvertisseurMainActivity.java rename to app/src/main/java/fr/univpau/convertisseur/MainActivity.java index 35077a5..18f3868 100644 --- a/app/src/main/java/fr/univpau/convertisseur/ConvertisseurMainActivity.java +++ b/app/src/main/java/fr/univpau/convertisseur/MainActivity.java @@ -1,3 +1,9 @@ +/* + * ConvertisseurMainActivity.java, 24/10/2024 + * UPPA M2 TI 2024-2025 + * MIT License (MIT) + */ + package fr.univpau.convertisseur; import android.os.Bundle; @@ -9,7 +15,12 @@ import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; -public class ConvertisseurMainActivity extends AppCompatActivity { +/** + * Main activity of the application. + * + * @author LucasVbr + */ +public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/fr/univpau/convertisseur/OnConvertListener.java b/app/src/main/java/fr/univpau/convertisseur/OnConvertListener.java index 7605440..577dcbe 100644 --- a/app/src/main/java/fr/univpau/convertisseur/OnConvertListener.java +++ b/app/src/main/java/fr/univpau/convertisseur/OnConvertListener.java @@ -1,3 +1,10 @@ +/* + * OnConvertListener.java, 24/10/2024 + * UPPA M2 TI 2024-2025 + * MIT License (MIT) + */ + + package fr.univpau.convertisseur; import android.util.Log; @@ -5,13 +12,32 @@ import android.view.View; import android.widget.EditText; import android.widget.Spinner; +/** + * Listener for the convert button. + * + * @author LucasVbr + */ public class OnConvertListener implements View.OnClickListener { + /** The spinner for the unit to convert from. */ private final Spinner spinnerFrom; + + /** The spinner for the unit to convert to. */ private final Spinner spinnerTo; + + /** The input field for the value to convert. */ private final EditText inputFrom; + + /** The input field for the result of the conversion. */ private final EditText inputTo; + /** + * Create a new listener for the convert button. + * @param spinnerFrom The spinner for the unit to convert from. + * @param spinnerTo The spinner for the unit to convert to. + * @param inputFrom The input field for the value to convert. + * @param inputTo The input field for the result of the conversion. + */ public OnConvertListener(Spinner spinnerFrom, Spinner spinnerTo, EditText inputFrom, EditText inputTo) { this.spinnerFrom = spinnerFrom; this.spinnerTo = spinnerTo; @@ -35,12 +61,22 @@ public class OnConvertListener implements View.OnClickListener { } } + /** + * Get the value from an input field. + * @param input The input field. + * @return The value from the input field as a double. + */ private double getInputValue(EditText input) { String inputFromText = input.getText().toString(); if (inputFromText.isEmpty()) return 0; return Double.parseDouble(inputFromText); } + /** + * Get the unit from a spinner. + * @param spinner The spinner. + * @return The unit from the spinner. + */ private Temperature.Units getUnit(Spinner spinner) { int unitIndex = spinner.getSelectedItemPosition(); return Temperature.Units.values()[unitIndex]; diff --git a/app/src/main/java/fr/univpau/convertisseur/Temperature.java b/app/src/main/java/fr/univpau/convertisseur/Temperature.java index 0dd80a0..f3c05b2 100644 --- a/app/src/main/java/fr/univpau/convertisseur/Temperature.java +++ b/app/src/main/java/fr/univpau/convertisseur/Temperature.java @@ -1,22 +1,52 @@ +/* + * Temperature.java, 24/10/2024 + * UPPA M2 TI 2024-2025 + * MIT License (MIT) + */ + package fr.univpau.convertisseur; +/** + * Class representing a temperature value. + * + * @author LucasVbr + */ public class Temperature { + /** Enumeration of the units for temperature. */ public enum Units { - CELSIUS, FAHRENHEIT, KELVIN + CELSIUS, FAHRENHEIT, KELVIN, RANKINE, REAUMUR } + /** The value of the temperature in Kelvin. */ double valueInKelvin; + /** + * Create a new temperature value. + * + * @param value The value of the temperature. + * @param from The unit of the temperature value. + */ public Temperature(double value, Temperature.Units from) { if (from == Units.CELSIUS) this.valueInKelvin = value + 273.15; if (from == Units.FAHRENHEIT) this.valueInKelvin = (value - 32) * 5 / 9 + 273.15; if (from == Units.KELVIN) this.valueInKelvin = value; + if (from == Units.RANKINE) this.valueInKelvin = (value - 491.67) * 5 / 9; + if (from == Units.REAUMUR) this.valueInKelvin = value * 5 / 4 + 273.15; } + /** + * Convert the temperature to the given unit. + * + * @param to The unit to convert to. + * @return The value of the temperature in the given unit. + */ public double convert(Units to) { if (to == Units.CELSIUS) return this.valueInKelvin - 273.15; if (to == Units.FAHRENHEIT) return (this.valueInKelvin - 273.15) * 9 / 5 + 32; + if (to == Units.RANKINE) return (this.valueInKelvin) * 9 / 5; + if (to == Units.REAUMUR) return (this.valueInKelvin - 273.15) * 4 / 5; + return this.valueInKelvin; } } diff --git a/app/src/main/res/layout-land/convertisseur_main.xml b/app/src/main/res/layout-land/convertisseur_main.xml index b46ce76..81ee3a8 100644 --- a/app/src/main/res/layout-land/convertisseur_main.xml +++ b/app/src/main/res/layout-land/convertisseur_main.xml @@ -5,7 +5,7 @@ android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ConvertisseurMainActivity"> + tools:context=".MainActivity"> + tools:context=".MainActivity"> Celsius Fahrenheit Kelvin + Rankine + Réaumur \ No newline at end of file