UTS Mobile Programing Aplikasi Login dan Hitung Gaji Lembur Karyawan Menggunakan Android Studio
Deskripsi Aplikasi
saya coba membuat aplikasi login sederhana dan menghitung gaji lembur karyawan menggunakan
android studio. Aplikasi nantinya berupa form isian yang terdiri dari :
- · Username
- · Password
- · Sign in
- · Sign up
Setelah form diisi maka selanjutnya tekan tombol sign in dan
akan menampilkan :
- · Masukan Nama
- · CheckBox Jenis Kelamin
- · RadioButton Jam Kerja Lembur
- · Hasil Gaji Lembur
Pertama masukan source code di activity_main.xml sbb:
<?xml version="1.0"
encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/girl"
tools:context="com.login.mobi.loginapp.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.8"
android:background="@drawable/gradient_bg" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp">
<EditText
android:id="@+id/emailinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorWhite"
android:fontFamily="sans-serif-light"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="@color/colorWhite"
android:textColorHint="@color/colorWhite"
android:textSize="17sp" />
<EditText
android:id="@+id/passwordinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/emailinput"
android:layout_marginTop="30dp"
android:backgroundTint="@color/colorWhite"
android:fontFamily="sans-serif-light"
android:hint="Password"
android:inputType="textPassword"
android:textColor="@color/colorWhite"
android:textColorHint="@color/colorWhite"
android:textSize="17sp" />
</RelativeLayout>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@drawable/ic_google_white" />
<Button
android:id="@+id/btSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/btSignUp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/button_white"
android:text="Sign In"
android:textColor="@color/colorPrimary" />
<Button
android:id="@+id/btSignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/button_red"
android:text="Sign Up"
android:textColor="@color/colorWhite" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="122dp"
android:text="Abi Sofyana" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/girl"
tools:context="com.login.mobi.loginapp.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.8"
android:background="@drawable/gradient_bg" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp">
<EditText
android:id="@+id/emailinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorWhite"
android:fontFamily="sans-serif-light"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="@color/colorWhite"
android:textColorHint="@color/colorWhite"
android:textSize="17sp" />
<EditText
android:id="@+id/passwordinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/emailinput"
android:layout_marginTop="30dp"
android:backgroundTint="@color/colorWhite"
android:fontFamily="sans-serif-light"
android:hint="Password"
android:inputType="textPassword"
android:textColor="@color/colorWhite"
android:textColorHint="@color/colorWhite"
android:textSize="17sp" />
</RelativeLayout>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@drawable/ic_google_white" />
<Button
android:id="@+id/btSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/btSignUp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/button_white"
android:text="Sign In"
android:textColor="@color/colorPrimary" />
<Button
android:id="@+id/btSignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/button_red"
android:text="Sign Up"
android:textColor="@color/colorWhite" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="122dp"
android:text="Abi Sofyana" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
Setelah itu
masukan source code di activity_user.xml sbb ;
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "Masukan Nama " /> <EditText android:id = "@+id/nama" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:hint="nama" /> <TextView android:layout_marginTop = "15dp" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "Jenis Kelamin" /> <CheckBox android:id="@+id/laki" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="laki-laki" /> <CheckBox android:id = "@+id/perem" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "perempuan" /> <TextView android:layout_marginTop = "15dp" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "Jam Kerja Lembur"/> <RadioGroup android:id = "@+id/rgGolongan" android:layout_width = "fill_parent" android:layout_height= "wrap_content" > <RadioButton android:id = "@+id/rbGolongan1" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "1 Jam Kerja" /> <RadioButton android:id = "@+id/rbGolongan2" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "2 Jam Kerja" /> <RadioButton android:id = "@+id/rbGolongan3" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "3 Jam Kerja"/> <RadioButton android:id = "@+id/rbGolongan4" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:text = "4 Jam Kerja"/> <Button android:layout_width="182dp" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:onClick="hitung" android:text="Hasil Gaji Lembur" /> </RadioGroup> <TextView android:id = "@+id/outputNama" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:gravity = "center" android:textSize = "20sp" android:text = "" /> <TextView android:id = "@+id/jeke" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:gravity = "center" android:textSize = "20sp" android:text = "" /> <TextView android:id = "@+id/outputGaji" android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:gravity = "center" android:textSize = "35sp" android:text = "" /> </LinearLayout>
Maka Tampilannya
sbb :
Setelah itu
masukan source code di UserActivity.java sbb :
package com.login.mobi.loginapp; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; public class UserActivity extends AppCompatActivity { int gajiST, gajiPerJam; RadioButton jm1, jm2, jm3, jm4; RadioGroup JamKerjaLembur; Button hitung; CheckBox jeke; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user); } public void hitung(View v) { EditText nama = (EditText) findViewById(R.id.nama); CheckBox jeke = (CheckBox) findViewById(R.id.laki); TextView outputNama = (TextView) findViewById(R.id.outputNama); TextView outputJenisKelamin = (TextView) findViewById(R.id.jeke); String name = nama.getText().toString(); String jk = jeke.getText().toString(); outputNama.setText("Total Gaji " + name); outputJenisKelamin.setText("Jenis Kelamin : " + jk); jeke = (CheckBox) findViewById(R.id.laki); if (jeke.isChecked()) { gajiST = 1500000; } ; JamKerjaLembur = (RadioGroup) findViewById(R.id.rgGolongan); int jm = JamKerjaLembur.getCheckedRadioButtonId(); if (jm == R.id.rbGolongan1) { gajiPerJam = 7000; } else if (jm == R.id.rbGolongan2) { gajiPerJam = 14000; } else if (jm == R.id.rbGolongan3) { gajiPerJam = 21000; } else if (jm == R.id.rbGolongan4) { gajiPerJam = 28000; } ; int totalGaji = gajiST + gajiPerJam; TextView total = (TextView) findViewById(R.id.outputGaji); total.setText(String.valueOf(totalGaji)); } }
Setelah source
code diisikan run app dan tampilannya seperti gambar dibawah :
Lalu buat akun
pada halaman login dengan isi username dan password, setelah itu pilih button
sign up.
Setelah akun
berhasil didaftarkan ketikkan ulang username dan password dan pilih button sign
in, jika berhasil login maka tampilannya sbb ;
Lalu saya akan
coba isi dengan data saya, dan hasilnya sbb :
Terima Kasih...
Semoga
Tutorialnya Bermanfaat...