From d939f30223229c7419ca750327810ad146987505 Mon Sep 17 00:00:00 2001 From: Areeshka Date: Sat, 26 Dec 2015 19:20:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Александрова Арина M3239 --- .gitignore | 7 + .idea/.name | 1 + .idea/compiler.xml | 22 +++ .idea/copyright/profiles_settings.xml | 3 + .idea/gradle.xml | 19 ++ .idea/misc.xml | 46 +++++ .idea/modules.xml | 9 + .idea/runConfigurations.xml | 12 ++ .idea/vcs.xml | 6 + Calculator.iml | 19 ++ app/.gitignore | 1 + app/app.iml | 97 ++++++++++ app/build.gradle | 26 +++ app/proguard-rules.pro | 17 ++ .../lalala/calculator/ApplicationTest.java | 13 ++ app/src/main/AndroidManifest.xml | 20 ++ .../lalala/calculator/MainActivity.java | 143 ++++++++++++++ app/src/main/res/layout/activity_main.xml | 178 ++++++++++++++++++ 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-w820dp/dimens.xml | 6 + app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/dimens.xml | 5 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 ++ .../lalala/calculator/ExampleUnitTest.java | 15 ++ build.gradle | 23 +++ gradle.properties | 18 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 49896 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 ++++++++++++++++ gradlew.bat | 90 +++++++++ settings.gradle | 1 + 36 files changed, 987 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.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 Calculator.iml create mode 100644 app/.gitignore create mode 100644 app/app.iml create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/example/lalala/calculator/ApplicationTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/example/lalala/calculator/MainActivity.java create mode 100644 app/src/main/res/layout/activity_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-w820dp/dimens.xml 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/lalala/calculator/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 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle 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/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..bd4202c --- /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..fbb6828 --- /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..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..e603305 --- /dev/null +++ b/app/app.iml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..2e9d119 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "com.example.lalala.calculator" + minSdkVersion 21 + 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' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f33d066 --- /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 /Users/lalala/Library/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 *; +#} diff --git a/app/src/androidTest/java/com/example/lalala/calculator/ApplicationTest.java b/app/src/androidTest/java/com/example/lalala/calculator/ApplicationTest.java new file mode 100644 index 0000000..34de24d --- /dev/null +++ b/app/src/androidTest/java/com/example/lalala/calculator/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.example.lalala.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..590f1c0 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/example/lalala/calculator/MainActivity.java b/app/src/main/java/com/example/lalala/calculator/MainActivity.java new file mode 100644 index 0000000..1a045c3 --- /dev/null +++ b/app/src/main/java/com/example/lalala/calculator/MainActivity.java @@ -0,0 +1,143 @@ +package com.example.lalala.calculator; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import java.util.Arrays; + +public class MainActivity extends AppCompatActivity { + + Button digits[], operations[], lastButton; + String token = "", operation = "calc"; + Double res = null; + TextView textView; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + textView = (TextView)findViewById(R.id.textView); + + digits = new Button[] { + (Button)findViewById(R.id.zero), (Button)findViewById(R.id.one), + (Button)findViewById(R.id.two), (Button)findViewById(R.id.three), + (Button)findViewById(R.id.four), (Button)findViewById(R.id.five), + (Button)findViewById(R.id.six), (Button)findViewById(R.id.seven), + (Button)findViewById(R.id.eight), (Button)findViewById(R.id.nine), + (Button)findViewById(R.id.point) + }; + operations = new Button[] { + (Button)findViewById(R.id.add), (Button)findViewById(R.id.subtract), + (Button)findViewById(R.id.multiply), (Button)findViewById(R.id.divide), + (Button)findViewById(R.id.calc) + }; + + for (final Button button : digits) { + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!Arrays.asList(digits).contains(lastButton)) { + if (!token.equals("")) { + res = Double.valueOf(token); + } + token = ""; + } + token = token + button.getText(); + textView.setText(token); + lastButton = button; + } + }); + } + + for (final Button button : operations) { + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (Arrays.asList(digits).contains(lastButton) && !token.equals("")) { + Double result = null; + switch (operation) { + case "add": + result = res + Double.valueOf(token); + break; + case "subtract": + result = res - Double.valueOf(token); + break; + case "multiply": + result = res * Double.valueOf(token); + break; + case "divide": + result = res / Double.valueOf(token); + break; + } + if (result != null) { + if (result.longValue() == result) { + token = Long.toString(result.longValue()); + } else { + token = Double.toString(result); + } + textView.setText(token); + } + operation = getResources().getResourceEntryName(button.getId()); + lastButton = button; + } + } + }); + } + + ((Button)findViewById(R.id.clear)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (token.length() > 0) { + token = token.substring(0, token.length() - 1); + textView.setText(token); + } + } + }); + + final Button button = (Button)findViewById(R.id.point); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!Arrays.asList(digits).contains(lastButton)) { + if (!token.equals("")) { + res = Double.valueOf(token); + } + token = ""; + } + if (token.contains(button.getText())) return; + if (token.equals("")) token = "0"; + token = token + button.getText(); + textView.setText(token); + lastButton = button; + } + }); + + if (savedInstanceState != null) { + token = savedInstanceState.getString("token"); + operation = savedInstanceState.getString("operation"); + if (savedInstanceState.getInt("lastButton") != 0) { + lastButton = (Button)findViewById(savedInstanceState.getInt("lastButton")); + } + res = savedInstanceState.getDouble("res"); + textView.setText(token); + } + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putString("token", token); + outState.putString("operation", operation); + if (lastButton != null) { + outState.putInt("lastButton", lastButton.getId()); + } + if (res != null) { + outState.putDouble("res", res); + } + } +} 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..fbb0e4e --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,178 @@ + + + + + + + +