Aplikasi Transfusi dan Donor Darah Berbasis Android

1

Android Manifest.Xml







android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"








































Activity_awal.xml












Universitas Sumatera Utara

4





awal.java
package com.example.root.bloodjobs;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Awal extends AppCompatActivity {

private ViewPager viewPager;

Universitas Sumatera Utara

5

private ViewPagerAdapter viewPagerAdapter;
private LinearLayout dotsLayout;
private TextView[] dots;
private int[] layouts;

private Button btnSkip, btnNext;

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

viewPager = (ViewPager) findViewById(R.id.view_pager);
dotsLayout = (LinearLayout) findViewById(R.id.layoutDots);
btnSkip = (Button) findViewById(R.id.btn_skip);
btnNext = (Button) findViewById(R.id.btn_next);

layouts = new int[]{
R.layout.activity_layar1,
R.layout.activity_layar2};

// adding bottom dots
addBottomDots(0);

viewPagerAdapter = new ViewPagerAdapter();

viewPager.setAdapter(viewPagerAdapter);

viewPager.addOnPageChangeListener(viewPagerPageChangeListener);

}

public

void btnSkipClick(View v)

{
launchHomeScreen();
}

Universitas Sumatera Utara

6

public


void btnNextClick(View v)

{
// checking for last page
// if last page home screen will be launched
int current = getItem(1);
if (current < layouts.length) {
// move to next screen
viewPager.setCurrentItem(current);
} else {
launchHomeScreen();
}
}

ViewPager.OnPageChangeListener viewPagerPageChangeListener =
new ViewPager.OnPageChangeListener() {

@Override
public void onPageSelected(int position) {
addBottomDots(position);


// changing the next button text 'NEXT' / 'GOT IT'
if (position == layouts.length - 1) {
// last page. make button text to GOT IT
btnNext.setText(getString(R.string.Start));
btnSkip.setVisibility(View.GONE);
} else {
// still pages are left
btnNext.setText(getString(R.string.next));
btnSkip.setVisibility(View.VISIBLE);
}
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {

Universitas Sumatera Utara

7


}

@Override
public void onPageScrollStateChanged(int arg0) {

}
};

private void addBottomDots(int currentPage) {
dots = new TextView[layouts.length];

dotsLayout.removeAllViews();
for (int i = 0; i < dots.length; i++) {
dots[i] = new TextView(this);
dots[i].setText(Html.fromHtml("•"));
dots[i].setTextSize(35);

dots[i].setTextColor(getResources().getColor(R.color.dot_inactive)
);
dotsLayout.addView(dots[i]);

}

if (dots.length > 0)

dots[currentPage].setTextColor(getResources().getColor(R.color.dot
_active));
}

private int getItem(int i) {
return viewPager.getCurrentItem() + i;
}

private void launchHomeScreen() {
startActivity(new Intent(this, Home.class));
finish();

Universitas Sumatera Utara

8


}

public class ViewPagerAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;

public ViewPagerAdapter() {

}

@Override
public Object instantiateItem(ViewGroup container, int
position) {
layoutInflater = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View view = layoutInflater.inflate(layouts[position],
container, false);
container.addView(view);

return view;
}

@Override
public int getCount() {
return layouts.length;
}

@Override
public boolean isViewFromObject(View view, Object obj) {
return view == obj;
}

@Override
public void destroyItem(ViewGroup container, int position,
Object object) {

Universitas Sumatera Utara

9

View view = (View) object;
container.removeView(view);
}
}
}
Bdarah.java
package com.example.root.bloodjobs;

import android.content.Intent;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class Bdarah extends AppCompatActivity {

TextView tvsk;

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

tvsk = (TextView)findViewById(R.id.sk);

tvsk.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
}

public void bdarah (View view){
Intent intent = new Intent(Bdarah.this,skbdarah.class);
startActivity(intent);
}
}
Activity_daftar.xml

Universitas Sumatera Utara

10

































































Universitas Sumatera Utara

18




Daftar.java
package com.example.root.bloodjobs;

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

public class Daftar extends AppCompatActivity {

TextView textView,textView2,textView9,sk;

EditText
edtnama,edtalamat,edtjk,edttgl,edtusia,edtnotelp,edtrhesus,edtgold
ar
,edtemail,edtpassword,edtline,edtwa,edtbbm,edtlain;
Button btndaftar;
String
snama,salamat,sjk,stgl,susia,snotelp,srhesus,sgoldar,semail,spassw
ord,sline,swa,sbbm,slain;

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

edtnama=(EditText)findViewById(R.id.edtnama);
edtalamat=(EditText)findViewById(R.id.edtalamat);

Universitas Sumatera Utara

19

edtjk=(EditText)findViewById(R.id.edtjk);
edttgl=(EditText)findViewById(R.id.edttgl);
edtusia=(EditText)findViewById(R.id.edtusia);
edtnotelp=(EditText)findViewById(R.id.edtnotelp);
edtrhesus=(EditText)findViewById(R.id.edtrhesus);
edtgoldar=(EditText)findViewById(R.id.edtgoldar);
edtemail=(EditText)findViewById(R.id.edtemail);
edtpassword=(EditText)findViewById(R.id.edtpassword);
edtline=(EditText)findViewById(R.id.edtline);
edtwa=(EditText)findViewById(R.id.edtwa);
edtbbm=(EditText)findViewById(R.id.edtbbm);
edtlain=(EditText)findViewById(R.id.edtlain);
btndaftar=(Button)findViewById(R.id.btndaftar);

String customFont = "Alegreya.ttf";
String customBold ="Alegreya-Bold.ttf";

Typeface typeface = Typeface.createFromAsset(getAssets(),
customFont);
Typeface typeface1 = Typeface.createFromAsset(getAssets(),
customBold);

textView=(TextView)findViewById(R.id.textView);
textView.setTypeface(typeface1);

textView2=(TextView)findViewById(R.id.textView2);
textView2.setTypeface(typeface1);

textView9=(TextView)findViewById(R.id.textView9);
textView9.setTypeface(typeface1);

sk=(TextView)findViewById(R.id.sk);
sk.setTypeface(typeface1);

}

Universitas Sumatera Utara

20

public void daftar (View view){

snama=edtnama.getText().toString();
salamat=edtalamat.getText().toString();
sjk=edtjk.getText().toString();
stgl=edttgl.getText().toString();
susia=edtusia.getText().toString();
snotelp=edtnotelp.getText().toString();
srhesus=edtrhesus.getText().toString();
sgoldar=edtgoldar.getText().toString();
semail=edtemail.getText().toString();
spassword=edtpassword.getText().toString();
sline=edtline.getText().toString();
swa=edtwa.getText().toString();
sbbm=edtline.getText().toString();
slain=edtlain.getText().toString();

String method ="register";
Proses proses = new Proses(this);

proses.execute(method,snama,salamat,sjk,stgl,susia,snotelp,srhesus
,sgoldar,semail,
spassword,sline,swa,sbbm,slain);
}

boolean doubleBackToExitPressedOnce = false;
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
Intent intent = new Intent(Daftar.this,HomeRelawan.class);
startActivity(intent);
return;
}
this.doubleBackToExitPressedOnce = true;
new Handler().postDelayed(new Runnable() {
@Override

Universitas Sumatera Utara

21

public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}

public void bdarah (View view){
Intent intent = new Intent(Daftar.this,skbdarah.class);
startActivity(intent);
}
}

Activity_donor.xml









Donor.java
package com.example.root.bloodjobs;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

public class Donor extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

NavigationView navigationView = null;
Toolbar toolbar = null;

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

//set initial fragment

tampilanContent tampilanContent = new tampilanContent();

Universitas Sumatera Utara

23

android.support.v4.app.FragmentTransaction
fragmentTransaction = getSupportFragmentManager()
.beginTransaction();

fragmentTransaction.replace(R.id.content_donor,tampilanContent);
fragmentTransaction.commit();

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

DrawerLayout drawer = (DrawerLayout)
findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout)
findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
finish();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it
is present.

Universitas Sumatera Utara

24

getMenuInflater().inflate(R.menu.donor, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Intent intent = new Intent(Donor.this,Daftar.class);
startActivity(intent);
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.nav_donor) {
DonorDarah donorDarah = new DonorDarah();
FragmentManager manager = getSupportFragmentManager();

manager.beginTransaction().replace(R.id.content_donor,donorDarah,d
onorDarah.getTag()).commit();
} else if (id == R.id.nav_transfusi) {
Transfusi transfusi = new Transfusi();
FragmentManager manager = getSupportFragmentManager();

manager.beginTransaction().replace(R.id.content_donor,transfusi,tr

Universitas Sumatera Utara

25

ansfusi.getTag()).commit();
} else if (id == R.id.nav_about) {
tentang tentang = new tentang();
FragmentManager manager = getSupportFragmentManager();

manager.beginTransaction().replace(R.id.content_donor,tentang,tent
ang.getTag()).commit();

} else if (id == R.id.nav_kontak) {
kontak kontak = new kontak();
FragmentManager manager = getSupportFragmentManager();

manager.beginTransaction().replace(R.id.content_donor,kontak,konta
k.getTag()).commit();
} else if (id == R.id.nav_goldar) {
tampilanContent tampilanContent = new tampilanContent();
FragmentManager manager = getSupportFragmentManager();

manager.beginTransaction().replace(R.id.content_donor,tampilanCont
ent,tampilanContent.getTag()).commit();
} else if (id == R.id.nav_kamus) {
Intent intent = new Intent(Donor.this,kamus.class);
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout)
findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

}

Fragment_donor_darah.xml

Universitas Sumatera Utara

26
















Universitas Sumatera Utara

28
















































DonorDarah.java
package com.example.root.bloodjobs;

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

Universitas Sumatera Utara

35

import android.widget.TextView;

/**
* A simple {@link Fragment} subclass.
*/
public class DonorDarah extends Fragment {

public DonorDarah() {
// Required empty public construct
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup
container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_donor_darah,
container, false);
Typeface myTypeface =
Typeface.createFromAsset(getActivity().getAssets(),
"Alegreya.ttf");
Typeface myTypeface1 =
Typeface.createFromAsset(getActivity().getAssets(),
"Alegreya-Bold.ttf");
TextView tv = (TextView) view.findViewById(R.id.textView4);
tv.setTypeface(myTypeface);

TextView tv1 = (TextView) view.findViewById(R.id.textView5);
tv1.setTypeface(myTypeface1);

TextView tv61 = (TextView) view.findViewById(R.id.textView61);
tv61.setTypeface(myTypeface1);

TextView tme1 = (TextView) view.findViewById(R.id.txtme1);
tme1.setTypeface(myTypeface);

Universitas Sumatera Utara

36

TextView tme2 = (TextView) view.findViewById(R.id.txtme2);
tme2.setTypeface(myTypeface);
TextView tme3 = (TextView) view.findViewById(R.id.txtme3);
tme3.setTypeface(myTypeface);
TextView tme4 = (TextView) view.findViewById(R.id.txtme4);
tme4.setTypeface(myTypeface);
TextView tme5 = (TextView) view.findViewById(R.id.txtme5);
tme5.setTypeface(myTypeface);
TextView tme6 = (TextView) view.findViewById(R.id.txtme6);
tme6.setTypeface(myTypeface);
TextView tme7 = (TextView) view.findViewById(R.id.txtme7);
tme7.setTypeface(myTypeface);
TextView tme8 = (TextView) view.findViewById(R.id.txtme8);
tme8.setTypeface(myTypeface);

TextView tv2 = (TextView) view.findViewById(R.id.txtm1);
tv2.setTypeface(myTypeface);

TextView tv3 = (TextView) view.findViewById(R.id.txtm2);
tv3.setTypeface(myTypeface);

TextView tv4 = (TextView) view.findViewById(R.id.txtm3);
tv4.setTypeface(myTypeface);

TextView tv5 = (TextView) view.findViewById(R.id.txtm4);
tv5.setTypeface(myTypeface);

TextView tv6 = (TextView) view.findViewById(R.id.txtm5);
tv6.setTypeface(myTypeface);

TextView tv7 = (TextView) view.findViewById(R.id.textView6);
tv7.setTypeface(myTypeface1);

TextView tv8 = (TextView) view.findViewById(R.id.txts1);
tv8.setTypeface(myTypeface);

Universitas Sumatera Utara

37

TextView tv9 = (TextView) view.findViewById(R.id.txts2);
tv9.setTypeface(myTypeface);

TextView tv10 = (TextView) view.findViewById(R.id.txts3);
tv10.setTypeface(myTypeface);

TextView tv11 = (TextView) view.findViewById(R.id.txts4);
tv11.setTypeface(myTypeface);

TextView tv12 = (TextView) view.findViewById(R.id.txts5);
tv12.setTypeface(myTypeface);

return view;
}

}

Activity_home.xml
























Home.java
package com.example.root.bloodjobs;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

public class Home extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Universitas Sumatera Utara

40

setContentView(R.layout.activity_home);
}

boolean doubleBackToExitPressedOnce = false;
@Override
public void onBackPressed() {
Toast.makeText(getApplicationContext(), "Ketuk dua kali untuk
keluar", Toast.LENGTH_SHORT).show();
if (doubleBackToExitPressedOnce) {
moveTaskToBack(true);
}
this.doubleBackToExitPressedOnce = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}

public void menu (View view){
Intent intent = new Intent(Home.this,Donor.class);
startActivity(intent);
}

public void relwan (View view){
Intent intent = new Intent(Home.this,Tap.class);
startActivity(intent);
}

}

Home_relawan.xml






















Universitas Sumatera Utara

43






HomeRelawan.java
package com.example.root.bloodjobs;

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

public class HomeRelawan extends AppCompatActivity {

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

public void profil (View view){
Intent intent = new Intent(HomeRelawan.this,profil.class);
startActivity(intent);
}

public void relawan (View view){
Intent intent = new

Universitas Sumatera Utara

44

Intent(HomeRelawan.this,kontak_relawan.class);
startActivity(intent);
}

public void back (View view){
Intent intent = new Intent(HomeRelawan.this,Home.class);
startActivity(intent);
}

public void jadirelawan (View view){
Intent intent = new Intent(HomeRelawan.this,Daftar.class);
startActivity(intent);
}

}

Activity_kamus.xml
















Kamus.java
package com.example.root.bloodjobs;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

public class kamus extends ListActivity {

ArrayList searchResults;

ArrayList originalValues;

LayoutInflater inflater;

@Override
public void onCreate(Bundle savedInstanceState) {

Universitas Sumatera Utara

47

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_kamus);
final EditText kotakpencari=(EditText)
findViewById(R.id.kotakpencari);
ListView playersListView=(ListView)
findViewById(android.R.id.list);

//mengambil LayoutInflater untuk inflating thcustomView
//disini akan menggunakan custom adapter
inflater=(LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);

//disini data aray akan di deklarasikan
//dan akan disimpan ke dalam Arraylist
//tipe data string untuk textview integer untuk gambar icon
String namakamus[]={"Plasma","Sel Darah
Merah","Darah","Hemoglobin","Sel Darah Putih","Rhesus"
,"Transfusi Darah","Golongan Darah"};
String penjelasan[]={"","","","","","","",""};

originalValues=new ArrayList();

//hasmap akan menyimpan data sementara dalam listview
HashMap temp;

//jumlah baris dalam ListView
int noOfPlayers=namakamus.length;

//pengulangan dalam Arraylist
for(int i=0;i