Archived
1
0

refactor: many if's to swich/when

This commit is contained in:
sweetbread
2023-05-03 20:53:44 +03:00
parent 1ed2aab856
commit c0bd1dca2c
7 changed files with 808 additions and 459 deletions
+123
View File
@@ -0,0 +1,123 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>
+5
View File
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
@@ -3,6 +3,7 @@ package meow.sweetbread.lincalc
import android.annotation.SuppressLint import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.os.LimitExceededException
import android.util.Log import android.util.Log
import android.widget.Button import android.widget.Button
import android.widget.ImageButton import android.widget.ImageButton
@@ -27,12 +28,14 @@ class MainActivity : AppCompatActivity() {
priority["*"] = 2 priority["*"] = 2
priority["/"] = 2 priority["/"] = 2
priority["^"] = 3 priority["^"] = 3
priority[""] = 3
tokensType["+"] = Tokens.Operations tokensType["+"] = Tokens.Operations
tokensType["-"] = Tokens.Operations tokensType["-"] = Tokens.Operations
tokensType["*"] = Tokens.Operations tokensType["*"] = Tokens.Operations
tokensType["/"] = Tokens.Operations tokensType["/"] = Tokens.Operations
tokensType["^"] = Tokens.Operations tokensType["^"] = Tokens.Operations
tokensType[""] = Tokens.Function
tokensType["+"] = Tokens.Operations tokensType["+"] = Tokens.Operations
tokensType["+"] = Tokens.Operations tokensType["+"] = Tokens.Operations
tokensType["("] = Tokens.BracketOpen tokensType["("] = Tokens.BracketOpen
@@ -63,7 +66,7 @@ class MainActivity : AppCompatActivity() {
findViewById<Button>(R.id.btn_sqrt).setOnClickListener { btn_listener(it as Button) } findViewById<Button>(R.id.btn_sqrt).setOnClickListener { btn_listener(it as Button) }
findViewById<Button>(R.id.btn_pi).setOnClickListener { btn_listener(it as Button) } findViewById<Button>(R.id.btn_pi).setOnClickListener { btn_listener(it as Button) }
findViewById<Button>(R.id.btn_elr).setOnClickListener { btn_listener(it as Button) } // findViewById<Button>(R.id.btn_elr).setOnClickListener { btn_listener(it as Button) }
findViewById<Button>(R.id.btn_x).setOnClickListener { btn_listener(it as Button) } findViewById<Button>(R.id.btn_x).setOnClickListener { btn_listener(it as Button) }
@@ -71,12 +74,14 @@ class MainActivity : AppCompatActivity() {
val image = findViewById<TextView>(R.id.input) val image = findViewById<TextView>(R.id.input)
findViewById<ImageButton>(R.id.del).setOnClickListener { findViewById<Button>(R.id.btn_del).setOnClickListener {
image.text = image.text.dropLast(1) image.text = image.text.dropLast(1)
} }
findViewById<Button>(R.id.btn_sbm).setOnClickListener { findViewById<Button>(R.id.btn_sbm).setOnClickListener {
findViewById<TextView>(R.id.last_exp_out).text = findViewById<TextView>(R.id.input).text.toString() try {
findViewById<TextView>(R.id.last_exp_out).text =
findViewById<TextView>(R.id.input).text.toString()
val equations = findViewById<TextView>(R.id.input).text.toString().split('=') val equations = findViewById<TextView>(R.id.input).text.toString().split('=')
if (equations.size == 1) { if (equations.size == 1) {
val answer = evaluate(toRpn(tokenizer(equations[0]))) val answer = evaluate(toRpn(tokenizer(equations[0])))
@@ -92,7 +97,8 @@ class MainActivity : AppCompatActivity() {
var right = evaluate(toRpn(tokenizer(equations[1]))) var right = evaluate(toRpn(tokenizer(equations[1])))
if (((left.type == Tokens.Number) and (right.type != Tokens.Number)) or if (((left.type == Tokens.Number) and (right.type != Tokens.Number)) or
(left.type == Tokens.Linear) and (right.type == Tokens.Quadratic)) { (left.type == Tokens.Linear) and (right.type == Tokens.Quadratic)
) {
val tmp = right val tmp = right
left = right left = right
right = tmp right = tmp
@@ -116,7 +122,7 @@ class MainActivity : AppCompatActivity() {
else else
(left.value as Linear - right.value as Linear).answer() (left.value as Linear - right.value as Linear).answer()
val value: String val value: String
value = if (answer.toString().split('.')[1] == "0") value = if (answer.toFloat().toString().split('.')[1] == "0")
answer.toInt().toString() answer.toInt().toString()
else answer.toString() else answer.toString()
findViewById<TextView>(R.id.last_exp_out).text = findViewById<TextView>(R.id.last_exp_out).text =
@@ -127,6 +133,10 @@ class MainActivity : AppCompatActivity() {
} }
} }
} catch (e: java.lang.Exception) {
findViewById<TextView>(R.id.last_exp_out).text = "Ошибка"
findViewById<TextView>(R.id.right_out).text = e.stackTraceToString()
}
} }
} }
@@ -149,21 +159,37 @@ class MainActivity : AppCompatActivity() {
pos++ pos++
} }
if (tokens.isNotEmpty()) { if (tokens.isNotEmpty()) {
if (tokens.last().type in arrayOf(Tokens.BracketClose, Tokens.Constant, Tokens.Variable)) if (tokens.last().type in arrayOf(
Tokens.BracketClose,
Tokens.Constant,
Tokens.Variable
)
)
tokens += Token(Tokens.Operations, "*") tokens += Token(Tokens.Operations, "*")
} }
tokens += Token(Tokens.Number, exp.substring(position, pos).toDouble()) tokens += Token(Tokens.Number, exp.substring(position, pos).toDouble())
position = pos position = pos
} else if (chr == 'X') { } else if (chr == 'X') {
if (tokens.isNotEmpty()) { if (tokens.isNotEmpty()) {
if (tokens.last().type in arrayOf(Tokens.BracketClose, Tokens.Constant, Tokens.Number)) if (tokens.last().type in arrayOf(
Tokens.BracketClose,
Tokens.Constant,
Tokens.Number
)
)
tokens += Token(Tokens.Operations, "*") tokens += Token(Tokens.Operations, "*")
} }
tokens += Token(Tokens.Variable, chr.toString()) tokens += Token(Tokens.Variable, chr.toString())
position++ position++
} else if (chr.toString() in constants.keys){ } else if (chr.toString() in constants.keys) {
if (tokens.isNotEmpty()) { if (tokens.isNotEmpty()) {
if (tokens.last().type in arrayOf(Tokens.BracketClose, Tokens.Constant, Tokens.Variable, Tokens.Number)) if (tokens.last().type in arrayOf(
Tokens.BracketClose,
Tokens.Constant,
Tokens.Variable,
Tokens.Number
)
)
tokens += Token(Tokens.Operations, "*") tokens += Token(Tokens.Operations, "*")
} }
tokens += Token(Tokens.Constant, chr.toString()) tokens += Token(Tokens.Constant, chr.toString())
@@ -176,21 +202,26 @@ class MainActivity : AppCompatActivity() {
pos++ pos++
} }
if (tokens.isNotEmpty()) { if (tokens.isNotEmpty()) {
if (tokens.last().type in arrayOf(Tokens.BracketClose, Tokens.Constant, Tokens.Variable)) if (tokens.last().type in arrayOf(
Tokens.BracketClose,
Tokens.Constant,
Tokens.Variable
)
)
tokens += Token(Tokens.Operations, "*") tokens += Token(Tokens.Operations, "*")
} }
tokens += Token(Tokens.Function, exp.substring(position, pos)) tokens += Token(Tokens.Function, exp.substring(position, pos))
position = pos position = pos
} } else if (tokensType.containsKey(chr.toString())) {
else if (tokensType.containsKey(chr.toString())) {
if (tokens.isNotEmpty()) { if (tokens.isNotEmpty()) {
if ((tokensType[chr.toString()]!! == Tokens.BracketOpen) and if ((tokensType[chr.toString()]!! == Tokens.BracketOpen) and
(tokens.last().type in arrayOf(Tokens.Number, Tokens.Variable))) (tokens.last().type in arrayOf(Tokens.Number, Tokens.Variable))
)
tokens += Token(Tokens.Operations, "*") tokens += Token(Tokens.Operations, "*")
if ((chr == '-') and (tokens.last().type != Tokens.Number)) // if ((chr == '-') and (tokens.last().type != Tokens.Number))
tokens += Token(Tokens.Number, 0.toDouble()) // tokens += Token(Tokens.Number, 0.0)
} else if (chr == '-') } // else if (chr == '-')
tokens += Token(Tokens.Number, 0.toDouble()) // tokens += Token(Tokens.Number, 0.0)
tokens += Token(tokensType[chr.toString()]!!, chr.toString()) tokens += Token(tokensType[chr.toString()]!!, chr.toString())
position++ position++
} else { } else {
@@ -232,7 +263,8 @@ class MainActivity : AppCompatActivity() {
while ( while (
(priority[token.value]!! < priority[act_buf.last().value]!!) or (priority[token.value]!! < priority[act_buf.last().value]!!) or
((priority[token.value]!! == priority[act_buf.last().value]!!) and ((priority[token.value]!! == priority[act_buf.last().value]!!) and
(token.value in leftAssociative))) { (token.value in leftAssociative))
) {
out_buf += act_buf.removeLast() out_buf += act_buf.removeLast()
if (act_buf.isEmpty()) if (act_buf.isEmpty())
break break
@@ -241,7 +273,7 @@ class MainActivity : AppCompatActivity() {
act_buf += token act_buf += token
} else if (token.type == Tokens.BracketOpen) } else if (token.type == Tokens.BracketOpen)
act_buf += token act_buf += token
else if (token.type == Tokens.BracketClose){ else if (token.type == Tokens.BracketClose) {
while (act_buf.last().type != Tokens.BracketOpen) while (act_buf.last().type != Tokens.BracketOpen)
out_buf += act_buf.removeLast() out_buf += act_buf.removeLast()
act_buf.removeLast() act_buf.removeLast()
@@ -268,63 +300,182 @@ class MainActivity : AppCompatActivity() {
var tmp_buf = listOf<Token>() var tmp_buf = listOf<Token>()
while (buffer.size != 1) { while (buffer.size != 1) {
val token = buffer[position] var token = buffer[position]
if (token.type == Tokens.Function) { if (token.type == Tokens.Function) {
if (token.value == "sqrt") { if (token.value == "") {
tmp_buf = buffer.dropLast(ext.size - position + 1) tmp_buf = buffer.dropLast(ext.size - position + 1)
var res = Token(Tokens.Number, sqrt(buffer[position - 1].value as Double)) var res = Token(Tokens.Number, sqrt(buffer[position - 1].value as Double))
tmp_buf += res tmp_buf += res
tmp_buf += buffer.drop(position+1) tmp_buf += buffer.drop(position + 1)
} }
} else if (token.type == Tokens.Operations) { } else if (token.type == Tokens.Operations) {
val first = buffer[position-2] val first = buffer[position - 2].value
val second = buffer[position-1] val second = buffer[position - 1].value
//TODO: make operations with other objects //TODO: make operations with other objects
if (token.value == "+") { when (token.value) {
"+" -> {
tmp_buf = buffer.dropLast(ext.size - position + 2) tmp_buf = buffer.dropLast(ext.size - position + 2)
var res: Token val res: Token =
if ((first.type == Tokens.Number) and (second.type == Tokens.Number)) if ((first is Double) and (second is Double))
res = Token(Tokens.Number, (first.value as Double + second.value as Double)) Token(
else if ((first.type == Tokens.Variable) and (second.type == Tokens.Number)) Tokens.Number,
res = Token(Tokens.Linear, Linear(first.value as String, second.value as Double, 0.toDouble())) (first as Double + second as Double)
)
else if ((first is String) and (second is Double))
Token(
Tokens.Linear,
Linear(first as String, second as Double, 0.0)
)
else if ((first is Linear) and (second is Double))
Token(
Tokens.Linear, Linear(
(first as Linear).name,
(first as Linear).add + (second as Double),
(first as Linear).mul
)
)
else else
res = Token(Tokens.Linear, Linear(second.value as String, first.value as Double, 0.toDouble())) Token(
tmp_buf += res Tokens.Linear,
tmp_buf += buffer.drop(position+1) Linear(second as String, first as Double, 0.0)
} else if (token.value == "-") {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res = Token(Tokens.Number, (first.value as Double - second.value as Double))
tmp_buf += res
tmp_buf += buffer.drop(position+1)
} else if (token.value == "*") {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res: Token
res = if ((first.type == Tokens.Number) and (second.type == Tokens.Number))
Token(Tokens.Number, first.value as Double*second.value as Double)
else if ((first.type == Tokens.Number) and (second.type == Tokens.Variable))
Token(Tokens.Linear, Linear(second.value as String, 0.toDouble(), first.value as Double))
else if ((first.type == Tokens.Variable) and (second.type == Tokens.Number))
Token(Tokens.Linear, Linear(first.value as String, 0.toDouble(), second.value as Double))
else //if ((first.type == Tokens.Variable) and (second.type == Tokens.Variable))
Token(Tokens.Quadratic, Quadratic(first.value as String, 0.toDouble(), 0.toDouble(), 2.toDouble()))
tmp_buf += res
tmp_buf += buffer.drop(position+1)
} else if (token.value == "/") {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res = Token(Tokens.Number, first.value as Double/second.value as Double)
tmp_buf += res
tmp_buf += buffer.drop(position+1)
} else if (token.value == "^") {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res = Token(
Tokens.Number, (first.value as Double)
.pow(second.value as Double)
) )
tmp_buf += res tmp_buf += res
tmp_buf += buffer.drop(position + 1) tmp_buf += buffer.drop(position + 1)
} }
"-" -> {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res: Token = when (first) {
is Double -> {
when (second) {
is Double -> {
Token(Tokens.Number, (first - second))
}
is String -> {
Token(Tokens.Linear, Linear(second, first, -1.0))
}
is Linear -> {
Token(
Tokens.Linear,
Linear(
second.name,
first - second.add,
-1.0 * second.mul
)
)
}
else -> {
Token(Tokens.Linear, "")
}
}
}
is String -> {
when (second) {
is Double -> {
Token(Tokens.Linear, Linear(first, -second, 1.0))
}
is String -> {
Token(Tokens.Quadratic, Quadratic(first, 0.0, 1.0, 2.0))
}
else -> {
Token(Tokens.Linear, "")
}
}
}
is Linear -> {
when (second) {
is Double -> {
Token(
Tokens.Linear,
Linear(first.name, first.add - second, first.mul)
)
}
else -> {
Token(Tokens.Linear, "")
}
}
}
else -> {
Token(Tokens.Linear, "")
}
}
tmp_buf += res
tmp_buf += buffer.drop(position + 1)
}
"*" -> {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res: Token = when (first) {
is Double -> {
when (second) {
is Double -> {
Token(Tokens.Number, first * second)
}
is String -> {
Token(Tokens.Linear, Linear(second, 0.0, first))
}
is Linear -> {
Token(Tokens.Linear, second * first)
}
else -> {
Token(Tokens.Linear, "")
}
}
}
is String -> {
when (second) {
is Double -> {
Token(Tokens.Linear, Linear(first, 0.0, second))
}
is String -> {
Token(Tokens.Quadratic, "")
}
is Linear -> {
Token(Tokens.Quadratic, "")
}
else -> {
Token(Tokens.Quadratic, "")
}
}
}
else -> {
Token(Tokens.Quadratic, "")
}
}
tmp_buf += res
tmp_buf += buffer.drop(position + 1)
}
"/" -> {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res: Token =
if ((first is Double) and (second is Double))
Token(Tokens.Number, first as Double / second as Double)
else if ((first is String) and (second is Double))
Token(
Tokens.Linear,
Linear(
first as String,
0.0,
1.0 / (second as Double)
)
)
else
Token(Tokens.Number, 0.0)
tmp_buf += res
tmp_buf += buffer.drop(position + 1)
}
"^" -> {
tmp_buf = buffer.dropLast(ext.size - position + 2)
val res = Token(
Tokens.Number, (first as Double)
.pow(second as Double)
)
tmp_buf += res
tmp_buf += buffer.drop(position + 1)
}
}
} else { } else {
position++ position++
continue continue
@@ -352,7 +503,7 @@ enum class Tokens {
Quadratic Quadratic
} }
class Token (val type: Tokens, var value: Any) { class Token(val type: Tokens, val value: Any) {
override fun toString(): String { override fun toString(): String {
return "<$type, $value>" return "<$type, $value>"
} }
@@ -364,22 +515,26 @@ open class MathObject(val value: Any) {
} }
} }
class Linear(val name: String, private val add: Double, private val mul: Double) : MathObject("$mul*$name+$add") { class Linear(val name: String, val add: Double, val mul: Double) : MathObject("$mul*$name+$add") {
//TODO: Implement more methods //TODO: Implement more methods
override fun toString(): String { override fun toString(): String {
return "$mul*$name+$add" return "$mul*$name+$add"
} }
operator fun minus(num: Double): Linear { operator fun minus(num: Double): Linear {
return Linear(name, add-num, mul) return Linear(name, add - num, mul)
} }
operator fun minus(lin: Linear): Linear { operator fun minus(lin: Linear): Linear {
// if (name != lin.name) throw IllegalArgumentException // if (name != lin.name) throw IllegalArgumentException
return Linear(name, add-lin.add, mul-lin.mul) return Linear(name, add - lin.add, mul - lin.mul)
} }
fun answer() = -add/mul operator fun times(num: Double): Linear {
return Linear(name, add, mul * num)
}
fun answer() = -add / mul
} }
class Quadratic(name: String, add: Double, mul: Double, pow: Double) { class Quadratic(name: String, add: Double, mul: Double, pow: Double) {
+198 -132
View File
@@ -21,12 +21,21 @@
<TextView <TextView
android:id="@+id/input" android:id="@+id/input"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:textSize="60sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/last_exp_out"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@+id/input" />
<TextView <TextView
android:id="@+id/RPN_out" android:id="@+id/RPN_out"
@@ -49,27 +58,119 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/left_out" /> app:layout_constraintTop_toBottomOf="@+id/left_out" />
<TextView <Space
android:id="@+id/last_exp_out" android:id="@+id/space"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/input" /> app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.55" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/imageView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/space">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:backgroundTint="#4D333333"
android:orientation="vertical">
<Button
android:id="@+id/btn_sbm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#80505050"
android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="Вычислить"
android:textSize="20sp"
app:cornerRadius="0dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/btn_x"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:backgroundTint="#80505050"
android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="X"
android:textSize="24sp"
app:cornerRadius="0dp" />
<Button
android:id="@+id/btn_equ"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:backgroundTint="#80505050"
android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="="
android:textSize="24sp"
app:cornerRadius="0dp" />
<Button
android:id="@+id/btn_pi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:backgroundTint="#80505050"
android:backgroundTintMode="src_in"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="π"
android:textAllCaps="false"
android:textSize="24sp"
app:cornerRadius="0dp" />
<Button
android:id="@+id/btn_dot"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:backgroundTint="#80505050"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="."
android:textSize="24sp"
app:cornerRadius="0dp" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/linearLayout2" android:id="@+id/linearLayout2"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:orientation="horizontal" android:layout_weight="1"
app:layout_constraintBottom_toTopOf="@+id/linearLayout" android:orientation="horizontal">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button <Button
android:id="@+id/button25" android:id="@+id/btn_add"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80323232" android:backgroundTint="#80323232"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -77,11 +178,12 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="+" android:text="+"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button22" android:id="@+id/btn_sub"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80323232" android:backgroundTint="#80323232"
@@ -90,11 +192,12 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="-" android:text="-"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button24" android:id="@+id/btn_mul"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80323232" android:backgroundTint="#80323232"
@@ -103,11 +206,12 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="*" android:text="*"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button23" android:id="@+id/btn_div"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80323232" android:backgroundTint="#80323232"
@@ -116,32 +220,32 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="/" android:text="/"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/linearLayout" android:id="@+id/linearLayout"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:orientation="horizontal" android:layout_weight="4"
app:layout_constraintBottom_toBottomOf="@+id/imageView2" android:orientation="horizontal">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TableLayout <TableLayout
android:id="@+id/tableLayout2" android:id="@+id/tableLayout2"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="3"> android:layout_weight="3">
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="0dp"
android:layout_weight="1">
<Button <Button
android:id="@+id/button13" android:id="@+id/btn_1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -149,12 +253,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="1" android:text="1"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button12" android:id="@+id/btn_2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -162,12 +267,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="2" android:text="2"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button" android:id="@+id/btn_3"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -175,18 +281,20 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="3" android:text="3"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
</TableRow> </TableRow>
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="0dp"
android:layout_weight="1">
<Button <Button
android:id="@+id/button5" android:id="@+id/btn_4"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -194,12 +302,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="4" android:text="4"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button15" android:id="@+id/btn_5"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -207,12 +316,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="5" android:text="5"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button14" android:id="@+id/btn_6"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -220,18 +330,20 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="6" android:text="6"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
</TableRow> </TableRow>
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="0dp"
android:layout_weight="1">
<Button <Button
android:id="@+id/button6" android:id="@+id/btn_7"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -239,12 +351,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="7" android:text="7"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button16" android:id="@+id/btn_8"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -252,12 +365,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="8" android:text="8"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button10" android:id="@+id/btn_9"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -265,17 +379,19 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="9" android:text="9"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
</TableRow> </TableRow>
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="0dp"
android:layout_weight="1">
<Button <Button
android:id="@+id/button17" android:id="@+id/btn_0"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -283,12 +399,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="0" android:text="0"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button11" android:id="@+id/btn_bro"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -296,12 +413,13 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="(" android:text="("
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button7" android:id="@+id/btn_brc"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="#80141414" android:backgroundTint="#80141414"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -309,44 +427,49 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text=")" android:text=")"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
</TableRow> </TableRow>
</TableLayout> </TableLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
<Button <Button
android:id="@+id/button21" android:id="@+id/btn_pow"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1"
android:backgroundTint="#80323232" android:backgroundTint="#80323232"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false" android:hapticFeedbackEnabled="false"
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="^" android:text="^"
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button19" android:id="@+id/btn_sqrt"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1"
android:backgroundTint="#80323232" android:backgroundTint="#80323232"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false" android:hapticFeedbackEnabled="false"
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:text="sqrt" android:text=""
android:textSize="24sp"
app:cornerRadius="0dp" /> app:cornerRadius="0dp" />
<Button <Button
android:id="@+id/button20" android:id="@+id/btn_del"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="2" android:layout_weight="2"
android:backgroundTint="#803A2121" android:backgroundTint="#803A2121"
android:backgroundTintMode="src_in" android:backgroundTintMode="src_in"
@@ -360,75 +483,18 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/button26"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#80505050"
android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="X"
app:cornerRadius="0dp" />
<Button
android:id="@+id/button27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#80505050"
android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="="
app:cornerRadius="0dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:backgroundTint="#4D333333"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/button28"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#80505050"
android:backgroundTintMode="src_in"
android:hapticFeedbackEnabled="false"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="Вычеслить"
app:cornerRadius="0dp" />
</LinearLayout> </LinearLayout>
<!-- <EditText--> <!-- <EditText-->
<!-- android:id="@+id/function_in"--> <!-- android:id="@+id/function_in"-->
<!-- android:layout_width="0dp"--> <!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"--> <!-- android:layout_height="wrap_content"-->
<!-- android:ems="10"--> <!-- android:ems="10"-->
<!-- android:hint="Введите уравнение:"--> <!-- android:hint="Введите уравнение:"-->
<!-- android:inputType="textPersonName"--> <!-- android:inputType="textPersonName"-->
<!-- android:text="y = "--> <!-- android:text="y = "-->
<!-- app:layout_constraintEnd_toEndOf="parent"--> <!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"--> <!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@+id/graph" />--> <!-- app:layout_constraintTop_toBottomOf="@+id/graph" />-->
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
+2 -2
View File
@@ -4,11 +4,11 @@
<!-- Primary brand color. --> <!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item> <item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item> <item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item> <item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. --> <!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item> <item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item> <item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item> <item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
+2 -2
View File
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
id 'com.android.application' version '7.3.1' apply false id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.3.1' apply false id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
} }
+1 -1
View File
@@ -1,6 +1,6 @@
#Wed Nov 16 21:17:09 MSK 2022 #Wed Nov 16 21:17:09 MSK 2022
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME