Minggu, 05 Januari 2020

TUGAS/UAS/MOBILE_PROGRAMMING

TUGAS UAS MOBILE PROGRAMMING
MEMBUAT APLIKASI TERKONEKSI DATABASE SQLITE PADA ANDROID STUDIO
"LIST GROUP KPOP"

Assalamualaikum Wr. Wb

1. Deskripsi Project

Aplikasi List View "GROUP KPOP" saya buat untuk menampilkan daftar para member Group KPOP Boys & Girls, tidak lupa juga saya membuat menu login untuk masuk ke daftar listviewnya. Menu login pada aplikasi ini sudah terkoneksi dengan DatabaseSqlite. Tampilan login terdiri dari username, password, button login dan button register. Button login digunakan untuk masuk aplikasi dengan insert username dan password, sedangkan button register untuk mendaftarkan akun baru. Saya membuat 10 daftar nama group, yang mana ketika di klik salah satunya akan muncul penjelasan singkat mengenai latar belakang terbentuknya group tersebut beserta foto para membernya.

2. Design Project










3. Source Code

a. LOGIN

- activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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/blues"
    tools:context=".MainActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:layout_alignTop="@+id/textView4"
            android:layout_marginStart="17dp"
            android:layout_marginLeft="17dp"
            android:layout_marginTop="18dp"
            android:layout_toEndOf="@+id/TFpassword"
            android:layout_toRightOf="@+id/TFpassword"
            android:background="@drawable/gembok" />

        <TextView

            android:id="@+id/textView"

            android:layout_width="206dp"

            android:layout_height="31dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30dp"
            android:text="LOGIN HERE"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="30sp"
            android:textStyle="normal|bold" />


        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="52dp"
            android:layout_marginLeft="52dp"
            android:layout_marginTop="116dp"
            android:text="Username" />

        <EditText
            android:id="@+id/TFusername"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView3"
            android:layout_alignStart="@+id/textView3"
            android:layout_alignLeft="@+id/textView3"
            android:layout_marginStart="1dp"
            android:layout_marginLeft="1dp"
            android:layout_marginTop="17dp"
            android:ems="10"
            android:inputType="textPersonName" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/TFusername"
            android:layout_alignStart="@+id/TFusername"
            android:layout_alignLeft="@+id/TFusername"
            android:layout_marginStart="4dp"
            android:layout_marginLeft="4dp"
            android:layout_marginTop="46dp"
            android:text="Password" />

        <EditText
            android:id="@+id/TFpassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView4"
            android:layout_alignStart="@+id/textView4"
            android:layout_alignLeft="@+id/textView4"
            android:layout_marginStart="-4dp"
            android:layout_marginLeft="-4dp"
            android:layout_marginTop="24dp"
            android:ems="10"
            android:inputType="textPassword" />

        <Button

            android:id="@+id/Blogin"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/TFpassword"
            android:layout_alignStart="@+id/TFpassword"
            android:layout_alignLeft="@+id/TFpassword"
            android:layout_marginStart="12dp"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="50dp"
            android:onClick="onButtonClick"
            android:text="Login" />

        <Button
            android:id="@+id/bregister"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/TFpassword"
            android:layout_alignRight="@+id/TFpassword"
            android:layout_alignParentBottom="true"
            android:layout_marginEnd="-30dp"
            android:layout_marginRight="-30dp"
            android:layout_marginBottom="5dp"
            android:onClick="onButtonClick"
            android:text="Register" />
    </RelativeLayout>
</ScrollView>


- MainActivity.java

package list.kpop;

import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {
    DatabaseHelper helper = new DatabaseHelper(this);
    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().setTitle("RUBI_SULASTRI_161021450368");
    }
    public void onButtonClick (View v)
    {
        if (v.getId()==R.id.Blogin)
        {
            EditText a = (EditText)findViewById(R.id.TFusername);
            EditText b = (EditText)findViewById(R.id.TFpassword);
            String str = a.getText().toString();
            String pass = b.getText().toString();
            String password = helper.searchPass(str);
            if (a.length()==0 && b.length()==0)
            {
                a.setError("Mohon di isi");
                b.setError("Mohon di isi");
            }
            else if (a.length()==0)
            {
                a.setError("Mohon di isi");
            }
            else if (b.length()==0)
            {
                b.setError("Mohon di isi");
            }
            else if (pass.equals(password))
            {
                Intent i = new Intent(MainActivity.this, listkorea.class);
                startActivity(i);
            }
            else{
                Toast.makeText(MainActivity.this, "Password dont match", Toast.LENGTH_SHORT).show();
            }
        }
        if (v.getId()==R.id.bregister)
        {
            Intent i = new Intent(MainActivity.this, Register.class);
            startActivity(i);
        }
    }
}




-register.xml


<?xml version="1.0" encoding="utf-8"?>

<ScrollView

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/blues">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="12dp"
            android:layout_marginStart="12dp"
            android:layout_marginTop="22dp"
            android:text="Nama" />

        <EditText
            android:id="@+id/TFname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView6"
            android:layout_alignStart="@+id/textView6"
            android:layout_below="@+id/textView6"
            android:ems="10"
            android:inputType="textPersonName" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/TFname"
            android:layout_alignStart="@+id/TFname"
            android:layout_below="@+id/TFname"
            android:layout_marginTop="23dp"
            android:text="Email" />

        <EditText
            android:id="@+id/TFemail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView7"
            android:layout_alignStart="@+id/textView7"
            android:layout_below="@+id/textView7"
            android:ems="10"
            android:inputType="textPersonName" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/TFemail"
            android:layout_alignStart="@+id/TFemail"
            android:layout_below="@+id/TFemail"
            android:layout_marginTop="26dp"
            android:text="Username" />

        <EditText
            android:id="@+id/TFuname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView8"
            android:layout_alignStart="@+id/textView8"
            android:layout_below="@+id/textView8"
            android:ems="10"
            android:inputType="textPersonName" />

        <TextView
            android:id="@+id/textView9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/TFuname"
            android:layout_alignStart="@+id/TFuname"
            android:layout_below="@+id/TFuname"
            android:layout_marginTop="25dp"
            android:text="Password 1st" />

        <EditText
            android:id="@+id/TFpass1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView9"
            android:layout_alignStart="@+id/textView9"
            android:layout_below="@+id/textView9"
            android:ems="10"
            android:inputType="textPassword" />

        <TextView
            android:id="@+id/textView10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/TFpass2"
            android:layout_alignStart="@+id/TFpass2"
            android:layout_below="@+id/TFpass1"
            android:layout_marginTop="23dp"
            android:text="Password 2nd" />

        <EditText
            android:id="@+id/TFpass2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPassword"
            android:layout_below="@+id/textView10"
            android:layout_alignLeft="@+id/TFpass1"
            android:layout_alignStart="@+id/TFpass1" />

        <Button
            android:id="@+id/Bregister"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/textView10"
            android:layout_alignRight="@+id/textView10"
            android:layout_below="@+id/TFpass2"
            android:layout_marginTop="63dp"
            android:onClick="onRegisterClick"
            android:text="Register" />

    </RelativeLayout>
</ScrollView>


- Contact.java

package list.kpop;

public class Contact {
    String name, email, uname, pass;
    public void setName (String name)
    {
        this.name=name;
    }
    public String getName()
    {
        return this.name;
    }
    public void setEmail (String email)
    {
        this.email=email;
    }
    public String getEmail()
    {
        return this.email;
    }
    public void setUname (String uname)
    {
        this.uname=uname;
    }
    public String getUname()
    {
        return this.uname;
    }
    public void setPass (String pass)
    {
        this.pass=pass;
    }
    public String getPass()
    {
        return this.pass;
    }
}





- DatabaseHelper.java

package list.kpop;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "contacts";
    private static final String TABLE_NAME = "contacts";
    private static final String COLUMN_ID = "id";
    private static final String COLUMN_NAME = "name";
    private static final String COLUMN_EMAIL = "email";
    private static final String COLUMN_UNAME = "uname";
    private static final String COLUMN_PASS = "pass";
    SQLiteDatabase db;

    private static final String TABLE_CREATE = "create table contacts(id integer primary key not null, " +
            "name text not null, email text not null, uname text not null,pass text not null);";
    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
        this.db = db;
    }

    public void insertContact(list.kpop.Contact c) {
        db = this.getWritableDatabase();
        String query = "select * from contacts ";
        Cursor cursor = db.rawQuery(query, null);
        int count = cursor.getCount();
        ContentValues values = new ContentValues();
        values.put(COLUMN_ID, count);
        values.put(COLUMN_NAME, c.getName());
        values.put(COLUMN_EMAIL, c.getEmail());
        values.put(COLUMN_UNAME, c.getUname());
        values.put(COLUMN_PASS, c.getPass());
        db.insert(TABLE_NAME, null, values);
        db.close();
    }

    public String searchPass(String uname) {
        db = this.getReadableDatabase();
        String query = "select uname, pass from " + TABLE_NAME;
        Cursor cursor = db.rawQuery(query, null);
        String a, b;
        b = "not found";
        if (cursor.moveToFirst()) {
            do {
                a = cursor.getString(0);
                if (a.equals(uname)) {
                    b = cursor.getString(1);
                    break;
                }
            }
            while (cursor.moveToNext());
        }
        return b;
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String query = "DROP TABLE IF EXISTS " + TABLE_NAME;
        db.execSQL(query);
        this.onCreate(db);
    }
}



- Register.java


package list.kpop;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;


public class Register extends Activity {
    DatabaseHelper helper = new DatabaseHelper(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
    }
    public void onRegisterClick (View v)
    {
        if (v.getId()==R.id.Bregister)
        {
            EditText name = (EditText)findViewById(R.id.TFname);
            EditText email = (EditText)findViewById(R.id.TFemail);
            EditText uname = (EditText)findViewById(R.id.TFuname);
            EditText pass1 = (EditText)findViewById(R.id.TFpass1);
            EditText pass2 = (EditText)findViewById(R.id.TFpass2);

            String namestr = name.getText().toString();
            String emailstr = email.getText().toString();
            String unamestr = uname.getText().toString();
            String pass1str = pass1.getText().toString();
            String pass2str = pass2.getText().toString();

            if (namestr.length()==0)
            {
                name.setError("Nama kosong, mohon di isi");
            }

            else if (emailstr.length()==0)
            {
                email.setError("Email kosong, mohon di isi");
            }

            else if (unamestr.length()==0)
            {
                uname.setError("username kosong, mohon di isi");
            }
            else if (!pass1str.equals(pass2str))
            {
                Toast.makeText(Register.this, "Password Unmatch",
                        Toast.LENGTH_SHORT).show();
            }

            else{
                list.kpop.Contact c = new list.kpop.Contact();
                c.setName(namestr);
                c.setEmail(emailstr);
                c.setUname(unamestr);
                c.setPass(pass1str);
                helper.insertContact(c);
                finish();
                Toast.makeText(Register.this,
                        "Username & password berhasil dibuat",
                        Toast.LENGTH_SHORT).show();
            }
        }
    }
}



b. Design Listview

-activity_listkorea.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:background="@drawable/love"
    tools:context=".listkorea">

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </ListView>


</LinearLayout>


- listkorea.java


package list.kpop;

import androidx.appcompat.app.AppCompatActivity;

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

public class listkorea extends AppCompatActivity {

    ListView LV;
    String[] group = {"BTS", "BLACK PINK", "BLOCK B", "IKON", "ITZY",
            "KNK", "MAMAMOO", "MONSTA X", "RED VELVET", "SF9"};

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

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
// TODO Auto-generated method stub
                int itemke = arg2;
                String itemText = (String) LV.getItemAtPosition(arg2);
                Toast.makeText(getBaseContext(), "Anda Memilih " + itemText, Toast.LENGTH_LONG).show();

                if (itemText.equals("BTS")) {
                    Intent BTSIntent = new Intent(arg0.getContext(), bts.class);
                    startActivityForResult(BTSIntent, 0);
                } else if (itemText.equals("BLACK PINK")) {
                    Intent BLACKPINKIntent = new Intent(arg0.getContext(), blackpink.class);
                    startActivityForResult(BLACKPINKIntent, 0);
                } else if (itemText.equals("BLOCK B")) {
                    Intent BLOCKBIntent = new Intent(arg0.getContext(), blockb.class);
                    startActivityForResult(BLOCKBIntent, 0);
                } else if (itemText.equals("IKON")) {
                    Intent IKONIntent = new Intent(arg0.getContext(), ikon.class);
                    startActivityForResult(IKONIntent, 0);
                } else if (itemText.equals("ITZY")) {
                    Intent ITZYIntent = new Intent(arg0.getContext(), itzy.class);
                    startActivityForResult(ITZYIntent, 0);
                } else if (itemText.equals("KNK")) {
                    Intent KNKIntent = new Intent(arg0.getContext(), knk.class);
                    startActivityForResult(KNKIntent, 0);
                }  else if (itemText.equals("MAMAMOO")) {
                    Intent MAMAMOOIntent = new Intent(arg0.getContext(), mamamoo.class);
                    startActivityForResult(MAMAMOOIntent, 0);
                }  else if (itemText.equals("MONSTA X")) {
                    Intent MONSTAXIntent = new Intent(arg0.getContext(), monstax.class);
                    startActivityForResult(MONSTAXIntent, 0);
                }  else if (itemText.equals("RED VELVET")) {
                    Intent REDVELVETIntent = new Intent(arg0.getContext(), redvelvet.class);
                    startActivityForResult(REDVELVETIntent, 0);
                }  else if (itemText.equals("SF9")) {
                    Intent SF9Intent = new Intent(arg0.getContext(), sf9.class);
                    startActivityForResult(SF9Intent, 0);
                }
            }

        });

    }
}



- bts.java


package list.kpop;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class bts extends AppCompatActivity {

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


- Hasil RUN





- Lampiran Lembar Soal UAS



Demikian postingan kali ini, semoga bermanfaat, atas salah dan kurangnya saya mohon maaf.
Terimakasih. 

Wassalamualaikum Wr. Wb.


Tidak ada komentar:

Posting Komentar

TUGAS/UAS/MOBILE_PROGRAMMING

TUGAS UAS MOBILE PROGRAMMING MEMBUAT APLIKASI TERKONEKSI DATABASE SQLITE PADA ANDROID STUDIO "LIST GROUP KPOP" Assalamuala...