From 7a9f4f05c718756258a17bd85aea3c0538aea9c2 Mon Sep 17 00:00:00 2001 From: "TAEGANGER\\max" Date: Sat, 8 Apr 2017 19:50:49 -0700 Subject: [PATCH] version1 --- .gitignore | 9 + .idea/compiler.xml | 22 + .idea/copyright/profiles_settings.xml | 3 + .idea/encodings.xml | 6 + .idea/gradle.xml | 18 + .idea/misc.xml | 46 ++ .idea/modules.xml | 9 + .idea/runConfigurations.xml | 12 + .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle | 31 ++ app/proguard-rules.pro | 25 + .../ExampleInstrumentedTest.java | 26 ++ app/src/main/AndroidManifest.xml | 23 + .../scientificcalculator/MainActivity.java | 372 +++++++++++++++ app/src/main/res/layout/activity_main.xml | 426 ++++++++++++++++++ app/src/main/res/layout/content_main.xml | 18 + app/src/main/res/menu/menu_main.xml | 10 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/dimens.xml | 3 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/values/styles.xml | 20 + .../scientificcalculator/ExampleUnitTest.java | 17 + build.gradle | 23 + gradle.properties | 17 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++++++ gradlew.bat | 90 ++++ settings.gradle | 1 + 35 files changed, 1410 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/example/max/scientificcalculator/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/example/max/scientificcalculator/MainActivity.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/content_main.xml create mode 100644 app/src/main/res/menu/menu_main.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/example/max/scientificcalculator/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..13c1b11 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..5bdff51 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "25.0.0" + defaultConfig { + applicationId "com.example.max.scientificcalculator" + minSdkVersion 16 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:24.2.1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + compile 'com.android.support:design:24.2.1' + testCompile 'junit:junit:4.12' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..077e3c7 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\max\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# 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 diff --git a/app/src/androidTest/java/com/example/max/scientificcalculator/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/max/scientificcalculator/ExampleInstrumentedTest.java new file mode 100644 index 0000000..4f936ac --- /dev/null +++ b/app/src/androidTest/java/com/example/max/scientificcalculator/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.max.scientificcalculator; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.max.scientificcalculator", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d528498 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/max/scientificcalculator/MainActivity.java b/app/src/main/java/com/example/max/scientificcalculator/MainActivity.java new file mode 100644 index 0000000..6accab9 --- /dev/null +++ b/app/src/main/java/com/example/max/scientificcalculator/MainActivity.java @@ -0,0 +1,372 @@ +package com.example.max.scientificcalculator; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +public class MainActivity extends AppCompatActivity { + private static final String ADDITION = "+"; + private static final String MULTIPLICATION = "*"; + private static final String DIVISION = "/"; + private static final String SUBTRACTION = "-"; + private static final String SINE = "Sin"; + private static final String COSINE = "Cos"; + private static final String TANGENT = "Tan"; + private static final String ASINE = "ASin"; + private static final String ACOSINE = "ACos"; + private static final String ATANGENT = "ATan"; + private static final String EXPONENTIAL = "exp"; + private static final String FACTORIAL = "factorial"; + private static final String NEXTPRIME = "nextPrime"; + private String CURRENT_ACTION; + private Button btnSubtraction, btnMultiplication, btnAddition, btnDivision; + private Button btnOne, btnTwo, btnThree, btnFour, btnFive, btnSix, btnSeven, btnEight, btnNine, btnZero; + private Button btnDelete, btnDot, btnClear, btnNextPrime, btnFactorial, btnExp, btnEqual; + private Button btnSin, btnCos, btnTan, btnASin, btnACos, btnATan, btnPi; + + private TextView result,op1,op2; + private EditText digit; + private double operand1 = Double.NaN; + private double operand2; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + op1 = (TextView) findViewById(R.id.op1); + op2 = (TextView) findViewById(R.id.op2); + btnSubtraction = (Button) findViewById(R.id.btnSubtract); + btnMultiplication = (Button) findViewById(R.id.btnMultiply); + btnAddition = (Button) findViewById(R.id.btnAdd); + btnDivision = (Button) findViewById(R.id.btnDivide); + btnSin = (Button) findViewById(R.id.btnSine); + btnCos = (Button) findViewById(R.id.btnCosine); + btnTan = (Button) findViewById(R.id.btnTangent); + btnACos = (Button) findViewById(R.id.btnArcCosine); + btnASin = (Button) findViewById(R.id.btnArcSine); + btnATan = (Button) findViewById(R.id.btnArcTangent); + btnExp = (Button) findViewById(R.id.btnExponential); + btnNextPrime = (Button) findViewById(R.id.btnNextPrime); + btnFactorial = (Button) findViewById(R.id.btnFactorization); + btnOne = (Button) findViewById(R.id.btnOne); + btnTwo = (Button) findViewById(R.id.btnTwo); + btnThree = (Button) findViewById(R.id.btnThree); + btnFour = (Button) findViewById(R.id.btnFour); + btnFive = (Button) findViewById(R.id.btnFive); + btnSix = (Button) findViewById(R.id.btnSix); + btnSeven = (Button) findViewById(R.id.btnSeven); + btnEight = (Button) findViewById(R.id.btnEight); + btnNine = (Button) findViewById(R.id.btnNine); + btnZero = (Button) findViewById(R.id.btnZero); + btnDelete = (Button) findViewById(R.id.btnDel); + btnClear = (Button) findViewById(R.id.btnClear); + btnEqual = (Button) findViewById(R.id.btnEqual); + btnPi = (Button) findViewById(R.id.btnPi); + digit = (EditText) findViewById(R.id.digit); + result = (TextView) findViewById(R.id.resultText); + btnZero.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"0"); + result.setText(result.getText().toString() + "0"); + } + }); + btnOne.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"1"); + result.setText(result.getText().toString() + "1"); + } + }); + btnTwo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"2"); + result.setText(result.getText().toString() + "2"); + } + }); + btnThree.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"3"); + result.setText(result.getText().toString() + "3"); + } + }); + btnFour.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"4"); + result.setText(result.getText().toString() + "4"); + } + }); + btnFive.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"5"); + result.setText(result.getText().toString() + "5"); + } + }); + btnSix.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + result.setText(result.getText().toString() + "6"); + digit.setText(digit.getText().toString()+"6"); + } + }); + btnSeven.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"7"); + result.setText(result.getText().toString() + "7"); + } + }); + btnEight.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"8"); + result.setText(result.getText().toString() + "8"); + } + }); + btnNine.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"9"); + result.setText(result.getText().toString() + "9"); + + } + }); + btnPi.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + digit.setText(digit.getText().toString()+"3.14159"); + result.setText(result.getText().toString() + "3.14159"); + + } + }); + + btnAddition.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + compute(); + CURRENT_ACTION = ADDITION; + digit.setText(""); + result.setText(operand1 + "+"); + } + }); + + btnDivision.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + compute(); + CURRENT_ACTION = DIVISION; + result.setText(operand1 + "/"); + digit.setText(""); + + } + }); + btnMultiplication.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + compute(); + CURRENT_ACTION = MULTIPLICATION; + result.setText(operand1 + "*"); + digit.setText(""); + + } + }); + btnSubtraction.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + compute(); + CURRENT_ACTION = SUBTRACTION; + result.setText(operand1 + "-"); + digit.setText(""); + + } + }); + btnEqual.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + compute(); + result.setText(operand1+""); + operand1 = Double.NaN; + CURRENT_ACTION = "0"; + } + }); + btnDelete.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(digit.getText().length() > 0) { + CharSequence currentDigitText = digit.getText(); + digit.setText(currentDigitText.subSequence(0, currentDigitText.length() - 1)); + } + if(result.getText().length() > 0) { + CharSequence currentText = result.getText(); + result.setText(currentText.subSequence(0, currentText.length()-1)); + + } else { + operand1 = Double.NaN; + operand2 = Double.NaN; + result.setText(null); + digit.setText(null); + } + } + }); + btnClear.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + operand1 = Double.NaN; + operand2 = Double.NaN; + + + result.setText(null); + digit.setText(null); + + } + }); + btnSin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = SINE; + compute(); + result.setText(operand1+""); + } + }); + btnCos.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = COSINE; + compute(); + result.setText(operand1+""); + } + }); + btnTan.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = TANGENT; + compute(); + result.setText(operand1+""); + } + }); + btnACos.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = ACOSINE; + compute(); + result.setText(operand1+""); + } + }); + btnASin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = ASINE; + compute(); + result.setText(operand1+""); + } + }); + btnATan.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = ATANGENT; + compute(); + result.setText(operand1+""); + } + }); + btnExp.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + compute(); + CURRENT_ACTION = EXPONENTIAL; + + result.setText(operand1+""); + } + }); + btnFactorial.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = FACTORIAL; + compute(); + result.setText(operand1+""); + } + }); + btnNextPrime.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CURRENT_ACTION = NEXTPRIME; + compute(); + result.setText(operand1+""); + } + }); + } + + private void compute() { + if (!Double.isNaN(operand1)) { + operand2 = Double.parseDouble(digit.getText().toString()); + if (CURRENT_ACTION == ADDITION) { + operand1 = this.operand1 + operand2; + } else if (CURRENT_ACTION == SUBTRACTION){ + operand1 = this.operand1 - operand2; + } else if (CURRENT_ACTION == MULTIPLICATION){ + operand1 = this.operand1 * operand2; + } else if(CURRENT_ACTION ==DIVISION) { + operand1 = this.operand1 / operand2; + } else if(CURRENT_ACTION == EXPONENTIAL){ + operand1 = Math.pow(operand1,operand2); + } + } else { + try { + operand1 = Double.parseDouble(result.getText().toString()); + if(CURRENT_ACTION==SINE) { + operand1 = Math.sin(operand1*Math.PI/180); + } else if (CURRENT_ACTION == COSINE){ + operand1 = Math.cos(operand1*Math.PI/180); + } else if (CURRENT_ACTION == TANGENT){ + operand1 = Math.tan(operand1*Math.PI/180); + } else if(CURRENT_ACTION == ACOSINE){ + operand1 = Math.acos(operand1)*180/Math.PI; + } else if(CURRENT_ACTION == ASINE){ + operand1 = Math.asin(operand1)*180/Math.PI; + } else if(CURRENT_ACTION == ATANGENT){ + operand1 = Math.atan(operand1)*180/Math.PI; + } else if(CURRENT_ACTION == FACTORIAL) { + operand1 = factorial(operand1); + } + } catch (Exception e){} + } + } + + private double factorial(double b){ + if(b==0){ + return 1; + } else { + return b*factorial(b-1); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..df2649f --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + +