first commit

This commit is contained in:
Arif Rifai Dwiyanto 2025-10-09 18:38:14 +07:00
parent db7c551684
commit 9578077533

View File

@ -1,71 +1,76 @@
package com.example.myapplication
package com.example.happybirthday
import android.os.Bundle
import androidx.activity.ComponentActivity
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.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
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() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
MyApplicationTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
// Data awal
val data = arrayOf(19, 15, 1, 14, 3)
val before = data.joinToString(", ")
// Jalankan insertion sort
insertionSort(data)
val after = data.joinToString(", ")
Greeting(
text = "Array sebelum: $before\nArray sesudah: $after",
modifier = Modifier.padding(innerPadding)
HappyBirthdayTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
GreetingText(
message = "Happy Birthday Sam!",
from = "From Emma",
modifier = Modifier.padding(8.dp)
)
}
}
}
}
// 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
fun Greeting(text: String, modifier: Modifier = Modifier) {
Text(
text = text,
fun GreetingText(message: String, from: String, modifier: Modifier = Modifier) {
Column(
verticalArrangement = Arrangement.Center,
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)
@Composable
fun GreetingPreview() {
MyApplicationTheme {
Greeting("Array sebelum: 9, 5, 1, 4, 3\nArray sesudah: 1, 3, 4, 5, 9")
fun BirthdayCardPreview() {
HappyBirthdayTheme {
GreetingText(message = "Happy Birthday Sam!", from = "From Emma")
}
}
@Composable
fun HappyBirthdayTheme(content: @Composable () -> Unit) {
TODO("Not yet implemented")
}