Minggu, 07 April 2019

UAS MOBILE PROGRAMMING APLIKASI PEMESANAN KOPI

PEMESANAN KOPI
·         DESKRIPSI
Pada kesempatan kali ini, saya akan membuat sebuah program pemesanan kopi sederhana yang berbasis android dengan menggunakan eclipse dimana aplikasi ini berfungsi layaknya Cafe yang terinspirasi ingin menggunakan aplikasi tersebut. Maka dengan menggunakan aplikasi ini kemungkinan bisa memudahkan pemesanan dan transaksinya sekaligus.
Didalam aplikasi ini terdapat 3 activity yaitu : Login,Daftar Menu dan tampilan daftar kopi
1.      Login
Pada activity login ini berisikan mengenai user name dan password ketika mengisi activity tersebut maka kita bisa klik button Login dan masuk ke activity berikut nya.
2.      Daftar Menu
Didalam activity menu ini menggunakan listview untuk daftar menu pemesanan kopinya.
3.      Kopi
Dan Activity terakhir ini terdapat EditText,Radio Button dan Button dimana activity ini berfungsi untuk menghitung jumlah pesanan dan total pesanan keseluruhan.

·         XML Teks
XML Login
            <RelativeLayout 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"
    tools:context=".LoginActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="FROM LOGIN"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="35sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="14dp"
        android:text="User Name" />

    <EditText
        android:id="@+id/userNameEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:ems="10" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/userNameEditText"
        android:layout_marginTop="21dp"
        android:text="Password" />

    <EditText
        android:id="@+id/passwordEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView3"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/tutupButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/loginButton"
        android:layout_alignBottom="@+id/loginButton"
        android:layout_marginLeft="27dp"
        android:layout_toRightOf="@+id/loginButton"
        android:layout_weight="1"
        android:text="Tutup"
        android:textSize="30sp" />

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/passwordEditText"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="44dp"
        android:layout_weight="3"
        android:text="Login"
        android:textSize="30sp" />

</RelativeLayout>

Menu Activity
            <RelativeLayout 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"
    tools:context=".MenuActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Daftar Menu"
        android:textSize="30sp" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView1" >

    </ListView>

</RelativeLayout>

      Kopi Activity
      <RelativeLayout 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"
    tools:context=".KopiActivity" >
   
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/GroupCoffee"
        android:layout_toRightOf="@+id/GroupCoffee"
        android:text="Menu kopi yang akan dipesan"
        android:textSize="20sp" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_toRightOf="@+id/GroupCoffee" >

        <RadioButton
            android:id="@+id/cafe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Indocafe" />

        <RadioButton
            android:id="@+id/Mocca"
·         android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Moccacino" />

        <RadioButton
            android:id="@+id/Cappu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cappucino" />
    </RadioGroup>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/radioGroup1"
        android:text="Tambahan apa yang akan dimasukan kedalam kopi" />

    <CheckBox
        android:id="@+id/KRIM"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:text="CREAMER" />

    <CheckBox
        android:id="@+id/GUL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/KRIM"
        android:text="GULA" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/GUL"
        android:layout_below="@+id/GUL"
        android:layout_marginTop="31dp"
        android:text="TOTAL" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/TTL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="29dp"
        android:text="TOTAL" />

    <Button
        android:id="@+id/KEM"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TTL"
        android:layout_alignBottom="@+id/TTL"
        android:layout_marginLeft="24dp"
        android:layout_toRightOf="@+id/radioGroup1"
        android:text="KEMBALI" />
   

</RelativeLayout>

·         XML Grafik

Login Activity


Activity Menu


Activity Kopi



·         Source Koding Java
a.       Source Koding Login
package com.example.gitafitriani161011401381;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LoginActivity extends Activity {
            EditText userNameTxt;
            EditText passwordTxt;
            Button loginBtn;
            Button tutupBtn;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_login);
                        userNameTxt = (EditText) findViewById(R.id.userNameEditText);
        passwordTxt = (EditText) findViewById(R.id.passwordEditText);
        loginBtn = (Button) findViewById(R.id.loginButton);
        tutupBtn = (Button) findViewById(R.id.tutupButton);
       
        loginBtn.setOnClickListener(new View.OnClickListener() {
           
            public void onClick(View v) {
                                                // TODO Auto-generated method stub
                                                Intent i = new Intent(LoginActivity.this, MenuActivity.class);
                                                i.putExtra("pesan", "Sukses Login");
                                                startActivity(i);
                                    }
                        });
       
        tutupBtn.setOnClickListener(new View.OnClickListener() {
                                   
                                    public void onClick(View v) {
                                                // TODO Auto-generated method stub
                                                moveTaskToBack(true);
                                                android.os.Process.killProcess(android.os.Process.myPid());
                                                System.exit(0);
                                    }
                        });
    }
           

            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                        // Inflate the menu; this adds items to the action bar if it is present.
                        getMenuInflater().inflate(R.menu.activity_login, menu);
                        return true;
            }

}

b.      Source Koding Daftar Menu
package com.example.gitafitriani161011401381;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MenuActivity extends Activity {
            ListView LV;
            String [] Menu = {"Kopi", "Jus", "Teh","Keluar"
                       
            };
           

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_menu);
                        LV = (ListView) findViewById (R.id.listView1);
                        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_single_choice,Menu);
                        LV.setAdapter(adapter);
                       
                        LV.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                                    @Override
                                    public void onItemClick(AdapterView<?> arg0, View arg1, int itemKe,
                                                            long arg3) {
                                                // TODO Auto-generated method stub
                                                String itemText=(String) LV.getItemAtPosition(itemKe);
                                                Toast.makeText(getBaseContext(), "Anda Mengklik"+itemText, Toast.LENGTH_LONG).show();
                                                if(itemText.equals("Kopi")){
                                                            Intent KopiInten = new Intent (arg0.getContext(),KopiActivity.class);
                                                            startActivityForResult(KopiInten,0);
                                    }
                                    }
                        });
            }

            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                        // Inflate the menu; this adds items to the action bar if it is present.
                        getMenuInflater().inflate(R.menu.activity_menu, menu);
                        return true;
            }

}

Source Koding Kopi
package com.example.gitafitriani161011401381;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
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.Toast;

public class KopiActivity extends Activity {
            RadioButton Indocafe;
            RadioButton Moccacino;
            RadioButton Cappucino;
            RadioGroup Kopi;
            EditText total;
            Button Total;
            Button kembali;
            int HargaIndocafe = 4000;
            int HargaMoccacino = 10000;
            int HargaCappucino = 15000;
            CheckBox Creamer;
            CheckBox Gula;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_kopi);
                        Indocafe = (RadioButton) findViewById(R.id.cafe);
                        Moccacino = (RadioButton) findViewById(R.id.Mocca);
                        Cappucino = (RadioButton) findViewById(R.id.Cappu);
                        Kopi = (RadioGroup) findViewById(R.id.radioGroup1);
                        total = (EditText) findViewById(R.id.editText1);
                        Total = (Button) findViewById(R.id.TTL);
                        kembali = (Button) findViewById(R.id.KEM);
                       
                        Total.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View arg0) {
                                                // TODO Auto-generated method stub
                                                String Pilihan = "Kopi";
                                                String ket = "Total Harga";
                                               
                                                int radioId=Kopi.getCheckedRadioButtonId();
                                                if(Indocafe.getId()==radioId){
                                                            int totalHarga = HargaIndocafe;
                                                            Pilihan = Pilihan + "Kopi Indocafe" + "" + ket + totalHarga;
                                                            total.setText(""+totalHarga);
                                                }else if(Moccacino.getId()==radioId){
                                                            int totalHarga =HargaMoccacino;
                                                            Pilihan = Pilihan + "Kopi Moccacino" + "" + ket + totalHarga;
                                                            total.setText(""+totalHarga);
                                                }else{
                                                            int totalHarga = HargaCappucino;
                                                            Pilihan = Pilihan + "Kopi Cappucino" + "" + ket + totalHarga;
                                                            total.setText(""+totalHarga);
                                               
                                    }
                                                Toast.makeText(getApplicationContext(), Pilihan, Toast.LENGTH_LONG).show();
                                   
                                    }
                        });
            }

            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                        // Inflate the menu; this adds items to the action bar if it is present.
                        getMenuInflater().inflate(R.menu.activity_kopi, menu);
                        return true;
            }

}

·         Hasil Run
Login

Daftar Menu

Kopi

Sekian dan terimakasih,mudah-mudahan bisa bermanfaat baik bagi penulis maupun yang membaca :)