Implementasi Algoritma Dijkstra Dalam Penentuan Rute Terpendek Berbasis Mobile GIS (Studi Kasus: Universitas Sumatera Utara)

  

LAMPIRAN A : LISTING PROGRAM

1.

  Listing Program Eclipse (Java dan XML)

  • MainActivity.java package com.mobilegisdijkstra; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private Button btnMenu; private Button btnCaraPenggunaan; private Button btnTentangAplikasi; public void onCreate(Bundle savedInstanceState) { final Context context = this; super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnMenu = (Button) findViewById(R.id.button1); btnCaraPenggunaan = (Button) findViewById(R.id.button2); btnTentangAplikasi = (Button) findViewById(R.id.button3); btnMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, MenuPilihan.class); startActivity(intent); } }); btnCaraPenggunaan.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, CaraPenggunaan.class); startActivity(intent); } }); btnTentangAplikasi.setOnClickListener(new OnClickListener()) { @Override

  public void onClick(View arg0) { Intent intent = new Intent(context, TentangAplikasi.class); startActivity(intent); } }); } }

  • Activity_main.xml

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="horizontal|vertical" android:orientation="vertical" > android:layout_gravity="center" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:fontFamily="Times New Roman" android:text="@string/usu" android:textSize="50sp" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/title" android:textAppearance="?android:attr/textAppearanceLarge" android:textStyle="bold" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/subtitle" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/button1" android:layout_width="803dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/enter" android:typeface="serif" /> <Button android:id="@+id/button2" android:layout_width="803dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/howtouse" android:typeface="serif" /> <Button android:id="@+id/button3" android:layout_width="803dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/about" android:typeface="serif" /> <TextView android:id="@+id/textView10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView9"

android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:fontFamily="Arial" android:text="@string/judul1" android:textColor="#CCFF00" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:fontFamily="Lucida Handwriting" android:text="@string/judul2" android:textColor="#CCFF00" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout>

  • CaraPenggunaan.java package com.mobilegisdijkstra; import android.os.Bundle; import android.app.Activity; public class CaraPenggunaan extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_howtouse); } }
  • layout_howtouse.xml

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:scrollbarStyle="outsideInset" android:scrollbars="horizontal|vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge"/> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/howtouse" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/artihowtouse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="@string/isihowtouse" android:textColor="#669966" android:textAppearance="?android:attr/textAppearanceLarge" android:textStyle="italic" android:typeface="serif" /> </LinearLayout>

  • TentangAplikasi.java package com.mobilegisdijkstra; import android.os.Bundle; import android.app.Activity; public class TentangAplikasi extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_about); } }
  • layout_about.xml

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="horizontal|vertical" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/about" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/artiabout" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView3" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="@string/isiabout" android:textAlignment="center" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#669966" android:textStyle="italic" android:typeface="serif" /> </LinearLayout>

  • MenuPilihan.java package com.mobilegisdijkstra; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MenuPilihan extends MainActivity { private Button btnTampilPeta; private Button btnCariRuteTerpendek; private Button btnCaraPenggunaan; public void onCreate(Bundle savedInstanceState) { final Context context = this; super.onCreate(savedInstanceState); setContentView(R.layout.layout_enterapp); btnTampilPeta = (Button) findViewById(R.id.button1); btnCariRuteTerpendek = (Button) findViewById(R.id.button2); btnCaraPenggunaan = (Button) findViewById(R.id.button3); btnTampilPeta.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, TampilPeta.class); startActivity(intent); } }); btnCariRuteTerpendek.setOnClickListener(new OnClickListener()) { @Override public void onClick(View arg0) { Intent intent = new Intent(context, PilihVerteks.class); startActivity(intent); } });
public void onClick(View arg0) { Intent intent = new Intent(context, CaraPenggunaan.class); startActivity(intent); } }); } }

  • layout_enterapp.xml

  <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="horizontal|vertical" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/opsi" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/artiopsi" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/showmap" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/findpath" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/backhowto" /> </LinearLayout>

  • TampilPeta.java package com.mobilegisdijkstra; import com.mobilegisdijkstra.R; import android.os.Bundle;
import android.view.MotionEvent; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.webkit.WebView; import android.widget.ViewFlipper; public class TampilPeta extends Activity { private ViewFlipper vf; private WebView webView; private float oldTouchValue; @SuppressLint("SetJavaScriptEnabled") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_vf_showmap); vf=(ViewFlipper)findViewById(R.id.ViewFlipper01); webView = (WebView) findViewById(R.id.webView2); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("http://10.0.2.2:8081/geoserver/workspaceUSU/wms?servic e=WMS&version=1.1.0&request=GetMap&layers=grupUSU&styles=&bbox= 6.222626893282417,4.485378590078277,426.6114958610236,566.11317665 nlayers"); } @Override public boolean onTouchEvent(MotionEvent touchevent) { switch (touchevent.getAction()) { case MotionEvent.ACTION_DOWN: { oldTouchValue = touchevent.getX(); break; } case MotionEvent.ACTION_UP: { float currentX = touchevent.getX(); if (oldTouchValue < currentX) { vf.setInAnimation(inFromLeftAnimation()); vf.setOutAnimation(outToRightAnimation()); vf.showNext(); } if (oldTouchValue > currentX) { vf.setInAnimation(inFromRightAnimation()); vf.setOutAnimation(outToLeftAnimation()); vf.showPrevious(); } break; } }

  Animation inFromRight = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f ); inFromRight.setDuration(350); inFromRight.setInterpolator(new AccelerateInterpolator()); return inFromRight; } public static Animation outToLeftAnimation() { Animation outtoLeft = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f ); outtoLeft.setDuration(350); outtoLeft.setInterpolator(new AccelerateInterpolator()); return outtoLeft; } public static Animation inFromLeftAnimation() { Animation inFromLeft = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, inFromLeft.setDuration(350); inFromLeft.setInterpolator(new AccelerateInterpolator()); return inFromLeft; } public static Animation outToRightAnimation() { Animation outtoRight = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f ); outtoRight.setDuration(350); outtoRight.setInterpolator(new AccelerateInterpolator()); return outtoRight; } }

  • layout_vf_showmap.xml

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <include android:id="@+id/libraryView1" layout="@layout/layout_vf_showmap_map" /> <include android:id="@+id/libraryView2" layout="@layout/layout_vf_showmap_legend" /> </ViewFlipper> </RelativeLayout>

  • layout_vf_showmap_legend.xml

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/dragshowmap" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="120dp" > <Button android:id="@+id/button2" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#FF0000" android:textColor="#000000" /> <Button android:id="@+id/button3" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fkedokteran" /> <Button android:id="@+id/button4" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#CCCCCC" android:textColor="#000000" /> <Button android:id="@+id/button5" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/filkom" /> <Button android:id="@+id/button6" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#CCFFFF" android:textColor="#000000" /> <Button android:id="@+id/button7" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content"

  <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="180dp" > <Button android:id="@+id/button8" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#666666" android:textColor="#000000" /> <Button android:id="@+id/button9" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fhukum" /> <Button android:id="@+id/button10" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#000033" android:textColor="#000000" /> <Button android:id="@+id/button11" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fmipa" /> <Button android:id="@+id/button12" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#6600CC" android:textColor="#000000" /> android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fpsikologi" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="240dp" > <Button android:id="@+id/button14" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#FFCC00" android:textColor="#000000" /> <Button android:id="@+id/button15" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fkeperawatan" /> <Button android:id="@+id/button16" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#FF00FF" android:textColor="#000000" /> android:text="@string/fkm" /> <Button android:id="@+id/button18" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#993300" android:textColor="#000000" /> <Button android:id="@+id/button19" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fteknik" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="300dp" > <Button android:id="@+id/button20" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#9933FF" android:textColor="#000000" /> <Button android:id="@+id/button21" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fpertanian" /> <Button android:id="@+id/button22" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" /> <Button android:id="@+id/button23" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fekonomi" /> <Button android:id="@+id/button24" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#CC0099" android:textColor="#000000" /> <Button android:id="@+id/button25" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fsospol" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="360dp" > <Button android:id="@+id/button26" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content"

  <Button android:id="@+id/button27" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/fkedokterangigi" /> <Button android:id="@+id/button28" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#000066" android:textColor="#000000" /> <Button android:id="@+id/button29" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/birek" /> <Button android:id="@+id/button30" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#009900" android:textColor="#000000" /> <Button android:id="@+id/button31" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/audit" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="420dp" > android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#0066CC" android:textColor="#000000" /> <Button android:id="@+id/button33" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/stadion" /> <Button android:id="@+id/button34" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#66FF99" android:textColor="#000000" /> <Button android:id="@+id/button35" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/poliklinik" /> <Button android:id="@+id/button36" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#990066" android:textColor="#000000" /> <Button android:id="@+id/button37" style="?android:attr/buttonStyleSmall"

  </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="480dp" > <Button android:id="@+id/button38" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#999933" android:textColor="#000000" /> <Button android:id="@+id/button39" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/perpus" /> <Button android:id="@+id/button40" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#CC9900" android:textColor="#000000" /> <Button android:id="@+id/button41" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/pendopo" /> <Button android:id="@+id/button42" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sign" android:background="#CCCC00" <Button android:id="@+id/button43" style="?android:attr/buttonStyleSmall" android:layout_width="360dp" android:layout_height="wrap_content" android:text="@string/gema" /> </LinearLayout> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="60dp" android:text="@string/legend" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>

  • layout_vf_showmap_map.xml

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools="http://schemas.android.com/tools" tools:context=".ReLayoutShowMap_Map" android:layout_width="match_parent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/dragshowlegend" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button1" android:layout_centerHorizontal="true" android:text="@string/usumap" android:textAppearance="?android:attr/textAppearanceLarge" /> <WebView android:id="@+id/webView2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="80dp" /> </RelativeLayout>

  • PilihVerteks.java package com.mobilegisdijkstra; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.Button; import android.widget.Spinner; import android.widget.TextView; import android.widget.ArrayAdapter; public class PilihVerteks extends Activity { TextView tvIDTitikAwal; TextView tvIDTitikAkhir; Spinner spinTitikAwal; Spinner spinTitikAkhir; Button btndijkstra;

  @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_chooseverteks); tvIDTitikAwal = (TextView) findViewById(R.id.textView12); tvIDTitikAkhir = (TextView) findViewById(R.id.textView13); spinTitikAwal = (Spinner) findViewById(R.id.spinner1); spinTitikAkhir = (Spinner) findViewById(R.id.spinner2); btndijkstra = (Button) findViewById(R.id.button1); btndijkstra.setOnClickListener(listenerdijkstra); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.fakultas_array,android.R.layout.simple_spinner_dropdown_item); spinTitikAwal.setAdapter(adapter); spinTitikAkhir.setAdapter(adapter); spinTitikAwal.setOnItemSelectedListener(listener1); spinTitikAkhir.setOnItemSelectedListener(listener2); } public OnItemSelectedListener listener1 = new OnItemSelectedListener() { @Override public void onItemSelected (AdapterView<?> parent, View view, int pos, long id) { String ids [] = getResources().getStringArray(R.array.id_array); tvIDTitikAwal.setText(nilai_id1); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }; public OnItemSelectedListener listener2 = new OnItemSelectedListener() { @Override public void onItemSelected (AdapterView<?> parent, View view, int pos, long id) { String ids [] = getResources().getStringArray(R.array.id_array); nilai_id2 = ids [pos]; tvIDTitikAkhir.setText(nilai_id2); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }; public OnClickListener listenerdijkstra = new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, HasilProsesDijkstra.class); intent.putExtra("ttkawl", tvIDTitikAwal.getText().toString()); intent.putExtra("ttkakr", tvIDTitikAkhir.getText().toString()); startActivity(intent); } }; }

  • layout_chooseverteks.xml

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="horizontal|vertical" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/choosevertex" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/artichoosevertex" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/vstart" android:textAppearance="?android:attr/textAppearanceLarge" /> <Spinner android:id="@+id/spinner1" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/vid" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView12" android:layout_width="wrap_content" android:layout_height="wrap_content"

  </LinearLayout> <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/vend" android:textAppearance="?android:attr/textAppearanceLarge" /> <Spinner android:id="@+id/spinner2" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/vid" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" </LinearLayout> <TextView android:id="@+id/textView8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/fsp" /> </LinearLayout>

  • HasilProsesDijkstra.java package com.mobilegisdijkstra; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.PriorityQueue;
import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import com.mobilegisdijkstra.model.Edge; import com.mobilegisdijkstra.model.Verteks; import com.mobilegisdijkstra.PilihVerteks; import android.content.res.AssetManager; import android.os.Bundle; import android.view.MotionEvent; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.webkit.WebView; import android.widget.TextView; import android.annotation.SuppressLint; import android.widget.ViewFlipper; public class HasilProsesDijkstra extends PilihVerteks { TextView hasil, jarak; private WebView wvPeta; private ViewFlipper vf; public void cariJalurDijkstra(Verteks asal) { asal.jarakTerpendek = 0.; PriorityQueue<Verteks> antrianVerteks = new PriorityQueue<Verteks>(); antrianVerteks.add(asal); while (!antrianVerteks.isEmpty()) { Verteks u = antrianVerteks.poll(); for (Edge e : u.tetangga) { Verteks v = e.tujuan; double bobot = e.bobot; double jarakMelewatiU = u.jarakTerpendek + bobot; if (jarakMelewatiU < v.jarakTerpendek) { antrianVerteks.remove(v); v.jarakTerpendek = jarakMelewatiU ; v.previous = u; antrianVerteks.add(v); } } } } public List<Verteks> cariJalurTerpendekKe(Verteks tujuan) { List<Verteks> jalur = new ArrayList<Verteks>(); for (Verteks verteks = tujuan; verteks != null; verteks = verteks.previous)

return jalur; } public int parseString(String s) { return Integer.parseInt(s); } public Verteks[] parsingVerteks(String XMLName) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); AssetManager assetManager = getAssets(); InputStream fileInputStream = assetManager.open(XMLName); Document doc = dBuilder.parse(fileInputStream); doc.getDocumentElement().normalize(); NodeList nlVerteks = doc.getElementsByTagName("Vertex"); NodeList nlChildVerteks; Verteks[] nVertices = new Verteks[nlVerteks.getLength()]; NodeList nListEdge; NodeList nListChildEdge; String idVerteks; String namaVerteks; String idEdge; String namaEdge; String jarak; indeksVerteks++) { Element eVertex = (Element) nlVerteks.item(indeksVerteks); nlChildVerteks = eVertex.getChildNodes(); idVerteks = nlChildVerteks.item(1).getTextContent(); namaVerteks = nlChildVerteks.item(3).getTextContent(); nVertices[indeksVerteks] = new Verteks(idVerteks, namaVerteks); } for (int indeksVerteks = 0 ; indeksVerteks < nlVerteks.getLength(); indeksVerteks++) { Element eVertex = (Element) nlVerteks.item(indeksVerteks); nListEdge = eVertex.getElementsByTagName("Edge"); Edge[] arrayEdge = new Edge[nListEdge.getLength()]; for (int indexEdge = 0 ; indexEdge < nListEdge.getLength() ; indexEdge++) { Element eEdge = (Element) nListEdge.item(indexEdge); nListChildEdge = eEdge.getChildNodes(); idEdge = nListChildEdge.item(1).getTextContent(); namaEdge = nListChildEdge.item(3).getTextContent(); jarak = nListChildEdge.item(5).getTextContent(); arrayEdge[indexEdge] = new Edge(nVertices[parseString(idEdge)],

  System.arraycopy(arrayEdge, 0, nVertices[indeksVerteks].tetangga, 0, arrayEdge.length); } return nVertices; } catch(Exception e) { e.printStackTrace(); } return null; } @SuppressLint("SetJavaScriptEnabled") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_vf_result); vf=(ViewFlipper)findViewById(R.id.ViewFlipper02); hasil = (TextView) findViewById(R.id.textView12); jarak = (TextView) findViewById(R.id.textView30); wvPeta = (WebView) findViewById(R.id.webView2); wvPeta.getSettings().setJavaScriptEnabled(true); Bundle extras = getIntent().getExtras(); int titikAwal = parseString(extras.getString("titikAwal")); int titikAkhir = parseString(extras.getString("titikAkhir")); String grafisVerteksAwal = extras.getString("ttkawl"); String grafisVerteksAkhir = extras.getString("ttkakr"); String urlVerteks = "nodeawal:"+grafisVerteksAwal+";nodeakhir:"+grafisVerteksAkhir+";"; cariJalurDijkstra(verteksGraf[titikAwal]); List<Verteks> jalur = cariJalurTerpendekKe(verteksGraf[titikAkhir]); hasil.setText(jalur.toString()); jarak.setText("" + verteksGraf[titikAkhir].jarakTerpendek); String vSekarang; String vSelanjutnya; Verteks V; Edge [] kumpulanEdge; String[] jalurEdge = new String[jalur.size()-1]; int indeksJalur = 0; for (int i=0 ; i< jalur.size()-1; i++) { vSekarang = jalur.get(i).getId(); vSelanjutnya = jalur.get(i+1).getId(); V = verteksGraf[parseString(vSekarang)]; kumpulanEdge = V.tetangga; for (int j = 0 ; j <kumpulanEdge.length; j++) { if (kumpulanEdge[j].tujuan.id == vSelanjutnya) { jalurEdge[indeksJalur] = kumpulanEdge[j].name;

  String urlEdge= "&env="; for (int i = 0 ; i < jalurEdge.length; i++) { urlEdge+="edge"+(i+1)+":"+jalurEdge[i]+";"; } String urlPeta = "http://10.0.2.2:8081/geoserver/workspaceUSU/wms?service=WMS&version= 1.1.0&request=GetMap&layers=grupUSU&styles=&bbox=6.2226268932824 17,4.485378590078277,426.6114958610236,566.1131766502311&width=121 2&height=562&srs=EPSG:23845&format=application/openlayers"; wvPeta.loadUrl(urlPeta + urlEdge + urlVerteks); } @Override public boolean onTouchEvent(MotionEvent touchevent) { switch (touchevent.getAction()) { case MotionEvent.ACTION_DOWN: { oldTouchValue = touchevent.getX(); break; } case MotionEvent.ACTION_UP: { float currentX = touchevent.getX(); if (oldTouchValue < currentX) { vf.setInAnimation(inFromLeftAnimation()); vf.setOutAnimation(outToRightAnimation()); vf.showNext(); } if (oldTouchValue > currentX) { vf.setOutAnimation(outToLeftAnimation()); vf.showPrevious(); } break; } } return false; } public static Animation inFromRightAnimation() { Animation inFromRight = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f ); inFromRight.setDuration(350); inFromRight.setInterpolator(new AccelerateInterpolator()); return inFromRight; } public static Animation outToLeftAnimation() { Animation outtoLeft = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, outtoLeft.setInterpolator(new AccelerateInterpolator()); return outtoLeft; } public static Animation inFromLeftAnimation() { Animation inFromLeft = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f ); inFromLeft.setDuration(350); inFromLeft.setInterpolator(new AccelerateInterpolator()); return inFromLeft; } public static Animation outToRightAnimation() { Animation outtoRight = new TranslateAnimation ( Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f ); outtoRight.setDuration(350); outtoRight.setInterpolator(new AccelerateInterpolator()); return outtoRight; } }

  • layout_vf_result.xml

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ViewFlipper android:id="@+id/ViewFlipper02" android:layout_width="fill_parent" android:layout_height="fill_parent" > <include android:id="@+id/libraryView3" layout="@layout/layout_vf_result_map" /> <include android:id="@+id/libraryView4" layout="@layout/layout_vf_result_string" /> <include android:id="@+id/libraryView4" layout="@layout/layout_vf_result_distance" /> </ViewFlipper> </RelativeLayout>

  • layout_vf_result_distance.xml

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.50" android:text="@string/dragresult_distancemap" /> <Button android:id="@+id/button2" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.50" android:text="@string/dragresult_distancestring" /> </LinearLayout> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="10dp" android:text="@string/resultdistance" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView30" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textSize="150sp" android:textAppearance="?android:attr/textAppearanceLarge"/> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/meter" android:textAppearance="?android:attr/textAppearanceLarge" android:textSize="60sp" /> </LinearLayout>

  • layout_vf_result_map.xml