From 372f34ff03ac8d8bdb8358682a4d7addb2f7e746 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 16 Oct 2024 22:48:25 -0400 Subject: [PATCH] make it look nice --- .../assignment1/MainCalculatorActivity.java | 26 + app/src/main/res/drawable/rounded_button.xml | 4 + .../layout-land/activity_main_calculator.xml | 8 +- .../res/layout/activity_main_calculator.xml | 514 +++++++----------- app/src/main/res/values/colors.xml | 5 + app/src/main/res/values/styles.xml | 26 +- 6 files changed, 267 insertions(+), 316 deletions(-) create mode 100644 app/src/main/res/drawable/rounded_button.xml diff --git a/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java b/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java index 8289f3f..d482dec 100644 --- a/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java +++ b/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java @@ -8,8 +8,34 @@ import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; + public class MainCalculatorActivity extends AppCompatActivity { + public static String formatDecimal(double value) { + BigDecimal decimalValue = BigDecimal.valueOf(value); + + String pattern; + + if (decimalValue.stripTrailingZeros().scale() <= 0) { + pattern = "#,##0"; + } else { + pattern = "#,##0.##"; + } + + DecimalFormat df = new DecimalFormat(pattern); + + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + symbols.setGroupingSeparator(','); + + df.setDecimalFormatSymbols(symbols); + + return df.format(value); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/res/drawable/rounded_button.xml b/app/src/main/res/drawable/rounded_button.xml new file mode 100644 index 0000000..819d221 --- /dev/null +++ b/app/src/main/res/drawable/rounded_button.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/activity_main_calculator.xml b/app/src/main/res/layout-land/activity_main_calculator.xml index 9e30ba6..af31b29 100644 --- a/app/src/main/res/layout-land/activity_main_calculator.xml +++ b/app/src/main/res/layout-land/activity_main_calculator.xml @@ -16,6 +16,7 @@ android:clickable="false" android:minHeight="?attr/actionBarSize" android:theme="?attr/actionBarTheme" + app:layout_constraintTop_toTopOf="parent" app:subtitleTextAppearance="@style/TextAppearance.AppCompat.Large"> - - - -