diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.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 diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..5962c17 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Empty Minds App \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ac6b0ae --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.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/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..61d300e --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + + defaultConfig { + applicationId "com.emptyminds.emptymindsapp" + minSdkVersion 23 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/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/app/src/androidTest/java/com/emptyminds/emptymindsapp/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/emptyminds/emptymindsapp/ExampleInstrumentedTest.java new file mode 100644 index 0000000..d7bc165 --- /dev/null +++ b/app/src/androidTest/java/com/emptyminds/emptymindsapp/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.emptyminds.emptymindsapp; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.emptyminds.emptymindsapp", appContext.getPackageName()); + } +} \ 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..b80e8ad --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/emptyminds/emptymindsapp/CalculatorActivity.java b/app/src/main/java/com/emptyminds/emptymindsapp/CalculatorActivity.java new file mode 100644 index 0000000..9871eae --- /dev/null +++ b/app/src/main/java/com/emptyminds/emptymindsapp/CalculatorActivity.java @@ -0,0 +1,156 @@ +package com.emptyminds.emptymindsapp; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +public class CalculatorActivity extends AppCompatActivity implements View.OnClickListener { + + private Button btnAnswer; + private EditText txtQuery; + private TextView txtAnswer; + private Button btn0; + private Button btn1; + private Button btn2; + private Button btn3; + private Button btn4; + private Button btn5; + private Button btn6; + private Button btn7; + private Button btn8; + private Button btn9; + private Double answer = 0.0; + private Boolean isDirty = false; + private String operator; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_calculator); + + btnAnswer = findViewById(R.id.btnEquals); + btnAnswer.setOnClickListener(this); + btn0 = findViewById(R.id.btn0); + btn0.setOnClickListener(this); + btn1 = findViewById(R.id.btn1); + btn1.setOnClickListener(this); + btn2 = findViewById(R.id.btn2); + btn2.setOnClickListener(this); + btn3 = findViewById(R.id.btn3); + btn3.setOnClickListener(this); + btn4 = findViewById(R.id.btn4); + btn4.setOnClickListener(this); + btn5 = findViewById(R.id.btn5); + btn5.setOnClickListener(this); + btn6 = findViewById(R.id.btn6); + btn6.setOnClickListener(this); + btn7 = findViewById(R.id.btn7); + btn7.setOnClickListener(this); + btn8 = findViewById(R.id.btn8); + btn8.setOnClickListener(this); + btn9 = findViewById(R.id.btn9); + btn9.setOnClickListener(this); + + findViewById(R.id.btnClearAll).setOnClickListener(this); + findViewById(R.id.btnDecimal).setOnClickListener(this); + findViewById(R.id.btnDivision).setOnClickListener(this); + findViewById(R.id.btnMultiply).setOnClickListener(this); + findViewById(R.id.btnAddition).setOnClickListener(this); + findViewById(R.id.btnSubtraction).setOnClickListener(this); + } + + + @Override + public void onClick(View v) { + if (!isDirty && v.getId() == R.id.btn0) { + return; + } + + txtQuery = findViewById(R.id.txtQuery); + txtAnswer = findViewById(R.id.txtAnswer); + Button btnTemp; + btnTemp = findViewById(v.getId()); + + switch (v.getId()) { + case R.id.btn0: + case R.id.btn1: + case R.id.btn2: + case R.id.btn3: + case R.id.btn4: + case R.id.btn5: + case R.id.btn6: + case R.id.btn7: + case R.id.btn8: + case R.id.btn9: + case R.id.btnDecimal: + if (isDirty) { + txtQuery.append(btnTemp.getText().toString()); + } else { + txtQuery.setText(btnTemp.getText().toString()); + isDirty = true; + } + break; + case R.id.btnDivision: + case R.id.btnMultiply: + case R.id.btnAddition: + case R.id.btnSubtraction: + case R.id.btnEquals: + calculate(btnTemp.getText().toString()); + break; + case R.id.btnClearAll: + isDirty = false; + answer = 0.0; + operator = null; + txtQuery.setText(""); + txtAnswer.setText(""); + break; + } + } + + private void calculate(String operator) { + if (isDirty) { + Double temp = Double.parseDouble(txtQuery.getText().toString()); + + if (this.operator != null) { + switch (this.operator) { + case "÷": + answer /= temp; + break; + case "×": + answer *= temp; + break; + case "+": + answer += temp; + break; + case "-": + answer -= temp; + break; + } + } else { + answer = Double.parseDouble(txtQuery.getText().toString()); + } + this.operator = operator; + temp = answer; + + StringBuilder txtViewString = new StringBuilder(txtAnswer.getText().toString()); + txtViewString.append(txtQuery.getText().toString()).append(" ").append(operator).append(" "); + if (operator.equals("=")) { + txtViewString.append(answer + "\n"); + answer = 0.0; + this.operator = null; + } + + txtAnswer.setText(txtViewString); + txtQuery.setText(temp.toString()); + isDirty = false; + } else if (this.operator != null && !this.operator.equals("=")) { + this.operator = operator; + String strReplace = txtAnswer.getText().toString(); + txtAnswer.setText(strReplace.substring(0, strReplace.length() - 2).concat(operator + " ")); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/emptyminds/emptymindsapp/MainActivity.java b/app/src/main/java/com/emptyminds/emptymindsapp/MainActivity.java new file mode 100644 index 0000000..4f6516d --- /dev/null +++ b/app/src/main/java/com/emptyminds/emptymindsapp/MainActivity.java @@ -0,0 +1,73 @@ +package com.emptyminds.emptymindsapp; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + + private EditText txtEmail, txtPassword; + private Button btnLogin; + private long backPressedTime; + private Toast toast; + + @Override + public void onBackPressed() { + try { + toast.cancel(); + } catch (NullPointerException e) { + } + if (backPressedTime + 2000 > System.currentTimeMillis()) { + toast.cancel(); + super.onBackPressed(); + return; + } else { + toast = Toast.makeText(this, "Press back again to exit", Toast.LENGTH_SHORT); + toast.show(); + } + backPressedTime = System.currentTimeMillis(); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + txtEmail = findViewById(R.id.email); + txtPassword = findViewById(R.id.password); + btnLogin = findViewById(R.id.btnLogin); + + btnLogin.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + try { + toast.cancel(); + } catch (NullPointerException e) { + } + + switch (v.getId()) { + case R.id.btnLogin: + String email = txtEmail.getText().toString().trim(); + String password = txtPassword.getText().toString().trim(); + + if (email.equals(getResources().getString(R.string.username)) && password.equals(getResources().getString(R.string.password))) { + Intent calcIntent = new Intent(this, CalculatorActivity.class); + startActivity(calcIntent); +// finish(); + +// toast = Toast.makeText(this, "Login Successful", Toast.LENGTH_SHORT); + } else { + toast = Toast.makeText(this, "Invalid Credentials", Toast.LENGTH_SHORT); + toast.show(); + } + break; + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_calculator.xml b/app/src/main/res/layout/activity_calculator.xml new file mode 100644 index 0000000..0877f99 --- /dev/null +++ b/app/src/main/res/layout/activity_calculator.xml @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..2e487e4 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + +