diff --git a/.gradle/config.properties b/.gradle/config.properties
new file mode 100644
index 0000000..76e9d26
--- /dev/null
+++ b/.gradle/config.properties
@@ -0,0 +1,2 @@
+#Tue Nov 26 00:44:34 KST 2024
+java.home=C\:\\Program Files\\Android\\Android Studio1\\jbr
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..99b49d3
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+assignment02
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..ddf7151
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,233 @@
+
+
+
+
+
+
+
+
+
+ @style/Theme.Assignment02
+
+
+
+
+ @style/Theme.Assignment02
+
+
+
+
+ @style/Theme.Assignment02
+
+
+
+
+ @style/Theme.Assignment02
+
+
+
+
+ @style/Theme.Assignment02
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "keyToString": {
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.cidr.known.project.marker": "true",
+ "cf.first.check.clang-format": "false",
+ "cidr.known.project.marker": "true",
+ "com.google.services.firebase.aqiPopupShown": "true",
+ "last_directory_selection": "C:/Users/Public/assignment02/app/src/main/java",
+ "last_opened_file_path": "C:/Users/Public/assignment02",
+ "settings.editor.selected.configurable": "AndroidSdkUpdater"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1731406527910
+
+
+ 1731406527910
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 166076e..25059fe 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -5,7 +5,7 @@ plugins {
android {
namespace = "com.example.assignment02"
- compileSdk = 34
+ compileSdk = 35
defaultConfig {
applicationId = "com.example.assignment02"
@@ -36,11 +36,11 @@ android {
}
dependencies {
- implementation("androidx.activity:activity-ktx:1.7.0")
- implementation("androidx.core:core-ktx:1.13.1")
+
+ implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
- implementation("androidx.constraintlayout:constraintlayout:2.1.4")
+ implementation("androidx.constraintlayout:constraintlayout:2.2.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c9ef4a9..27c7204 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,10 @@
+
+
+
+
-
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/assignment02/MainActivity.kt b/app/src/main/java/com/example/assignment02/MainActivity.kt
index acbfa04..79533cf 100644
--- a/app/src/main/java/com/example/assignment02/MainActivity.kt
+++ b/app/src/main/java/com/example/assignment02/MainActivity.kt
@@ -1,42 +1,117 @@
package com.example.assignment02
-import android.app.Activity
-import android.content.Intent
+import android.Manifest
+import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
import android.widget.TextView
-import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
+import androidx.core.content.ContentProviderCompat.requireContext
+import androidx.core.content.ContextCompat
+import androidx.fragment.app.Fragment
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
class MainActivity : AppCompatActivity() {
+ private var running = false
+ private var timer: Job? = null
+ private var time: Long = 0
+ private var stime: Long = 0
+ private var etime: Long = 0
+
+ private var adapter: TimeAdapter? = null
+ private var time_list = mutableListOf()
+
+ private lateinit var time_text: TextView
+ private lateinit var start_text: TextView
+ private lateinit var stop_text: TextView
+ private lateinit var lap_text: TextView
+ private lateinit var time_view: RecyclerView
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
- val number_text: TextView = findViewById(R.id.number_text)
- val count_btn: TextView = findViewById(R.id.count_btn)
- val toast_btn: TextView = findViewById(R.id.toast_btn)
- val random_btn: TextView = findViewById(R.id.random_btn)
- val intent = Intent(this, RandomActivity::class.java)
-
- val resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
- if (result.resultCode == Activity.RESULT_OK) {
- number_text.text = result.data?.getIntExtra("random_number", 0).toString()
- Toast.makeText(this, "OK", Toast.LENGTH_SHORT).show()
+
+ time_text = findViewById(R.id.timeText)
+ start_text = findViewById(R.id.startText)
+ stop_text = findViewById(R.id.stopText)
+ lap_text = findViewById(R.id.lapText)
+ time_view = findViewById(R.id.timeList)
+
+ time_view.layoutManager = LinearLayoutManager(this)
+ time_view.adapter = TimeAdapter(time_list)
+
+ start_text.setOnClickListener {
+ if (running) {
+ start_text.text = "START"
+ pauseTimer()
}
- else {
- Toast.makeText(this, "오류", Toast.LENGTH_SHORT).show()
+ if (!running) {
+ start_text.text = "PAUSE"
+ startTimer()
}
+ running = !running
}
-
- count_btn.setOnClickListener {
- number_text.text = (number_text.text.toString().toInt()+1).toString()
+ stop_text.setOnClickListener {
+ start_text.text = "START"
+ time_text.text = String.format("00:00:00")
+ running = false
+ pauseTimer()
+ time = 0
+ }
+ lap_text.setOnClickListener {
+ time_list.add(time_text.text.toString())
+ adapter?.notifyItemInserted(time_list.size - 1) // 리스트가 업데이트된 항목만 갱신
+ time_view.scrollToPosition(time_list.size - 1)
}
- toast_btn.setOnClickListener {
- Toast.makeText(this, "숫자 : "+number_text.text, Toast.LENGTH_LONG).show()
+ }
+
+ private fun startTimer(){
+ stime = System.currentTimeMillis()
+ timer = CoroutineScope(Dispatchers.Main).launch {
+ while(true){
+ delay(5)
+ etime = System.currentTimeMillis()
+ time += etime-stime
+ time_text.text = String.format("%02d:%02d:%02d", time/60000, (time%60000)/1000, (time%1000)/10)
+ stime = etime
+ }
}
- random_btn.setOnClickListener {
- intent.putExtra("number", number_text.text.toString().toInt())
- resultLauncher.launch(intent)
+ }
+
+ private fun pauseTimer(){
+ timer?.cancel()
+ }
+}
+
+class TimeAdapter(private val timeList: List) :
+ RecyclerView.Adapter() {
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TimeViewHolder {
+ val view = LayoutInflater.from(parent.context)
+ .inflate(R.layout.list_item, parent, false)
+ return TimeViewHolder(view)
+ }
+
+ override fun onBindViewHolder(holder: TimeViewHolder, position: Int) {
+ holder.bind(timeList[position])
+ }
+
+ override fun getItemCount(): Int = timeList.size
+
+ class TimeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ private val time_text: TextView = itemView.findViewById(R.id.timeText)
+
+ fun bind(time: String) {
+ time_text.text = time
}
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/assignment02/RandomActivity.kt b/app/src/main/java/com/example/assignment02/RandomActivity.kt
deleted file mode 100644
index 095b881..0000000
--- a/app/src/main/java/com/example/assignment02/RandomActivity.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.example.assignment02
-
-import android.content.Intent
-import android.os.Bundle
-import android.widget.TextView
-import androidx.appcompat.app.AppCompatActivity
-import kotlin.random.Random
-
-class RandomActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_random)
- val number_text: TextView = findViewById(R.id.number_text)
- val number = intent.getIntExtra("number", 1) // 123
- val resultIntent = Intent()
-
- if (number > 0){
- val random_number = Random.nextInt(0, number) // 0부터 99까지의 랜덤 값
- number_text.text = random_number.toString()
- resultIntent.putExtra("random_number", random_number)
- setResult(RESULT_OK, resultIntent)
- } else {
- number_text.text = number.toString()
- resultIntent.putExtra("random_number", number)
- setResult(RESULT_OK, resultIntent)
- }
- }
-}
\ 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 0fb246d..0f3007b 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -4,49 +4,59 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:padding="30dp"
+ android:padding="25dp"
tools:context=".MainActivity">
+ app:layout_constraintEnd_toEndOf="parent" />
-
+ android:layout_margin="5dp"
+ android:gravity="center"
+ android:padding="20dp"
+ android:text="START"
+ app:layout_constraintStart_toStartOf="@id/timeText"
+ app:layout_constraintTop_toBottomOf="@id/timeText" />
-
+ android:layout_margin="5dp"
+ android:gravity="center"
+ android:padding="20dp"
+ android:text="STOP"
+ app:layout_constraintEnd_toEndOf="@id/timeText"
+ app:layout_constraintStart_toStartOf="@id/timeText"
+ app:layout_constraintTop_toBottomOf="@id/timeText" />
-
+ android:layout_margin="5dp"
+ android:gravity="center"
+ android:padding="20dp"
+ android:text="LAP"
+ app:layout_constraintEnd_toEndOf="@id/timeText"
+ app:layout_constraintTop_toBottomOf="@id/timeText" />
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_random.xml b/app/src/main/res/layout/activity_random.xml
deleted file mode 100644
index 3f6e6ae..0000000
--- a/app/src/main/res/layout/activity_random.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml
new file mode 100644
index 0000000..2978e85
--- /dev/null
+++ b/app/src/main/res/layout/list_item.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 731cd98..b849030 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,4 +1,4 @@
-#Tue Nov 12 19:15:37 KST 2024
+#Tue Nov 26 00:44:39 KST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip