first commit
This commit is contained in:
parent
db7c551684
commit
9578077533
@ -1,71 +1,76 @@
|
|||||||
package com.example.myapplication
|
package com.example.happybirthday
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import com.example.myapplication.ui.theme.MyApplicationTheme
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
//import com.example.happybirthday.ui.theme.HappyBirthdayTheme
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
|
||||||
setContent {
|
setContent {
|
||||||
MyApplicationTheme {
|
HappyBirthdayTheme {
|
||||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
// A surface container using the 'background' color from the theme
|
||||||
|
Surface(
|
||||||
// Data awal
|
modifier = Modifier.fillMaxSize(),
|
||||||
val data = arrayOf(19, 15, 1, 14, 3)
|
color = MaterialTheme.colorScheme.background
|
||||||
val before = data.joinToString(", ")
|
) {
|
||||||
|
GreetingText(
|
||||||
// Jalankan insertion sort
|
message = "Happy Birthday Sam!",
|
||||||
insertionSort(data)
|
from = "From Emma",
|
||||||
val after = data.joinToString(", ")
|
modifier = Modifier.padding(8.dp)
|
||||||
|
|
||||||
Greeting(
|
|
||||||
text = "Array sebelum: $before\nArray sesudah: $after",
|
|
||||||
modifier = Modifier.padding(innerPadding)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi insertion sort
|
|
||||||
private fun insertionSort(array: Array<Int>) {
|
|
||||||
for (i in 1 until array.size) {
|
|
||||||
val key = array[i]
|
|
||||||
var j = i - 1
|
|
||||||
|
|
||||||
// Pindahkan elemen yang lebih besar dari key ke satu posisi di depan
|
|
||||||
while (j >= 0 && array[j] > key) {
|
|
||||||
array[j + 1] = array[j]
|
|
||||||
j--
|
|
||||||
}
|
|
||||||
array[j + 1] = key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Greeting(text: String, modifier: Modifier = Modifier) {
|
fun GreetingText(message: String, from: String, modifier: Modifier = Modifier) {
|
||||||
Text(
|
Column(
|
||||||
text = text,
|
verticalArrangement = Arrangement.Center,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
)
|
) {
|
||||||
|
Text(
|
||||||
|
text = message,
|
||||||
|
fontSize = 100.sp,
|
||||||
|
lineHeight = 116.sp,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = from,
|
||||||
|
fontSize = 36.sp,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
.align(alignment = Alignment.End)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun GreetingPreview() {
|
fun BirthdayCardPreview() {
|
||||||
MyApplicationTheme {
|
HappyBirthdayTheme {
|
||||||
Greeting("Array sebelum: 9, 5, 1, 4, 3\nArray sesudah: 1, 3, 4, 5, 9")
|
GreetingText(message = "Happy Birthday Sam!", from = "From Emma")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun HappyBirthdayTheme(content: @Composable () -> Unit) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user