diff --git a/DiceRoller/.idea/deploymentTargetDropDown.xml b/DiceRoller/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000000000000000000000000000000000000..75666bd56303113d31f08094acaa5d7129c27b30 --- /dev/null +++ b/DiceRoller/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="deploymentTargetDropDown"> + <targetSelectedWithDropDown> + <Target> + <type value="QUICK_BOOT_TARGET" /> + <deviceKey> + <Key> + <type value="VIRTUAL_DEVICE_PATH" /> + <value value="C:\Users\hp\.android\avd\Pixel_3_XL_API_29.avd" /> + </Key> + </deviceKey> + </Target> + </targetSelectedWithDropDown> + <timeTargetWasSelectedWithDropDown value="2022-03-03T10:59:10.496023800Z" /> + </component> +</project> \ No newline at end of file diff --git a/DiceRoller/.idea/misc.xml b/DiceRoller/.idea/misc.xml index 36d438b92347805199e1b6a2716555270ee1f875..b3e4a97168a6060dee25fe60678a9f425481bed8 100644 --- a/DiceRoller/.idea/misc.xml +++ b/DiceRoller/.idea/misc.xml @@ -4,7 +4,7 @@ <option name="filePathToZoomLevelMap"> <map> <entry key="..\:/PROJECT/AndroidStudioProjects/DiceRoller/app/src/main/res/layout/activity_main.xml" value="0.7333333333333334" /> - <entry key="..\:/PROJECT/pbd-exercise/DiceRoller/app/src/main/res/layout/activity_main.xml" value="0.3333333333333333" /> + <entry key="..\:/PROJECT/pbd-exercise/DiceRoller/app/src/main/res/layout/activity_main.xml" value="0.1" /> </map> </option> </component> diff --git a/TipTime/.idea/deploymentTargetDropDown.xml b/TipTime/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000000000000000000000000000000000000..8b04192613223b8fd63b55d4e1a6c061d4e72792 --- /dev/null +++ b/TipTime/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="deploymentTargetDropDown"> + <runningDeviceTargetSelectedWithDropDown> + <Target> + <type value="RUNNING_DEVICE_TARGET" /> + <deviceKey> + <Key> + <type value="SERIAL_NUMBER" /> + <value value="RR8MC06LCHA" /> + </Key> + </deviceKey> + </Target> + </runningDeviceTargetSelectedWithDropDown> + <timeTargetWasSelectedWithDropDown value="2022-03-08T08:36:15.177742500Z" /> + </component> +</project> \ No newline at end of file diff --git a/TipTime/.idea/misc.xml b/TipTime/.idea/misc.xml index 5358d1ac0fb799f6fef8f9670b330315d83f9e57..0dc5e5c254d20fb0132a7f578acb97db680da408 100644 --- a/TipTime/.idea/misc.xml +++ b/TipTime/.idea/misc.xml @@ -3,7 +3,7 @@ <component name="DesignSurface"> <option name="filePathToZoomLevelMap"> <map> - <entry key="..\:/PROJECT/pbd-exercise/TipTime/app/src/main/res/layout/activity_main.xml" value="0.1" /> + <entry key="..\:/PROJECT/pbd-exercise/TipTime/app/src/main/res/layout/activity_main.xml" value="0.6" /> <entry key="..\:/Users/hp/AndroidStudioProjects/TipTime/app/src/main/res/layout/activity_main.xml" value="0.1" /> </map> </option> diff --git a/TipTime/app/build.gradle b/TipTime/app/build.gradle index 6cce0ada83fcfe545a6b513a082bf83e30baab3f..1a44ecac6191810a500c0db25b6bf7277a26b5d5 100644 --- a/TipTime/app/build.gradle +++ b/TipTime/app/build.gradle @@ -29,6 +29,10 @@ android { kotlinOptions { jvmTarget = '1.8' } + + buildFeatures { + viewBinding true + } } dependencies { diff --git a/TipTime/app/src/main/java/com/example/tiptime/MainActivity.kt b/TipTime/app/src/main/java/com/example/tiptime/MainActivity.kt index 6ab37fd1f1f5ad9c9a107eec5d7b55dbcf420688..69be9d61ee29e172ac773142e0ea3b15da1f229c 100644 --- a/TipTime/app/src/main/java/com/example/tiptime/MainActivity.kt +++ b/TipTime/app/src/main/java/com/example/tiptime/MainActivity.kt @@ -2,10 +2,39 @@ package com.example.tiptime import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import com.example.tiptime.databinding.ActivityMainBinding +import java.text.NumberFormat class MainActivity : AppCompatActivity() { + + private lateinit var binding: ActivityMainBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + binding.calculateButton.setOnClickListener{ calculateTip() } + } + + private fun calculateTip(){ + val stringInTextField = binding.costOfService.text.toString() + val cost = stringInTextField.toDoubleOrNull() + if (cost == null) { + binding.tipResult.text = "" + return + } + val tipPercentage = when (binding.tipOptions.checkedRadioButtonId) { + R.id.option_twenty_percent -> 0.20 + R.id.option_eighteen_percent -> 0.18 + else -> 0.15 + } + var tip = tipPercentage * cost + if (binding.roundUpSwitch.isChecked){ + tip = kotlin.math.ceil(tip) + } + val formattedTip = NumberFormat.getCurrencyInstance().format(tip) + binding.tipResult.text = getString(R.string.tip_amount, formattedTip) + } + } \ No newline at end of file diff --git a/TipTime/app/src/main/res/layout/activity_main.xml b/TipTime/app/src/main/res/layout/activity_main.xml index 9a7985b9202312d469eaf85a601b32fd343c1863..5a30c3a04027211bceb7799aad2f9f17cd8e6d09 100644 --- a/TipTime/app/src/main/res/layout/activity_main.xml +++ b/TipTime/app/src/main/res/layout/activity_main.xml @@ -78,7 +78,7 @@ android:id="@+id/tip_result" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/tip_amount" + tools:text="Tip Amount: $10" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/calculate_button" /> diff --git a/TipTime/app/src/main/res/values/strings.xml b/TipTime/app/src/main/res/values/strings.xml index 7ae71439f6a96ae974ac83f8a4ac85cef7e03ade..d42b488f6ec7ca95a58f4293f6924bcbf1ce6a5f 100644 --- a/TipTime/app/src/main/res/values/strings.xml +++ b/TipTime/app/src/main/res/values/strings.xml @@ -7,5 +7,5 @@ <string name="okay_service">Okay(15%)</string> <string name="round_up_tip">Round up tip?</string> <string name="calculate">Calculate</string> - <string name="tip_amount">Tip Amount</string> + <string name="tip_amount">Tip Amount: %s</string> </resources> \ No newline at end of file