Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions Tutorial_03/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
## Seb's .gitignore template
# You can find the most up-to-date version at https://go.sebastiano.dev/gitignore
# Partly based on templates by https://plugins.jetbrains.com/plugin/7495--ignore
# Released under a CC-0 License https://creativecommons.org/share-your-work/public-domain/cc0/

### Windows template
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Linux template
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

*.iml
*.ipr
*.iws
/.idea/*

# Exclude non-user-specific stuff
!.idea/.name
!.idea/codeInsightSettings.xml
!.idea/codeStyles/
!.idea/copyright/
!.idea/dataSources.xml
!.idea/detekt.xml
!.idea/encodings.xml
!.idea/externalDependencies.xml
!.idea/file.template.settings.xml
!.idea/fileTemplates/
!.idea/icon.svg
!.idea/inspectionProfiles/
!.idea/runConfigurations/
!.idea/scopes/
!.idea/vcs.xml

### Kotlin template
# Compiled class file
*.class

# Log file
*.log

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Gradle template
.gradle

# Note that you may need to exclude by hand other folders
# named build if necessary (e.g., in src/)
**/build/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle/wrapper/gradle-wrapper.jar

# Cache of project
.gradletasknamecache
1 change: 1 addition & 0 deletions Tutorial_03/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Tutorial_03/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Tutorial_03/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
각자 작업하신거 `./{LectureName}/` 폴더 만드시고 PR해주세요
1 change: 1 addition & 0 deletions Tutorial_03/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions Tutorial_03/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}

android {
namespace = "com.example.swpp.cloud_code"
compileSdk = 36

defaultConfig {
applicationId = "com.example.swpp.cloud_code"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.google.code.gson:gson:2.8.9")
implementation("com.squareup.retrofit2:converter-gson:2.4.0")
}
21 changes: 21 additions & 0 deletions Tutorial_03/app/proguard-rules.pro
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.swpp.cloud_code

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.swpp.cloud_code", appContext.packageName)
}
}
27 changes: 27 additions & 0 deletions Tutorial_03/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme._03_code"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>


</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.swpp.cloud_code

import com.google.gson.annotations.SerializedName

data class CodeMessageResponse(
@SerializedName("code")
val code: Int,

@SerializedName("message")
val message: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.example.swpp.cloud_code

import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class MainActivity : AppCompatActivity() {

private lateinit var nameInput: TextView
private lateinit var idInput: TextView
private lateinit var writeButton: Button
private lateinit var targetNameInput: TextView
private lateinit var readButton: Button
private lateinit var targetNameOutput: TextView
private lateinit var idText: TextView

private lateinit var service: ServiceApi

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

nameInput = findViewById(R.id.NameInput)
idInput = findViewById(R.id.IdInput)
writeButton = findViewById(R.id.WriteBtn)
targetNameInput = findViewById(R.id.TargetNameInput)
readButton = findViewById(R.id.ReadBtn)
targetNameOutput = findViewById(R.id.TargetNameOutput)
idText = findViewById(R.id.IdOutput)

service = RetrofitClient.getClient().create(ServiceApi::class.java)

writeButton.setOnClickListener {
val userName = nameInput.text.toString()
val userId = idInput.text.toString()

val requestData = NameIdData(userName, userId)

service.userWrite(requestData).enqueue(object : Callback<CodeMessageResponse> {
override fun onResponse(
call: Call<CodeMessageResponse>,
response: Response<CodeMessageResponse>
) {
val result = response.body()
Toast.makeText(this@MainActivity, result?.message, Toast.LENGTH_SHORT).show()
}

override fun onFailure(call: Call<CodeMessageResponse>, t: Throwable) {
Toast.makeText(this@MainActivity, "Write Error", Toast.LENGTH_SHORT).show()
}
})
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.swpp.cloud_code

import com.google.gson.annotations.SerializedName

data class NameIdData(
@SerializedName("userName")
val userName: String,

@SerializedName("userId")
val userId: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.swpp.cloud_code

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitClient {
private const val BASE_URL = "http://ec2-16-184-15-144.ap-northeast-2.compute.amazonaws.com:3000" // TODO: Replace with your actual EC2 endpoint

private var retrofit: Retrofit? = null

fun getClient(): Retrofit {
if (retrofit == null) {
retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
return retrofit!!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.swpp.cloud_code

import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST

interface ServiceApi {
@POST("/user/write")
fun userWrite(@Body data: NameIdData): Call<CodeMessageResponse>
}
Loading