Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interaction between app and calculator Some logic in CalculatorActivity
- Loading branch information
1 parent
6dda049
commit e6f8b76
Showing
20 changed files
with
299 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
package com.example.multimodule | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Button | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.calculator.ui.CalculatorActivity | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
bindListeners() | ||
} | ||
|
||
private fun bindListeners() { | ||
findViewById<Button>(R.id.calculator_button).setOnClickListener { | ||
startCalculatorActivity() | ||
} | ||
} | ||
|
||
private fun startCalculatorActivity() { | ||
startActivity( | ||
Intent(this, CalculatorActivity::class.java) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<resources> | ||
<string name="app_name">dagger-multimodule-app</string> | ||
<string name="go_to_calculator">Calculator</string> | ||
<string name="tools">Tools</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
android { | ||
compileSdkVersion 29 | ||
|
||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles 'consumer-rules.pro' | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'androidx.core:core-ktx:1.2.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
24 changes: 24 additions & 0 deletions
24
calculator/src/androidTest/java/com/example/calculator/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.calculator | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.example.calculator.test", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.calculator"> | ||
|
||
<application> | ||
<activity | ||
android:theme="@style/Theme.Calculator" | ||
android:label="Calculator" | ||
android:name=".ui.CalculatorActivity" | ||
android:screenOrientation="portrait" /> | ||
</application> | ||
|
||
</manifest> |
48 changes: 48 additions & 0 deletions
48
calculator/src/main/java/com/example/calculator/ui/CalculatorActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.calculator.ui | ||
|
||
import android.os.Bundle | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.calculator.R | ||
import com.example.calculator.usecase.SumUseCase | ||
|
||
class CalculatorActivity : AppCompatActivity() { | ||
|
||
lateinit var sumUseCase: SumUseCase | ||
|
||
lateinit var firstNumberEditText: EditText | ||
lateinit var secondNumberEditText: EditText | ||
lateinit var resultTextView: TextView | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.acitivity_calculator) | ||
|
||
sumUseCase = SumUseCase() | ||
|
||
bindViews() | ||
bindListeners() | ||
} | ||
|
||
private fun calculateSum() { | ||
val firstNumber = firstNumberEditText.text.toString().toInt() | ||
val secondNumber = secondNumberEditText.text.toString().toInt() | ||
val result = sumUseCase.execute(firstNumber, secondNumber) | ||
resultTextView.text = result.toString() | ||
} | ||
|
||
private fun bindViews() { | ||
firstNumberEditText = findViewById(R.id.first_number_edittext) | ||
secondNumberEditText = findViewById(R.id.second_number_edittext) | ||
resultTextView = findViewById(R.id.result_textview) | ||
} | ||
|
||
private fun bindListeners() { | ||
findViewById<Button>(R.id.button_calculate).setOnClickListener { | ||
calculateSum() | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
calculator/src/main/java/com/example/calculator/usecase/SumUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.calculator.usecase | ||
|
||
class SumUseCase { | ||
|
||
fun execute(firstNumber: Int, secondNumber: Int): Int { | ||
return firstNumber + secondNumber | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:orientation="vertical" | ||
android:background="@android:color/white"> | ||
|
||
|
||
<EditText | ||
android:id="@+id/first_number_edittext" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginTop="20dp" | ||
android:layout_marginRight="20dp" | ||
android:textSize="18sp" | ||
android:textColor="@android:color/black" | ||
android:ems="10" | ||
android:hint="@string/insert_first_number_hint" | ||
android:inputType="number" /> | ||
|
||
<EditText | ||
android:id="@+id/second_number_edittext" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginTop="20dp" | ||
android:layout_marginRight="20dp" | ||
android:textSize="18sp" | ||
android:ems="10" | ||
android:textColor="@android:color/black" | ||
android:hint="@string/insert_second_number_hint" | ||
android:inputType="number" /> | ||
|
||
<Button | ||
android:id="@+id/button_calculate" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="32dp" | ||
android:padding="8dp" | ||
style="@style/Widget.AppCompat.Button.Colored" | ||
android:layout_gravity="center" | ||
android:text="@string/calculate" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:padding="8dp" | ||
android:layout_gravity="center" | ||
android:layout_height="wrap_content" | ||
android:textStyle="bold" | ||
android:text="@string/result" /> | ||
|
||
<TextView | ||
android:id="@+id/result_textview" | ||
android:layout_width="wrap_content" | ||
android:padding="8dp" | ||
android:textSize="24sp" | ||
android:layout_gravity="center" | ||
android:layout_height="wrap_content" | ||
tools:text="200" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#008577</color> | ||
<color name="colorPrimaryDark">#00574B</color> | ||
<color name="colorAccent">#D81B60</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<resources> | ||
<string name="app_name">calculator</string> | ||
<string name="insert_second_number_hint">Put another number here</string> | ||
<string name="insert_first_number_hint">Put a number here</string> | ||
<string name="calculate">Calculate sum!</string> | ||
<string name="result">Result</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="Theme.Calculator" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
17 changes: 17 additions & 0 deletions
17
calculator/src/test/java/com/example/calculator/ExampleUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.calculator | ||
|
||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
include ':app' | ||
include ':app', ':calculator' | ||
rootProject.name='dagger-multimodule-app' |