mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-04-23 14:37:21 +02:00
Merge pull request #212 from dagkalis/feature_186
turn number to negative on minus-btn long-press
This commit is contained in:
commit
cdf1cbf4e0
@ -42,6 +42,10 @@ class MainActivity : SimpleActivity(), Calculator {
|
|||||||
btn_power.setOnClickListener { calc.handleOperation(POWER); checkHaptic(it) }
|
btn_power.setOnClickListener { calc.handleOperation(POWER); checkHaptic(it) }
|
||||||
btn_root.setOnClickListener { calc.handleOperation(ROOT); checkHaptic(it) }
|
btn_root.setOnClickListener { calc.handleOperation(ROOT); checkHaptic(it) }
|
||||||
|
|
||||||
|
btn_minus.setOnLongClickListener {
|
||||||
|
calc.turnToNegative()
|
||||||
|
}
|
||||||
|
|
||||||
btn_clear.setOnClickListener { calc.handleClear(); checkHaptic(it) }
|
btn_clear.setOnClickListener { calc.handleClear(); checkHaptic(it) }
|
||||||
btn_clear.setOnLongClickListener { calc.handleReset(); true }
|
btn_clear.setOnLongClickListener { calc.handleReset(); true }
|
||||||
|
|
||||||
|
@ -123,6 +123,25 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
|||||||
showNewResult(inputDisplayedFormula)
|
showNewResult(inputDisplayedFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun turnToNegative(): Boolean {
|
||||||
|
if (inputDisplayedFormula.isEmpty()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inputDisplayedFormula.trimStart('-').any { it.toString() in operations } && inputDisplayedFormula.replace(",", "").toDouble() != 0.0) {
|
||||||
|
inputDisplayedFormula = if (inputDisplayedFormula.first() == '-') {
|
||||||
|
inputDisplayedFormula.substring(1)
|
||||||
|
} else {
|
||||||
|
"-$inputDisplayedFormula"
|
||||||
|
}
|
||||||
|
|
||||||
|
showNewResult(inputDisplayedFormula)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// handle percents manually, it doesn't seem to be possible via net.objecthunter:exp4j. "%" is used only for modulo there
|
// handle percents manually, it doesn't seem to be possible via net.objecthunter:exp4j. "%" is used only for modulo there
|
||||||
private fun handlePercent() {
|
private fun handlePercent() {
|
||||||
var result = calculatePercentage(baseValue, getSecondValue(), lastOperation)
|
var result = calculatePercentage(baseValue, getSecondValue(), lastOperation)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user