Skip to content

Commit 3662f86

Browse files
authored
Add files via upload
1 parent 9b2cc6b commit 3662f86

28 files changed

Lines changed: 840 additions & 0 deletions

app/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'com.example.calc'
7+
compileSdk 33
8+
9+
defaultConfig {
10+
applicationId "com.example.calc"
11+
minSdk 24
12+
targetSdk 33
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'com.google.android.material:material:1.9.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
36+
implementation 'com.faendir.rhino:rhino-android:1.5.2'
37+
testImplementation 'junit:junit:4.13.2'
38+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
39+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
40+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.calc;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.example.calc", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/Theme.Calc"
13+
tools:targetApi="31">
14+
<activity
15+
android:name=".MainActivity"
16+
android:exported="true">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package com.example.calc;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
import com.google.android.material.button.MaterialButton;
9+
10+
import org.mozilla.javascript.Context;
11+
import org.mozilla.javascript.ScriptableObject;
12+
13+
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
14+
15+
TextView resultsTv, solutionTv;
16+
17+
MaterialButton btnAc, btnMult, btnDiv, btnBack, btn7, btn8, btn9, btnPlus, btn4, btn5, btn6, btnSub, btn1, btn2, btn3, btnPer, btnPt, btn0, btn00, btnSol;
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_main);
23+
24+
resultsTv = findViewById(R.id.result_tv);
25+
solutionTv = findViewById(R.id.sol_tv);
26+
27+
assignId(btnAc, R.id.btnAC);
28+
assignId(btnMult, R.id.btnMult);
29+
assignId(btnDiv, R.id.btnDiv);
30+
assignId(btnBack, R.id.btnBack);
31+
assignId(btn7, R.id.btn7);
32+
assignId(btn8, R.id.btn8);
33+
assignId(btn9, R.id.btn9);
34+
assignId(btnPlus, R.id.btnPlus);
35+
assignId(btn4, R.id.btn4);
36+
assignId(btn5, R.id.btn5);
37+
assignId(btn6, R.id.btn6);
38+
assignId(btnSub, R.id.btnSub);
39+
assignId(btn1, R.id.btn1);
40+
assignId(btn2, R.id.btn2);
41+
assignId(btn3, R.id.btn3);
42+
assignId(btnPer, R.id.btnPer);
43+
assignId(btnPt, R.id.btnPt);
44+
assignId(btn0, R.id.btn0);
45+
assignId(btn00, R.id.btn00);
46+
assignId(btnSol, R.id.btnSol);
47+
}
48+
49+
void assignId(MaterialButton btn, int id){
50+
btn = findViewById(id);
51+
btn.setOnClickListener(this);
52+
}
53+
54+
@Override
55+
public void onClick(View view) {
56+
MaterialButton button = (MaterialButton) view;
57+
String buttonText = button.getText().toString();
58+
String datatoCalculate = solutionTv.getText().toString();
59+
60+
if(buttonText.equals("AC")){
61+
solutionTv.setText("");
62+
resultsTv.setText("0");
63+
return;
64+
}
65+
if(buttonText.equals("=")){
66+
solutionTv.setText(resultsTv.getText());
67+
return;
68+
}
69+
if(buttonText.equals("C")){
70+
if(datatoCalculate.length() != 0) {
71+
datatoCalculate = datatoCalculate.substring(0, datatoCalculate.length()-1);
72+
}
73+
}else {
74+
datatoCalculate = datatoCalculate + buttonText;
75+
}
76+
77+
if(datatoCalculate.endsWith("/")) {
78+
datatoCalculate = datatoCalculate.replace("*/", "/");
79+
datatoCalculate = datatoCalculate.replace("+/", "/");
80+
datatoCalculate = datatoCalculate.replace("-/", "/");
81+
datatoCalculate = datatoCalculate.replace("%/", "/");
82+
} else if(datatoCalculate.endsWith("*")) {
83+
datatoCalculate = datatoCalculate.replace("/*", "*");
84+
datatoCalculate = datatoCalculate.replace("+*", "*");
85+
datatoCalculate = datatoCalculate.replace("-*", "*");
86+
datatoCalculate = datatoCalculate.replace("%*", "*");
87+
} else if(datatoCalculate.endsWith("%")) {
88+
datatoCalculate = datatoCalculate.replace("*%", "%");
89+
datatoCalculate = datatoCalculate.replace("+%", "%");
90+
datatoCalculate = datatoCalculate.replace("-%", "%");
91+
datatoCalculate = datatoCalculate.replace("/%", "%");
92+
} else if(datatoCalculate.endsWith("+")) {
93+
datatoCalculate = datatoCalculate.replace("*+", "+");
94+
datatoCalculate = datatoCalculate.replace("/+", "+");
95+
datatoCalculate = datatoCalculate.replace("-+", "+");
96+
datatoCalculate = datatoCalculate.replace("%+", "+");
97+
} else if(datatoCalculate.endsWith("-")) {
98+
datatoCalculate = datatoCalculate.replace("*-", "-");
99+
datatoCalculate = datatoCalculate.replace("+-", "-");
100+
datatoCalculate = datatoCalculate.replace("/-", "-");
101+
datatoCalculate = datatoCalculate.replace("%-", "-");
102+
}
103+
solutionTv.setText(datatoCalculate);
104+
105+
String finalResult = getResult(datatoCalculate);
106+
107+
if(!finalResult.equals("Err")){
108+
resultsTv.setText(finalResult);
109+
}
110+
}
111+
String getResult(String data) {
112+
try{
113+
Context context = Context.enter();
114+
context.setOptimizationLevel(-1);
115+
ScriptableObject scriptable = context.initSafeStandardObjects();
116+
String finalResult = context.evaluateString(scriptable, data, "Javascript", 1, null).toString();
117+
if(finalResult.endsWith(".0")){
118+
finalResult = finalResult.replace(".0", "");
119+
}
120+
return finalResult;
121+
}catch (Exception e){
122+
return "Err";
123+
}
124+
}
125+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
8+
<aapt:attr name="android:fillColor">
9+
<gradient
10+
android:endX="85.84757"
11+
android:endY="92.4963"
12+
android:startX="42.9492"
13+
android:startY="49.59793"
14+
android:type="linear">
15+
<item
16+
android:color="#44000000"
17+
android:offset="0.0" />
18+
<item
19+
android:color="#00000000"
20+
android:offset="1.0" />
21+
</gradient>
22+
</aapt:attr>
23+
</path>
24+
<path
25+
android:fillColor="#FFFFFF"
26+
android:fillType="nonZero"
27+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
28+
android:strokeWidth="1"
29+
android:strokeColor="#00000000" />
30+
</vector>

0 commit comments

Comments
 (0)