From 591f3f9c70d686449c8fd4e27830204408a1783c Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 16 Oct 2024 23:58:42 -0400 Subject: [PATCH] fix layout --- .../assignment1/MainCalculatorActivity.java | 51 ++-- .../mouseboy/assignment1/helpers/Utils.java | 32 ++ app/src/main/res/drawable/rounded_button.xml | 7 +- .../layout-land/activity_main_calculator.xml | 273 ++++++------------ .../res/layout/activity_main_calculator.xml | 84 ++---- app/src/main/res/values/styles.xml | 3 +- 6 files changed, 181 insertions(+), 269 deletions(-) create mode 100644 app/src/main/java/com/mouseboy/assignment1/helpers/Utils.java diff --git a/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java b/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java index d482dec..fb18093 100644 --- a/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java +++ b/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java @@ -1,6 +1,7 @@ package com.mouseboy.assignment1; import android.os.Bundle; +import android.view.View; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; @@ -11,30 +12,13 @@ import androidx.core.view.WindowInsetsCompat; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import java.util.ArrayList; public class MainCalculatorActivity extends AppCompatActivity { - public static String formatDecimal(double value) { - BigDecimal decimalValue = BigDecimal.valueOf(value); + // I missing having decltype already + public static final ArrayList buttonIDs = new ArrayList<>(); - 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) { @@ -46,5 +30,32 @@ public class MainCalculatorActivity extends AppCompatActivity { v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); + + // evil. + buttonIDs.add(R.id.b0); + buttonIDs.add(R.id.b1); + buttonIDs.add(R.id.b2); + buttonIDs.add(R.id.b3); + buttonIDs.add(R.id.b4); + buttonIDs.add(R.id.b5); + buttonIDs.add(R.id.b6); + buttonIDs.add(R.id.b7); + buttonIDs.add(R.id.b8); + buttonIDs.add(R.id.b9); + + buttonIDs.add(R.id.bac); + buttonIDs.add(R.id.bc); + + buttonIDs.add(R.id.bplus); + buttonIDs.add(R.id.bdiv); + buttonIDs.add(R.id.bminus); + buttonIDs.add(R.id.bmul); + + buttonIDs.add(R.id.bdot); + buttonIDs.add(R.id.bneg); + buttonIDs.add(R.id.bequals); + buttonIDs.add(R.id.bpar); + } + } \ No newline at end of file diff --git a/app/src/main/java/com/mouseboy/assignment1/helpers/Utils.java b/app/src/main/java/com/mouseboy/assignment1/helpers/Utils.java new file mode 100644 index 0000000..fd59e1f --- /dev/null +++ b/app/src/main/java/com/mouseboy/assignment1/helpers/Utils.java @@ -0,0 +1,32 @@ +package com.mouseboy.assignment1.helpers; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; + +public class Utils { + + // why does java not have a nice decimal formatter + 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); + } + +} diff --git a/app/src/main/res/drawable/rounded_button.xml b/app/src/main/res/drawable/rounded_button.xml index 819d221..ba28e8d 100644 --- a/app/src/main/res/drawable/rounded_button.xml +++ b/app/src/main/res/drawable/rounded_button.xml @@ -1,4 +1,7 @@ - - + + + + \ 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 af31b29..8d72fa3 100644 --- a/app/src/main/res/layout-land/activity_main_calculator.xml +++ b/app/src/main/res/layout-land/activity_main_calculator.xml @@ -7,52 +7,26 @@ android:layout_height="match_parent" tools:context=".MainCalculatorActivity"> - - - - - + android:orientation="vertical"> + android:layout_weight="1" + android:background="?android:attr/listDivider" /> - - - - -