Skip to content

Commit

Permalink
*Final Update*
Browse files Browse the repository at this point in the history
* Redid the layout
 * Added Dividers to give it a clean look

*Changed the coloring
 *Green & White

*Added a quality text at bottom
 *Updated dynamically as you scroll the scroll bar
  • Loading branch information
lilrebel17 committed Aug 4, 2022
1 parent 21218a9 commit 4f9f376
Show file tree
Hide file tree
Showing 35 changed files with 462 additions and 183 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
.externalNativeBuild
.cxx
local.properties
/app/src/androidTest/java/com/example/hiptips/
/app/src/test/java/com/example/hiptips/
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 87 additions & 8 deletions app/src/main/java/com/example/hiptips/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@


public class MainActivity extends AppCompatActivity {
//Setting up Variables to be initialized later on.
SeekBar tipSlider;
TextView tipPercent;
TextView tipAmount;
TextView totalAmount;
EditText priceInput;
TextView qualityText;


//The onCreate method fires when the application starts up
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//This line is just telling our program what content to show on screen.
//In this case R. stands for resource. So were looking in Resources/Layout/ for activity_main
//in res/layout we have the matching .xml file
//setContentView just takes a layout, and tells the program what to show.
setContentView(R.layout.activity_main);

//Initializing variables for all of our labels/inputs
Expand All @@ -34,17 +34,26 @@ protected void onCreate(Bundle savedInstanceState) {
tipAmount = findViewById(R.id.tvTip_Amount);
totalAmount = findViewById(R.id.tvTotal_Amount);
priceInput = findViewById(R.id.tvPrice_Input);
qualityText = findViewById(R.id.qualityText);

//Gives us a number format for the labels.
//Since its dollars, were formatting things with 0.00
NumberFormat dollarFormat = new DecimalFormat("#0.00");

//We take the SeekBar and and give it a change listener so our program is always listening
//for any changes.
tipSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
//Just takes the tipPercent. and sets the text to % + i.
//i = whatever the slider is on.

//This just takes i and sets it as the percent text, also adds % at the end.
tipPercent.setText(i + "%");
//We then update the tip label
UpdateTipLabel(i);
//Finally we update the quality label.
UpdateQualityLabel(i);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Expand All @@ -65,11 +74,11 @@ public void UpdateTipLabel(Integer percent) {
else {
//We parse the user input to a double so they can input decimals.
Float price = Float.parseFloat(inputValue);
//We then divide our percent variable which we get passed into this function from the slider
//We must do 100.0 here or it will try to divide an int and a double.
//This would result in it being 0 until it reaches 100/100 because Ints dont have decimal places.
//The equation is simple. We take the %(the current place of the slider)
//and multiply it by the price the user inputs. then divide by 100.
Float rawResult = (percent*price)/100;
//Setting a String variable with the proper dollar format.
//This is taking our raw result, which can have a lot of decimal places.
//And uses our dollar format that we setup on line 41
String formattedResult = "$"+dollarFormat.format(rawResult);
//Finally we put our formatted result in a string to be written to the screen.
tipAmount.setText(formattedResult);
Expand All @@ -79,11 +88,81 @@ public void UpdateTipLabel(Integer percent) {
}

public void UpdateTotalLabel(Float rawResult, Float price) {
//To update the total we just add the price and rawResult from UpdateTipLabel.
Float rawTotal = rawResult + price;
//Then we format the rawResult with our dollarformat.
String formattedTotal = "$"+dollarFormat.format(rawTotal);

//Finally we just update the text to the proper textview.
totalAmount.setText(formattedTotal);
}

public void UpdateQualityLabel(Integer i) {

switch(i) {
case 0:
qualityText.setText("");
break;
case 1:
qualityText.setText(R.string.qual_bad);
qualityText.setTextColor(getResources().getColor(R.color.qual_0));
break;
case 3:
qualityText.setTextColor(getResources().getColor(R.color.qual_3));
break;
case 5:
qualityText.setText(R.string.qual_bad_better);
qualityText.setTextColor(getResources().getColor(R.color.qual_5));
break;
case 7:
qualityText.setTextColor(getResources().getColor(R.color.qual_7));
break;
case 9:
qualityText.setText(R.string.qual_fine);
qualityText.setTextColor(getResources().getColor(R.color.qual_9));
break;
case 11:
qualityText.setTextColor(getResources().getColor(R.color.qual_11));
break;
case 12:
qualityText.setTextColor(getResources().getColor(R.color.qual_12));
break;
case 13:
qualityText.setTextColor(getResources().getColor(R.color.qual_13));
break;
case 14:
qualityText.setTextColor(getResources().getColor(R.color.qual_14));
break;
case 15:
qualityText.setText(R.string.qual_average);
qualityText.setTextColor(getResources().getColor(R.color.qual_15));
break;
case 18:
qualityText.setText(R.string.qual_good);
qualityText.setTextColor(getResources().getColor(R.color.qual_18));
break;
case 25:
qualityText.setText(R.string.qual_great);
qualityText.setTextColor(getResources().getColor(R.color.qual_25));
break;
case 30:
qualityText.setText(R.string.qual_insane);
qualityText.setTextColor(getResources().getColor(R.color.qual_30));
break;
case 40:
qualityText.setTextColor(getResources().getColor(R.color.qual_40));
break;
case 50:
qualityText.setText(R.string.qual_wow);
qualityText.setTextColor(getResources().getColor(R.color.qual_50));
break;
case 70:
qualityText.setTextColor(getResources().getColor(R.color.qual_70));
break;
case 90:
qualityText.setTextColor(getResources().getColor(R.color.qual_90));
break;
}
}
});

}
Expand Down
30 changes: 0 additions & 30 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108"
android:tint="#FDFCFC">
<group android:scaleX="2.543795"
android:scaleY="2.543795"
android:translateX="24.887678"
android:translateY="23.474459">
<path
android:fillColor="@android:color/white"
android:pathData="M11.8,10.9c-2.27,-0.59 -3,-1.2 -3,-2.15 0,-1.09 1.01,-1.85 2.7,-1.85 1.78,0 2.44,0.85 2.5,2.1h2.21c-0.07,-1.72 -1.12,-3.3 -3.21,-3.81V3h-3v2.16c-1.94,0.42 -3.5,1.68 -3.5,3.61 0,2.31 1.91,3.46 4.7,4.13 2.5,0.6 3,1.48 3,2.41 0,0.69 -0.49,1.79 -2.7,1.79 -2.06,0 -2.87,-0.92 -2.98,-2.1h-2.2c0.12,2.19 1.76,3.42 3.68,3.83V21h3v-2.15c1.95,-0.37 3.5,-1.5 3.5,-3.55 0,-2.84 -2.43,-3.81 -4.7,-4.4z"/>
</group>
</vector>
Loading

0 comments on commit 4f9f376

Please sign in to comment.