Deskripsi

Aplikasi rental mobil menggunakan android studio ini dibuat bertujuan untuk memudahkan admin untuk menginput data para penyewa selain mempermudah aplikasi ini juga bisa menghemat kertas

Berikut adalah preview untuk aplikasi yang dibuat:




Dibawah ini adalah source code untuk xml :

ini adalah code xml form login

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:orientation="vertical">

        <EditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="Username"/>

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:hint="Password"/>

        <Button
            android:id="@+id/btnLogin"
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Login"/>

    </LinearLayout>


</android.support.constraint.ConstraintLayout>

ini adalah code xml form input data :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:orientation="vertical">

        <EditText
            android:id="@+id/nama"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:hint="Masukan Nama"/>

        <EditText
            android:id="@+id/noKtp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:hint="Masukan Nomor Ktp"/>

        <EditText
            android:id="@+id/noHp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:hint="Masukan Nomor Hp"/>

        <EditText
            android:id="@+id/tglSewa"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="date"
            android:hint="Masukan Tanggal Sewa"/>

        <EditText
            android:id="@+id/tglSelesaiSewa"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:hint="Masukan Tanggal Selesai Sewa"/>

        <Button
            android:id="@+id/btnSimpan"
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Simpan"/>

        <Button
            android:id="@+id/btnTampil"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lihat Sewa"/>

    </LinearLayout>

</RelativeLayout>


ini adalah code untuk melihat data yang sudah di input :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    app:cardCornerRadius="5dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Nama                    :  "/>
            <TextView
                android:id="@+id/tvNama"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="   "/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="No Ktp                   :  "/>
            <TextView
                android:id="@+id/tvNoKtp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="   "/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="No Hp                    :  "/>
            <TextView
                android:id="@+id/tvNoHp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="   "/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tgl Sewa               :  "/>
            <TextView
                android:id="@+id/tvTglSewa"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="   "/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tgl Selesai Sewa :  "/>
            <TextView
                android:id="@+id/tvTglSelesaiSewa"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="   "/>

        </LinearLayout>

    </LinearLayout>

</android.support.v7.widget.CardView>

Dan ini adalah code java nya
package com.andri161021450297.andrisetiawan;

import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.ContextThemeWrapper;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Toast;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

import io.realm.Realm;
import io.realm.RealmConfiguration;

public class DetailRentalActivity extends AppCompatActivity {

    EditText edtNama, edtNoKtp, edtNoHp, edtTglSewa, edtTglSelesaiSewa;
    String nama, noKtp, noHp, tglSewa, tglSelesaiSewa;
    Integer id;
    Button btn_ubah, btn_hapus, btn_kembali;
    RealmHelper realmHelper;
    Realm realm;
    Calendar myCalendar = Calendar.getInstance();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_rental);

        // Set up
        Realm.init(this);
        RealmConfiguration configuration = new RealmConfiguration.Builder().build();
        realm = Realm.getInstance(configuration);
        realmHelper = new RealmHelper(realm);

        // Inisialisasi
        edtNama = findViewById(R.id.etNama);
        edtNoKtp = findViewById(R.id.etNoKtp);
        edtNoHp = findViewById(R.id.etNoHp);
        edtTglSewa = findViewById(R.id.etTglSewa);
        edtTglSelesaiSewa = findViewById(R.id.etTglSelesaiSewa);
        btn_ubah = findViewById(R.id.btnUpdate);
        btn_hapus = findViewById(R.id.btnHapus);
        btn_kembali = findViewById(R.id.btnCancel);

        id = Integer.parseInt(getIntent().getStringExtra("id"));
        nama = getIntent().getStringExtra("nama");
        noKtp = getIntent().getStringExtra("noKtp");
        noHp = getIntent().getStringExtra("noHp");
        tglSewa = getIntent().getStringExtra("tglSewa");
        tglSelesaiSewa = getIntent().getStringExtra("tglSelesaiSewa");

        edtNama.setText(nama);
        edtNoKtp.setText(noKtp);
        edtNoHp.setText(noHp);
        edtTglSewa.setText(tglSewa);
        edtTglSelesaiSewa.setText(tglSelesaiSewa);

        //edtTglSewa
        edtTglSewa.setInputType(InputType.TYPE_NULL);
        edtTglSewa.setTextIsSelectable(true);
        edtTglSewa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogPickerTglSewa();
            }
        });
        edtTglSewa.setFocusable(false);

        //edtTglSelesaiSewa
        edtTglSelesaiSewa.setInputType(InputType.TYPE_NULL);
        edtTglSelesaiSewa.setTextIsSelectable(true);
        edtTglSelesaiSewa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogPickerTglSelesaiSewa();
            }
        });
        edtTglSelesaiSewa.setFocusable(false);

        btn_ubah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                realmHelper.update(id, edtNama.getText().toString(), edtNoKtp.getText().toString(), edtNoHp.getText().toString(),
                        edtTglSewa.getText().toString(), edtTglSelesaiSewa.getText().toString());
                Toast.makeText(DetailRentalActivity.this, "Update Success", Toast.LENGTH_SHORT).show();
                edtNama.setText("");
                edtNoKtp.setText("");
                edtNoHp.setText("");
                edtTglSewa.setText("");
                edtTglSelesaiSewa.setText("");
                finish();
            }
        });

        btn_hapus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                realmHelper.delete(id);
                Toast.makeText(DetailRentalActivity.this, "Delete Success", Toast.LENGTH_SHORT).show();
                finish();
            }
        });

        btn_kembali.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(DetailRentalActivity.this, RentalActivity.class));
                finish();
            }
        });

    }

    private void dialogPickerTglSewa() {
        DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                myCalendar.set(Calendar.YEAR, year);
                myCalendar.set(Calendar.MONTH, monthOfYear);
                myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateLabelTglSewa();
            }

        };

        final Context themedContext = new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog);
        final DatePickerDialog dialog = new FixedHoloDatePickerDialog(
                themedContext,
                date,
                myCalendar.get(Calendar.YEAR),
                myCalendar.get(Calendar.MONTH),
                myCalendar.get(Calendar.DAY_OF_MONTH)
        );

        dialog.show();

    }

    private void updateLabelTglSewa() {
        String myFormat = "dd/MM/yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
        edtTglSewa.setText(sdf.format(myCalendar.getTime()));
    }

    private void dialogPickerTglSelesaiSewa() {
        DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                myCalendar.set(Calendar.YEAR, year);
                myCalendar.set(Calendar.MONTH, monthOfYear);
                myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateLabelTglSelesaiSewa();
            }

        };

        final Context themedContext = new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog);
        final DatePickerDialog dialog = new FixedHoloDatePickerDialog(
                themedContext,
                date,
                myCalendar.get(Calendar.YEAR),
                myCalendar.get(Calendar.MONTH),
                myCalendar.get(Calendar.DAY_OF_MONTH)
        );

        dialog.show();

    }

    private void updateLabelTglSelesaiSewa() {
        String myFormat = "dd/MM/yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
        edtTglSelesaiSewa.setText(sdf.format(myCalendar.getTime()));
    }


}


package com.andri161021450297.andrisetiawan;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LoginActivity extends AppCompatActivity {

    Button btnlogin;
    EditText edtUsername, edtPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        // Inisialisasi
        btnlogin = findViewById(R.id.btnLogin);
        edtUsername = findViewById(R.id.nama);
        edtPassword = findViewById(R.id.noKtp);

        btnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LoginActivity.this, MainActivity.class));
            }
        });
    }

}

0 comments:

Post a Comment

 
Top