diff --git a/.gitignore b/.gitignore index 39fb081..01f2214 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /build /captures .externalNativeBuild +*.log diff --git a/app/build.gradle b/app/build.gradle index 6543b2f..1458e1d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,47 +1,59 @@ -apply plugin: 'com.android.application' -apply plugin: 'jacoco' -jacoco { - toolVersion='0.7.5.201505241946' -} -buildscript { - repositories { - mavenCentral() - } +plugins { + alias(libs.plugins.android.application) + id 'com.browserstack.gradle-tool' } android { - compileSdkVersion 30 - dataBinding.enabled = true + namespace 'com.sample.browserstack.samplecalculator' + compileSdk 34 defaultConfig { applicationId "com.sample.browserstack.samplecalculator" - minSdkVersion 15 - targetSdkVersion 30 + minSdk 26 + targetSdk 34 versionCode 1 versionName "1.0" - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debug { - testCoverageEnabled true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + + dataBinding { + enabled = true + } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' - androidTestImplementation 'androidx.test:rules:1.1.1' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - testImplementation 'junit:junit:4.12' -} \ No newline at end of file + implementation libs.appcompat + implementation libs.material + implementation libs.activity + implementation libs.constraintlayout + testImplementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core + + androidTestImplementation(group: 'com.browserstack', name: 'browserstack-java-sdk', version: '1.32.12') { + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + + configurations.all { + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } +} + +task printSdkVersion { + doLast { + println android.compileSdkVersion + } +} diff --git a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureInputTests.java b/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureInputTests.java deleted file mode 100644 index a765e24..0000000 --- a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureInputTests.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.sample.browserstack.samplecalculator; - -import androidx.test.filters.SmallTest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -/** - * Espresso tests to ensure that editText box is updated appropriately - * whenever buttons are clicked - */ - -@SmallTest -@RunWith(AndroidJUnit4.class) -public class EnsureInputTests { - - @Rule - public ActivityTestRule activityRule = - new ActivityTestRule(MainActivity.class); - - private MainActivity mainActivity; - - @Before - public void setUp() { - mainActivity = activityRule.getActivity(); - } - - @Test - public void ensureSingleInputIsHandled() { - NativeScreenshot.capture("initial_state"); - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("1"))); - NativeScreenshot.capture("post_single_btn_click"); - } - - @Test - public void ensureMultipleInputIsHandled() { - NativeScreenshot.capture("initial_state"); - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("12"))); - NativeScreenshot.capture("post_multiple_btn_click"); - } -} diff --git a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureOperationTests.java b/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureOperationTests.java deleted file mode 100644 index 48e1411..0000000 --- a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureOperationTests.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.sample.browserstack.samplecalculator; - -import androidx.test.filters.MediumTest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -/** - * Espresso tests to ensure that simple operations result in - * correct output when the number & operations buttons are clicked - */ - -@MediumTest -@RunWith(AndroidJUnit4.class) -public class EnsureOperationTests { - - @Rule - public ActivityTestRule activityRule = - new ActivityTestRule(MainActivity.class); - - private MainActivity mainActivity; - - @Before - public void setUp() { - mainActivity = activityRule.getActivity(); - } - - @Test - public void ensureAdditionWorks() { - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonAdd)).perform(click()); - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.buttonEqual)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("33"))); - NativeScreenshot.capture("post_addition"); - } - - @Test - public void ensureSubtractionWorks() { - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonSubtract)).perform(click()); - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.buttonEqual)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("11"))); - NativeScreenshot.capture("post_subtraction"); - } - - @Test - public void ensureMultiplicationWorks() { - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonMultiply)).perform(click()); - onView(withId(R.id.buttonFive)).perform(click()); - onView(withId(R.id.buttonEqual)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("60"))); - - NativeScreenshot.capture("post_multiplication"); - } - - @Test - public void ensureDivisionWorks() { - onView(withId(R.id.buttonOne)).perform(click()); - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonDivide)).perform(click()); - onView(withId(R.id.buttonThree)).perform(click()); - onView(withId(R.id.buttonEqual)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("4"))); - - NativeScreenshot.capture("post_division"); - } -} diff --git a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureRandomTests.java b/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureRandomTests.java deleted file mode 100644 index 9524c6c..0000000 --- a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureRandomTests.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.sample.browserstack.samplecalculator; - -import androidx.test.filters.MediumTest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -/** - * Espresso tests to ensure that random operation result are - * handled correctly and correct output is generated and the - * editText box is updated correctly - */ - - -@MediumTest -@RunWith(AndroidJUnit4.class) -public class EnsureRandomTests { - - @Rule - public ActivityTestRule activityRule = - new ActivityTestRule(MainActivity.class); - - @Test - public void testZeroMultiplication() { - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonMultiply)).perform(click()); - onView(withId(R.id.buttonZero)).perform(click()); - onView(withId(R.id.buttonEqual)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("0"))); - } - - @Test - public void testZeroDivision() { - onView(withId(R.id.buttonTwo)).perform(click()); - onView(withId(R.id.buttonDivide)).perform(click()); - onView(withId(R.id.buttonZero)).perform(click()); - onView(withId(R.id.buttonEqual)).perform(click()); - onView(withId(R.id.editText)).check(matches(withText("∞"))); - } - -} diff --git a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/sample/browserstack/samplecalculator/ExampleInstrumentedTest.java index 2e25e20..2d80c3e 100644 --- a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/sample/browserstack/samplecalculator/ExampleInstrumentedTest.java @@ -1,13 +1,25 @@ package com.sample.browserstack.samplecalculator; -import android.content.Context; -import androidx.test.platform.app.InstrumentationRegistry; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.replaceText; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +import android.util.Log; + +import androidx.test.espresso.Espresso; +import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import com.browserstack.accessibility.AccessibilityUtils; /** * Instrumented test, which will execute on an Android device. @@ -16,10 +28,94 @@ */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { + @Rule + public ActivityScenarioRule activityScenarioRule = + new ActivityScenarioRule<>(MainActivity.class); + + @Before + public void myBeforeEach() throws Exception{ + Log.d("TRANSFORMATION_LOGS", "From @Before"); + } + @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.sample.browserstack.samplecalculator", appContext.getPackageName()); + public void testLoginSuccess() { + android.util.Log.d("TRANSFORMATION_LOGS", "IN TEST"); + Espresso.onView(withId(R.id.username)).perform(replaceText("admin")); + Espresso.onView(withId(R.id.password)).perform(replaceText("12345")); + Espresso.onView(withId(R.id.loginbtn)).perform(click()); + } + + @Test + public void exceptionFailedTest() throws Exception { + Espresso.onView(withId(R.id.username)).perform(replaceText("admin")); + Espresso.onView(withId(R.id.password)).perform(replaceText("admin")); + Espresso.onView(withId(R.id.loginbtn)).perform(click()); + throw new Exception("EXCEPTION FROM TEST"); + } + + @Test + @Category(ExampleInstrumentedTest.class) + public void assertionFailedTest() throws Exception { + Log.d("TEST_LOGS", "testStarted"); + + Espresso.onView(withId(R.id.username)).perform(replaceText("admin")); + Espresso.onView(withId(R.id.password)).perform(replaceText("12345")); + Espresso.onView(withId(R.id.loginbtn)).perform(click()); + + Log.d("PERFORM_SCAN_LOGS", "beforeScan"); + AccessibilityUtils.performEspressoAppAccessibilityScan(""); + Log.d("PERFORM_SCAN_LOGS", "afterScan"); + + Thread.sleep(10000); + + Log.d("A11Y_RESULTS_SUMMARY", AccessibilityUtils.getResultsSummary().toString()); + // AccessibilityUtils.getResultsSummary(); + Log.d("A11Y_RESULTS", AccessibilityUtils.getResults().toString()); + // AccessibilityUtils.getResults(); + + Assert.assertTrue(false); + Thread.sleep(2000); + + Log.d("TEST_LOGS", "testEnded"); + } + + + @Test + @Category(MainActivity.class) + public void testTags() throws InterruptedException{ + Log.d("TEST_LOGS", "testStarted"); + + Assert.assertTrue(true); + Thread.sleep(10000); + + + Log.d("A11Y_RESULTS_SUMMARY", AccessibilityUtils.getResultsSummary().toString()); + // AccessibilityUtils.getResultsSummary(); + Log.d("A11Y_RESULTS", AccessibilityUtils.getResults().toString()); + // AccessibilityUtils.getResults(); + + Log.d("TEST_LOGS", "testEnded"); + } + + @Test + @Ignore + public void testIgnored() throws InterruptedException { + Log.d("TRANSFORMATION_LOGS", "testIgnored"); + Thread.sleep(2000); + } + + @Test + @Ignore("IGNORE MESSAGE") + public void testIgnoredWithMessage() throws InterruptedException { + Log.d("TRANSFORMATION_LOGS", "testIgnoredWithMessage"); + Thread.sleep(2000); + + } + + @Test + public void testAssumptionFailure() throws InterruptedException { + Assume.assumeTrue(false); + Thread.sleep(2000); } } + diff --git a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/NativeScreenshot.java b/app/src/androidTest/java/com/sample/browserstack/samplecalculator/NativeScreenshot.java deleted file mode 100644 index 479eecf..0000000 --- a/app/src/androidTest/java/com/sample/browserstack/samplecalculator/NativeScreenshot.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.sample.browserstack.samplecalculator; - -import android.graphics.Bitmap; -import android.os.Build; -import android.os.Environment; - -import androidx.test.runner.screenshot.BasicScreenCaptureProcessor; -import androidx.test.runner.screenshot.ScreenCapture; -import androidx.test.runner.screenshot.Screenshot; - -import java.io.File; -import java.io.IOException; -import java.util.regex.Pattern; - -public final class NativeScreenshot { - - private static String methodName; - private static String className; - private static final Pattern SCREENSHOT_NAME_VALIDATION = Pattern.compile("[a-zA-Z0-9_-]+"); - - private NativeScreenshot() {} - - /** - * Captures screenshot using Androidx Screenshot library and stores in the filesystem. - * Special Cases: - * If the screenshotName contains spaces or does not pass validation, the corresponding - * screenshot is not visible on BrowserStack's Dashboard. - * If there is any runtime exception while capturing screenshot, the method throws - * Exception and the test might fail if exception is not handled properly. - * @param screenshotName a screenshot identifier - * @return path to the screenshot file - */ - public static String capture(String screenshotName) { - StackTraceElement testClass = findTestClassTraceElement(Thread.currentThread().getStackTrace()); - className = testClass.getClassName().replaceAll("[^A-Za-z0-9._-]", "_"); - methodName = testClass.getMethodName(); - EspressoScreenCaptureProcessor screenCaptureProcessor = new EspressoScreenCaptureProcessor(); - - if (!SCREENSHOT_NAME_VALIDATION.matcher(screenshotName).matches()) { - throw new IllegalArgumentException("ScreenshotName must match " + SCREENSHOT_NAME_VALIDATION.pattern() + "."); - } else { - ScreenCapture capture = Screenshot.capture(); - capture.setFormat(Bitmap.CompressFormat.PNG); - capture.setName(screenshotName); - - try { - return screenCaptureProcessor.process(capture); - } catch (IOException e) { - throw new RuntimeException("Unable to capture screenshot.", e); - } - } - } - - /** - * Extracts the currently executing test's trace element based on the test runner - * or any framework being used. - * @param trace stacktrace of the currently running test - * @return StackTrace Element corresponding to the current test being executed. - */ - private static StackTraceElement findTestClassTraceElement(StackTraceElement[] trace) { - for(int i = trace.length - 1; i >= 0; --i) { - StackTraceElement element = trace[i]; - if ("android.test.InstrumentationTestCase".equals(element.getClassName()) && "runMethod".equals(element.getMethodName())) { - return extractStackElement(trace, i); - } - - if ("org.junit.runners.model.FrameworkMethod$1".equals(element.getClassName()) && "runReflectiveCall".equals(element.getMethodName())) { - return extractStackElement(trace, i); - } - - if ("cucumber.runtime.model.CucumberFeature".equals(element.getClassName()) && "run".equals(element.getMethodName())) { - return extractStackElement(trace, i); - } - } - - throw new IllegalArgumentException("Could not find test class!"); - } - - /** - * Based on the test runner or framework being used, extracts the exact traceElement. - * @param trace stacktrace of the currently running test - * @param i a reference index - * @return trace element based on the index passed - */ - private static StackTraceElement extractStackElement(StackTraceElement[] trace, int i) { - int testClassTraceIndex = Build.VERSION.SDK_INT >= 23 ? i - 2 : i - 3; - return trace[testClassTraceIndex]; - } - - private static class EspressoScreenCaptureProcessor extends BasicScreenCaptureProcessor { - private static final String SCREENSHOT = "screenshots"; - - EspressoScreenCaptureProcessor() { - File screenshotDir = new File(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)), SCREENSHOT); - File classDir = new File(screenshotDir, className); - mDefaultScreenshotPath = new File(classDir, methodName); - } - - /** - * Converts the filename to a standard path to be stored on device. - * Example: "post_addition" converts to "1648038895211_post_addition" - * which is later suffixed by the file extension i.e. png. - * @param filename a screenshot identifier - * @return custom filename format - */ - @Override - protected String getFilename(String filename) { - return System.currentTimeMillis() + "_" + filename; - } - } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 69a6e9f..6eb17dd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,16 +1,23 @@ + xmlns:tools="http://schemas.android.com/tools"> + + - - + android:theme="@style/Theme.Javaespressoapp" + tools:targetApi="31"> + diff --git a/app/src/main/java/com/sample/browserstack/samplecalculator/MainActivity.java b/app/src/main/java/com/sample/browserstack/samplecalculator/MainActivity.java index e9e7331..64a28d5 100644 --- a/app/src/main/java/com/sample/browserstack/samplecalculator/MainActivity.java +++ b/app/src/main/java/com/sample/browserstack/samplecalculator/MainActivity.java @@ -1,174 +1,35 @@ package com.sample.browserstack.samplecalculator; -import androidx.databinding.DataBindingUtil; -import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; +import android.widget.TextView; +import android.widget.Toast; -import com.sample.browserstack.samplecalculator.databinding.ActivityMainBinding; +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; -import java.text.DecimalFormat; +import com.google.android.material.button.MaterialButton; public class MainActivity extends AppCompatActivity { - private double firstNum = Double.NaN; - private double secondNum; - private boolean equalClicked = false; - private String operator = ""; - - private ActivityMainBinding binding; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - - binding = DataBindingUtil.setContentView(this, R.layout.activity_main); - binding.editText.setText(""); - - binding.buttonClear.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - binding.editText.setText(""); - } - }); - binding.buttonZero.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("0"); - } - }); - binding.buttonOne.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("1"); - } - }); - binding.buttonTwo.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("2"); - } - }); - binding.buttonThree.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("3"); - } - }); - binding.buttonFour.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("4"); - } - }); - binding.buttonFive.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("5"); - } - }); - binding.buttonSix.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("6"); - } - }); - binding.buttonSeven.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("7"); - } - }); - binding.buttonEight.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("8"); - } - }); - binding.buttonNine.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("9"); - } - }); - binding.buttonDot.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleInput("."); - } - }); - - binding.buttonAdd.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleOperation("+"); - } - }); - binding.buttonSubtract.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleOperation("-"); - } - }); - binding.buttonDivide.setOnClickListener(new View.OnClickListener() { + setContentView(R.layout.activity_main); + TextView username =(TextView) findViewById(R.id.username); + TextView password =(TextView) findViewById(R.id.password); + MaterialButton loginbtn = (MaterialButton) findViewById(R.id.loginbtn); + loginbtn.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View view) { - handleOperation("/"); - + public void onClick(View v) { + if(username.getText().toString().equals("admin") && password.getText().toString().equals("12345")){ + Toast.makeText(MainActivity.this,"LOGIN SUCCESSFUL",Toast.LENGTH_SHORT).show(); + }else + Toast.makeText(MainActivity.this,"LOGIN FAILED !!!",Toast.LENGTH_SHORT).show(); } }); - binding.buttonMultiply.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - handleOperation("*"); - } - }); - binding.buttonEqual.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - secondNum = Double.parseDouble(binding.editText.getText().toString()); - Double result = Double.NaN; - if (!Double.isNaN(firstNum)) { - if (operator == "+") { - result = firstNum + secondNum; - } else if (operator == "-") { - result = firstNum - secondNum; - } else if (operator == "/") { - result = firstNum / secondNum; - } else if (operator == "*") { - result = firstNum * secondNum; - } - } - operator = ""; - equalClicked = true; - firstNum = Double.NaN; - DecimalFormat df = new DecimalFormat("#.####"); - if (Double.isNaN(result)) { - binding.editText.setText(""); - } else { - binding.editText.setText(df.format(result).toString()); - } - } - }); - } - - private void handleOperation(String inputOperation) { - if (operator == "") { - firstNum = Double.parseDouble(binding.editText.getText().toString()); - binding.editText.setText(""); - operator = inputOperation; - } else { - operator = inputOperation; - } - equalClicked = false; - }; - - private void handleInput(String s) { - if (equalClicked) { - binding.editText.setText(""); - } - binding.editText.setText(binding.editText.getText() + s); - equalClicked = false; } } diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index c7bd21d..0000000 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml index d5fccc5..07d5da9 100644 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -2,169 +2,169 @@ + android:viewportWidth="108" + android:viewportHeight="108"> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6f36af3..234d48d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,209 +1,58 @@ - - + + - - - - - -