LISTING PROGRAM
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
ActivityMainBinding binding =
DataBindingUtil.setContentView(MainActivity.this, R.layout.activity_main);
GeneralHandler handler = new GeneralHandler(MainActivity.this); binding.setHandler(handler);
public class LokasiActivity extends AppCompatActivity {
final int GPS_PERMISSION = 1; MapFragment mapFragment; GoogleMap map;
Location mLastLocation;
LocationManager mLocationManager; Button btnSetLokasi;
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lokasi);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true); btnSetLokasi = (Button) findViewById(R.id.btn_set_lokasi); btnSetLokasi.setOnClickListener(new View.OnClickListener() { @Override
ActivityCompat.requestPermissions(LokasiActivity.this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION,
lng = mLastLocation.getLongitude(); map.addMarker(new MarkerOptions() .draggable(true)
.position(new
LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude())) .title("Posisi Anda"));
map.animateCamera(CameraUpdateFactory.newCameraPosition(position), null); }
private Location getLastKnownLocation() {
mLocationManager = (LocationManager)
getApplicationContext().getSystemService(LOCATION_SERVICE);
import android.support.v4.app.Fragment;
public class HasilActivity extends AppCompatActivity {
List<Node> allNode;
List<Connection> allConnection; Rute rute;
/*
* Limit titik bertujuan untuk menentukan berapa titik terdekat * yang akan dianggap sebagai tetangga dari sebuah node
*/
ListRouteFragment listRouteFragment; Double jarak = 0.0;
long waktu = 0; @Override
import android.widget.Button;
public class HalamanPencarian extends AppCompatActivity {
private final int ALGORITMA_GREEDY = 0;
private final int ALGORITMA_FLOYD = 1;
private Integer idTujuan, algo; List<Node> allNode;
List<Connection> allConnection; Button btnSearch;
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true); setContentView(R.layout.activity_halaman_pencarian);
spinnerAlgo = (Spinner) findViewById(R.id.spinner_algoritma); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, algoritma);
spinnerAlgo.setAdapter(adapter);
spinnerAlgo.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
spinnerTujuan.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) {
Log.d("RESULT_OK", "Latitude : " + data.getDoubleExtra("lat",
0) + " Longitude : " + data.getDoubleExtra("lng", 0)); TextView textView = (TextView)
findViewById(R.id.tv_position);
latitude = data.getDoubleExtra("lat", 0); longitude = data.getDoubleExtra("lng", 0);
String teks = "Lat : " + String.format("%.2f", latitude) + " Long : " + String.format("%.2f", longitude);
protected Object doInBackground(Object[] params) {
* Created by codetorium on 13/05/17. */
public class Rute implements Serializable {
List<Node> rute;
nama = "";
public void setTetangga(List<Node> tetangga) { this.tetangga = tetangga;
}
public double euclidean(Node a, Node b){
double derajatKeKM = 111.319;
}
public double euclidean(LatLng latLng){
double derajatKeKM = 111.319;
return (Math.sqrt(Math.pow(this.getLat() - latLng.latitude, 2) + Math.pow(this.getLng() - latLng.longitude, 2))) * derajatKeKM;
}
public Double getJarak(Node node){
if(node.getId() == this.getId()) return 0.; if(this.getTetangga().indexOf(node) == -1 &&
node.getTetangga().indexOf(this) == -1) return Double.POSITIVE_INFINITY; return euclidean(this, node);
} }
7.
Connection.Java
package com.example.codetorium.projekulfa.Model;
/**
* Created by codetorium on 28/04/17. */
public class Connection {
private int id, idAwal, idTujuan;
public int getId() {
return id; }
public void setId(int id) { this.id = id;
}
public int getIdAwal() {
return idAwal; }
public void setIdAwal(int idAwal) {
this.idAwal = idAwal; }
public int getIdTujuan() {
return idTujuan; }
public void setIdTujuan(int idTujuan) {
this.idTujuan = idTujuan; }
}
8.
DatabaseHelper.Java
package com.example.codetorium.projekulfa.Helper;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.example.codetorium.projekulfa.Model.Connection;
import com.example.codetorium.projekulfa.Model.Node;
import java.util.ArrayList;
/**
* Created by codetorium on 08/05/17. */
public class DatabaseHelper {
private AssetHelper assetHelper; private SQLiteDatabase db;
public DatabaseHelper(Context context){
assetHelper = new AssetHelper(context);
public List<Connection> getAllConnection(){ List<Connection> result = new ArrayList<>();
* Created by codetorium on 08/05/17. */
public class AssetHelper extends SQLiteAssetHelper {
private static final String DB_NAME = "apotek.sqlite";
public AssetHelper(Context context){
super(context, DB_NAME, null, DB_VERSION); }
}
10.
RouteFragment.Java
package com.example.codetorium.projekulfa.Helper;
import android.content.Context;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
/**
* Created by codetorium on 08/05/17. */
public class AssetHelper extends SQLiteAssetHelper {
private static final String DB_NAME = "apotek.sqlite";
private static final int DB_VERSION = 1;
public AssetHelper(Context context){
super(context, DB_NAME, null, DB_VERSION); }
}
11.
ListRouteFragment.Java
package com.example.codetorium.projekulfa.Fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import com.example.codetorium.projekulfa.Adapter.RouteAdapter;
import com.example.codetorium.projekulfa.Model.Node;
import com.example.codetorium.projekulfa.Model.Rute;
import com.example.codetorium.projekulfa.R;
import java.util.List;
/**
* A simple {@link Fragment} subclass. */
public class ListRouteFragment extends Fragment {
Rute rute;
public ListRouteFragment() {
// Required empty public constructor }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { // Inflate the layout for this fragment
container, false);
rute = (Rute) getArguments().getSerializable("rute"); RouteAdapter routeAdapter = new RouteAdapter(getActivity(),
rute.getRute());
ListView lvRute = (ListView) view.findViewById(R.id.listview_rute); lvRute.setAdapter(routeAdapter); return view;
} }
12.
Greedy.Java
package com.example.codetorium.projekulfa.Algorithm;
import android.util.Log;
import com.example.codetorium.projekulfa.Model.Node;
import java.util.ArrayList;
import java.util.List;
/**
* Created by codetorium on 28/04/17. */
public class Greedy {
List<Node> open, closed;
double totalJarak;
long totalWaktu;
public Greedy() {
this.open = new ArrayList<>(); this.closed = new ArrayList<>(); this.totalWaktu = 0;
this.totalJarak = 0; }
public double getTotalJarak() {
return totalJarak; }
public void setTotalJarak(double totalJarak) {
this.totalJarak = totalJarak; }
public long getTotalWaktu() {
return totalWaktu; }
public void setTotalWaktu(long totalWaktu) {
this.totalWaktu = totalWaktu; }
public List<Node> cariRute(Node awal, Node tujuan) { long start = System.currentTimeMillis();
double jarakMinimum;
boolean adaTetangga = true;
* Created by codetorium on 28/04/17. */
//TODO:Floyd - Warshall Diatur lagi
double totalJarak;
long totalWaktu;
public Floydwarshall(List<Node> allNode){ this.allNode = allNode;
public List<Node> cariRute(Node awal, Node tujuan){ List<Node> result = new ArrayList<>(); floydObjects[k][i].jarak != Double.POSITIVE_INFINITY) {
kj = floydObjects[k][j].jarak; if(ij > ik + kj){
floydObjects[i][j].rute.clear();
floydObjects[i][j].rute.addAll(floydObjects[i][k].rute);
floydObjects[i][j].rute.addAll(floydObjects[k][j].rute); floydObjects[i][j].jarak = ik + kj; }
} } }
int indexFrom, indexTo;
indexFrom = allNode.indexOf(awal); indexTo = allNode.indexOf(tujuan); if(indexFrom == -1 || indexTo == -1){
Log.d("ERROR_INDEX", "NODE TIDAK DITEMUKAN DALAM ALL NODE"); }
List<Node> rute = floydObjects[indexFrom][indexTo].rute; totalJarak = floydObjects[indexFrom][indexTo].jarak; Node prevNode = new Node();
prevNode.setId(-1); for(Node node : rute){
if(prevNode.getId() == node.getId()) continue; result.add(node);
prevNode = node; }
long end = System.currentTimeMillis(); this.totalWaktu = end - start;
for(Node node : result){
Log.d("FLOYD", node.getNama()); }
return result; }
}
14.
RouteAdapter.java
package com.example.codetorium.projekulfa.Adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.codetorium.projekulfa.Model.Node;
import com.example.codetorium.projekulfa.R;
import java.util.ArrayList;
import java.util.List;
* Created by codetorium on 11/05/17. */
public class RouteAdapter extends BaseAdapter {
List<Node> rute; Context context;
LayoutInflater inflater;
public RouteAdapter(Context context, List<Node> rute){ this.rute = new ArrayList<>(rute);
public View getView(int position, View convertView, ViewGroup parent) {
import android.view.View;
* Created by codetorium on 09/05/17. */
public class SpinnerAdapter extends BaseAdapter {
List<Node> allNode; Context context;
LayoutInflater inflater;
public SpinnerAdapter(Context context, List<Node> allNode){ this.context = context;
public View getView(int position, View convertView, ViewGroup parent) { tvNama.setText(allNode.get(position).getNama());
String latLng = "Latitude : " + String.format(Locale.UK, "%.2f",
allNode.get(position).getLat()) +
" Longitude : " + String.format(Locale.UK, "%.2f", allNode.get(position).getLng());
tvLatLng.setText(latLng);
tvKet.setText(allNode.get(position).getKet()); return view;
16.
ViewPageAdapter.Java
package com.example.codetorium.projekulfa.Adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.List;
/**
* Created by codetorium on 11/05/17. */
public class ViewPagerAdapter extends FragmentPagerAdapter {
List<Fragment> fragmentList; List<String> pageTitle;
public ViewPagerAdapter(FragmentManager fm, List<Fragment> fragmentList, List<String> pageTitle) {
super(fm);
this.fragmentList = fragmentList; this.pageTitle = pageTitle; }
@Override
public Fragment getItem(int position) { return fragmentList.get(position); }
@Override
public int getCount() {
return fragmentList.size(); }
@Override
public CharSequence getPageTitle(int position) { return pageTitle.get(position);
} }
17.
GeralAdapter.Java
package com.example.codetorium.projekulfa.ActionHandler;
import android.content.Context;
import android.content.Intent;
import com.example.codetorium.projekulfa.View.HalamanPencarian;
import com.example.codetorium.projekulfa.View.LokasiActivity;
/**
* Created by codetorium on 28/04/17. */
public class GeneralHandler {
Context context;
public GeneralHandler(Context context){
this.context = context; }
public void pengujianOnClick(){
context.startActivity(halamanPencarian); }
public void cariLokasi(){
Intent halamanLokasi = new Intent(context, LokasiActivity.class); context.startActivity(halamanLokasi);