-
Notifications
You must be signed in to change notification settings - Fork 1
[김예란_Android] 1주차 과제 제출 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| package com.example.android_25_2 | ||
|
|
||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import android.util.Log | ||
| import android.widget.Button | ||
| import android.widget.TextView | ||
| import android.widget.Toast | ||
| import androidx.activity.enableEdgeToEdge | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.core.view.ViewCompat | ||
| import androidx.core.view.WindowInsetsCompat | ||
| import kotlin.random.Random | ||
|
|
||
| class MainActivity : AppCompatActivity() { | ||
| private lateinit var launcher: ActivityResultLauncher<Intent> | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| enableEdgeToEdge() | ||
|
|
@@ -16,5 +25,33 @@ class MainActivity : AppCompatActivity() { | |
| v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) | ||
| insets | ||
| } | ||
|
|
||
| launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 과제에 |
||
|
|
||
| val textView: TextView = findViewById(R.id.textView_main) | ||
|
|
||
| val toastButton: Button = findViewById(R.id.button_toast) | ||
| toastButton.setOnClickListener { | ||
| Toast.makeText(this, getString(R.string.toast_message), Toast.LENGTH_SHORT).show() | ||
| } | ||
|
|
||
| val countButton: Button = findViewById(R.id.button_count) | ||
| countButton.setOnClickListener { | ||
| val currentText1 = textView.text.toString().toInt() | ||
| val newCount = currentText1 + 1 | ||
| textView.text = newCount.toString() | ||
| } | ||
|
|
||
| val randomButton: Button = findViewById(R.id.button_random) | ||
| randomButton.setOnClickListener { | ||
| val randomNumber = Random.nextInt(0, 15) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 과제 조건에 Random.nextInt(0,15) 로 0~14 사이의 랜덤한 숫자가 아닌 |
||
| launchSecondActivity(randomNumber) | ||
| } | ||
| } | ||
|
|
||
| private fun launchSecondActivity(randomNumber: Int) { | ||
| val intent = Intent(this, SecondActivity::class.java) | ||
| intent.putExtra("random_number", randomNumber) | ||
| launcher.launch(intent) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.example.android_25_2 | ||
|
|
||
| import android.app.Activity | ||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import android.util.Log | ||
| import android.widget.Button | ||
| import android.widget.TextView | ||
| import androidx.activity.result.ActivityResult | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import androidx.activity.result.registerForActivityResult | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.core.view.ViewCompat | ||
| import androidx.core.view.WindowInsetsCompat | ||
| import kotlin.random.Random | ||
|
|
||
| class SecondActivity : AppCompatActivity() { | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_second) | ||
| ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.Second)) { v, insets -> | ||
| val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) | ||
| v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) | ||
| insets | ||
| } | ||
| Log.e("MYLOG","done3") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 디버그용 로그는 지워주세요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 질문: Log.v, Log.d, Log.e의 차이는 무엇일까요
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log.v는 비교적 세세하며 Log.d는 디버깅용 로그입니다 Log.e는 에러 로그입니다 |
||
|
|
||
| val textView: TextView = findViewById(R.id.textView_main) | ||
| val randomButton: Button = findViewById(R.id.button_random) | ||
|
|
||
| val receivedRandomNumber = intent.getIntExtra("random_number", 0) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "random_number" 로 내부 str 선언이 아닌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추가로 상수 처리해도 괜찮을 것 같네요 |
||
| textView.text = receivedRandomNumber.toString() | ||
|
|
||
| randomButton.setOnClickListener { | ||
| val randomNumber = Random.nextInt(0, 15) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 마찬가지 0,14 의 랜덤값이 아닙니다. |
||
| textView.text = randomNumber.toString() | ||
| } | ||
|
|
||
| val resultIntent = Intent() | ||
| resultIntent.putExtra("random_number", textView.text) | ||
| setResult(Activity.RESULT_OK, resultIntent) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,63 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| <androidx.constraintlayout.widget.ConstraintLayout | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:id="@+id/main" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:background="@color/blue" | ||
| tools:context=".MainActivity"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/textView_main" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="0" | ||
| android:textSize="50sp" | ||
| android:textColor="@color/white" | ||
| android:textStyle="bold" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toTopOf="parent" | ||
| android:layout_marginTop="250dp"/> | ||
|
|
||
| <Button | ||
| android:id="@+id/button_count" | ||
| android:layout_width="80dp" | ||
| android:layout_height="35dp" | ||
| android:text="@string/message_button_count" | ||
| android:textSize="9dp" | ||
| android:backgroundTint="@color/purple_200" | ||
| app:layout_constraintTop_toBottomOf="@+id/textView_main" | ||
| android:layout_marginTop="200dp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent"/> | ||
|
|
||
| <Button | ||
| android:id="@+id/button_toast" | ||
| android:layout_width="80dp" | ||
| android:layout_height="35dp" | ||
| android:text="@string/message_button_toast" | ||
| android:textSize="9dp" | ||
| android:backgroundTint="@color/purple_200" | ||
| app:layout_constraintTop_toBottomOf="@+id/textView_main" | ||
| android:layout_marginTop="200dp" | ||
| android:layout_marginEnd="180dp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent"/> | ||
|
|
||
| <Button | ||
| android:id="@+id/button_random" | ||
| android:layout_width="80dp" | ||
| android:layout_height="35dp" | ||
| android:text="@string/message_button_random" | ||
| android:textSize="9dp" | ||
| android:backgroundTint="@color/purple_200" | ||
| app:layout_constraintTop_toBottomOf="@+id/textView_main" | ||
| android:layout_marginTop="200dp" | ||
| android:layout_marginStart="180dp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent"/> | ||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:id="@+id/Second" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:background="@color/purple_500" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| tools:context=".SecondActivity"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/textView_main" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="0" | ||
| android:textSize="50sp" | ||
| android:textColor="@color/white" | ||
| android:textStyle="bold" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toTopOf="parent" | ||
| android:layout_marginTop="250dp"/> | ||
|
|
||
| <Button | ||
| android:id="@+id/button_count" | ||
| android:layout_width="80dp" | ||
| android:layout_height="35dp" | ||
| android:text="@string/message_button_count" | ||
| android:textSize="9dp" | ||
| android:backgroundTint="@color/purple_200" | ||
| app:layout_constraintTop_toBottomOf="@+id/textView_main" | ||
| android:layout_marginTop="200dp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent"/> | ||
|
|
||
| <Button | ||
| android:id="@+id/button_toast" | ||
| android:layout_width="80dp" | ||
| android:layout_height="35dp" | ||
| android:text="@string/message_button_toast" | ||
| android:textSize="9dp" | ||
| android:backgroundTint="@color/purple_200" | ||
| app:layout_constraintTop_toBottomOf="@+id/textView_main" | ||
| android:layout_marginTop="200dp" | ||
| android:layout_marginEnd="180dp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent"/> | ||
|
|
||
| <Button | ||
| android:id="@+id/button_random" | ||
| android:layout_width="80dp" | ||
| android:layout_height="35dp" | ||
| android:text="@string/message_button_random" | ||
| android:textSize="9dp" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. textSize 는 sp 가 더 좋습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안드로이드에서 사용하는 길이 단위에 대해 알아보시면 좋을 것 같습니다 |
||
| android:backgroundTint="@color/purple_200" | ||
| app:layout_constraintTop_toBottomOf="@+id/textView_main" | ||
| android:layout_marginTop="200dp" | ||
| android:layout_marginStart="180dp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent"/> | ||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| <resources> | ||
| <string name="app_name">Android_25-2</string> | ||
| <string name="message_button_count">"COUNT"</string> | ||
| <string name="message_button_toast">"TOAST"</string> | ||
| <string name="message_button_random">"RANDOM"</string> | ||
| <string name="toast_message">"Boink"</string> | ||
| </resources> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
외부에 노출될 필요가 없는 Activity는
exported="false" 로 해주세요.