Share
Embed
devfest 2022 Compose Camp : Unit 3
devfest 2022 Compose Camp : Unit 3 발표 자료 PDF 파일입니다.
발표를 위한 파일이므로 description text를 대부분 뺀 자료입니다.
description이 필요한 경우 공개된 영상을 참고하시거나 구글 프레젠테이션 파일로 오픈해주시기 바랍니다.
https://docs.google.com/presentation/d/1Sdqi8vIEa5Mmdcqfoj3kZoiqwx0fMN96xKaTsGWBjv4/edit?usp=sharing
Hwang Yeonjin
October 27, 2022
Transcript
86 slides
-
This work is licensed under the Apache 2.0 License Compose
Camp Android Basics with Compose: Display lists and use Material Design -
This work is licensed under the Apache 2.0 License 황연진
Google Developer Student Clubs 숙명여자대학교 캠핑지기 -
This work is licensed under the Apache 2.0 License Unit3:
Display lists and use Material Design -
This work is licensed under the Apache 2.0 License 제네릭
class FillInTheBlankQuestion( val questionText: String, val answer: String, val difficulty: String ) class TrueOrFalseQuestion( val questionText: String, val answer: Boolean, val difficulty: String ) class NumericQuestion( val questionText: String, val answer: Int, val difficulty: String ) -
This work is licensed under the Apache 2.0 License 제네릭
class FillInTheBlankQuestion( val questionText: String, val answer: String, val difficulty: String ) class TrueOrFalseQuestion( val questionText: String, val answer: Boolean, val difficulty: String ) class NumericQuestion( val questionText: String, val answer: Int, val difficulty: String ) -
This work is licensed under the Apache 2.0 License 제네릭
class FillInTheBlankQuestion( val questionText: String, val answer: String, val difficulty: String ) class TrueOrFalseQuestion( val questionText: String, val answer: Boolean, val difficulty: String ) class NumericQuestion( val questionText: String, val answer: Int, val difficulty: String ) -
This work is licensed under the Apache 2.0 License 제네릭
class Question<T>( val questionText: String, val answer: T, val difficulty: String ) -
This work is licensed under the Apache 2.0 License 제네릭
fun main() { val question1 = Question<String>("___ 캠프", "compose", "medium") val question2 = Question<Boolean>("하늘은 초록색", false, "easy") val question3 = Question<Int>("보름은 몇 일인가?", 15, "hard") } -
This work is licensed under the Apache 2.0 License 확장
속성 val Quiz.StudentProgress.progressText: String get() = "${answered} of ${total} answered" -
This work is licensed under the Apache 2.0 License 확장
함수 fun Quiz.StudentProgress.printProgressBar() { repeat(Quiz.answered) { print("▓") } repeat(Quiz.total - Quiz.answered) { print("▒") } println() println(Quiz.progressText) } -
This work is licensed under the Apache 2.0 License 범위
함수 .let() fun printQuiz() { println(question1.questionText) println(question1.answer) println(question1.difficulty) println(question2.questionText) println(question2.answer) println(question2.difficulty) println(question3.questionText) println(question3.answer) println(question3.difficulty) } fun printQuiz() { question1.let { println(it.questionText) println(it.answer) println(it.difficulty) } question2.let { println(it.questionText) println(it.answer) println(it.difficulty) } question3.let { println(it.questionText) println(it.answer) println(it.difficulty) } } -
This work is licensed under the Apache 2.0 License 식별자
it? 변수명 -> it -
This work is licensed under the Apache 2.0 License 범위
함수 .apply() val quiz = Quiz().apply { printQuiz() } Quiz().apply { printQuiz() } -
This work is licensed under the Apache 2.0 License 배열
val rockPlanets = arrayOf<String>("Mercury", "Venus", "Earth", "Mars") -
This work is licensed under the Apache 2.0 License 배열
val rockPlanets = arrayOf("Mercury", "Venus", "Earth", "Mars") -
This work is licensed under the Apache 2.0 License 배열
val newSolarSystem = arrayOf("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune") solarSystem[8] = "Pluto" Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 8 out of bounds for length 8 -
This work is licensed under the Apache 2.0 License 컬렉션
- 리스트 val rockPlanets = listOf<String>("Mercury", "Venus", "Earth", "Mars") -
This work is licensed under the Apache 2.0 License 컬렉션
- 리스트 val rockPlanets = listOf("Mercury", "Venus", "Earth", "Mars") -
This work is licensed under the Apache 2.0 License MutableList
List MutableList val solarSystem = ListOf("Mercury", "Venus", "Earth", "Mars") solarSystem.add("Pluto") //X solarSystem.add(3, "Theia") //X solarSystem[1] = "Future Moon" //X val solarSystem = mutableListOf("Mercury", "Venus", "Earth", "Mars") solarSystem.add("Pluto") solarSystem.add(3, "Theia") solarSystem[1] = "Future Moon" -
This work is licensed under the Apache 2.0 License 컬렉션
- 세트 List보다 빠르지만 더 많은 메모리 사용 -
This work is licensed under the Apache 2.0 License 컬렉션
- 세트 println(myList.indexOf(5)) myList -
This work is licensed under the Apache 2.0 License 컬렉션
- 세트 println(mySet.indexOf(5)) mySet -
Build a scrollable list This work is licensed under the
Apache 2.0 License -
This work is licensed under the Apache 2.0 License Card
@Composable fun AffirmationCard(affirmation: Affirmation, modifier: Modifier = Modifier) { } -
This work is licensed under the Apache 2.0 License Card
@Composable fun AffirmationCard(affirmation: Affirmation, modifier: Modifier = Modifier) { Card(modifier = Modifier.padding(8.dp), elevation = 4.dp) { Column { } } } -
This work is licensed under the Apache 2.0 License Card
@Composable fun AffirmationCard(affirmation: Affirmation, modifier: Modifier = Modifier) { Card(modifier = Modifier.padding(8.dp), elevation = 4.dp) { Column { Image( painter = painterResource(affirmation.imageResourceId), contentDescription = stringResource(affirmation.stringResourceId), ) } } } -
This work is licensed under the Apache 2.0 License Card
@Composable fun AffirmationCard(affirmation: Affirmation, modifier: Modifier = Modifier) { Card(modifier = Modifier.padding(8.dp), elevation = 4.dp) { Column { Image( painter = painterResource(affirmation.imageResourceId), contentDescription = stringResource(affirmation.stringResourceId), modifier = Modifier .fillMaxWidth() .height(194.dp), contentScale = ContentScale.Crop ) } } } -
This work is licensed under the Apache 2.0 License Card
@Composable fun AffirmationCard(affirmation: Affirmation, modifier: Modifier = Modifier) { Card(modifier = Modifier.padding(8.dp), elevation = 4.dp) { Column { Image( painter = painterResource(affirmation.imageResourceId), contentDescription = stringResource(affirmation.stringResourceId), modifier = Modifier .fillMaxWidth() .height(194.dp), contentScale = ContentScale.Crop ) Text( text = stringResource(affirmation.stringResourceId), modifier = Modifier.padding(16.dp), style = MaterialTheme.typography.h6 ) } } } -
This work is licensed under the Apache 2.0 License LazyColumn을
이용한 List 생성 @Composable private fun AffirmationList(affirmationList: List<Affirmation>, modifier: Modifier = Modifier) { } -
This work is licensed under the Apache 2.0 License LazyColumn을
이용한 List 생성 @Composable private fun AffirmationList(affirmationList: List<Affirmation>, modifier: Modifier = Modifier) { LazyColumn { items(affirmationList){ } } } -
This work is licensed under the Apache 2.0 License LazyColumn을
이용한 List 생성 @Composable private fun AffirmationList(affirmationList: List<Affirmation>, modifier: Modifier = Modifier) { LazyColumn { items(affirmationList){ affirmation -> } } } -
This work is licensed under the Apache 2.0 License LazyColumn을
이용한 List 생성 @Composable private fun AffirmationList(affirmationList: List<Affirmation>, modifier: Modifier = Modifier) { LazyColumn { items(affirmationList){ affirmation -> AffirmationCard(affirmation) } } } -
This work is licensed under the Apache 2.0 License 상단
바 추가 image text Row Not Card! -
This work is licensed under the Apache 2.0 License 상단
바 추가 @Composable fun WoofApp() { LazyColumn(modifier = Modifier.background(MaterialTheme.colors.background)) { items(dogs) { DogItem(dog = it) } } } -
This work is licensed under the Apache 2.0 License 상단
바 추가 @Composable fun WoofApp() { Scaffold( ) { LazyColumn(modifier = Modifier.background(MaterialTheme.colors.background)) { items(dogs) { DogItem(dog = it) } } } } -
This work is licensed under the Apache 2.0 License 상단
바 추가 @Composable fun WoofApp() { Scaffold( topBar = { WoofTopAppBar() } ) { LazyColumn(modifier = Modifier.background(MaterialTheme.colors.background)) { items(dogs) { DogItem(dog = it) } } } } -
This work is licensed under the Apache 2.0 License 상단
바 추가 @Composable fun WoofApp() { Scaffold( topBar = { WoofTopAppBar() } ) { LazyColumn(modifier = Modifier.background(MaterialTheme.colors.background)) { items(dogs) { DogItem(dog = it) } } } } -
This work is licensed under the Apache 2.0 License 더
펼치기 아이콘 @Composable private fun DogItemButton( expanded: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier ) { IconButton(onClick = onClick) { Icon( imageVector = Icons.Filled.ExpandMore, tint = MaterialTheme.colors.secondary, contentDescription = stringResource(R.string.expand_button_content_description) ) } } -
This work is licensed under the Apache 2.0 License ()
-> Unit? function type -
This work is licensed under the Apache 2.0 License 더
펼치기 아이콘 @Composable private fun DogItemButton( expanded: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier ) { IconButton(onClick = onClick) { Icon( imageVector = Icons.Filled.ExpandMore, tint = MaterialTheme.colors.secondary, contentDescription = stringResource(R.string.expand_button_content_description) ) } } -
This work is licensed under the Apache 2.0 License var
expanded by remember { mutableStateOf(false) } card 더 펼치기 아이콘 -
This work is licensed under the Apache 2.0 License @Composable
fun DogItem(dog: Dog, modifier: Modifier = Modifier) { var expanded by remember { mutableStateOf(false) } Card( … ) { Column( … ) { Row( modifier = Modifier .fillMaxWidth() .padding(8.dp) ) { DogIcon(dog.imageResourceId) DogInformation(dog.name, dog.age) Spacer(Modifier.weight(1f)) DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) } if (expanded) { DogHobby(dog.hobbies) } } } } 더 펼치기 아이콘 -
This work is licensed under the Apache 2.0 License @Composable
fun DogItem(dog: Dog, modifier: Modifier = Modifier) { var expanded by remember { mutableStateOf(false) } Card( … ) { Column( … ) { Row( modifier = Modifier .fillMaxWidth() .padding(8.dp) ) { DogIcon(dog.imageResourceId) DogInformation(dog.name, dog.age) Spacer(Modifier.weight(1f)) DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) } if (expanded) { DogHobby(dog.hobbies) } } } } 더 펼치기 아이콘 -
This work is licensed under the Apache 2.0 License @Composable
fun DogItem(dog: Dog, modifier: Modifier = Modifier) { var expanded by remember { mutableStateOf(false) } Card( … ) { Column( … ) { Row( modifier = Modifier .fillMaxWidth() .padding(8.dp) ) { DogIcon(dog.imageResourceId) DogInformation(dog.name, dog.age) Spacer(Modifier.weight(1f)) DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) } if (expanded) { DogHobby(dog.hobbies) } } } } 더 펼치기 아이콘 -
This work is licensed under the Apache 2.0 License @Composable
fun DogItem(dog: Dog, modifier: Modifier = Modifier) { var expanded by remember { mutableStateOf(false) } Card( … ) { Column( … ) { Row( modifier = Modifier .fillMaxWidth() .padding(8.dp) ) { DogIcon(dog.imageResourceId) DogInformation(dog.name, dog.age) Spacer(Modifier.weight(1f)) DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) } if (expanded) { DogHobby(dog.hobbies) } } } } 더 펼치기 아이콘 -
This work is licensed under the Apache 2.0 License @Composable
fun DogItem(dog: Dog, modifier: Modifier = Modifier) { var expanded by remember { mutableStateOf(false) } Card( … ) { Column( … ) { Row( modifier = Modifier .fillMaxWidth() .padding(8.dp) ) { DogIcon(dog.imageResourceId) DogInformation(dog.name, dog.age) Spacer(Modifier.weight(1f)) DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) } if (expanded) { DogHobby(dog.hobbies) } } } } 컴포저블 추가 -
This work is licensed under the Apache 2.0 License @Composable
fun DogItem(dog: Dog, modifier: Modifier = Modifier) { var expanded by remember { mutableStateOf(false) } Card( … ) { Column( … ) { Row( modifier = Modifier .fillMaxWidth() .padding(8.dp) ) { DogIcon(dog.imageResourceId) DogInformation(dog.name, dog.age) Spacer(Modifier.weight(1f)) DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) } if (expanded) { DogHobby(dog.hobbies) } } } } 버튼 클릭 이벤트 -
This work is licensed under the Apache 2.0 License 버튼
클릭 이벤트 DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) 속성 -
This work is licensed under the Apache 2.0 License 버튼
클릭 이벤트 DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) 현재의 expanded 상태를 저장한 변수 -
This work is licensed under the Apache 2.0 License 버튼
클릭 이벤트 DogItemButton( expanded = expanded, onClick = { expanded = !expanded }, ) True or False