diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c4de58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..ca34746 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Calculator \ No newline at end of file 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..8f37467 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7158618 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dcdca1a --- /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..6564d52 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Calculator.iml b/Calculator.iml new file mode 100644 index 0000000..6aea003 --- /dev/null +++ b/Calculator.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ 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/app.iml b/app/app.iml new file mode 100644 index 0000000..b35c844 --- /dev/null +++ b/app/app.iml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..a852a88 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "com.example.user.calculator" + minSdkVersion 15 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.1.0' + compile 'com.android.support:design:23.1.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..8010560 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\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 *; +#} diff --git a/app/src/androidTest/java/com/example/user/calculator/ApplicationTest.java b/app/src/androidTest/java/com/example/user/calculator/ApplicationTest.java new file mode 100644 index 0000000..4c6fe95 --- /dev/null +++ b/app/src/androidTest/java/com/example/user/calculator/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.example.user.calculator; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..36f547f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/example/user/calculator/MainActivity.java b/app/src/main/java/com/example/user/calculator/MainActivity.java new file mode 100644 index 0000000..d12b5f9 --- /dev/null +++ b/app/src/main/java/com/example/user/calculator/MainActivity.java @@ -0,0 +1,292 @@ +package com.example.user.calculator; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.TextView; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + + } + + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt("opr", opr); + outState.putFloat("op1", op1); + outState.putFloat("op2", op2); + outState.putString("str", str); + TextView result = (TextView) findViewById(R.id.textView); + outState.putString("str2", (String) result.getText()); + + } + + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + op1 = savedInstanceState.getFloat("op1"); + op2 = savedInstanceState.getFloat("op1"); + opr = savedInstanceState.getInt("opr"); + str = savedInstanceState.getString("str"); + TextView result = (TextView) findViewById(R.id.textView); + result.setText(savedInstanceState.getString("str2")); + + } + + public float op1 = 0; + public float op2 = 0; + public int opr = 0; + + public String str = "0"; + + public void onClickdot(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str.indexOf(".") == -1) + str = str + "."; + result.setText(str); + } + + public void onClick1(View view) { + TextView result = (TextView) findViewById(R.id.textView); + + if (str == "0") str = ""; + str = str + "1"; + result.setText(str); + + + } + + public void onClick2(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "2"; + result.setText(str); + + + } + + public void onClick3(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "3"; + result.setText(str); + + + } + + public void onClick4(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "4"; + result.setText(str); + + + } + + public void onClick5(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "5"; + result.setText(str); + + + } + + public void onClick6(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "6"; + result.setText(str); + + + } + + public void onClick7(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "7"; + result.setText(str); + + + } + + public void onClick8(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "8"; + result.setText(str); + + + } + + public void onClick9(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "9"; + result.setText(str); + + + } + + public void onClick0(View view) { + TextView result = (TextView) findViewById(R.id.textView); + if (str == "0") str = ""; + str = str + "0"; + result.setText(str); + + + } + + public void onClickplus(View view) { + TextView result = (TextView) findViewById(R.id.textView); + CharSequence s = result.getText(); + String s1 = s.toString(); + + + if (opr == 1) { + op2 = Float.parseFloat(s1); + op1 = op1 + op2; + result.setText(Float.toString(op1)); + op2 = 0; + str = "0"; + } else { + opr = 1; + op1 = Float.parseFloat(s1); + str = "0"; + } + } + + public void onClickminus(View view) { + TextView result = (TextView) findViewById(R.id.textView); + CharSequence s = result.getText(); + String s1 = s.toString(); + + if (opr == 3) { + op2 = Float.parseFloat(s1); + op1 = op1 - op2; + result.setText(Float.toString(op1)); + op2 = 0; + str = "0"; + } else { + opr = 3; + op1 = Float.parseFloat(s1); + str = "0"; + } + + } + + public void onClickmul(View view) { + TextView result = (TextView) findViewById(R.id.textView); + CharSequence s = result.getText(); + String s1 = s.toString(); + + if (opr == 2) { + op2 = Float.parseFloat(s1); + op1 = op1 * op2; + result.setText(Float.toString(op1)); + op2 = 0; + str = "0"; + } else { + opr = 2; + op1 = Float.parseFloat(s1); + str = "0"; + } + + } + + public void onClickmod(View view) { + TextView result = (TextView) findViewById(R.id.textView); + CharSequence s = result.getText(); + String s1 = s.toString(); + + if (opr == 4) { + op2 = Float.parseFloat(s1); + if (op2 == 0) + op1 = 0; + else + op1 = op1 / op2; + result.setText(Float.toString(op1)); + op2 = 0; + str = "0"; + } else { + opr = 2; + op1 = Float.parseFloat(s1); + str = "0"; + } + } + + public void onClicc(View view) { + TextView result = (TextView) findViewById(R.id.textView); + op1 = op2 = 0; + opr = 0; + str = "0"; + result.setText("0"); + + + } + + public void onClickrav(View view) { + TextView result = (TextView) findViewById(R.id.textView); + CharSequence s = result.getText(); + String s1 = s.toString(); + op2 = Float.parseFloat(s1); + switch (opr) { + case 0: + break; + case 1: + op1 = op1 + op2; + break; + case 2: + op1 = op1 * op2; + break; + case 3: + op1 = op1 - op2; + break; + case 4: + if (op2 != 0) { + op1 = op1 / op2; + } else { + op1 = 0; + } + break; + } + op2 = 0; + opr = 0; + str = "0"; + + + s = Float.toString(op1); + result.setText(s); + + + } + + + @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..ce4cc46 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 0000000..0dc7cc1 --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,204 @@ + + + + + + + +