diff --git a/calculator/.gitignore b/calculator/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/calculator/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/calculator/.idea/.gitignore b/calculator/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/calculator/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/calculator/.idea/compiler.xml b/calculator/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/calculator/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/calculator/.idea/discord.xml b/calculator/.idea/discord.xml new file mode 100644 index 0000000..30bab2a --- /dev/null +++ b/calculator/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/calculator/.idea/gradle.xml b/calculator/.idea/gradle.xml new file mode 100644 index 0000000..a2d7c21 --- /dev/null +++ b/calculator/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/calculator/.idea/misc.xml b/calculator/.idea/misc.xml new file mode 100644 index 0000000..7455e26 --- /dev/null +++ b/calculator/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/.idea/vcs.xml b/calculator/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/calculator/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/calculator/app/.gitignore b/calculator/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/calculator/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/calculator/app/build.gradle b/calculator/app/build.gradle new file mode 100644 index 0000000..a88ef02 --- /dev/null +++ b/calculator/app/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' + id 'kotlin-android-extensions' +} + +android { + compileSdk 32 + + defaultConfig { + applicationId "com.yash.calculator" + minSdk 21 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.7.0' + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'org.mariuszgromada.math:MathParser.org-mXparser:4.4.2' + testImplementation 'junit:junit:4.13.2' + implementation 'com.intuit.ssp:ssp-android:1.0.5' + implementation 'com.intuit.sdp:sdp-android:1.0.5' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/calculator/app/proguard-rules.pro b/calculator/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/calculator/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/calculator/app/src/androidTest/java/com/yash/calculator/ExampleInstrumentedTest.kt b/calculator/app/src/androidTest/java/com/yash/calculator/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..f8cc772 --- /dev/null +++ b/calculator/app/src/androidTest/java/com/yash/calculator/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.yash.calculator + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.yash.calculator", appContext.packageName) + } +} \ No newline at end of file diff --git a/calculator/app/src/main/AndroidManifest.xml b/calculator/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d675c62 --- /dev/null +++ b/calculator/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/java/com/yash/calculator/MainActivity.kt b/calculator/app/src/main/java/com/yash/calculator/MainActivity.kt new file mode 100644 index 0000000..8e7d553 --- /dev/null +++ b/calculator/app/src/main/java/com/yash/calculator/MainActivity.kt @@ -0,0 +1,168 @@ +package com.yash.calculator + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.view.View +import android.widget.Button +import androidx.core.content.ContextCompat +import kotlinx.android.synthetic.main.activity_main.* +import org.mariuszgromada.math.mxparser.Expression +import java.text.DecimalFormat + +class MainActivity : AppCompatActivity() { + + private lateinit var clear : Button + private lateinit var button01 : Button + private lateinit var button02 : Button + private lateinit var button03 : Button + private lateinit var button04 : Button + private lateinit var button05 : Button + private lateinit var button06 : Button + private lateinit var button07 : Button + private lateinit var button08 : Button + private lateinit var button09 : Button + private lateinit var button00 : Button + private lateinit var add : Button + private lateinit var backspace : Button + private lateinit var substract : Button + private lateinit var expo : Button + private lateinit var multi : Button + private lateinit var divide : Button + private lateinit var dot : Button + private lateinit var modeswitch : Button + + private lateinit var btnEqual : Button + + + + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + clear = findViewById(R.id.Clear) + button00 = findViewById(R.id.button18) + button01 = findViewById(R.id.button13) + button02 = findViewById(R.id.button14) + button03 = findViewById(R.id.button15) + button04 = findViewById(R.id.button4) + button05 = findViewById(R.id.button10) + button06 = findViewById(R.id.button11) + button07 = findViewById(R.id.button5) + button08 = findViewById(R.id.button6) + button09 = findViewById(R.id.button7) + modeswitch = findViewById(R.id.button16) + add = findViewById(R.id.BtnAdd) + substract = findViewById(R.id.BtnMinus) + multi = findViewById(R.id.BtnMul) + expo = findViewById(R.id.BtnExpo) + backspace = findViewById(R.id.BtnBackspace) + divide = findViewById(R.id.button4) + btnEqual = findViewById(R.id.BtnEquals) + dot = findViewById(R.id.button19) + + + clear.setOnClickListener{ + input.text = "" + output.text = "" + + } + modeswitch.setOnClickListener{ + val intent =Intent(this@MainActivity, lightmode::class.java) + startActivity(intent) + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out ) + } + button00.setOnClickListener { + input.text = addToInputText(0) + } + button01.setOnClickListener { + input.text = addToInputText(1) + } + button02.setOnClickListener { + input.text = addToInputText(2) + } + button03.setOnClickListener { + input.text = addToInputText(3) + } + button04.setOnClickListener { + input.text = addToInputText(4) + } + button05.setOnClickListener { + input.text = addToInputText(5) + } + button06.setOnClickListener { + input.text = addToInputText(6) + } + button07.setOnClickListener { + input.text = addToInputText(7) + } + button08.setOnClickListener { + input.text = addToInputText(8) + } + button09.setOnClickListener { + input.text = addToInputText(9) + } + add.setOnClickListener { + input.text = addToInputText('+') + } + substract.setOnClickListener { + input.text = addToInputText('-') + } + dot.setOnClickListener { + input.text = addToInputText('.') + } + expo.setOnClickListener { + input.text = addToInputText('^') + } + multi.setOnClickListener { + input.text = addToInputText('×') + } + divide.setOnClickListener { + input.text = addToInputText('÷') + } + backspace.setOnClickListener { + val text = input.text.toString() + if(text.isNotEmpty()) { + input.text = text.drop(1) + } + + output.text = "" + } + btnEqual.setOnClickListener { + showResult() + } + } + + private fun showResult() { + try { + val expression = getInputExpression() + val result = Expression(expression).calculate() + if (result.isNaN()) { + // Show Error Message + output.text = "Error" + output.setTextColor(ContextCompat.getColor(this, R.color.red)) + } else { + // Show Result + output.text = DecimalFormat("0.##########").format(result).toString() + output.setTextColor(ContextCompat.getColor(this, R.color.black)) + } + } catch (e: Exception) { + // Show Error Message + output.text = "Error" + output.setTextColor(ContextCompat.getColor(this, R.color.red)) + + + } + } + + private fun addToInputText(buttonValue: Any): String{ + return "${input.text}$buttonValue" + } + private fun getInputExpression(): String { + var expression = input.text.replace(Regex("÷"),"/") + expression = expression.replace(Regex("×"),"*") + return expression + } + +} \ No newline at end of file diff --git a/calculator/app/src/main/java/com/yash/calculator/lightmode.kt b/calculator/app/src/main/java/com/yash/calculator/lightmode.kt new file mode 100644 index 0000000..e5ecbb9 --- /dev/null +++ b/calculator/app/src/main/java/com/yash/calculator/lightmode.kt @@ -0,0 +1,162 @@ +package com.yash.calculator + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Button +import androidx.core.content.ContextCompat +import kotlinx.android.synthetic.main.activity_main.* +import org.mariuszgromada.math.mxparser.Expression +import java.text.DecimalFormat + +class lightmode : AppCompatActivity() { + private lateinit var clear : Button + private lateinit var button01 : Button + private lateinit var button02 : Button + private lateinit var button03 : Button + private lateinit var button04 : Button + private lateinit var button05 : Button + private lateinit var button06 : Button + private lateinit var button07 : Button + private lateinit var button08 : Button + private lateinit var button09 : Button + private lateinit var button00 : Button + private lateinit var add : Button + private lateinit var backspace : Button + private lateinit var substract : Button + private lateinit var expo : Button + private lateinit var multi : Button + private lateinit var divide : Button + private lateinit var modeswitch : Button + private lateinit var dot : Button + + private lateinit var btnEqual : Button + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_lightmode) + clear = findViewById(R.id.Clear) + button00 = findViewById(R.id.button18) + button01 = findViewById(R.id.button13) + button02 = findViewById(R.id.button14) + button03 = findViewById(R.id.button15) + button04 = findViewById(R.id.button4) + button05 = findViewById(R.id.button10) + button06 = findViewById(R.id.button11) + modeswitch = findViewById(R.id.button16) + button07 = findViewById(R.id.button5) + button08 = findViewById(R.id.button6) + button09 = findViewById(R.id.button7) + add = findViewById(R.id.BtnAdd) + substract = findViewById(R.id.BtnMinus) + multi = findViewById(R.id.BtnMul) + expo = findViewById(R.id.BtnExpo) + backspace = findViewById(R.id.BtnBackspace) + divide = findViewById(R.id.button4) + btnEqual = findViewById(R.id.BtnEquals) + dot = findViewById(R.id.button19) + + + clear.setOnClickListener{ + input.text = "" + output.text = "" + + } + modeswitch.setOnClickListener{ + val intent = Intent(this@lightmode, MainActivity::class.java) + startActivity(intent) + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out ) + } + button00.setOnClickListener { + input.text = addToInputText(0) + } + button01.setOnClickListener { + input.text = addToInputText(1) + } + button02.setOnClickListener { + input.text = addToInputText(2) + } + button03.setOnClickListener { + input.text = addToInputText(3) + } + button04.setOnClickListener { + input.text = addToInputText(4) + } + button05.setOnClickListener { + input.text = addToInputText(5) + } + button06.setOnClickListener { + input.text = addToInputText(6) + } + button07.setOnClickListener { + input.text = addToInputText(7) + } + button08.setOnClickListener { + input.text = addToInputText(8) + } + button09.setOnClickListener { + input.text = addToInputText(9) + } + add.setOnClickListener { + input.text = addToInputText('+') + } + substract.setOnClickListener { + input.text = addToInputText('-') + } + dot.setOnClickListener { + input.text = addToInputText('.') + } + expo.setOnClickListener { + input.text = addToInputText('^') + } + multi.setOnClickListener { + input.text = addToInputText('×') + } + divide.setOnClickListener { + input.text = addToInputText('÷') + } + backspace.setOnClickListener { + val text = input.text.toString() + if(text.isNotEmpty()) { + input.text = text.drop(1) + } + + output.text = "" + } + btnEqual.setOnClickListener { + showResult() + } + } + + private fun showResult() { + try { + val expression = getInputExpression() + val result = Expression(expression).calculate() + if (result.isNaN()) { + // Show Error Message + output.text = "Error" + output.setTextColor(ContextCompat.getColor(this, R.color.red)) + } else { + // Show Result + output.text = DecimalFormat("0.##########").format(result).toString() + output.setTextColor(ContextCompat.getColor(this, R.color.black)) + } + } catch (e: Exception) { + // Show Error Message + output.text = "Error" + output.setTextColor(ContextCompat.getColor(this, R.color.red)) + + + } + } + + private fun addToInputText(buttonValue: Any): String{ + return "${input.text}$buttonValue" + } + private fun getInputExpression(): String { + var expression = input.text.replace(Regex("÷"),"/") + expression = expression.replace(Regex("×"),"*") + return expression + } + + +} diff --git a/calculator/app/src/main/res/drawable-v24/background_btn2.xml b/calculator/app/src/main/res/drawable-v24/background_btn2.xml new file mode 100644 index 0000000..7f893a6 --- /dev/null +++ b/calculator/app/src/main/res/drawable-v24/background_btn2.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/res/drawable-v24/background_btn3.xml b/calculator/app/src/main/res/drawable-v24/background_btn3.xml new file mode 100644 index 0000000..7e1b5d6 --- /dev/null +++ b/calculator/app/src/main/res/drawable-v24/background_btn3.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/res/drawable-v24/background_picture_darkmode.jpg b/calculator/app/src/main/res/drawable-v24/background_picture_darkmode.jpg new file mode 100644 index 0000000..0d695e6 Binary files /dev/null and b/calculator/app/src/main/res/drawable-v24/background_picture_darkmode.jpg differ diff --git a/calculator/app/src/main/res/drawable-v24/background_picture_light.jpg b/calculator/app/src/main/res/drawable-v24/background_picture_light.jpg new file mode 100644 index 0000000..aff172c Binary files /dev/null and b/calculator/app/src/main/res/drawable-v24/background_picture_light.jpg differ diff --git a/calculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/calculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/calculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/res/drawable/background_btn0.xml b/calculator/app/src/main/res/drawable/background_btn0.xml new file mode 100644 index 0000000..d8bd7ea --- /dev/null +++ b/calculator/app/src/main/res/drawable/background_btn0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/res/drawable/background_btn1.xml b/calculator/app/src/main/res/drawable/background_btn1.xml new file mode 100644 index 0000000..7a8e640 --- /dev/null +++ b/calculator/app/src/main/res/drawable/background_btn1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/res/drawable/background_btn4.xml b/calculator/app/src/main/res/drawable/background_btn4.xml new file mode 100644 index 0000000..c10f3a9 --- /dev/null +++ b/calculator/app/src/main/res/drawable/background_btn4.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/res/drawable/background_btn5.xml b/calculator/app/src/main/res/drawable/background_btn5.xml new file mode 100644 index 0000000..0bc78f4 --- /dev/null +++ b/calculator/app/src/main/res/drawable/background_btn5.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/calculator/app/src/main/res/drawable/ic_launcher_background.xml b/calculator/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/calculator/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/calculator/app/src/main/res/layout/activity_lightmode.xml b/calculator/app/src/main/res/layout/activity_lightmode.xml new file mode 100644 index 0000000..c1a39fd --- /dev/null +++ b/calculator/app/src/main/res/layout/activity_lightmode.xml @@ -0,0 +1,389 @@ + + + + + + + + + + + + + + + + +