Compare commits
35 Commits
kelompok-1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f289d0495f | |||
| 7c7b9c0ec6 | |||
| 373c8595d7 | |||
| d6dafed995 | |||
| b42d846e01 | |||
| 2638da3f05 | |||
| 08c24bdfdd | |||
| d3c1410a11 | |||
| 1ce89ad197 | |||
| 228d9f8f77 | |||
| 5dffb47576 | |||
| 992c0d627c | |||
| 4f1f8577bc | |||
| 6370eba0da | |||
| c4aee9ee3c | |||
| 5cccdf5368 | |||
| b73d429200 | |||
| 89c60eb81e | |||
| 6fcbb52b90 | |||
| cd156ca010 | |||
| 4488dfd0cb | |||
| 4281e24379 | |||
| 5170efe60e | |||
| 4ac1678d48 | |||
| 357a25744c | |||
| cf5adbd923 | |||
| d77a9409de | |||
| a115da0783 | |||
| 8f9ca68257 | |||
| 83fabde258 | |||
| 8f24ef2640 | |||
| 3e3da371dc | |||
| 6d30bb4a88 | |||
|
|
ae1ae8cd80 | ||
| 55d17abb93 |
10
.idea/deploymentTargetSelector.xml
generated
10
.idea/deploymentTargetSelector.xml
generated
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="deploymentTargetSelector">
|
|
||||||
<selectionStates>
|
|
||||||
<SelectionState runConfigName="app">
|
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
|
||||||
</SelectionState>
|
|
||||||
</selectionStates>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -26,3 +26,11 @@ Repository ini digunakan untuk praktikum perkuliahan pemrograman mobile.
|
|||||||
- 15. Indris Alpasela (202310715200)
|
- 15. Indris Alpasela (202310715200)
|
||||||
- 16. Raihan Ariq Muzakki (202310715297)
|
- 16. Raihan Ariq Muzakki (202310715297)
|
||||||
- 17. Dirson Ali Wardana (202310715246)
|
- 17. Dirson Ali Wardana (202310715246)
|
||||||
|
- 18. Dimas Hendri Pamungkas (202310715274)
|
||||||
|
- 19. Fadhlul Wafi (202310715188)
|
||||||
|
- 20. Muhammad Yusron Amrullah (202310715060)
|
||||||
|
- 21. Muhammad Fadillah (202310715213)
|
||||||
|
- 22. Hadi Guna Prakoso (202310715312)
|
||||||
|
- 23. Muhammad Rafi (202310715191)
|
||||||
|
- 24. Muhammad Rafly Al-Fathir (202310715043)
|
||||||
|
- 25. Jeremia Sebastian Marpaung (202310715096)
|
||||||
@ -50,8 +50,6 @@ dependencies {
|
|||||||
implementation(libs.androidx.compose.ui.graphics)
|
implementation(libs.androidx.compose.ui.graphics)
|
||||||
implementation(libs.androidx.compose.ui.tooling.preview)
|
implementation(libs.androidx.compose.ui.tooling.preview)
|
||||||
implementation(libs.androidx.compose.material3)
|
implementation(libs.androidx.compose.material3)
|
||||||
implementation("com.squareup.okhttp3:okhttp:4.11.0")
|
|
||||||
|
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
@ -59,4 +57,8 @@ dependencies {
|
|||||||
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||||
|
//praktikum 1
|
||||||
|
implementation("com.squareup.okhttp3:okhttp:4.11.0")
|
||||||
|
implementation("androidx.compose.material3:material3:1.1.1")
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -22,12 +22,6 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".JalurEvakuasiActivity"
|
|
||||||
android:exported="false"/>
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@ -1,47 +0,0 @@
|
|||||||
package id.ac.ubharajaya.panicbutton
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.activity.ComponentActivity
|
|
||||||
import androidx.activity.compose.setContent
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
|
|
||||||
class JalurEvakuasiActivity : ComponentActivity() {
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
|
|
||||||
setContent {
|
|
||||||
JalurEvakuasiScreen(onClose = { finish() })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun JalurEvakuasiScreen(onClose: () -> Unit) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(16.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.evakuasi),
|
|
||||||
contentDescription = "Jalur Evakuasi",
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(20.dp))
|
|
||||||
|
|
||||||
Button(onClick = onClose) {
|
|
||||||
Text("Close")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,25 +1,18 @@
|
|||||||
package id.ac.ubharajaya.panicbutton
|
package id.ac.ubharajaya.panicbutton
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
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.compose.foundation.border
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import id.ac.ubharajaya.panicbutton.ui.theme.PanicButtonTheme
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
@ -28,200 +21,32 @@ import okhttp3.RequestBody
|
|||||||
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 {
|
||||||
MyApp(
|
PanicButtonTheme {
|
||||||
onClose = { finish() },
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||||
onOpenEvacuation = {
|
Greeting(
|
||||||
startActivity(Intent(this, JalurEvakuasiActivity::class.java))
|
name = "Android",
|
||||||
|
modifier = Modifier.padding(innerPadding)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emoji untuk tiap kondisi
|
|
||||||
fun getEmoji(condition: String): String {
|
|
||||||
return when (condition) {
|
|
||||||
"Kebakaran" -> "🔥"
|
|
||||||
"Banjir" -> "⛈️"
|
|
||||||
"Tsunami" -> "🌊"
|
|
||||||
"Gunung Meletus" -> "🌋"
|
|
||||||
"Gempa Bumi" -> "🌏"
|
|
||||||
"Huru Hara/Demonstrasi" -> "👿"
|
|
||||||
"Binatang Buas" -> "🐍"
|
|
||||||
"Radiasi Nuklir" -> "☢️"
|
|
||||||
"Biohazard" -> "☣️"
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MyApp(onClose: () -> Unit, onOpenEvacuation: () -> Unit) {
|
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
||||||
val focusManager = LocalFocusManager.current
|
Text(
|
||||||
var message by remember { mutableStateOf("Klik tombol untuk mengirim notifikasi") }
|
text = "Hello $name!",
|
||||||
var selectedConditions by remember { mutableStateOf(mutableSetOf<String>()) }
|
modifier = modifier
|
||||||
var additionalNotes by remember { mutableStateOf(TextFieldValue("")) }
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
@Preview(showBackground = true)
|
||||||
modifier = Modifier
|
@Composable
|
||||||
.fillMaxSize()
|
fun GreetingPreview() {
|
||||||
.padding(16.dp),
|
PanicButtonTheme {
|
||||||
verticalArrangement = Arrangement.Top,
|
Greeting("Android")
|
||||||
horizontalAlignment = Alignment.Start
|
|
||||||
) {
|
|
||||||
// Judul
|
|
||||||
Text(
|
|
||||||
text = "Terjadi Kondisi Darurat:",
|
|
||||||
fontSize = 26.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = Color.Red,
|
|
||||||
modifier = Modifier.padding(bottom = 16.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Daftar kondisi
|
|
||||||
listOf(
|
|
||||||
"Kebakaran",
|
|
||||||
"Banjir",
|
|
||||||
"Tsunami",
|
|
||||||
"Gunung Meletus",
|
|
||||||
"Gempa Bumi",
|
|
||||||
"Huru Hara/Demonstrasi",
|
|
||||||
"Binatang Buas",
|
|
||||||
"Radiasi Nuklir",
|
|
||||||
"Biohazard",
|
|
||||||
"Lainnya"
|
|
||||||
).forEach { condition ->
|
|
||||||
val emoji = getEmoji(condition)
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
focusManager.clearFocus()
|
|
||||||
selectedConditions = selectedConditions.toMutableSet().apply {
|
|
||||||
if (contains(condition)) remove(condition) else add(condition)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(vertical = 4.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Checkbox(
|
|
||||||
checked = selectedConditions.contains(condition),
|
|
||||||
onCheckedChange = { isChecked ->
|
|
||||||
focusManager.clearFocus()
|
|
||||||
selectedConditions = selectedConditions.toMutableSet().apply {
|
|
||||||
if (isChecked) add(condition) else remove(condition)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "$emoji $condition",
|
|
||||||
modifier = Modifier.padding(start = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Catatan tambahan
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
Text(text = "Catatan tambahan:", fontWeight = FontWeight.Bold)
|
|
||||||
|
|
||||||
BasicTextField(
|
|
||||||
value = additionalNotes,
|
|
||||||
onValueChange = { additionalNotes = it },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(100.dp)
|
|
||||||
.padding(8.dp)
|
|
||||||
.border(1.dp, Color.Gray),
|
|
||||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
|
||||||
)
|
|
||||||
|
|
||||||
// ================================================
|
|
||||||
// Tombol Kirim + Lihat Jalur Evakuasi (Berdampingan)
|
|
||||||
// ================================================
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
|
|
||||||
// Tombol Kirim Laporan
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
val notes = additionalNotes.text
|
|
||||||
val conditions = selectedConditions.joinToString(", ") {
|
|
||||||
"${getEmoji(it)} $it"
|
|
||||||
}
|
|
||||||
val report = "Kondisi: $conditions\nCatatan: $notes"
|
|
||||||
|
|
||||||
sendNotification(report) { response ->
|
|
||||||
message = response
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
colors = ButtonDefaults.buttonColors(containerColor = Color.Red)
|
|
||||||
) {
|
|
||||||
Text(text = "Kirim Laporan", color = Color.White)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
|
||||||
|
|
||||||
// Tombol Jalur Evakuasi
|
|
||||||
Button(
|
|
||||||
onClick = onOpenEvacuation,
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFF0080FF))
|
|
||||||
) {
|
|
||||||
Text(text = "Lihat Jalur Evakuasi", color = Color.White)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
Text(
|
|
||||||
text = "“JANGAN PANIK! SEGERA EVAKUASI\nDIRI ANDA KE TITIK KUMPUL”",
|
|
||||||
color = Color.Red,
|
|
||||||
fontSize = 15.sp
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(20.dp))
|
|
||||||
|
|
||||||
// Tombol Tutup (opsional)
|
|
||||||
Button(onClick = onClose) {
|
|
||||||
Text("Tutup")
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
Text(text = message)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===============================================================
|
|
||||||
// Fungsi Kirim Notifikasi ke Server ntfy.ubharajaya.ac.id
|
|
||||||
// ===============================================================
|
|
||||||
fun sendNotification(report: String, onResult: (String) -> Unit) {
|
|
||||||
val client = OkHttpClient()
|
|
||||||
val url = "https://ntfy.ubharajaya.ac.id/panic-button"
|
|
||||||
|
|
||||||
val requestBody = RequestBody.create("text/plain".toMediaType(), report)
|
|
||||||
|
|
||||||
val request = Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.addHeader("Title", "Alert")
|
|
||||||
.addHeader("Priority", "urgent")
|
|
||||||
.post(requestBody)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
Thread {
|
|
||||||
try {
|
|
||||||
val response = client.newCall(request).execute()
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
onResult("Notifikasi berhasil dikirim!")
|
|
||||||
} else {
|
|
||||||
onResult("Gagal mengirim notifikasi: ${response.code}")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
onResult("Error: ${e.message}")
|
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.8 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 269 KiB |
Loading…
x
Reference in New Issue
Block a user