fix layout

main
Brett 2024-10-16 23:58:42 -04:00
parent 372f34ff03
commit 591f3f9c70
6 changed files with 181 additions and 269 deletions

View File

@ -1,6 +1,7 @@
package com.mouseboy.assignment1; package com.mouseboy.assignment1;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import androidx.activity.EdgeToEdge; import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -11,30 +12,13 @@ import androidx.core.view.WindowInsetsCompat;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
public class MainCalculatorActivity extends AppCompatActivity { public class MainCalculatorActivity extends AppCompatActivity {
public static String formatDecimal(double value) { // I missing having decltype already
BigDecimal decimalValue = BigDecimal.valueOf(value); public static final ArrayList<Integer> 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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -46,5 +30,32 @@ public class MainCalculatorActivity extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets; 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);
} }
} }

View File

@ -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);
}
}

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="16dp" /> <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="32dp"/>
<stroke android:width="2dp" android:color="#FF3700B3"/>
</shape> </shape>

View File

@ -7,52 +7,26 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainCalculatorActivity"> tools:context=".MainCalculatorActivity">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/materialToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/colorPrimary"
android:clickable="false"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintTop_toTopOf="parent"
app:subtitleTextAppearance="@style/TextAppearance.AppCompat.Large">
<TextView
android:id="@+id/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="Balculator"
android:textColor="#FBFBFB"
android:textSize="34sp" />
</com.google.android.material.appbar.MaterialToolbar>
<LinearLayout <LinearLayout
android:id="@+id/alignmentLayout" android:id="@+id/alignmentLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="vertical" android:orientation="vertical">
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/materialToolbar">
<LinearLayout <LinearLayout
android:id="@+id/calsbar" android:id="@+id/calsbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="10" android:layout_weight="2"
android:orientation="vertical"> android:orientation="vertical">
<View <View
android:id="@+id/divider" android:id="@+id/divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:background="?android:attr/listDivider" android:layout_weight="1"
android:layout_weight="1"/> android:background="?android:attr/listDivider" />
<TextView <TextView
android:id="@+id/output" android:id="@+id/output"
@ -60,241 +34,162 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="10" android:layout_weight="10"
android:paddingEnd="8dp" android:gravity="end|center_vertical"
android:paddingStart="8dp" android:paddingStart="8dp"
android:gravity="end" android:paddingEnd="8dp"
android:text="" /> android:text="" />
<View <View
android:id="@+id/divider2" android:id="@+id/divider2"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:background="?android:attr/listDivider"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/row1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/bs"
style="@style/CalculatorButtonTextStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1" android:layout_weight="1"
android:text="S" /> android:background="?android:attr/listDivider" />
<Button
android:id="@+id/br"
style="@style/CalculatorButtonTextStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="R" />
<Button
android:id="@+id/ba"
style="@style/CalculatorButtonTextStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="A" />
<Button
android:id="@+id/bc"
style="@style/CalculatorButtonTextStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="C" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/row2" android:id="@+id/row2"
android:layout_width="match_parent" style="@style/LinearLayoutStyle">
android:layout_height="wrap_content"
android:layout_weight="1" <Button
android:orientation="horizontal"> android:id="@+id/bdiv"
style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/operatorButtons"
android:text="÷" />
<Button <Button
android:id="@+id/b7" android:id="@+id/b7"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="7" /> android:text="7" />
<Button <Button
android:id="@+id/b8" android:id="@+id/b8"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="8" /> android:text="8" />
<Button <Button
android:id="@+id/b9" android:id="@+id/b9"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="9" /> android:text="9" />
<Button <Button
android:id="@+id/bdiv" android:id="@+id/bac"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/clearButtons"
android:layout_height="match_parent" android:text="AC" />
android:layout_margin="2dp"
android:layout_weight="1"
android:text="÷" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/row3" android:id="@+id/row3"
android:layout_width="match_parent" style="@style/LinearLayoutStyle">
android:layout_height="wrap_content"
android:layout_weight="1" <Button
android:orientation="horizontal"> android:id="@+id/bmul"
style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/operatorButtons"
android:text="*" />
<Button <Button
android:id="@+id/b4" android:id="@+id/b4"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="4" /> android:text="4" />
<Button <Button
android:id="@+id/b5" android:id="@+id/b5"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="5" /> android:text="5" />
<Button <Button
android:id="@+id/b6" android:id="@+id/b6"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="6" /> android:text="6" />
<Button <Button
android:id="@+id/bmul" android:id="@+id/bc"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/clearButtons"
android:layout_height="match_parent" android:text="C" />
android:layout_margin="2dp"
android:layout_weight="1"
android:text="*" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/row4" android:id="@+id/row4"
android:layout_width="match_parent" style="@style/LinearLayoutStyle">
android:layout_height="wrap_content"
android:layout_weight="1" <Button
android:orientation="horizontal"> android:id="@+id/bminus"
style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/operatorButtons"
android:text="-" />
<Button <Button
android:id="@+id/b1" android:id="@+id/b1"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="1" /> android:text="1" />
<Button <Button
android:id="@+id/b2" android:id="@+id/b2"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="2" /> android:text="2" />
<Button <Button
android:id="@+id/b3" android:id="@+id/b3"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/numberButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="3" /> android:text="3" />
<Button <Button
android:id="@+id/bminus" android:id="@+id/bpar"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="2dp" android:backgroundTint="@color/specialButtons"
android:layout_weight="1" android:text="( )"/>
android:text="-" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/row5" android:id="@+id/row5"
android:layout_width="match_parent" android:paddingBottom="2dp"
android:layout_height="wrap_content" style="@style/LinearLayoutStyle">
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/bdot"
style="@style/CalculatorButtonTextStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="." />
<Button
android:id="@+id/b0"
style="@style/CalculatorButtonTextStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="0" />
<Button <Button
android:id="@+id/bplus" android:id="@+id/bplus"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/operatorButtons"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="+" /> android:text="+" />
<Button
android:id="@+id/bneg"
style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/specialButtons"
android:text="+/-" />
<Button
android:id="@+id/b0"
style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons"
android:text="0" />
<Button
android:id="@+id/bdot"
style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/specialButtons"
android:text="." />
<!-- i put equals last because it puts it close to the thumb--> <!-- i put equals last because it puts it close to the thumb-->
<Button <Button
android:id="@+id/bequals" android:id="@+id/bequals"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:layout_width="wrap_content" android:backgroundTint="@color/equalsButton"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="=" /> android:text="=" />
</LinearLayout> </LinearLayout>

View File

@ -17,37 +17,6 @@
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:id="@+id/titlebar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/materialToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#7986CB"
android:clickable="false"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<TextView
android:id="@+id/titleText"
style="@style/TextAutoScaleStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Balculator"
android:textColor="#FBFBFB" />
</com.google.android.material.appbar.MaterialToolbar>
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/calsbar" android:id="@+id/calsbar"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -88,25 +57,26 @@
<Button <Button
android:id="@+id/bpar" android:id="@+id/bpar"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="#4DB6AC" android:layout_height="match_parent"
android:text="( )" /> android:backgroundTint="@color/specialButtons"
android:text="( )"/>
<Button <Button
android:id="@+id/bac" android:id="@+id/bac"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/clearButtons" android:backgroundTint="@color/clearButtons"
android:text="AC" /> android:text="AC" />
<Button <Button
android:id="@+id/bc" android:id="@+id/bc"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/clearButtons" android:backgroundTint="@color/clearButtons"
android:text="C" /> android:text="C" />
<Button <Button
android:id="@+id/bplus" android:id="@+id/bplus"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/operatorButtons" android:backgroundTint="@color/operatorButtons"
android:text="+" /> android:text="+" />
@ -118,25 +88,25 @@
<Button <Button
android:id="@+id/b7" android:id="@+id/b7"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="7" /> android:text="7" />
<Button <Button
android:id="@+id/b8" android:id="@+id/b8"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="8" /> android:text="8" />
<Button <Button
android:id="@+id/b9" android:id="@+id/b9"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="9" /> android:text="9" />
<Button <Button
android:id="@+id/bdiv" android:id="@+id/bdiv"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/operatorButtons" android:backgroundTint="@color/operatorButtons"
android:text="÷" /> android:text="÷" />
@ -148,25 +118,25 @@
<Button <Button
android:id="@+id/b4" android:id="@+id/b4"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="4" /> android:text="4" />
<Button <Button
android:id="@+id/b5" android:id="@+id/b5"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="5" /> android:text="5" />
<Button <Button
android:id="@+id/b6" android:id="@+id/b6"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="6" /> android:text="6" />
<Button <Button
android:id="@+id/bmul" android:id="@+id/bmul"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/operatorButtons" android:backgroundTint="@color/operatorButtons"
android:text="*" /> android:text="*" />
@ -178,25 +148,25 @@
<Button <Button
android:id="@+id/b1" android:id="@+id/b1"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="1" /> android:text="1" />
<Button <Button
android:id="@+id/b2" android:id="@+id/b2"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="2" /> android:text="2" />
<Button <Button
android:id="@+id/b3" android:id="@+id/b3"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="3" /> android:text="3" />
<Button <Button
android:id="@+id/bminus" android:id="@+id/bminus"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/operatorButtons" android:backgroundTint="@color/operatorButtons"
android:text="-" /> android:text="-" />
@ -208,27 +178,27 @@
style="@style/LinearLayoutStyle"> style="@style/LinearLayoutStyle">
<Button <Button
android:id="@+id/bdot" android:id="@+id/bneg"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/specialButtons" android:backgroundTint="@color/specialButtons"
android:text="." /> android:text="+/-" />
<Button <Button
android:id="@+id/b0" android:id="@+id/b0"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/numberButtons" android:backgroundTint="@color/numberButtons"
android:text="0" /> android:text="0" />
<Button <Button
android:id="@+id/bneg" android:id="@+id/bdot"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/specialButtons" android:backgroundTint="@color/specialButtons"
android:text="+/-" /> android:text="." />
<!-- i put equals last because it puts it close to the thumb--> <!-- i put equals last because it puts it close to the thumb-->
<Button <Button
android:id="@+id/bequals" android:id="@+id/bequals"
style="@style/CalculatorButtonTextStyle" style="@style/CalculatorButtonStyle"
android:backgroundTint="@color/equalsButton" android:backgroundTint="@color/equalsButton"
android:text="=" /> android:text="=" />

View File

@ -7,7 +7,7 @@
<item name="autoSizeStepGranularity">2sp</item> <item name="autoSizeStepGranularity">2sp</item>
</style> </style>
<style name="CalculatorButtonTextStyle"> <style name="CalculatorButtonStyle">
<item name="autoSizeTextType">uniform</item> <item name="autoSizeTextType">uniform</item>
<item name="autoSizeMinTextSize">10sp</item> <item name="autoSizeMinTextSize">10sp</item>
<item name="autoSizeMaxTextSize">256sp</item> <item name="autoSizeMaxTextSize">256sp</item>
@ -19,6 +19,7 @@
<item name="android:layout_height">match_parent</item> <item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item> <item name="android:layout_weight">1</item>
<item name="android:gravity">center</item> <item name="android:gravity">center</item>
</style> </style>
<style name="LinearLayoutStyle"> <style name="LinearLayoutStyle">