Client Server Part_11

1. TampilanAwal.java

package com.example.pmb_poligon;



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

public class TampilanAwal extends Activity {

Button login;
Button daftar;
Button alur;
Button info;
Button kontak;

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

login = (Button)findViewById(R.id.btn_masuk);
daftar = (Button)findViewById(R.id.btn_daftar);
alur = (Button)findViewById(R.id.btn_alur);
info = (Button)findViewById(R.id.btn_info);
kontak = (Button)findViewById(R.id.btn_kontak);

login.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),Login.class);
startActivity(i);
// TODO Auto-generated method stub

}
});

daftar.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),Pendaftaran_Step_1.class);
startActivity(i);
// TODO Auto-generated method stub

}
});

alur.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),Alur.class);
startActivity(i);
// TODO Auto-generated method stub

}
});

info.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),Informasi.class);
startActivity(i);
// TODO Auto-generated method stub

}
});

kontak.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),Kontak.class);
startActivity(i);
// TODO Auto-generated method stub

}
});
}

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

}


2. TampilanAwal.xml

<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"
    android:background="@drawable/bg"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".TampilanAwal" >

    <TextView
        android:id="@+id/logopmb"
        android:layout_width="290dp"
        android:layout_height="70dp"
        android:layout_alignRight="@+id/btn_reg"
        android:layout_below="@+id/btn_reg"
        android:layout_marginRight="1dp"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="50dp"
        android:background="@drawable/logopmb" />

    <Button
        android:id="@+id/btn_daftar"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_alignLeft="@+id/logopmb"
        android:layout_below="@+id/logopmb"
        android:layout_marginTop="35dp"
        android:background="@drawable/pendaftaran" />

    <Button
        android:id="@+id/btn_kontak"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_alignBaseline="@+id/btn_info"
        android:layout_alignBottom="@+id/btn_info"
        android:layout_toRightOf="@+id/btn_daftar"
        android:background="@drawable/kontak" />

    <Button
        android:id="@+id/btn_info"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_alignLeft="@+id/btn_daftar"
        android:layout_below="@+id/btn_daftar"
        android:background="@drawable/info" />

    <Button
        android:id="@+id/btn_alur"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_above="@+id/btn_kontak"
        android:layout_toRightOf="@+id/btn_daftar"
        android:background="@drawable/alur1" />

    <Button
        android:id="@+id/btn_masuk"
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_marginTop="1dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/login"
        android:textColor="#00cccc"
        android:textSize="10dp"
        android:textStyle="bold" />

</RelativeLayout>

3. PendaftaranStep_1.java

package com.example.pmb_poligon;

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

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;


import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
public class Pendaftaran_Step_1 extends Activity {

EditText nama_lengkap,nisn,nama_sekolah,alamat_sekolah,tahun_lahir,anak_ke,jumlah_saudara,penyakit,alamat_rumah,no_telp;
RadioGroup jk,status_perkawinan;
Spinner spiner1, spiner2;
DatePickerDialog datePickerDialog;
SimpleDateFormat dateFormatter;
TextView tvDateResult,status;
Button btDatePicker,saveandnext;

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pendaftaran__step_1);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy); 
nama_lengkap=(EditText)findViewById(R.id.add_new_nama);
nisn=(EditText)findViewById(R.id.add_new_nisn);
nama_sekolah=(EditText)findViewById(R.id.add_new_nama_sekolah);
alamat_sekolah=(EditText)findViewById(R.id.add_new_alamat_sekolah);
tahun_lahir=(EditText)findViewById(R.id.tv_dateresult);
jk=(RadioGroup)findViewById(R.id.rg_gender);
spiner1=(Spinner)findViewById(R.id.spiner1);
spiner2=(Spinner)findViewById(R.id.spiner2);
status_perkawinan=(RadioGroup)findViewById(R.id.rg_status_kawin);
anak_ke=(EditText)findViewById(R.id.add_new_anak_ke);
jumlah_saudara=(EditText)findViewById(R.id.add_new_jumlah_saudara);
penyakit=(EditText)findViewById(R.id.add_new_penyakit);
alamat_rumah=(EditText)findViewById(R.id.add_new_alamat_rumah);
no_telp=(EditText)findViewById(R.id.add_new_no_telp);
saveandnext=(Button)findViewById(R.id.btn_saveandnext); 
status=(TextView)findViewById(R.id.txtstatus);
/**
         * Kita menggunakan format tanggal dd-MM-yyyy
         * jadi nanti tanggal nya akan diformat menjadi
         * misalnya 01-12-2017
         */
        dateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);

        tvDateResult = (TextView) findViewById(R.id.tv_dateresult);
        btDatePicker = (Button) findViewById(R.id.bt_datepicker);
        
        btDatePicker.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDateDialog();
            }
        });
        
        saveandnext.setOnClickListener(new View.OnClickListener() {
       
       
   
    @Override
    public void onClick(View v) {
    Intent a=new Intent(getApplicationContext(),Pendaftaran_Step_2.class);
    startActivity(a);
   
   
   
    // TODO Auto-generated method stub
             
            //atur variabel utk menampung pilihan jenis kelamin
            String type0=null;
            switch (jk.getCheckedRadioButtonId()) {
            case R.id.rb_male:
            type0="Pria";
            break;
            case R.id.rb_female:
            type0="Perempuan";
            break;
            }
             
             
      
             
            String type3=null;
            switch (status_perkawinan.getCheckedRadioButtonId()) {
            case R.id.rb_kawin:
            type3="Kawin";
            break;
            case R.id.rb_belum:
            type3="Belum Kawin";
            break;
            }
   
    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("nama_lengkap", nama_lengkap.getText().toString()));
                postParameters.add(new BasicNameValuePair("nisn", nisn.getText().toString()));
                postParameters.add(new BasicNameValuePair("nama_sekolah", nama_sekolah.getText().toString()));
                postParameters.add(new BasicNameValuePair("alamat_sekolah", alamat_sekolah.getText().toString()));
                postParameters.add(new BasicNameValuePair("tahun_lahir", tahun_lahir.getText().toString()));
                postParameters.add(new BasicNameValuePair("jenis_kelamin", type0));
                postParameters.add(new BasicNameValuePair("agama", spiner1.getSelectedItem().toString()));
                postParameters.add(new BasicNameValuePair("gol_darah", spiner2.getSelectedItem().toString()));
                postParameters.add(new BasicNameValuePair("status_perkawinan", type3));
                postParameters.add(new BasicNameValuePair("anak_ke", anak_ke.getText().toString()));
                postParameters.add(new BasicNameValuePair("jumlah_saudara", jumlah_saudara.getText().toString()));
                postParameters.add(new BasicNameValuePair("penyakit", penyakit.getText().toString()));
                postParameters.add(new BasicNameValuePair("alamat_rumah", alamat_rumah.getText().toString()));
                postParameters.add(new BasicNameValuePair("no_telp", no_telp.getText().toString()));
                
                /*            String valid = "1";*/      
                
                String response = null;
                
                try {
                   
                   response = CustomHttpClient.executeHttpPost("http://192.168.100.27/pmb/step1.php", postParameters);
                   
                   String res = response.toString();
                   
                   res = res.trim();
                   
                   res = res.replaceAll("\\s+","");
                   
                   status.setText(res);
                   
                   if (res.equals("1")) status.setText("Data tidak Tersimpan Ke server");
                   
                   else status.setText("");
                   
                }
                
                catch (Exception e) {
                   
                   nama_lengkap.setText(e.toString());
                   
                }
                   
             }
                
   
                
          });
}

private void showDateDialog(){

        /**
         * Calendar untuk mendapatkan tanggal sekarang
         */
        Calendar newCalendar = Calendar.getInstance();

        /**
         * Initiate DatePicker dialog
         */
        datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

                /**
                 * Method ini dipanggil saat kita selesai memilih tanggal di DatePicker
                 */

                /**
                 * Set Calendar untuk menampung tanggal yang dipilih
                 */
                Calendar newDate = Calendar.getInstance();
                newDate.set(year, monthOfYear, dayOfMonth);

                /**
                 * Update TextView dengan tanggal yang kita pilih
                 */
                tvDateResult.setText(dateFormatter.format(newDate.getTime()));
            }

        },newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));

        /**
         * Tampilkan DatePicker dialog
         */
        datePickerDialog.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.pendaftaran__step_1, menu);
return true;
}

}


4. PendaftaranStep_1.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    tools:context=".FormMahasiswa"
     android:id="@+id/scrollView1"
     android:background="#ffffff"
     android:layout_width="match_parent"
     android:layout_height="wrap_content" >

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="#ffffff"
         android:orientation="vertical" >
   
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:layout_marginLeft="10dp"
        android:textSize="20dp"
        android:text="DATA PRIBADI" />
         
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nama Lengkap" />

    <EditText
        android:id="@+id/add_new_nama"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="nama lengkap"
        android:layout_marginBottom="30dp"
        android:ems="10" >
        <requestFocus />
    </EditText>
         
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NISN" />

    <EditText
        android:id="@+id/add_new_nisn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="nomor induk siswa nasional"
        android:inputType="number"
        android:layout_marginBottom="30dp"
        android:ems="10" />
        
  
    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nama Sekolah" />

    <EditText
        android:id="@+id/add_new_nama_sekolah"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="nama sekolah"
        android:layout_marginBottom="30dp"
        android:ems="10" />
    
    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Alamat Sekolah" />

    <EditText
         android:id="@+id/add_new_alamat_sekolah"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="80dp"
        android:hint="alamat sekolah"
        android:inputType="textPostalAddress"
        android:layout_marginBottom="30dp"
        android:ems="10" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:text="Tahun Lahir" />
   
    <Button
        android:id="@+id/bt_datepicker"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="end"
        android:layout_margin="1dp"
        android:background="@drawable/date"
        android:textColor="#00cccc" />

    <EditText
        android:id="@+id/tv_dateresult"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:ems="10"
        android:hint="tahun lahir" />
    
    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Jenis Kelamin"
        android:layout_marginBottom="5dp" />

    <RadioGroup
        android:id="@+id/rg_gender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

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

        <RadioButton
            android:id="@+id/rb_female"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Perempuan"
            android:layout_marginBottom="30dp"
        android:ems="10" />
    </RadioGroup>
    
    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Agama" />

    <Spinner 
        android:id="@+id/spiner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/agama_array"
        android:prompt="@string/agama"
        android:layout_marginBottom="30dp"
        android:ems="10"/>
    
    <TextView
        android:id="@+id/textView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Golongan Darah"
        android:layout_marginBottom="5dp" />

   <Spinner 
        android:id="@+id/spiner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/gol_darah_array"
        android:prompt="@string/gol_darah"
        android:layout_marginBottom="30dp"
        android:ems="10"/>
 
    
    <TextView
        android:id="@+id/textView10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Anak Ke-" />

    <EditText
        android:id="@+id/add_new_anak_ke"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="anank ke?"
        android:layout_marginBottom="30dp"
        android:ems="10" />
    
    <TextView
        android:id="@+id/textView11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Jumlah Saudara" />

    <EditText
        android:id="@+id/add_new_jumlah_saudara"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="jumlah saudara"
        android:inputType="number"
        android:layout_marginBottom="30dp"
        android:ems="10" />
    
    <TextView
        android:id="@+id/textView12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Penyakit Yang Di Derita" />

    <EditText
        android:id="@+id/add_new_penyakit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="penyakit yang di derita"
        android:layout_marginBottom="30dp"
        android:ems="10" />
    
    <TextView
        android:id="@+id/textView13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Status Perkawinan" />

    <RadioGroup
        android:id="@+id/rg_status_kawin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/rb_kawin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:text="Kawin" />

        <RadioButton
            android:id="@+id/rb_belum"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Belum Kawin"
            android:layout_marginBottom="30dp"
        android:ems="10" />
    </RadioGroup>
    
    <TextView
        android:id="@+id/textView14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Alamat Rumah" />

    <EditText
        android:id="@+id/add_new_alamat_rumah"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="alamat rumah"
        android:layout_marginBottom="30dp"
        android:ems="10" />
    
    <TextView
        android:id="@+id/textView15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No_Telepon" />

    <EditText
        android:id="@+id/add_new_no_telp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="no_telepon"
        android:inputType="number"
        android:layout_marginBottom="30dp"
        android:ems="10" />
    
    <Button
             android:id="@+id/btn_saveandnext"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginBottom="1dp"
             android:layout_marginLeft="20dp"
             android:layout_marginRight="20dp"
             android:layout_weight="1.73"
             android:background="@drawable/tombol"
             android:text="Save and Next"
             android:textColor="#00cccc"
             android:textSize="15dp"
             android:textStyle="bold" />

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

        </LinearLayout>
    </ScrollView>

Client Server Part_10


1. Registrasi.java

package com.example.pmb_poligon;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Registrasi extends Activity {

/** Called when the activity is first created. */

EditText email,username,password;
TextView status;
Button login,kelogin;


    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registrasi);
       
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy);
       
email=(EditText) findViewById(R.id.txtemail);
        username=(EditText) findViewById(R.id.txtusername);
        password=(EditText) findViewById(R.id.txtpassword);
        status=(TextView) findViewById (R.id.txtstatus);
       

     
        login=(Button) findViewById (R.id.btn_login);
        kelogin=(Button) findViewById (R.id.btn_ke_login);

        kelogin.setOnClickListener(new View.OnClickListener() {
            @Override
    public void onClick(View v) {
    Intent a=new Intent(getApplicationContext(),Login.class);
    startActivity(a);
            }
            });
     
        login.setOnClickListener(new View.OnClickListener() {
   
    @Override
    public void onClick(View v) {
   
   
    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("email", email.getText().toString()));
                postParameters.add(new BasicNameValuePair("username", username.getText().toString()));
                postParameters.add(new BasicNameValuePair("password", password.getText().toString()));
   
                /*            String valid = "1";*/     
               
                String response = null;
               
                try {
                 
                   response = CustomHttpClient.executeHttpPost("http://192.168.100.27/pmb/regis.php", postParameters);
                 
                   String res = response.toString();
                 
                   res = res.trim();
                 
                   res = res.replaceAll("\\s+","");
                 
                   status.setText(res);
                 
                   if (res.equals("1")) status.setText("Maaf!! Anda Belum Terdaftar");
                 
                 
                   else status.setText("Anda Sudah Terdaftar, Silahkan Login!");
                 
                }
               
                catch (Exception e) {
                 
                   username.setText(e.toString());
                 
                }
                 
             }
               
               
          });
     
     // penutup buka dari public void onCreate
    } 
       

 
   
 
}

2. Registrasi.xml

<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/bgs"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Login" >
    
    <LinearLayout
    android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" >
         
        <ImageView android:src="@drawable/logopmb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="2dp"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="10dp"/>
         
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Email" />

    <EditText
        android:id="@+id/txtemail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="italic"
        android:hint="contoh@gmail.com"
        android:layout_marginBottom="30dp"
        android:ems="10" >
        <requestFocus />
    </EditText>
    
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username" />

    <EditText
        android:id="@+id/txtusername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="username"
        android:layout_marginBottom="30dp"
        android:ems="10" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password" />

    <EditText
        android:id="@+id/txtpassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="password"
        android:inputType="textPassword"
        android:layout_marginBottom="30dp"
        android:ems="10" />
    
    <Button
        android:id="@+id/btn_login"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/tombol"
        android:layout_marginBottom="10dp"
        android:text="Daftar"
        android:textColor="#00cccc"
        android:textSize="20dp"
        android:textStyle="bold" 
        android:ems="10" 
        />
    <Button
        android:id="@+id/btn_ke_login"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/tombol"
        android:layout_marginBottom="10dp"
        android:text="Login"
        android:textColor="#00cccc"
        android:textSize="20dp"
        android:textStyle="bold" 
        android:ems="10" 
        />

    
     <TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="" />
    
</LinearLayout>
</ScrollView>


3. Splashscreen.java

package com.example.pmb_poligon;



import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;

public class Splash_Screen extends Activity {

//Set waktu lama splashscreen
   private static int splashInterval = 3000;
   
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.activity_splash__screen);

      new Handler().postDelayed(new Runnable() {
         @Override
         public void run() {
         // TODO Auto-generated method stub
            Intent i = new Intent(Splash_Screen.this, Login.class);
            startActivity(i);
            
            //jeda selesai Splashscreen
            this.finish();
          }

      private void finish() {
      // TODO Auto-generated method stub
      }
   }, splashInterval);
};

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

}


4. Splashscreen.xml

<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"
    android:background="#ffffff"
    tools:context=".Splash_Screen" >

   <ImageView 
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="@drawable/splash"/>

   <ProgressBar
       android:id="@+id/progressBar1"
       style="?android:attr/progressBarStyleLarge"
       android:layout_width="500dp"
       android:layout_height="50dp"
       android:layout_alignParentBottom="true"
       android:layout_centerHorizontal="true"
       android:layout_marginBottom="91dp" />

</RelativeLayout>

Client Server Part_9

1. CostumHttp.java

package com.example.pmb_poligon;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

public class CustomHttpClient {
/** The time it takes for our client to timeout */
    public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds

    /** Single instance of our HttpClient */
    private static HttpClient mHttpClient;

    /**
     * Get our single instance of our HttpClient object.
     *
     * @return an HttpClient object with connection parameters set
     */
    private static HttpClient getHttpClient() {
        if (mHttpClient == null) {
            mHttpClient = new DefaultHttpClient();
            final HttpParams params = mHttpClient.getParams();
            HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
            HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
            ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
        }
        return mHttpClient;
    }

    /**
     * Performs an HTTP Post request to the specified url with the
     * specified parameters.
     *
     * @param url The web address to post the request to
     * @param postParameters The parameters to send via the request
     * @return The result of the request
     * @throws Exception
     */
    public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            HttpPost request = new HttpPost(url);
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
            request.setEntity(formEntity);
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();

            String result = sb.toString();
            return result;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * Performs an HTTP GET request to the specified url.
     *
     * @param url The web address to post the request to
     * @return The result of the request
     * @throws Exception
     */
    public static String executeHttpGet(String url) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(url));
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();

            String result = sb.toString();
            return result;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

2. Login.java

package com.example.pmb_poligon;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;



import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
public class Login extends Activity {

/** Called when the activity is first created. */
EditText username,password;
TextView status;
Button login,daftar;


    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
       
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy);
       
        username=(EditText) findViewById(R.id.txtusername);
        password=(EditText) findViewById(R.id.txtpassword);
        status=(TextView) findViewById (R.id.txtstatus);
       

     
        login=(Button) findViewById (R.id.btn_login);
        daftar=(Button) findViewById (R.id.btn_regis);
       
        daftar.setOnClickListener(new View.OnClickListener() {
        @Override
public void onClick(View v) {
Intent a=new Intent(getApplicationContext(),Registrasi.class);
startActivity(a);
        }
        });
       
        login.setOnClickListener(new View.OnClickListener() {
           
            @Override
           
            public void onClick(View v) {
             
               // TODO Auto-generated method stub
             
               ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
             
               postParameters.add(new BasicNameValuePair("username", username.getText().toString()));
                 
               postParameters.add(new BasicNameValuePair("password", password.getText().toString()));
             
   /*            String valid = "1";*/     
             
               String response = null;
             
               try {
                 
                  response = CustomHttpClient.executeHttpPost("http://192.168.100.27/pmb/check.php", postParameters);
                 
                  String res = response.toString();
                 
                  res = res.trim();
                 
                  res = res.replaceAll("\\s+","");
                 
                  status.setText(res);
                 
                  if (res.equals("1"))
                  {
                   status.setText("");
                   berhasil(v);
                 
                  }
                  else {
                    status.setText("Maaf!! User Dan Password Salah");
                   
                       }
               }
             
               catch (Exception e) {
                 
                  status.setText(e.toString());
                 
               }
             
            }
           
            });
     
     // penutup buka dari public void onCreate
    } 
       

 
   
    public void daftar (View theButton)
    {
    Intent d = new Intent (this, Registrasi.class);
    startActivity(d);
    }
   

// apabila user berhasil login.
   
    public void berhasil (View theButton)
    {
    Intent s = new Intent (this, TampilanAwal.class);
    startActivity(s);
    }
   
}

3. Login.xml

<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/bgs"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Login" >
   
    <LinearLayout
    android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" >
       
        <ImageView android:src="@drawable/logopmb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="2dp"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="10dp"/>
       
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username" />

    <EditText
        android:id="@+id/txtusername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="username"
        android:layout_marginBottom="30dp"
        android:ems="10" >
        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password" />

    <EditText
        android:id="@+id/txtpassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="password"
        android:inputType="textPassword"
        android:layout_marginBottom="30dp"
        android:ems="10" />
   
    <Button
        android:id="@+id/btn_login"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/tombol"
        android:layout_marginBottom="10dp"
        android:text="Login"
        android:textColor="#00cccc"
        android:textSize="20dp"
        android:textStyle="bold"
        android:ems="10"
        />
   
    <Button
        android:id="@+id/btn_regis"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/tombol"
        android:layout_marginBottom="10dp"
        android:text="Registrasi"
        android:textColor="#00cccc"
        android:textSize="20dp"
        android:textStyle="bold"
        android:ems="10"
        />
   
     <TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="" />
   
</LinearLayout>
</ScrollView>



Client Server Part_8

Hay pada kesempatan kali ini saya akan membuat sebuah tampilan delivery diaplikasi rumah makan yang sudah saat buat sebelumnya. Untuk membuat tampilan ini ada baiknya kita desain dulu background, image button, dan image view agar supaya tampilan androidnya akan terlihat bagus.
Baiklah langsung saja saya akan menjelaskan proses order diaplikasi ini
Langkah pertama kita pilih dulu jenis rumah makan apa yang akan kita pilih

Setelah memilih rumah makan akan tampil menu dengan 2 pilihan makan di rumah makan dan delivery, klik delivery untuk pesan jarak jauh.


Untuk memesan makanan kita lihat dulu menu yang tersedia di paket dengan cara mengklik gambar kotak yang ada di layout. Didalam kotak itu ada penjelasan tentang isi paket.