diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 73c8d91..50a9935 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -24,6 +24,11 @@
+
launchSettings()
R.id.about -> launchAbout()
+ R.id.scientific -> launchScientific()
else -> return super.onOptionsItemSelected(item)
}
return true
@@ -111,6 +112,9 @@ class MainActivity : SimpleActivity(), Calculator {
private fun launchSettings() {
startActivity(Intent(applicationContext, SettingsActivity::class.java))
}
+ private fun launchScientific() {
+ startActivity(Intent(applicationContext, ScientificActivity::class.java))
+ }
private fun launchAbout() {
val licenses = LICENSE_AUTOFITTEXTVIEW or LICENSE_ROBOLECTRIC or LICENSE_ESPRESSO
diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/ScientificActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/ScientificActivity.kt
new file mode 100644
index 0000000..7f1c8ec
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/ScientificActivity.kt
@@ -0,0 +1,19 @@
+package com.simplemobiletools.calculator.activities
+
+import android.os.Bundle
+import com.simplemobiletools.calculator.R
+import com.simplemobiletools.calculator.extensions.config
+import com.simplemobiletools.calculator.extensions.updateViewColors
+import kotlinx.android.synthetic.main.activity_main.*
+import com.simplemobiletools.calculator.BuildConfig
+import com.simplemobiletools.commons.extensions.*
+
+class ScientificActivity : SimpleActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?){
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.scientific_activity)
+ appLaunched(BuildConfig.APPLICATION_ID)
+ updateViewColors(calculator_holder, config.textColor)
+ }
+}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt
index c133cfa..0a98dd2 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt
@@ -111,7 +111,7 @@ class WidgetConfigureActivity : SimpleActivity() {
config_save.setTextColor(mTextColor)
val viewIds = intArrayOf(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, R.id.btn_8,
- R.id.btn_9, R.id.btn_percent, R.id.btn_power, R.id.btn_root, R.id.btn_clear, R.id.btn_reset, R.id.btn_divide, R.id.btn_multiply,
+ R.id.btn_9, R.id.btn_percent, R.id.btn_power, R.id.btn_root, R.id.btn_factorial, R.id.btn_clear, R.id.btn_reset, R.id.btn_divide, R.id.btn_multiply,
R.id.btn_minus, R.id.btn_plus, R.id.btn_decimal, R.id.btn_equals)
result.setTextColor(mTextColor)
formula.setTextColor(mTextColor)
diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt
index ef49e15..5706849 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt
@@ -58,6 +58,8 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
if (sign == "√") {
setFormula(sign + first)
+ } else if (sign == "!"){
+ setFormula(first + sign)
} else if (!sign.isEmpty()) {
var formula = first + sign + second
if (mWasPercentLast) {
@@ -102,6 +104,11 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
calculateResult()
}
+ private fun handleFactorial() {
+ mBaseValue = getDisplayedNumberAsDouble()
+ calculateResult()
+ }
+
private fun calculateResult() {
updateFormula()
if (mWasPercentLast) {
@@ -118,7 +125,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
fun handleOperation(operation: String) {
mWasPercentLast = operation == PERCENT
- if (lastKey == DIGIT && operation != ROOT) {
+ if (lastKey == DIGIT && operation != ROOT && operation!= FACTORIAL) {
handleResult()
}
@@ -130,6 +137,10 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
handleRoot()
mResetValue = false
}
+ if (operation == FACTORIAL) {
+ handleFactorial()
+ mResetValue = false
+ }
}
fun handleClear() {
@@ -195,6 +206,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
PERCENT -> "%"
POWER -> "^"
ROOT -> "√"
+ FACTORIAL -> "!"
else -> ""
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt
index 8e8af42..5f30e06 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt
@@ -12,6 +12,7 @@ const val ROOT = "root"
const val DECIMAL = "decimal"
const val CLEAR = "clear"
const val RESET = "reset"
+const val FACTORIAL = "factorial"
const val NAN = "NaN"
const val ZERO = "zero"
diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt
index ecf467d..925c476 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt
@@ -48,6 +48,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
setupIntent(context, views, PERCENT, R.id.btn_percent)
setupIntent(context, views, POWER, R.id.btn_power)
setupIntent(context, views, ROOT, R.id.btn_root)
+ setupIntent(context, views, FACTORIAL, R.id.btn_factorial )
setupIntent(context, views, CLEAR, R.id.btn_clear)
setupIntent(context, views, RESET, R.id.btn_reset)
@@ -80,7 +81,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
private fun updateTextColors(views: RemoteViews, color: Int) {
val viewIds = intArrayOf(R.id.formula, R.id.result, 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, R.id.btn_8, R.id.btn_9, R.id.btn_percent, R.id.btn_power, R.id.btn_root, R.id.btn_clear, R.id.btn_reset, R.id.btn_divide,
+ R.id.btn_7, R.id.btn_8, R.id.btn_9, R.id.btn_percent, R.id.btn_power, R.id.btn_root, R.id.btn_factorial, R.id.btn_clear, R.id.btn_reset, R.id.btn_divide,
R.id.btn_multiply, R.id.btn_minus, R.id.btn_plus, R.id.btn_decimal, R.id.btn_equals)
for (i in viewIds) {
@@ -91,7 +92,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
when (action) {
- DECIMAL, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, EQUALS, CLEAR, RESET, PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT -> myAction(action, context)
+ DECIMAL, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, EQUALS, CLEAR, RESET, PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT, FACTORIAL -> myAction(action, context)
else -> super.onReceive(context, intent)
}
}
@@ -116,7 +117,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
EQUALS -> calc!!.handleEquals()
CLEAR -> calc!!.handleClear()
RESET -> calc!!.handleReset()
- PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT -> calc!!.handleOperation(action)
+ PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT, FACTORIAL -> calc!!.handleOperation(action)
}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/operation/FactorialOperation.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/operation/FactorialOperation.kt
new file mode 100644
index 0000000..d8be339
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/calculator/operation/FactorialOperation.kt
@@ -0,0 +1,20 @@
+package com.simplemobiletools.calculator.operation
+
+import com.simplemobiletools.calculator.operation.base.Operation
+import com.simplemobiletools.calculator.operation.base.UnaryOperation
+
+class FactorialOperation(value: Double) : UnaryOperation(value), Operation {
+
+ override fun getResult(): Double{
+ var result = 1.0
+ if (value==0.0 || value==1.0){
+ return result
+ }else{
+ var base = value.toInt()
+ for(i in 1..base){
+ result *= i
+ }
+ }
+ return result
+ }
+}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/operation/OperationFactory.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/operation/OperationFactory.kt
index 4869433..091aa4f 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calculator/operation/OperationFactory.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calculator/operation/OperationFactory.kt
@@ -14,6 +14,7 @@ object OperationFactory {
PERCENT -> PercentOperation(baseValue, secondValue)
POWER -> PowerOperation(baseValue, secondValue)
ROOT -> RootOperation(baseValue)
+ FACTORIAL -> FactorialOperation(baseValue)
else -> null
}
}
diff --git a/app/src/main/res/layout/scientific_activity.xml b/app/src/main/res/layout/scientific_activity.xml
new file mode 100644
index 0000000..f205381
--- /dev/null
+++ b/app/src/main/res/layout/scientific_activity.xml
@@ -0,0 +1,320 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml
index 815619c..0a7e563 100644
--- a/app/src/main/res/menu/menu.xml
+++ b/app/src/main/res/menu/menu.xml
@@ -1,6 +1,10 @@