LAYOUT MENU UTAMA
<Button android:id="@+id/profesi" android:text="Zakat Profesi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginRight="1dip" android:width="250dip"/> <Button android:id="@+id/niaga" android:text="Zakat Perdagangan" android:layout_width="wrap_content"
Universitas Sumatera Utara
android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:width="250dip"/>
LAYOUT ZAKAT PROFESI <ScrollView xmlns:android="http://schemas.android.com/apk/res/ android" android:id="@+id/scrollView" android:layout_width="fill_parent" android:layout_height="fill_parent" >
<EditText android:text="" android:id="@+id/txtGaji" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="numberSigned|numberDecimal"/>
Universitas Sumatera Utara
android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bonus pertahun:" /> <EditText android:text="" android:id="@+id/txtBonus" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="numberSigned|numberDecimal"/> <Button android:text="Hitung" android:id="@+id/btnHitung" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="hitungZakat"/> <EditText android:text="" android:id="@+id/txtzakat" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="numberSigned|numberDecimal" android:enabled="false"/> <Button android:text="Kembali ke Menu" android:id="@+id/btnBack" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="backtoMenu"/>
Universitas Sumatera Utara
LAYOUT ZAKAT PERDAGANGAN <ScrollView xmlns:android="http://schemas.android.com/apk/res/ android" android:id="@+id/scrollView" android:layout_width="fill_parent" android:layout_height="fill_parent" >
<EditText android:text="" android:id="@+id/txtKekayaan" android:inputType="numberSigned|numberDecimal" android:width="120dip" android:layout_height="match_parent" android:layout_width="60dip"/> <EditText android:text=""
Universitas Sumatera Utara
android:id="@+id/txtHutang" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="numberSigned|numberDecimal"/> <EditText android:text="" android:id="@+id/txtKepemilikan" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="numberSigned|numberDecimal"/> <Button android:text="Hitung" android:id="@+id/btnHitung" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="hitungNiaga"/> <EditText android:text="" android:id="@+id/txtJmlBersih" android:layout_width="fill_parent" android:layout_height="wrap_content" android:editable="false" android:enabled="false"/>
Universitas Sumatera Utara
android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:text="" android:id="@+id/txtJmlZakat" android:layout_width="fill_parent" android:layout_height="wrap_content" android:editable="false" android:enabled="false"/> <Button android:text="Kembali ke Menu" android:id="@+id/btnBack" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="backtoMenu"/>
Source Code Java MENU package com.example.urlgrabber; import java.io.IOException; import import import import import
org.apache.http.HttpResponse; org.apache.http.client.HttpClient; org.apache.http.client.methods.HttpGet; org.apache.http.impl.client.DefaultHttpClient; org.apache.http.util.EntityUtils;
import import import import import import
android.app.Activity; android.content.Intent; android.os.Bundle; android.view.View; android.widget.Button; android.widget.TextView;
public class urlgrabber extends Activity { /** Called when the activity is first created. */ private TextView txtemas; private TextView txtnisab; public Button niaga;
Universitas Sumatera Utara
public Button profesi; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtemas = (TextView) findViewById(R.id.txtemas); txtnisab = (TextView) findViewById(R.id.txtnisab); Button profesi = (Button)findViewById(R.id.profesi); Button niaga = (Button)findViewById(R.id.niaga);
profesi.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent j = new Intent(urlgrabber.this, HitungProfesi.class); j.putExtra("pesan",txtnisab.getText()); startActivity(j); } }); niaga.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent k = new Intent(urlgrabber.this, HitungNiaga.class); k.putExtra("pesan",txtnisab.getText()); startActivity(k); } }); String html = null; try { html = getURLHttpGet("http://kurs.dollar.web.id/harga-emashari-ini.php");
Universitas Sumatera Utara
//html = getURLHttpGet("http://www.emas24karat.com/news.asp"); } catch (IOException e) { e.printStackTrace(); } parseHTML(html); } private void parseHTML(String html) { // TODO Auto-generated method stub String[] parts, parts2; // Ambil harga emas dollar.web.id parts=html.split("
"); parts2 = parts[1].split(" | "); txtemas.setText(parts2[0].replace(".","")); //Ambil emas dr emas24karat.com //parts=html.split("
"); //parts2 = parts[1].split(""); //String ambil = (parts2[0].replace(" ","")); //String awal = (ambil.substring(0, 3)); //String akhir = (ambil.substring(4)); //txtemas.setText(awal+akhir); //String emas = txtemas.getText().toString(); long nisab1 = Long.valueOf(txtemas.getText().toString()); long nisab2 = nisab1*85; txtnisab.setText(String.valueOf(nisab2)); } private String getURLHttpGet(String url) throws IOException { // TODO Auto-generated method stub HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); String responseBody = EntityUtils.toString(response.getEntity()); return responseBody;
Universitas Sumatera Utara
} }
ZAKAT PROFESI package com.example.urlgrabber; import import import import import import import
android.app.Activity; android.content.Intent; android.os.Bundle; android.view.View; android.widget.Button; android.widget.EditText; android.widget.Toast;
public class HitungProfesi extends Activity { private EditText txtGaji; private EditText txtBonus; private EditText txtzakat; public Button btnHitung; /** * Method yang dipanggil pada saat applikaasi dijalankan * */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.prof); txtGaji = (EditText) findViewById(R.id.txtGaji); txtBonus= (EditText) findViewById(R.id.txtBonus); txtzakat= (EditText) findViewById(R.id.txtzakat); btnHitung = (Button)findViewById(R.id.btnHitung); } /** * Method untuk Menghitung Luas Persegi panjang dipanggil pada saat button
Universitas Sumatera Utara
* Hitung Luas diklik * * @param view */ public void hitungZakat(View view) { try { long gaji = Integer.parseInt(txtGaji.getText().toString()); long bonus = Integer.parseInt(txtBonus.getText().toString()); long jmlgajisetahun = gaji * 12; long jmltotal = jmlgajisetahun + bonus ; Intent j = this.getIntent(); long nisab = Long.valueOf((j.getStringExtra("pesan"))); if (jmltotal > nisab){ double zakat = (2.5 / 100) * jmltotal; txtzakat.setEnabled(true); txtzakat.setText("Rp."+String.valueOf(zakat)); }else{ Toast.makeText(this,"belum mencapai Nisab", Toast.LENGTH_LONG).show(); } //finish(); } catch (Exception e) { e.printStackTrace(); } } /** * Method untuk menutup activity dan kembali ke menu * @param view */ public void backtoMenu(View view){ finish(); } }
Universitas Sumatera Utara
PZAKAT PERDAGANGAN package com.example.urlgrabber; import import import import import import import
android.app.Activity; android.content.Intent; android.os.Bundle; android.view.View; android.widget.Button; android.widget.EditText; android.widget.Toast;
public class HitungNiaga extends Activity { private EditText txtKekayaan; private EditText txtHutang; private EditText txtKepemilikan; private EditText txtJmlBersih; private EditText txtJmlZakat; public Button btnHitung; /** * Method yang dipanggil pada saat applikaasi dijalankan * */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.niaga); //Zakatapp ambil = ((Zakatapp)getApplicationContext()); txtKekayaan = (EditText) findViewById(R.id.txtKekayaan); txtHutang= (EditText) findViewById(R.id.txtHutang); txtKepemilikan= (EditText) findViewById(R.id.txtKepemilikan); txtJmlBersih= (EditText) findViewById(R.id.txtJmlBersih); txtJmlZakat= (EditText) findViewById(R.id.txtJmlZakat); btnHitung = (Button)findViewById(R.id.btnHitung);
Universitas Sumatera Utara
} public void hitungNiaga(View view) { try { if (txtKekayaan.getText().length() == 0) { Toast.makeText(this,"Silahkan isi Angka yang benar!", Toast.LENGTH_LONG).show(); return; } if (txtHutang.getText().length() == 0) { Toast.makeText(this,"Silahkan isi Angka yang benar!", Toast.LENGTH_LONG).show(); return; } if (txtKepemilikan.getText().length() == 0) { Toast.makeText(this,"Silahkan isi Angka yang benar!", Toast.LENGTH_LONG).show(); return; } long kekayaan = Integer.parseInt(txtKekayaan.getText().toString()); long hutang = Integer.parseInt(txtHutang.getText().toString()); long kepemilikan = Integer.parseInt(txtKepemilikan.getText().toString()); long jmlbersih =( kepemilikan/100)*(kekayaan-hutang); Intent k = this.getIntent(); long nisab = Long.valueOf((k.getStringExtra("pesan"))); if (jmlbersih > nisab){ double zakat = (2.5 / 100) * jmlbersih; txtJmlBersih.setEnabled(true); txtJmlZakat.setEnabled(true); txtJmlBersih.setText(String.valueOf("Rp "+jmlbersih)); txtJmlZakat.setText("Rp. "+String.valueOf(zakat)); }else{ Toast.makeText(this,"belum mencapai nisab", Toast.LENGTH_LONG).show(); } //finish(); } catch (Exception e) { e.printStackTrace();
Universitas Sumatera Utara
} } /** * Method untuk menutup activity dan kembali ke menu * @param view */ public void backtoMenu(View view){ finish(); } }
Universitas Sumatera Utara