Tugas 6 - Pemograman Perangkat Bergeral

Nama : Sayid Ziyad Ibrahim Alaydrus
NRP : 5025201147
Kelas : PPB F

Tugas : membuat Image Scroll


1. mendowload resource pada github:
2. membuat model pada package affirmation



3. membuat file kotlin di DataSource affirmation untuk menampung gambar-gambar yang dibutuhkan dan uncomment kode.




4. menambahkan kode pada mainactivity.kt seperti berikut


  1. /*
  2. * Copyright (C) 2023 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.example.affirmations
  17. import android.os.Bundle
  18. import androidx.activity.ComponentActivity
  19. import androidx.activity.compose.setContent
  20. import androidx.compose.foundation.Image
  21. import androidx.compose.foundation.layout.Column
  22. import androidx.compose.foundation.layout.fillMaxSize
  23. import androidx.compose.foundation.layout.fillMaxWidth
  24. import androidx.compose.foundation.layout.height
  25. import androidx.compose.foundation.layout.padding
  26. import androidx.compose.foundation.lazy.LazyColumn
  27. import androidx.compose.foundation.lazy.items
  28. import androidx.compose.material3.Card
  29. import androidx.compose.material3.MaterialTheme
  30. import androidx.compose.material3.Surface
  31. import androidx.compose.material3.Text
  32. import androidx.compose.runtime.Composable
  33. import androidx.compose.ui.Modifier
  34. import androidx.compose.ui.layout.ContentScale
  35. import androidx.compose.ui.platform.LocalContext
  36. import androidx.compose.ui.res.painterResource
  37. import androidx.compose.ui.res.stringResource
  38. import androidx.compose.ui.tooling.preview.Preview
  39. import androidx.compose.ui.unit.dp
  40. import com.example.affirmations.data.Datasource
  41. import com.example.affirmations.model.Affirmation
  42. import com.example.affirmations.ui.theme.AffirmationsTheme
  43. class MainActivity : ComponentActivity() {
  44. override fun onCreate(savedInstanceState: Bundle?) {
  45. super.onCreate(savedInstanceState)
  46. setContent {
  47. AffirmationsTheme {
  48. // A surface container using the 'background' color from the theme
  49. Surface(
  50. modifier = Modifier.fillMaxSize(),
  51. color = MaterialTheme.colorScheme.background
  52. ) {
  53. AffirmationsApp()
  54. }
  55. }
  56. }
  57. }
  58. }
  59. @Composable
  60. fun AffirmationsApp() {
  61. AffirmationList(affirmationList = Datasource().loadAffirmations())
  62. }
  63. @Composable
  64. fun AffirmationCard(affirmation: Affirmation, modifier: Modifier = Modifier){
  65. Card(modifier = modifier) {
  66. Column {
  67. Image(painter = painterResource(affirmation.imageResourceId),
  68. contentDescription = stringResource(affirmation.stringResourceId),
  69. modifier = Modifier
  70. .fillMaxWidth()
  71. .height(194.dp),
  72. contentScale = ContentScale.Crop
  73. )
  74. Text(
  75. text = LocalContext.current.getString(affirmation.stringResourceId),
  76. modifier = Modifier.padding(16.dp),
  77. style = MaterialTheme.typography.headlineSmall)
  78. }
  79. }
  80. }
  81. @Preview(
  82. showSystemUi = true,
  83. showBackground = true
  84. )
  85. @Composable
  86. private fun AffirmationCardPreview() {
  87. AffirmationCard(affirmation = Affirmation(R.string.affirmation1, R.drawable.image1))
  88. }
  89. @Composable
  90. fun AffirmationList(affirmationList: List<Affirmation>, modifier: Modifier = Modifier){
  91. LazyColumn (modifier = modifier){
  92. items(affirmationList){affirmation ->
  93. AffirmationCard(affirmation,
  94. modifier = Modifier.padding(16.dp),
  95. )
  96. }
  97. }
  98. }

5. hasil dan dokumentasi

Comments

Popular posts from this blog

Tugas 1 -Evolusi Perangkat Lunak

Tugas 6 - Evolusi Perangkat Lunak

Tugas 3- Evolusi perangkat Lunak