correct some operations after equals

This commit is contained in:
tibbi 2015-12-24 22:56:56 +01:00
parent 9b1c979be6
commit 637c47f5b5
1 changed files with 12 additions and 6 deletions

View File

@ -135,22 +135,18 @@ public class MainActivity extends AppCompatActivity {
lastKey = EQUALS; lastKey = EQUALS;
} }
@OnClick(R.id.btn_decimal)
public void decimalClicked() { public void decimalClicked() {
String value = getDisplayedNumber(); String value = getDisplayedNumber();
if (!value.contains(".")) if (!value.contains("."))
value += "."; value += ".";
result.setText(value); result.setText(value);
lastKey = DIGIT;
} }
@OnClick(R.id.btn_0)
public void zeroClicked() { public void zeroClicked() {
String value = getDisplayedNumber(); String value = getDisplayedNumber();
if (!value.isEmpty() && !value.equals("0")) if (!value.isEmpty() && !value.equals("0"))
value += "0"; value += "0";
result.setText(value); result.setText(value);
lastKey = DIGIT;
} }
private void handleEquals() { private void handleEquals() {
@ -172,10 +168,20 @@ public class MainActivity extends AppCompatActivity {
} }
} }
@OnClick({R.id.btn_1, R.id.btn_2, R.id.btn_3, R.id.btn_4, R.id.btn_5, R.id.btn_6, R.id.btn_7, R.id.btn_8, R.id.btn_9}) @OnClick({R.id.btn_decimal, R.id.btn_0, R.id.btn_1, R.id.btn_2, R.id.btn_3, R.id.btn_4, R.id.btn_5, R.id.btn_6, R.id.btn_7,
public void digitClicked(View view) { R.id.btn_8, R.id.btn_9})
public void numpadClicked(View view) {
if (lastKey == EQUALS)
lastOperation = EQUALS;
lastKey = DIGIT; lastKey = DIGIT;
switch (view.getId()) { switch (view.getId()) {
case R.id.btn_decimal:
decimalClicked();
break;
case R.id.btn_0:
zeroClicked();
break;
case R.id.btn_1: case R.id.btn_1:
addDigit(1); addDigit(1);
break; break;