1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-12-04 21:28:10 -05:00

Minor tweaks before submit homework 2

This commit is contained in:
DjBushido 2014-02-10 23:34:50 -05:00
parent 44524c7f70
commit 34b77955ff

View File

@ -17,18 +17,23 @@ import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
// Our main activity implements a lot of different functionality.
// If we had even more things we needed to add, likely need to split off
// into separate files. As it stands though, for purpose of project,
// easier to leave it in one area.
public class MainActivity extends Activity implements OnCheckedChangeListener, public class MainActivity extends Activity implements OnCheckedChangeListener,
OnSeekBarChangeListener, View.OnClickListener, TextWatcher OnSeekBarChangeListener, View.OnClickListener, TextWatcher
{ {
final static double TEN = .10; final static double TEN_PERCENT = .10;
final static double TWOFIVE = .25; final static double TWENTY_FIVE_PERCENT = .25;
final static double FIVEZERO = .50; final static double FIFTY_PERCENT = .50;
RadioGroup percents; RadioGroup percents;
SeekBar customBar; SeekBar customBar;
Button exit; Button exit;
EditText listPrice; EditText listPrice;
TextView saved, paid, customPercent; TextView saved, paid, customPercent;
NumberFormat currencyFormat, percentFormat; NumberFormat currencyFormat, percentFormat;
int currentCustomPercent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
@ -66,6 +71,7 @@ public class MainActivity extends Activity implements OnCheckedChangeListener,
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
{ {
customPercent.setText(percentFormat.format(progress/100.0)); customPercent.setText(percentFormat.format(progress/100.0));
currentCustomPercent = progress;
} }
@Override @Override
@ -84,32 +90,28 @@ public class MainActivity extends Activity implements OnCheckedChangeListener,
@Override @Override
public void onClick(View v) public void onClick(View v)
{ {
// TODO Auto-generated method stub // Exit button is the only thing to click on this application
finish(); finish();
} }
@Override @Override
public void onCheckedChanged(RadioGroup rg, int checkedId) public void onCheckedChanged(RadioGroup rg, int checkedId)
{ {
// TODO Auto-generated method stub
updateCost(); updateCost();
} }
@Override @Override
public void afterTextChanged(Editable arg0) { public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
updateCost(); updateCost();
} }
@Override @Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) { int arg3) {
// TODO Auto-generated method stub
} }
@Override @Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
updateCost(); updateCost();
if(listPrice.getText().toString().trim().equals("")) if(listPrice.getText().toString().trim().equals(""))
{ {
@ -125,24 +127,23 @@ public class MainActivity extends Activity implements OnCheckedChangeListener,
double startPrice = Double.parseDouble(listPrice.getText().toString()); double startPrice = Double.parseDouble(listPrice.getText().toString());
if (((RadioButton)findViewById(R.id.rad10Pct)).isChecked()) if (((RadioButton)findViewById(R.id.rad10Pct)).isChecked())
{ {
savedAmount=startPrice * TEN; savedAmount=startPrice * TEN_PERCENT;
paidAmount=startPrice * (1 - TEN); paidAmount=startPrice * (1 - TEN_PERCENT);
} }
else if (((RadioButton)findViewById(R.id.rad25Pct)).isChecked()) else if (((RadioButton)findViewById(R.id.rad25Pct)).isChecked())
{ {
savedAmount=startPrice * TWOFIVE; savedAmount=startPrice * TWENTY_FIVE_PERCENT;
paidAmount=startPrice * (1 - TWOFIVE); paidAmount=startPrice * (1 - TWENTY_FIVE_PERCENT);
} }
else if (((RadioButton)findViewById(R.id.rad50Pct)).isChecked()) else if (((RadioButton)findViewById(R.id.rad50Pct)).isChecked())
{ {
savedAmount=startPrice * FIVEZERO; savedAmount=startPrice * FIFTY_PERCENT;
paidAmount=startPrice * (1 - FIVEZERO); paidAmount=startPrice * (1 - FIFTY_PERCENT);
} }
else else
{ {
int percentage=Integer.parseInt(customPercent.getText().toString().replaceAll("[\\D]","")); savedAmount=startPrice * currentCustomPercent/100;
savedAmount=startPrice * percentage/100; paidAmount=startPrice * (1 - currentCustomPercent/100);
paidAmount=startPrice * (1 - percentage/100);
} }
} }
catch (Exception e) catch (Exception e)