PPB - PERTEMUAN 6
DOKUMENTASI PPB
Nama : Dawamul Fikri Aqil
NRP : 5025201025
Kelas : PPB F
Tahun : 2024
Tugas : LoginPage
DOKUMENTASI TUGAS
PENDAHULUAN
Pada pertemuan ke 6, penulis diajarkan materi mengenai "Studi Kasus - Membuat Halaman Login". Halaman login digunakan untuk tujuan otentikasi dalam aplikasi. Penulis membutuhkan halaman login pertama di mana pengguna akan dapat masuk lebih lanjut menggunakan nama pengguna dan kata sandi. Dalam tugas ini, penulis telah membuat halaman login sederhana di studio android di mana tujuan otentikasi statis, yang berarti nama pengguna dan kata sandi sudah akan ditetapkan dalam kode.
Setelah diajarkan materi penulis diberikan tugas untuk membuat aplikasi LoginPage/LoginForm sederhana. Untuk implementasi tugas ada di bawah ini.
Setelah diajarkan materi penulis diberikan tugas untuk membuat aplikasi LoginPage/LoginForm sederhana. Untuk implementasi tugas ada di bawah ini.
IMPLEMENTASI CODE
- MainActivity.kt
package com.example.loginpage
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
LoginScreen()
}
}
}
- LoginScreen.kt
package com.example.loginpage
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
fun LoginScreen() {
var email by remember {
mutableStateOf("")
}
var password by remember {
mutableStateOf("")
}
//Layout column and full width, center to center
Column(
modifier = Modifier.fillMaxSize().background(color = Color.White),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = R.drawable.icf),
contentDescription = "Login Image",
modifier = Modifier.size(200.dp)
)
Text(text = "Welcome", fontSize = 28.sp, fontWeight = FontWeight.Bold, modifier = Modifier.clickable { })
Spacer(modifier = Modifier.height(4.dp))
Text(text = "Login to your Account")
//Input interface
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(value = email, onValueChange = { email = it}, label = {
Text(text = "Email Address")
})
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(value = password, onValueChange = { password = it}, label = {
Text(text = "Password")
}, visualTransformation = PasswordVisualTransformation())
//End of input
//Submit Btn
Spacer(modifier = Modifier.height(16.dp))
Button(onClick = { Log.i("Credential", "Email : $email Password : $password") }) {
Text(text = "Login")
}
Spacer(modifier = Modifier.height(32.dp))
TextButton(onClick = { /*TODO*/ }) {
Text(text = "Forgot Password")
}
TextButton(onClick = { /*TODO*/ }) {
Text(text = "Or sign in with")
}
//Layout opt login
Row (
modifier = Modifier
.fillMaxSize()
.padding(10.dp),
horizontalArrangement = Arrangement.SpaceEvenly
) {
Image(painter = painterResource(id = R.drawable.gm), contentDescription = "Gmail icon",
modifier = Modifier
.size(40.dp)
.clickable { }
)
Image(painter = painterResource(id = R.drawable.fb), contentDescription = "Facebook icon",
modifier = Modifier
.size(40.dp)
.clickable { }
)
Image(painter = painterResource(id = R.drawable.x), contentDescription = "Twitter icon",
modifier = Modifier
.size(40.dp)
.clickable { }
)
}
}
}
TAMPILAN UI
Komentar
Posting Komentar