99
APPENDIX Application Courier Coding MapsActivity.java package com.example.couriermyshopz; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.graphics.Color; import android.location.Location; import android.location.LocationManager; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.app.FragmentActivity; import android.util.Log; import android.widget.TextView; import android.widget.Toast; import com.akexorcist.googledirection.DirectionCallback; import com.akexorcist.googledirection.GoogleDirection; import com.akexorcist.googledirection.constant.TransportMode; import com.akexorcist.googledirection.model.Direction; import com.akexorcist.googledirection.util.DirectionConverter; import com.firebase.client.Firebase; import com.firebase.client.FirebaseError; import com.firebase.client.Query; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener { private GoogleMap mMap; private FusedLocationProviderApi locationProvider = LocationServices.FusedLocationApi; A

PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

APPENDIX

Application Courier

Coding MapsActivity.java

package com.example.couriermyshopz;import android.Manifest;import android.content.Context;import android.content.pm.PackageManager;import android.graphics.Color;import android.location.Location;import android.location.LocationManager;import android.os.AsyncTask;import android.os.Bundle;import android.support.annotation.NonNull;import android.support.annotation.Nullable;import android.support.v4.app.ActivityCompat;import android.support.v4.app.FragmentActivity;import android.util.Log;import android.widget.TextView;import android.widget.Toast;import com.akexorcist.googledirection.DirectionCallback;import com.akexorcist.googledirection.GoogleDirection;import com.akexorcist.googledirection.constant.TransportMode;import com.akexorcist.googledirection.model.Direction;import com.akexorcist.googledirection.util.DirectionConverter;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import com.firebase.client.Query;import com.google.android.gms.common.ConnectionResult;import com.google.android.gms.common.api.GoogleApiClient;import com.google.android.gms.location.FusedLocationProviderApi;import com.google.android.gms.location.LocationListener;import com.google.android.gms.location.LocationRequest;import com.google.android.gms.location.LocationServices;import com.google.android.gms.maps.CameraUpdateFactory;import com.google.android.gms.maps.GoogleMap;import com.google.android.gms.maps.OnMapReadyCallback;import com.google.android.gms.maps.SupportMapFragment;import com.google.android.gms.maps.model.LatLng;import com.google.android.gms.maps.model.MarkerOptions;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.util.ArrayList;public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener { private GoogleMap mMap; private FusedLocationProviderApi locationProvider = LocationServices.FusedLocationApi;

A

Page 2: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

private GoogleApiClient googleapiclient; private LocationRequest locationrequest; private double latitude, longtitude; private double myLatitude, myLongitude; private String KEYID; private String a, b; private Firebase keyFB; private Firebase mRef; private LatLng origin, destination; private LatLng lokasiUser; private double lata, longb; private String urls; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); Firebase.setAndroidContext(this); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); LocationManager locationManager = (LocationManager) getSystemService(android.content.Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode,String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } Firebase firebase = new Firebase("https://buydata-66bfa.firebaseio.com/detailz"); Query query = firebase.orderByChild("status").equalTo("Belum Terkirim"); query.addChildEventListener(new com.firebase.client.ChildEventListener() { @Override public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String s) { KEYID = dataSnapshot.getKey();

B

Page 3: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

String value = dataSnapshot.getValue().toString().replace("{", "").replace("}", "").replace(",", "\n"); } @Override public void onChildChanged(com.firebase.client.DataSnapshot dataSnapshot, String s) { } @Override public void onChildRemoved(com.firebase.client.DataSnapshot dataSnapshot) { } @Override public void onChildMoved(com.firebase.client.DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(FirebaseError firebaseError) { } }); Bundle bundle = getIntent().getExtras(); if (bundle != null) { a = bundle.getString("LatUser"); b = bundle.getString("LongUser"); } googleapiclient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(MapsActivity.this) .addOnConnectionFailedListener(this) .build(); locationrequest = new LocationRequest(); locationrequest.setInterval(10 * 1000); locationrequest.setFastestInterval(10 * 1000); locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; lata = Double.parseDouble(a); longb = Double.parseDouble(b); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode,String[] permissions,

C

Page 4: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

// int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } Location mylocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); latitude = mylocation.getLatitude(); longtitude = mylocation.getLongitude(); lokasiUser = new LatLng(lata, longb); String serverKey = "AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU"; origin = new LatLng(latitude, longtitude); destination = lokasiUser; urls = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" + latitude + "," + longtitude + "&destinations=-6.990150,110.422987&key=AIzaSyATk8ph2-yClUcaVaFH6IsxaHQ7jP4kYn0"; new ParsingJson(MapsActivity.this).execute(urls); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(origin, 17)); GoogleDirection.withServerKey(serverKey) .from(origin) .to(destination) .transportMode(TransportMode.DRIVING) .execute(new DirectionCallback() { @Override public void onDirectionSuccess(Direction direction,String rawBody) { if (direction.isOK()) { mMap.addMarker(new MarkerOptions().position(origin)); mMap.addMarker(new MarkerOptions().position(destination)); ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint(); mMap.addPolyline(DirectionConverter.createPolyline(MapsActivity.this, directionPositionList, 2, Color.RED)); } } @Override public void onDirectionFailure(Throwable t) { } }); } private class ParsingJson extends AsyncTask<String, Void, String>{ public ParsingJson(MapsActivity pesanActivity) { } @Override protected String doInBackground(String... params) { try { URL url=new URL(params[0]); HttpURLConnection con= (HttpURLConnection) url.openConnection();

D

Page 5: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

con.setRequestMethod("GET"); con.connect(); int statuscode=con.getResponseCode(); if(statuscode==HttpURLConnection.HTTP_OK) { BufferedReader br=new BufferedReader(new InputStreamReader(con.getInputStream())); StringBuilder sb=new StringBuilder(); String line=br.readLine(); while(line!=null) { sb.append(line); line=br.readLine(); } String json=sb.toString(); JSONObject root=new JSONObject(json); JSONArray array_rows=root.getJSONArray("rows"); JSONObject object_rows=array_rows.getJSONObject(0); JSONArray array_elements=object_rows.getJSONArray("elements"); JSONObject object_elements=array_elements.getJSONObject(0); JSONObject object_duration=object_elements.getJSONObject("duration"); JSONObject object_distance=object_elements.getJSONObject("distance"); return object_duration.getString("value")+","+object_distance.getString("value"); } } catch (MalformedURLException e) { Log.d("error", "error1"); } catch (IOException e) { Log.d("error", "error2"); } catch (JSONException e) { Log.d("error","error3"); } return null; } protected void onPostExecute(String aDouble) { super.onPostExecute(aDouble); if(aDouble!=null) { setDouble(aDouble); } else Toast.makeText(MapsActivity.this, "Error Please Try Again", Toast.LENGTH_SHORT).show(); } private void setDouble(String result) { String res[]=result.split(","); Double min=Double.parseDouble(res[0])/60; int dist=Integer.parseInt(res[1])/1000; TextView tvDuration = (TextView) findViewById(R.id.tvDuration);

E

Page 6: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

TextView tvDistance = (TextView) findViewById(R.id.tvDistance); tvDuration.setText("Waktu Sampai= " + (int) (min / 60) + " hr " + (int) (min % 60) + " mins"); tvDistance.setText("Jarak = " + dist + " Kilometers"); } } public void buatPetaBaru() { mMap.clear(); String serverKey = "AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU"; origin = new LatLng(latitude, longtitude); destination = lokasiUser; mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(origin, 17)); GoogleDirection.withServerKey(serverKey) .from(origin) .to(destination) .transportMode(TransportMode.DRIVING) .execute(new DirectionCallback() { @Override public void onDirectionSuccess(Direction direction, String rawBody) { if (direction.isOK()) { mMap.addMarker(new MarkerOptions().position(origin)); mMap.addMarker(new MarkerOptions().position(destination)); ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint(); mMap.addPolyline(DirectionConverter.createPolyline(MapsActivity.this, directionPositionList, 2, Color.RED)); } } @Override public void onDirectionFailure(Throwable t) { } }); } @Override public void onConnected(@Nullable Bundle bundle) { requestLocationUpdates(); } private void requestLocationUpdates() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions

F

Page 7: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

// here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } LocationServices.FusedLocationApi.requestLocationUpdates(googleapiclient,locationrequest, this); } @Override public void onConnectionSuspended(int i) { } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { } @Override public void onLocationChanged(Location location) { // keyFB = mRef.child(KEYID); // keyFB.child("Latitude Courier").setValue(latitude); // keyFB.child("Longtitude Courier").setValue(longtitude); buatPetaBaru(); } @Override protected void onStart() { super.onStart(); googleapiclient.connect(); } @Override protected void onResume() { super.onResume(); if (googleapiclient.isConnected()) { requestLocationUpdates(); } } @Override protected void onPause() { super.onPause(); LocationServices.FusedLocationApi.removeLocationUpdates(googleapiclient, this); } @Override protected void onStop() { super.onStop(); googleapiclient.disconnect(); } }

G

Page 8: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding LoginActivity.java

package com.example.couriermyshopz;import android.content.Intent;import android.os.Bundle;import android.support.annotation.NonNull;import android.support.v7.app.AppCompatActivity;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.google.android.gms.tasks.OnCompleteListener;import com.google.android.gms.tasks.Task;import com.google.firebase.auth.AuthResult;import com.google.firebase.auth.FirebaseAuth;public class LoginActivity extends AppCompatActivity { private EditText mEmail; private EditText mPassword; private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mAuth = FirebaseAuth.getInstance(); mEmail = (EditText) findViewById(R.id.email); mPassword = (EditText) findViewById(R.id.password); Button mLogin = (Button) findViewById(R.id.login); mAuthListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { if(firebaseAuth.getCurrentUser() != null ) { startActivity(new Intent(LoginActivity.this,MainActivity.class)); } } }; mLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startSignIn(); } }); } @Override public void onStart() { super.onStart(); mAuth.addAuthStateListener(mAuthListener); } @Override public void onStop() { super.onStop(); if (mAuthListener != null) {

H

Page 9: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

mAuth.removeAuthStateListener(mAuthListener); } } private void startSignIn() { String Email = mEmail.getText().toString(); String Password = mPassword.getText().toString(); if (TextUtils.isEmpty(Email) || TextUtils.isEmpty(Password)) { Toast.makeText(LoginActivity.this, "Field Are Empty", Toast.LENGTH_SHORT).show(); } else { mAuth.signInWithEmailAndPassword(Email, Password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Toast.makeText(LoginActivity.this, "SignIn Berhasil", Toast.LENGTH_SHORT).show(); } // ... } }); } }}

I

Page 10: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding MainActivity.java

package com.example.couriermyshopz;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.TextView;import com.google.firebase.auth.FirebaseAuth;import com.google.firebase.auth.FirebaseUser;public class MainActivity extends AppCompatActivity { private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAuth = FirebaseAuth.getInstance(); FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser(); Button mLogout = (Button) findViewById(R.id.logout); TextView emails = (TextView) findViewById(R.id.email); String tampil = firebaseUser.getEmail(); emails.setText(tampil); mLogout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mAuth.removeAuthStateListener(mAuthListener); FirebaseAuth.getInstance().signOut(); Intent intent = new Intent(MainActivity.this,LoginActivity.class); finish(); startActivity(intent); } }); } public void sendMap(View view) { Intent intents = new Intent(MainActivity.this,MapsActivity.class); startActivity(intents); } public void sendbuy(View view) { Intent intentss = new Intent(MainActivity.this,BuylistActivity.class); startActivity(intentss); }}

J

Page 11: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding BuylistActivity.java

package com.example.couriermyshopz;import android.app.Activity;import android.content.Intent;import android.content.pm.PackageManager;import android.location.Location;import android.location.LocationManager;import android.os.Bundle;import android.support.v4.app.ActivityCompat;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.ListView;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import com.firebase.client.Query;import com.google.firebase.auth.FirebaseAuth;import com.google.firebase.auth.FirebaseUser;import java.util.ArrayList;public class BuylistActivity extends Activity { private ArrayList<String> mDetail = new ArrayList<>(); private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; private String Keyz, nama, telepon, alamat,userlatitude,userlongtitude; double latitude; double longtitude; private Firebase keyfbz; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_buylist); Firebase.setAndroidContext(this); final ListView mValueView = (ListView) findViewById(R.id.valueViewz); mAuth = FirebaseAuth.getInstance(); FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser(); final String tampil = firebaseUser.getEmail(); LocationManager locationManager = (LocationManager) getSystemService(android.content.Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode,String[] permissions, // int[] grantResults)

K

Page 12: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

// to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } Location mylocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); latitude = mylocation.getLatitude(); longtitude = mylocation.getLongitude(); final ArrayAdapter<String> arrayAdapters = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mDetail); mValueView.setAdapter(arrayAdapters); final Firebase firebase = new Firebase("https://buydata-66bfa.firebaseio.com/detailz"); Query query = firebase.orderByChild("status").equalTo("Belum Terkirim"); query.addChildEventListener(new com.firebase.client.ChildEventListener() { @Override public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String s) { String value =dataSnapshot.getValue().toString().replace("{","").replace("}","").replace(",","\n"); Keyz = dataSnapshot.getKey(); nama = dataSnapshot.child("nama").getValue().toString(); telepon = dataSnapshot.child("nomor telepon").getValue().toString(); userlatitude = dataSnapshot.child("Latitude User").getValue().toString(); userlongtitude = dataSnapshot.child("Longtitude User").getValue().toString(); mDetail.add(value); arrayAdapters.notifyDataSetChanged();//buat list view real time } @Override public void onChildChanged(com.firebase.client.DataSnapshot dataSnapshot, String s) { } @Override public void onChildRemoved(com.firebase.client.DataSnapshot dataSnapshot) { } @Override public void onChildMoved(com.firebase.client.DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(FirebaseError firebaseError) { } }); mValueView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override

L

Page 13: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) { Firebase mRef = new Firebase("https://buydata-66bfa.firebaseio.com/detailz"); keyfbz = mRef.child(Keyz); keyfbz.child("status").setValue("Terkirim"); keyfbz.child("Latitude Courier").setValue(latitude); keyfbz.child("Longtitude Courier").setValue(longtitude); Intent i = new Intent(BuylistActivity.this,MapsActivity.class); i.putExtra("LatUser",userlatitude); i.putExtra("LongUser",userlongtitude); startActivity(i); } }); }

M

Page 14: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Modules/DirectionFinder.java

package Modules;import android.os.AsyncTask;import com.google.android.gms.maps.model.LatLng;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.MalformedURLException;import java.net.URL;import java.net.URLEncoder;import java.util.ArrayList;import java.util.List;public class DirectionFinder { private static final String DIRECTION_URL_API = "https://maps.googleapis.com/maps/api/directions/json?"; private static final String GOOGLE_API_KEY = "AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU"; private DirectionFinderListener listener; private String origin; private String destination; public DirectionFinder(DirectionFinderListener listener, String origin, String destination) { this.listener = listener; this.origin = origin; this.destination = destination; } public void execute() throws UnsupportedEncodingException { listener.onDirectionFinderStart(); new DownloadRawData().execute(createUrl()); } private String createUrl() throws UnsupportedEncodingException { String urlOrigin = URLEncoder.encode(origin, "utf-8"); String urlDestination = URLEncoder.encode(destination, "utf-8"); return DIRECTION_URL_API + "origin=" + urlOrigin + "&destination=" + urlDestination + "&key=" + GOOGLE_API_KEY; } private class DownloadRawData extends AsyncTask<String, Void, String>{ @Override protected String doInBackground(String... params) { String link = params[0]; try { URL url = new URL(link); InputStream is = url.openConnection().getInputStream(); StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n");

N

Page 15: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

} return buffer.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String res) { try { parseJSon(res); } catch (JSONException e) { e.printStackTrace(); } } } private void parseJSon(String data) throws JSONException { if (data == null) return; List<Route> routes = new ArrayList<Route>(); JSONObject jsonData = new JSONObject(data); JSONArray jsonRoutes = jsonData.getJSONArray("routes"); for (int i = 0; i < jsonRoutes.length(); i++) { JSONObject jsonRoute = jsonRoutes.getJSONObject(i); Route route = new Route(); JSONObject overview_polylineJson = jsonRoute.getJSONObject("overview_polyline"); JSONArray jsonLegs = jsonRoute.getJSONArray("legs"); JSONObject jsonLeg = jsonLegs.getJSONObject(0); JSONObject jsonDistance = jsonLeg.getJSONObject("distance"); JSONObject jsonDuration = jsonLeg.getJSONObject("duration"); JSONObject jsonEndLocation = jsonLeg.getJSONObject("end_location"); JSONObject jsonStartLocation = jsonLeg.getJSONObject("start_location"); route.distance = new Distance(jsonDistance.getString("text"), jsonDistance.getInt("value")); route.duration = new Duration(jsonDuration.getString("text"), jsonDuration.getInt("value")); route.endAddress = jsonLeg.getString("end_address"); route.startAddress = jsonLeg.getString("start_address"); route.startLocation = new LatLng(jsonStartLocation.getDouble("lat"), jsonStartLocation.getDouble("lng")); route.endLocation = new LatLng(jsonEndLocation.getDouble("lat"), jsonEndLocation.getDouble("lng")); route.points = decodePolyLine(overview_polylineJson.getString("points")); routes.add(route); } listener.onDirectionFinderSuccess(routes); }

O

Page 16: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

private List<LatLng> decodePolyLine(final String poly) { int len = poly.length(); int index = 0; List<LatLng> decoded = new ArrayList<LatLng>(); int lat = 0; int lng = 0; while (index < len) { int b; int shift = 0; int result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; decoded.add(new LatLng( lat / 100000d, lng / 100000d )); } return decoded; }}

Coding Modules/DirectionFinderListener.java

package Modules;import java.util.List;public interface DirectionFinderListener { void onDirectionFinderStart(); void onDirectionFinderSuccess(List<Route> route);}

P

Page 17: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Modules/Distance.java

package Modules;public class Distance { public String text; public int value; public Distance(String text, int value) { this.text = text; this.value = value; }}

Coding Modules/Duration.java

package Modules;public class Duration { public String text; public int value; public Duration(String text, int value) { this.text = text; this.value = value; }}

Coding Modules/Route.java

package Modules;import com.google.android.gms.maps.model.LatLng;import java.util.List;public class Route { public Distance distance; public Duration duration; public String endAddress; public LatLng endLocation; public String startAddress; public LatLng startLocation; public List<LatLng> points;}

}

Q

Page 18: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Activity_Buylist.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rowLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/IdB" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TextView" android:visibility="visible" /> <ListView android:id="@+id/valueViewz" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>

R

Page 19: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding ActivityBuy.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" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.couriermyshopz.BuyActivity"> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="13dp" android:text="Buy" android:textSize="50sp" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/gelasplastik" android:layout_toEndOf="@+id/gelasplastik" /> <TextView android:id="@+id/piringplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="120dp" android:text="Piring Plastik" android:textSize="20sp" android:layout_below="@+id/textView5" android:layout_toLeftOf="@+id/editpiringplastik" android:layout_toStartOf="@+id/editpiringplastik" /> <TextView android:id="@+id/sabut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="13dp" android:text="Sabut" android:textSize="20sp" android:layout_marginRight="22dp" android:layout_marginEnd="22dp" android:layout_below="@+id/editgelasplastik" android:layout_alignRight="@+id/gelasplastik" android:layout_alignEnd="@+id/gelasplastik" /> <TextView android:id="@+id/plastikultah" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="Plastik Ultah" android:layout_below="@+id/sedotanplastik" android:layout_alignLeft="@+id/sedotanplastik" android:layout_alignStart="@+id/sedotanplastik" android:textSize="20sp" />

S

Page 20: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<TextView android:id="@+id/sedotanplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="22dp" android:text="Sedotan Plastik" android:textSize="20sp" android:layout_below="@+id/sabut" android:layout_alignLeft="@+id/piringplastik" android:layout_alignStart="@+id/piringplastik" /> <TextView android:id="@+id/gelasplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Gelas Plastik" android:textSize="20sp" android:layout_alignBaseline="@+id/editgelasplastik" android:layout_alignBottom="@+id/editgelasplastik" android:layout_alignRight="@+id/plastikultah" android:layout_alignEnd="@+id/plastikultah" /> <Button android:id="@+id/buy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="56dp" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:text="Buy" /> <EditText android:id="@+id/editpiringplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignTop="@+id/piringplastik" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editgelasplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editpiringplastik" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:ems="10" android:inputType="number" />

T

Page 21: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<EditText android:id="@+id/editsabut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/sabut" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:ems="10" android:inputType="number" />

<EditText android:id="@+id/editsedotanplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/sedotanplastik" android:layout_alignLeft="@+id/editplastikultah" android:layout_alignStart="@+id/editplastikultah" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editplastikultah" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/plastikultah" android:layout_alignBottom="@+id/plastikultah" android:layout_marginLeft="21dp" android:layout_marginStart="21dp" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:ems="10" android:inputType="number" /> <Button android:id="@+id/Buylist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/buy" android:layout_marginLeft="12dp" android:layout_marginStart="12dp" android:layout_toEndOf="@+id/buy" android:layout_toRightOf="@+id/buy" android:onClick="sendlistView" android:text="List Detail" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="18dp" android:text="No.Telepon" android:textSize="20sp" android:layout_above="@+id/editpiringplastik" android:layout_alignLeft="@+id/piringplastik" android:layout_alignStart="@+id/piringplastik" />

U

Page 22: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<EditText android:id="@+id/editnotelp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/textView4" android:layout_toEndOf="@+id/gelasplastik" android:layout_toRightOf="@+id/gelasplastik" android:ems="10" android:inputType="phone" />

<TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView4" android:layout_alignLeft="@+id/sabut" android:layout_alignStart="@+id/sabut" android:layout_marginBottom="16dp" android:text="Nama" android:textSize="20sp" /> <EditText android:id="@+id/editnama" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignTop="@+id/textView6" android:ems="10" android:inputType="textPersonName" /></RelativeLayout>

V

Page 23: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Activity_Login.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" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.couriermyshopz.LoginActivity" tools:layout_editor_absoluteY="81dp" tools:layout_editor_absoluteX="0dp"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="88dp" android:text="Login" android:textSize="50sp" /> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="35dp" android:text="Login" android:layout_below="@+id/password" android:layout_centerHorizontal="true" /> <EditText android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/textView2" android:layout_marginLeft="70dp" android:layout_marginStart="70dp" android:layout_marginTop="32dp" android:ems="10" android:hint="Email" android:inputType="textEmailAddress" /> <EditText android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/email" android:layout_centerHorizontal="true" android:layout_marginTop="33dp" android:ems="10" android:hint="Password" android:inputType="textPassword" /></RelativeLayout>

W

Page 24: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Activity_main.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.couriermyshopz.MainActivity"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="34dp" android:text="Welcome" /> <TextView android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_centerHorizontal="true" android:layout_marginTop="9dp" /> <Button android:id="@+id/Map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="sendMap" android:text="View Map" android:layout_marginTop="32dp" android:layout_below="@+id/button2" android:layout_alignRight="@+id/button2" android:layout_alignEnd="@+id/button2" /> <Button android:id="@+id/logout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignEnd="@+id/Map" android:layout_alignRight="@+id/Map" android:layout_below="@+id/Map" android:layout_marginTop="23dp" android:text="Logout" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/email" android:layout_centerHorizontal="true" android:layout_marginTop="30dp" android:onClick="sendbuy" android:text="List Buy" /></RelativeLayout>

X

Page 25: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Activity_maps.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rel" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#372492" android:weightSum="1"> <!-- The map fragments will go here --> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myapplication.MapsActivity" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:id="@+id/tvDistance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginLeft="29dp" android:layout_marginStart="29dp" android:layout_marginTop="33dp" android:text="TextView" /> <TextView andro<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.couriermyshopz">

<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" />

Y

Page 26: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".BuylistActivity" /> <activity android:name=".MainActivity" /> <!-- The API key for Google Maps-based APIs is defined as a string resource. (See the file "res/values/google_maps_api.xml"). Note that the API key is linked to the encryption key used to sign the APK. You need a different API key for each encryption key, including the release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" />

<activity android:name=".MapsActivity" />

</application>

</manifest>id:id="@+id/tvDuration" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvDistance" android:layout_alignStart="@+id/tvDistance" android:layout_below="@+id/tvDistance" android:layout_marginTop="7dp" android:text="TextView" /></RelativeLayout>

Z

Page 27: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.couriermyshopz"><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".BuylistActivity" /> <activity android:name=".MainActivity" /> <!-- The API key for Google Maps-based APIs is defined as a string resource. (See the file "res/values/google_maps_api.xml"). Note that the API key is linked to the encryption key used to sign the APK. You need a different API key for each encryption key, includingthe release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" /> <activity android:name=".MapsActivity" /></application></manifest>

AA

Page 28: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Gradle CourierMyShopz

// Top-level build file where you can add configuration options common toall sub-projects/modules.buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.google.gms:google-services:3.0.0' }}allprojects { repositories { jcenter() maven { url 'https://maven.fabric.io/public' } }}task clean(type: Delete) { delete rootProject.buildDir}

AB

Page 29: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Gradle app CourierMyShopz

apply plugin: 'com.android.application'android { compileSdkVersion 25 buildToolsVersion "25.0.3" defaultConfig { applicationId "com.example.couriermyshopz" minSdkVersion 16 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/ASL2.0' }}dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.firebase:firebase-client-android:2.3.1' compile 'com.firebaseui:firebase-ui:1.2.0' compile 'com.google.android.gms:play-services-maps:10.2.0' compile 'com.google.android.gms:play-services-location:10.2.0' compile 'com.google.firebase:firebase-auth:10.2.0' compile 'com.google.firebase:firebase-database:10.2.0' compile 'com.akexorcist:googledirectionlibrary:1.0.4' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:recyclerview-v7:25.1.1' testCompile 'junit:junit:4.12'}apply plugin: 'com.google.gms.google-services'

AC

Page 30: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Application MyShopz

Coding BuyActivity.java

package com.example.myshopz;import android.app.Activity;import android.content.Intent;import android.content.pm.PackageManager;import android.location.Location;import android.location.LocationManager;import android.os.Bundle;import android.support.v4.app.ActivityCompat;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.firebase.client.Firebase;import com.google.firebase.auth.FirebaseAuth;import com.google.firebase.auth.FirebaseUser;import com.google.firebase.database.DatabaseReference;import com.google.firebase.database.FirebaseDatabase;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class BuyActivity extends Activity { private String nama; private String notelp; private String piringplastik; private String gelasplastik; private String sabut; private String sedotanplastik; private String plastikultah; String tampils; private EditText editnama; private EditText editnotelp; private EditText editPiringplastik; private EditText editGelasplastik; private EditText editSabut; private EditText editSedotanplastik; private EditText editPlastikultah; double latitude,longtitude; Date today = Calendar.getInstance().getTime(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss"); String date = formatter.format(today); private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_buy); Firebase.setAndroidContext(this); mAuth = FirebaseAuth.getInstance(); final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser(); final String tampil = firebaseUser.getEmail(); final Button buy = (Button) findViewById(R.id.buybtn);

AD

Page 31: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

editnama = (EditText) findViewById(R.id.editnama); editnotelp = (EditText) findViewById(R.id.editnotelp); editPiringplastik = (EditText) findViewById(R.id.editpiringplastik); editGelasplastik = (EditText) findViewById(R.id.editgelasplastik); editSabut = (EditText) findViewById(R.id.editsabut); editSedotanplastik = (EditText) findViewById(R.id.editsedotanplastik); editPlastikultah = (EditText) findViewById(R.id.editplastikultah); final Firebase ref = new Firebase("https://buydata-66bfa.firebaseio.com/"); LocationManager locationManager = (LocationManager) getSystemService(android.content.Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode,String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } Location mylocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); latitude = mylocation.getLatitude(); longtitude = mylocation.getLongitude(); //final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("detailz"); buy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if ( editnama.getText().toString().equals("") | editnotelp.getText().toString().equals("") | editPiringplastik.getText().toString().equals("") | editGelasplastik.getText().toString().equals("") | editSabut.getText().toString().equals("") | editSedotanplastik.getText().toString().equals("") |

AE

Page 32: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

editPlastikultah.getText().toString().equals("") ) { nama = editnama.getText().toString().trim(); String email = tampil; notelp = editnotelp.getText().toString().trim(); piringplastik = editPiringplastik.getText().toString().trim(); gelasplastik = editGelasplastik.getText().toString().trim(); sabut = editSabut.getText().toString().trim(); sedotanplastik = editSedotanplastik.getText().toString().trim(); plastikultah = editPlastikultah.getText().toString().trim(); String tanggal = date; String idBuy = date; tampils = firebaseUser.getEmail().replace(".",","); final Firebase detail = ref.child("detailz").push(); detail.child("IdBuy").setValue(tanggal); detail.child("nama").setValue(nama); detail.child("email").setValue(email); detail.child("nomor telepon").setValue(notelp); detail.child("alamat asal").setValue(getIntent().getStringExtra("origin")); detail.child("alamat tujuan").setValue(getIntent().getStringExtra("destination")); detail.child("piring plastik").setValue("0"); detail.child("gelas plastik").setValue("0"); detail.child("sabut").setValue("0"); detail.child("sedotan plastik").setValue("0"); detail.child("plastik ultah").setValue("0"); detail.child("status").setValue("Belum Terkirim"); } else { nama = editnama.getText().toString().trim(); String email = tampil; notelp = editnotelp.getText().toString().trim(); piringplastik = editPiringplastik.getText().toString().trim(); gelasplastik = editGelasplastik.getText().toString().trim(); sabut = editSabut.getText().toString().trim(); sedotanplastik = editSedotanplastik.getText().toString().trim(); plastikultah = editPlastikultah.getText().toString().trim(); String tanggal = date; final Firebase detail = ref.child("detailz").push(); detail.child("idbuy").setValue(tanggal); detail.child("nama").setValue(nama); detail.child("email").setValue(email); detail.child("nomor telepon").setValue(notelp);

AF

Page 33: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

detail.child("Latitude User").setValue(latitude); detail.child("Longtitude User").setValue(longtitude); detail.child("alamat asal").setValue(getIntent().getStringExtra("origin")); detail.child("alamat tujuan").setValue(getIntent().getStringExtra("destination")); detail.child("piring plastik").setValue(piringplastik); detail.child("gelas plastik").setValue(gelasplastik); detail.child("sabut").setValue(sabut); detail.child("sedotan plastik").setValue(sedotanplastik); detail.child("plastik ultah").setValue(plastikultah); detail.child("status").setValue("Belum Terkirim"); Toast.makeText(getApplicationContext(), "Data Has Been Saved", Toast.LENGTH_LONG).show(); } } }); } public void sendlistView(View view) { Intent intent = new Intent(BuyActivity.this,BuylistActivity.class); startActivity(intent); }}

AG

Page 34: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding BuylistActivity.java

package com.example.myshopz;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import com.firebase.client.ChildEventListener;import com.firebase.client.DataSnapshot;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import com.firebase.client.Query;import com.google.firebase.auth.FirebaseAuth;import com.google.firebase.auth.FirebaseUser;import java.util.ArrayList;public class BuylistActivity extends Activity { private ArrayList<Object> mDetail = new ArrayList<>(); private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_buylist); ListView mValueView = (ListView) findViewById(R.id.valueViewz); mAuth = FirebaseAuth.getInstance(); FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser(); String tampil = firebaseUser.getEmail(); final Firebase mRef = new Firebase("https://buydata-66bfa.firebaseio.com/detailz"); Query mref = mRef.orderByChild("email").startAt(tampil).endAt(tampil); final ArrayAdapter<Object> arrayAdapters = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mDetail); mValueView.setAdapter(arrayAdapters); mref.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { Object value =dataSnapshot.getValue().toString().replace("{","").replace("}","").replace(",","\n"); mDetail.add(value); arrayAdapters.notifyDataSetChanged();//buat list view real time } @Override public void onChildChanged(DataSnapshot dataSnapshot, Strings) { } @Override public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) {

AH

Page 35: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

} @Override public void onCancelled(FirebaseError firebaseError) { } }); }}

AI

Page 36: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding ListActivity.java

package com.example.myshopz;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import com.firebase.client.ChildEventListener;import com.firebase.client.DataSnapshot;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import java.util.ArrayList;public class ListActivity extends Activity { private ArrayList<String> mCoordinat = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); ListView mValueView = (ListView) findViewById(R.id.valueView); Firebase mRef = new Firebase("https://maps-9d8af.firebaseio.com/LatLong"); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mCoordinat); mValueView.setAdapter(arrayAdapter); mRef.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { String value = dataSnapshot.getValue(String.class); mCoordinat.add(value); arrayAdapter.notifyDataSetChanged(); } @Override public void onChildChanged(DataSnapshot dataSnapshot, Strings) { } @Override public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The read failed: " + firebaseError.getMessage()); } }); }}

AJ

Page 37: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding LoginActivity.java

package com.example.myshopz;import android.content.Intent;import android.os.Bundle;import android.support.annotation.NonNull;import android.support.v7.app.AppCompatActivity;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.google.android.gms.tasks.OnCompleteListener;import com.google.android.gms.tasks.Task;import com.google.firebase.auth.AuthResult;import com.google.firebase.auth.FirebaseAuth;public class LoginActivity extends AppCompatActivity { private EditText mEmail; private EditText mPassword; private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mAuth = FirebaseAuth.getInstance(); mEmail = (EditText) findViewById(R.id.email); mPassword = (EditText) findViewById(R.id.password); Button mLogin = (Button) findViewById(R.id.login); mAuthListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { if(firebaseAuth.getCurrentUser() != null ) { startActivity(new Intent(LoginActivity.this,MainActivity.class)); } } }; mLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startSignIn(); } }); } @Override public void onStart() { super.onStart(); mAuth.addAuthStateListener(mAuthListener); } public void sendRegister(View view) { Intent intent = new Intent(LoginActivity.this,RegisterActivity.class); startActivity(intent);

AK

Page 38: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

} private void startSignIn() { String Email = mEmail.getText().toString(); String Password = mPassword.getText().toString(); if (TextUtils.isEmpty(Email) || TextUtils.isEmpty(Password)) { Toast.makeText(LoginActivity.this, "Field Are Empty", Toast.LENGTH_SHORT).show(); } else { mAuth.signInWithEmailAndPassword(Email, Password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Toast.makeText(LoginActivity.this, "SignIn Berhasil", Toast.LENGTH_SHORT).show(); } // ... } }); } }}

AL

Page 39: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding MainActivity.java

package com.example.myshopz;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.TextView;import com.google.firebase.auth.FirebaseAuth;import com.google.firebase.auth.FirebaseUser;public class MainActivity extends AppCompatActivity { private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAuth = FirebaseAuth.getInstance(); FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser(); Button mLogout = (Button) findViewById(R.id.logout); TextView emails = (TextView) findViewById(R.id.email); String tampil = firebaseUser.getEmail(); emails.setText(tampil); mLogout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mAuth.removeAuthStateListener(mAuthListener); FirebaseAuth.getInstance().signOut(); Intent intent = new Intent(MainActivity.this,LoginActivity.class); startActivity(intent); } }); } public void sendMap(View view) { Intent intents = new Intent(MainActivity.this,MapsActivity.class); startActivity(intents); } public void sendBuy(View view) { Intent intent2 = new Intent(MainActivity.this,BuyActivity.class); startActivity(intent2); }}

AM

Page 40: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding MapsActivity.java

package com.example.myshopz;import android.app.ProgressDialog;import android.content.Context;import android.content.Intent;import android.content.pm.PackageManager;import android.graphics.Color;import android.location.Address;import android.location.Geocoder;import android.location.Location;import android.location.LocationManager;import android.os.Bundle;import android.support.v4.app.ActivityCompat;import android.support.v4.app.FragmentActivity;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;import com.firebase.client.Firebase;import com.google.android.gms.common.api.GoogleApiClient;import com.google.android.gms.location.LocationListener;import com.google.android.gms.location.LocationRequest;import com.google.android.gms.location.LocationServices;import com.google.android.gms.maps.CameraUpdateFactory;import com.google.android.gms.maps.GoogleMap;import com.google.android.gms.maps.OnMapReadyCallback;import com.google.android.gms.maps.SupportMapFragment;import com.google.android.gms.maps.model.BitmapDescriptorFactory;import com.google.android.gms.maps.model.Marker;import com.google.android.gms.maps.model.MarkerOptions;import com.google.android.gms.maps.model.Polyline;import com.google.android.gms.maps.model.PolylineOptions;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.util.ArrayList;import java.util.List;import java.util.Locale;import Modules.DirectionFinder;import Modules.DirectionFinderListener;import Modules.Route;public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, DirectionFinderListener { private GoogleMap mMap; private LocationListener locationListener; private Firebase mRef; private Button btnFindPath; private EditText etOrigin; private EditText etDestination; private List<Marker> originMarkers = new ArrayList<>(); private List<Marker> destinationMarkers = new ArrayList<>(); private List<Polyline> polylinePaths = new ArrayList<>(); private ProgressDialog progressDialog; GoogleApiClient mGoogleApiClient; LocationRequest mLocationRequest; @Override protected void onCreate(Bundle savedInstanceState) {

AN

Page 41: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); btnFindPath = (Button) findViewById(R.id.btnFindPath); etOrigin = (EditText) findViewById(R.id.etOrigin); etDestination = (EditText) findViewById(R.id.etDestination); btnFindPath.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendRequest(); String origin = etOrigin.getText().toString(); String destination = etDestination.getText().toString(); Intent intent = new Intent(v.getContext(),BuyActivity.class); intent.putExtra("origin", origin); intent.putExtra("destination",destination); startActivity(intent); } }); locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (mGoogleApiClient != null) { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,locationListener ); } } }; } private void sendRequest() { String origin = etOrigin.getText().toString(); String destination = etDestination.getText().toString(); if (origin.isEmpty()) { Toast.makeText(this, "Please enter origin address!", Toast.LENGTH_SHORT).show(); return; } if (destination.isEmpty()) { Toast.makeText(this, "Please enter destination address!", Toast.LENGTH_SHORT).show(); return; } try { new DirectionFinder(this, origin, destination).execute(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }

AO

Page 42: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode,String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } mMap.setMyLocationEnabled(true); mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { @Override public boolean onMyLocationButtonClick() { if (mGoogleApiClient != null) { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationListener); } Geocoder geocoder; Location location; LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); List<Address> addresses; if (location != null) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); geocoder = new Geocoder(MapsActivity.this, Locale.getDefault()); try { addresses = geocoder.getFromLocation(latitude,longitude, 1); String address = addresses.get(0).getAddressLine(0); String country = addresses.get(0).getSubAdminArea(); String fullAddress = address+ ", " + country; etOrigin.setText(fullAddress, TextView.BufferType.EDITABLE); } catch (IOException e) { e.printStackTrace();

AP

Page 43: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

} } return false; } }); } @Override public void onDirectionFinderStart() { progressDialog = ProgressDialog.show(this, "Please wait.", "Finding direction..!", true); if (originMarkers != null) { for (Marker marker : originMarkers) { marker.remove(); } } if (destinationMarkers != null) { for (Marker marker : destinationMarkers) { marker.remove(); } } if (polylinePaths != null) { for (Polyline polyline:polylinePaths ) { polyline.remove(); } } } @Override public void onDirectionFinderSuccess(List<Route> routes) { progressDialog.dismiss(); polylinePaths = new ArrayList<>(); originMarkers = new ArrayList<>(); destinationMarkers = new ArrayList<>(); for (Route route : routes) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 16)); ((TextView) findViewById(R.id.tvDuration)).setText(route.duration.text); ((TextView) findViewById(R.id.tvDistance)).setText(route.distance.text); originMarkers.add(mMap.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue)) .title(route.startAddress) .position(route.startLocation))); destinationMarkers.add(mMap.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green)) .title(route.endAddress) .position(route.endLocation))); PolylineOptions polylineOptions = new PolylineOptions(). geodesic(true). color(Color.BLUE). width(10);

AQ

Page 44: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

for (int i = 0; i < route.points.size(); i++) polylineOptions.add(route.points.get(i)); polylinePaths.add(mMap.addPolyline(polylineOptions)); } }}

AR

Page 45: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Register.java

package com.example.myshopz;import android.content.Intent;import android.os.Bundle;import android.support.annotation.NonNull;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.firebase.client.Firebase;import com.google.android.gms.tasks.OnCompleteListener;import com.google.android.gms.tasks.Task;import com.google.firebase.auth.AuthResult;import com.google.firebase.auth.FirebaseAuth;public class RegisterActivity extends AppCompatActivity { private EditText mEmail; private EditText mPassword; private FirebaseAuth mAuth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); Firebase.setAndroidContext(this); mAuth = FirebaseAuth.getInstance(); mEmail = (EditText) findViewById(R.id.email); mPassword = (EditText) findViewById(R.id.password); Button mRegister = (Button) findViewById(R.id.register); mRegister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startRegister(); } }); } public void sendLogin(View view) { Intent intent = new Intent(RegisterActivity.this,LoginActivity.class); startActivity(intent); } private void startRegister() { final String Email = mEmail.getText().toString(); final String Password = mPassword.getText().toString(); final Firebase mref = new Firebase("https://myshopz-38cc8.firebaseio.com/"); mAuth.createUserWithEmailAndPassword(Email, Password) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { Toast.makeText(RegisterActivity.this,"Sign Up Berhasil", Toast.LENGTH_LONG).show();

AS

Page 46: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

final Firebase detail = mref.child("EmailnPassword").push(); detail.child("Email").setValue(Email); detail.child("Password").setValue(Password); detail.push(); } else { Toast.makeText(RegisterActivity.this,task.getException().getMessage(),Toast.LENGTH_LONG).show(); } } }); }}

AT

Page 47: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Modules/DirectionFinder.java

package Modules;import android.os.AsyncTask;import com.google.android.gms.maps.model.LatLng;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.MalformedURLException;import java.net.URL;import java.net.URLEncoder;import java.util.ArrayList;import java.util.List;public class DirectionFinder { private static final String DIRECTION_URL_API = "https://maps.googleapis.com/maps/api/directions/json?"; private static final String GOOGLE_API_KEY = "AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU"; private DirectionFinderListener listener; private String origin; private String destination; public DirectionFinder(DirectionFinderListener listener, String origin, String destination) { this.listener = listener; this.origin = origin; this.destination = destination; } public void execute() throws UnsupportedEncodingException { listener.onDirectionFinderStart(); new DownloadRawData().execute(createUrl()); } private String createUrl() throws UnsupportedEncodingException { String urlOrigin = URLEncoder.encode(origin, "utf-8"); String urlDestination = URLEncoder.encode(destination, "utf-8"); return DIRECTION_URL_API + "origin=" + urlOrigin + "&destination=" + urlDestination + "&key=" + GOOGLE_API_KEY; } private class DownloadRawData extends AsyncTask<String, Void, String>{ @Override protected String doInBackground(String... params) { String link = params[0]; try { URL url = new URL(link); InputStream is = url.openConnection().getInputStream(); StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n");

AU

Page 48: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

} return buffer.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String res) { try { parseJSon(res); } catch (JSONException e) { e.printStackTrace(); } } } private void parseJSon(String data) throws JSONException { if (data == null) return; List<Route> routes = new ArrayList<Route>(); JSONObject jsonData = new JSONObject(data); JSONArray jsonRoutes = jsonData.getJSONArray("routes"); for (int i = 0; i < jsonRoutes.length(); i++) { JSONObject jsonRoute = jsonRoutes.getJSONObject(i); Route route = new Route(); JSONObject overview_polylineJson = jsonRoute.getJSONObject("overview_polyline"); JSONArray jsonLegs = jsonRoute.getJSONArray("legs"); JSONObject jsonLeg = jsonLegs.getJSONObject(0); JSONObject jsonDistance = jsonLeg.getJSONObject("distance"); JSONObject jsonDuration = jsonLeg.getJSONObject("duration"); JSONObject jsonEndLocation = jsonLeg.getJSONObject("end_location"); JSONObject jsonStartLocation = jsonLeg.getJSONObject("start_location"); route.distance = new Distance(jsonDistance.getString("text"), jsonDistance.getInt("value")); route.duration = new Duration(jsonDuration.getString("text"), jsonDuration.getInt("value")); route.endAddress = jsonLeg.getString("end_address"); route.startAddress = jsonLeg.getString("start_address"); route.startLocation = new LatLng(jsonStartLocation.getDouble("lat"), jsonStartLocation.getDouble("lng")); route.endLocation = new LatLng(jsonEndLocation.getDouble("lat"), jsonEndLocation.getDouble("lng")); route.points = decodePolyLine(overview_polylineJson.getString("points")); routes.add(route); } listener.onDirectionFinderSuccess(routes); }

AV

Page 49: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

private List<LatLng> decodePolyLine(final String poly) { int len = poly.length(); int index = 0; List<LatLng> decoded = new ArrayList<LatLng>(); int lat = 0; int lng = 0; while (index < len) { int b; int shift = 0; int result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; decoded.add(new LatLng( lat / 100000d, lng / 100000d )); } return decoded; }}

Coding Modules/DirectionFinderListener.java

package Modules;import java.util.List;public interface DirectionFinderListener { void onDirectionFinderStart(); void onDirectionFinderSuccess(List<Route> route);}

AW

Page 50: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Modules/Distance.java

package Modules;public class Distance { public String text; public int value; public Distance(String text, int value) { this.text = text; this.value = value; }}

Coding Modules/Duration.java

package Modules;public class Duration { public String text; public int value; public Duration(String text, int value) { this.text = text; this.value = value; }}

Coding Modules/Route.java

package Modules;import com.google.android.gms.maps.model.LatLng;import java.util.List;public class Route { public Distance distance; public Duration duration; public String endAddress; public LatLng endLocation; public String startAddress; public LatLng startLocation; public List<LatLng> points;}

AX

Page 51: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_buy.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" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myshopz.BuyActivity"> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="13dp" android:text="@string/buy" android:textSize="50sp" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/gelasplastik" android:layout_toEndOf="@+id/gelasplastik" /> <TextView android:id="@+id/piringplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="120dp" android:text="@string/piring_plastik" android:textSize="20sp" android:layout_below="@+id/textView5" android:layout_toLeftOf="@+id/editpiringplastik" android:layout_toStartOf="@+id/editpiringplastik" /> <TextView android:id="@+id/sabut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="13dp" android:text="@string/sabut" android:textSize="20sp" android:layout_marginRight="22dp" android:layout_marginEnd="22dp" android:layout_below="@+id/editgelasplastik" android:layout_alignRight="@+id/gelasplastik" android:layout_alignEnd="@+id/gelasplastik" /> <TextView android:id="@+id/plastikultah" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="@string/plastik_ultah" android:layout_below="@+id/sedotanplastik" android:layout_alignLeft="@+id/sedotanplastik" android:layout_alignStart="@+id/sedotanplastik" android:textSize="20sp" /> <TextView android:id="@+id/sedotanplastik" android:layout_width="wrap_content"

AY

Page 52: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

android:layout_height="wrap_content" android:layout_marginTop="22dp" android:text="@string/sedotan_plastik" android:textSize="20sp" android:layout_below="@+id/sabut" android:layout_alignLeft="@+id/piringplastik" android:layout_alignStart="@+id/piringplastik" /> <TextView android:id="@+id/gelasplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/gelas_plastik" android:textSize="20sp" android:layout_alignBaseline="@+id/editgelasplastik" android:layout_alignBottom="@+id/editgelasplastik" android:layout_alignRight="@+id/plastikultah" android:layout_alignEnd="@+id/plastikultah" /> <Button android:id="@+id/buybtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="56dp" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:text="buy" /> <EditText android:id="@+id/editpiringplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignTop="@+id/piringplastik" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editgelasplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editpiringplastik" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editsabut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/sabut" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:ems="10" android:inputType="number" />

AZ

Page 53: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<EditText android:id="@+id/editsedotanplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/sedotanplastik" android:layout_alignLeft="@+id/editplastikultah" android:layout_alignStart="@+id/editplastikultah" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editplastikultah" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/plastikultah" android:layout_alignBottom="@+id/plastikultah" android:layout_marginLeft="21dp" android:layout_marginStart="21dp" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:ems="10" android:inputType="number" /> <Button android:id="@+id/Buylist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/buybtn" android:layout_marginLeft="12dp" android:layout_marginStart="12dp" android:layout_toEndOf="@+id/buybtn" android:layout_toRightOf="@+id/buybtn" android:onClick="sendlistView" android:text="@string/list_detail" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="18dp" android:text="@string/no_telepon" android:textSize="20sp" android:layout_above="@+id/editpiringplastik" android:layout_alignLeft="@+id/piringplastik" android:layout_alignStart="@+id/piringplastik" /> <EditText android:id="@+id/editnotelp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/textView4" android:layout_toEndOf="@+id/gelasplastik" android:layout_toRightOf="@+id/gelasplastik" android:ems="10" android:inputType="phone" />

BA

Page 54: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView4" android:layout_alignLeft="@+id/sabut" android:layout_alignStart="@+id/sabut" android:layout_marginBottom="16dp" android:text="@string/nama" android:textSize="20sp" /> <EditText android:id="@+id/editnama" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignTop="@+id/textView6" android:ems="10" android:inputType="textPersonName" /> <TextView android:id="@+id/TextViewSubtotal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/plastikultah" android:layout_alignStart="@+id/plastikultah" android:layout_below="@+id/editplastikultah" android:layout_marginLeft="11dp" android:layout_marginStart="11dp" android:layout_marginTop="9dp" android:text="Total" android:layout_alignRight="@+id/textView4" android:layout_alignEnd="@+id/textView4" android:layout_alignBottom="@+id/buybtn" /></RelativeLayout>

Coding activity_buylist.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/valueViewz" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>

BB

Page 55: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_list.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/valueView" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>

BC

Page 56: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_login.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myshopz.LoginActivity" tools:layout_editor_absoluteY="81dp" tools:layout_editor_absoluteX="0dp"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="88dp" android:text="Login" android:textSize="50sp" /> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="35dp" android:text="Login" android:layout_below="@+id/password" android:layout_centerHorizontal="true" /> <EditText android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/textView2" android:layout_marginLeft="70dp" android:layout_marginStart="70dp" android:layout_marginTop="32dp" android:ems="10" android:hint="Email" android:inputType="textEmailAddress" /> <EditText android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/email" android:layout_centerHorizontal="true" android:layout_marginTop="33dp" android:ems="10" android:hint="Password" android:inputType="textPassword" />

BD

Page 57: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="44dp" android:text="Doesn't Have Account?" android:layout_alignParentBottom="true" android:layout_alignLeft="@+id/password" android:layout_alignStart="@+id/password" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView3" android:layout_alignBottom="@+id/textView3" android:layout_toEndOf="@+id/login" android:layout_toRightOf="@+id/login" android:clickable="true" android:onClick="sendRegister" android:text="Register" android:textColor="@color/colorAccent" /></RelativeLayout>

BE

Page 58: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_register.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myshopz.MainActivity"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="34dp" android:text="Welcome" /> <TextView android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_centerHorizontal="true" android:layout_marginTop="9dp" /> <Button android:id="@+id/buybtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/email" android:layout_centerHorizontal="true" android:layout_marginTop="83dp" android:onClick="sendBuy" android:text="Buy" /> <Button android:id="@+id/Map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="sendMap" android:text="View Map" android:layout_centerVertical="true" android:layout_alignLeft="@+id/buybtn" android:layout_alignStart="@+id/buybtn" /> <Button android:id="@+id/logout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignEnd="@+id/Map" android:layout_alignRight="@+id/Map" android:layout_below="@+id/Map" android:layout_marginTop="23dp" android:text="Logout" /></RelativeLayout>

BF

Page 59: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Gradle MyShopz

// Top-level build file where you can add configuration options common toall sub-projects/modules.buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.google.gms:google-services:3.0.0' }}allprojects { repositories { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}

BG

Page 60: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding app MyShopz

apply plugin: 'com.android.application'android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.example.myshopz" minSdkVersion 14 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/ASL2.0' }}dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.firebase:firebase-client-android:2.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.google.firebase:firebase-auth:10.2.6' compile 'com.google.firebase:firebase-database:10.2.6' compile 'com.google.android.gms:play-services-maps:10.2.6' compile 'com.google.android.gms:play-services-location:10.2.6' testCompile 'junit:junit:4.12'}apply plugin: 'com.google.gms.google-services'

BH

Page 61: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Android Manifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myshopz"> <!-- The ACCESS_COARSE/FINE_LOCATION permissions are not required touse Google Maps Android API v2, but you must specify either coarse or fine location permissions for the 'MyLocation' functionality. --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="Myshopz" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <!-- The API key for Google Maps-based APIs is defined as a string resource. (See the file "res/values/google_maps_api.xml"). Note that the API key is linked to the encryption key usedto sign the APK. You need a different API key for each encryption key, including the release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU" /> <activity android:name=".MapsActivity" android:label="@string/title_activity_maps" /> <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".RegisterActivity" android:label="Register" /> <activity android:name=".ListActivity" android:label="List" />

BI

Page 62: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<activity android:name=".MainActivity" android:label="Myshopz" /> <activity android:name=".BuyActivity" android:label="Buy" /> <activity android:name=".BuylistActivity" android:label="BuyList" /></activity> </application></manifest>

BJ

Page 63: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Application Maps

Coding MapsActivity.java

package com.example.maps;import android.app.ProgressDialog;import android.content.Context;import android.content.Intent;import android.content.pm.PackageManager;import android.graphics.Color;import android.location.Address;import android.location.Geocoder;import android.location.Location;import android.location.LocationManager;import android.os.Build;import android.os.Bundle;import android.support.v4.app.ActivityCompat;import android.support.v4.app.FragmentActivity;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;import com.firebase.client.Firebase;import com.google.android.gms.common.api.GoogleApiClient;import com.google.android.gms.location.LocationServices;import com.google.android.gms.maps.CameraUpdateFactory;import com.google.android.gms.maps.GoogleMap;import com.google.android.gms.location.LocationListener;import com.google.android.gms.location.LocationRequest;import com.google.android.gms.maps.OnMapReadyCallback;import com.google.android.gms.maps.SupportMapFragment;import com.google.android.gms.maps.model.BitmapDescriptorFactory;import com.google.android.gms.maps.model.Marker;import com.google.android.gms.maps.model.MarkerOptions;import com.google.android.gms.maps.model.Polyline;import com.google.android.gms.maps.model.PolylineOptions;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.util.ArrayList;import java.util.List;import java.util.Locale;import Modules.DirectionFinder;import Modules.DirectionFinderListener;import Modules.Route;public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, DirectionFinderListener { private Button mSaveData; private LocationListener locationListener; private LocationManager locationManager; private Firebase mRef; private Button btnFindPath; private EditText etOrigin; private EditText etDestination; private List<Marker> originMarkers = new ArrayList<>(); private List<Marker> destinationMarkers = new ArrayList<>(); private List<Polyline> polylinePaths = new ArrayList<>(); private ProgressDialog progressDialog;

BK

Page 64: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

private GoogleMap mMap; GoogleApiClient mGoogleApiClient; LocationRequest mLocationRequest; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); Firebase.setAndroidContext(this); mSaveData = (Button) findViewById(R.id.saveFb); mRef = new Firebase("https://maps-9d8af.firebaseio.com/"); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); etOrigin = (EditText)findViewById(R.id.etOrigin); locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { final double latitude = location.getLatitude(); final double longitude = location.getLongitude(); mSaveData.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { Firebase mRefChild = mRef.child("LatLong").push(); mRefChild.setValue(latitude + " " + longitude); } }); if (mGoogleApiClient != null) { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,locationListener ); } } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{ android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.INTERNET }, 10); return; } } // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map);

BL

Page 65: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

mapFragment.getMapAsync(this); btnFindPath = (Button) findViewById(R.id.btnFindPath); etDestination = (EditText) findViewById(R.id.etDestination); btnFindPath.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendRequest(); String origin = etOrigin.getText().toString(); String destination = etDestination.getText().toString(); Intent intent = new Intent(v.getContext(),BuyActivity.class); intent.putExtra("origin", origin); intent.putExtra("destination",destination); startActivity(intent); } }); } public void sendMessage(View view) { Intent intent = new Intent(MapsActivity.this, ListActivity.class); startActivity(intent); } private void sendRequest() { String origin = etOrigin.getText().toString(); String destination = etDestination.getText().toString(); if (origin.isEmpty()) { Toast.makeText(this, "Please enter origin address!", Toast.LENGTH_SHORT).show(); return; } if (destination.isEmpty()) { Toast.makeText(this, "Please enter destination address!", Toast.LENGTH_SHORT).show(); return; } try { new DirectionFinder(this, origin, destination).execute(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mMap.setMyLocationEnabled(true); mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { @Override public boolean onMyLocationButtonClick() { if (mGoogleApiClient != null) { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationListener); }

BM

Page 66: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Geocoder geocoder; Location location; LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); List<Address> addresses; if (location != null) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); geocoder = new Geocoder(MapsActivity.this, Locale.getDefault()); try { addresses = geocoder.getFromLocation(latitude, longitude, 1); String address = addresses.get(0).getAddressLine(0); String country = addresses.get(0).getSubAdminArea(); String fullAddress = address+ ", " + country; etOrigin.setText(fullAddress, TextView.BufferType.EDITABLE); } catch (IOException e) { e.printStackTrace(); } } return false; } }); } @Override public void onDirectionFinderStart() { progressDialog = ProgressDialog.show(this, "Please wait.", "Finding direction..!", true); if (originMarkers != null) { for (Marker marker : originMarkers) { marker.remove(); } } if (destinationMarkers != null) { for (Marker marker : destinationMarkers) { marker.remove(); } } if (polylinePaths != null) { for (Polyline polyline:polylinePaths ) { polyline.remove(); } } } @Override public void onDirectionFinderSuccess(List<Route> routes) { progressDialog.dismiss(); polylinePaths = new ArrayList<>();

BN

Page 67: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

originMarkers = new ArrayList<>(); destinationMarkers = new ArrayList<>(); for (Route route : routes) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 16)); ((TextView) findViewById(R.id.tvDuration)).setText(route.duration.text); ((TextView) findViewById(R.id.tvDistance)).setText(route.distance.text); originMarkers.add(mMap.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue)) .title(route.startAddress) .position(route.startLocation))); destinationMarkers.add(mMap.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green)) .title(route.endAddress) .position(route.endLocation))); PolylineOptions polylineOptions = new PolylineOptions(). geodesic(true). color(Color.BLUE). width(10); for (int i = 0; i < route.points.size(); i++) polylineOptions.add(route.points.get(i)); polylinePaths.add(mMap.addPolyline(polylineOptions)); } }}

BO

Page 68: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding CourierEmaillistActivity.java

package com.example.maps;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import com.firebase.client.ChildEventListener;import com.firebase.client.DataSnapshot;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import com.firebase.client.Query;import java.util.ArrayList;public class CourierEmaillistActivity extends Activity { private ArrayList<Object> mCoordinat = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_emaillist); Firebase.setAndroidContext(this); final ListView mValueView = (ListView) findViewById(R.id.valueView); Firebase mRef = new Firebase("https://myshopz-38cc8.firebaseio.com/EmailnPassword"); final Query mref = mRef.orderByChild("email"); final ArrayAdapter<Object> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mCoordinat); mValueView.setAdapter(arrayAdapter); mref.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { Object value = dataSnapshot.getValue().toString().replace("{","").replace("}","").replace(",","\n"); mCoordinat.add(value); arrayAdapter.notifyDataSetChanged(); } @Override public void onChildChanged(DataSnapshot dataSnapshot, Strings) { } @Override public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The read failed: " + firebaseError.getMessage()); } }); }}

BP

Page 69: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding EmaillistActivity.java

package com.example.maps;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import com.firebase.client.ChildEventListener;import com.firebase.client.DataSnapshot;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import com.firebase.client.Query;import java.util.ArrayList;public class EmaillistActivity extends Activity { private ArrayList<Object> mCoordinat = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_emaillist); Firebase.setAndroidContext(this); final ListView mValueView = (ListView) findViewById(R.id.valueView); Firebase mRef = new Firebase("https://myshopz-38cc8.firebaseio.com/EmailnPassword"); final Query mref = mRef.orderByChild("email"); final ArrayAdapter<Object> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mCoordinat); mValueView.setAdapter(arrayAdapter); mref.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { Object value = dataSnapshot.getValue().toString().replace("{","").replace("}","").replace(",","\n"); mCoordinat.add(value); arrayAdapter.notifyDataSetChanged(); } @Override public void onChildChanged(DataSnapshot dataSnapshot, Strings) { } @Override public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The read failed: " + firebaseError.getMessage()); } }); }}

BQ

Page 70: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding ListActivity.java

package com.example.maps;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import com.firebase.client.ChildEventListener;import com.firebase.client.DataSnapshot;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import com.firebase.client.Query;import java.util.ArrayList;public class EmaillistActivity extends Activity { private ArrayList<Object> mCoordinat = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_emaillist); Firebase.setAndroidContext(this); final ListView mValueView = (ListView) findViewById(R.id.valueView); Firebase mRef = new Firebase("https://myshopz-38cc8.firebaseio.com/EmailnPassword"); final Query mref = mRef.orderByChild("email"); final ArrayAdapter<Object> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mCoordinat); mValueView.setAdapter(arrayAdapter); mref.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { Object value = dataSnapshot.getValue().toString().replace("{","").replace("}","").replace(",","\n"); mCoordinat.add(value); arrayAdapter.notifyDataSetChanged(); } @Override public void onChildChanged(DataSnapshot dataSnapshot, Strings) { } @Override public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The read failed: " + firebaseError.getMessage()); } }); }}

BR

Page 71: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding MainActivity.java

package com.example.maps;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void sendMap(View view) { Intent intents = new Intent(MainActivity.this,MapsActivity.class); startActivity(intents); } public void sendBuy(View view) { Intent intent2 = new Intent(MainActivity.this,BuyActivity.class); startActivity(intent2); } public void senduseremail(View view) { Intent intent3 = new Intent(MainActivity.this,EmaillistActivity.class); startActivity(intent3); } public void sendcourieremail(View view) { Intent intent4 = new Intent(MainActivity.this,EmaillistActivity.class); startActivity(intent4); }}

BS

Page 72: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding BuyActivity.java

package com.example.maps;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.firebase.client.Firebase;public class BuyActivity extends Activity { private String nama; private String notelp; private String piringplastik; private String gelasplastik; private String sabut; private String sedotanplastik; private String plastikultah; private EditText editnama; private EditText editnotelp; private EditText editPiringplastik; private EditText editGelasplastik; private EditText editSabut; private EditText editSedotanplastik; private EditText editPlastikultah; //String date = DateFormat.getDateTimeInstance().format(new Date()); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_buy); Firebase.setAndroidContext(this); editnama = (EditText) findViewById(R.id.editnama); editnotelp = (EditText) findViewById(R.id.editnotelp); editPiringplastik = (EditText) findViewById(R.id.editpiringplastik); editGelasplastik = (EditText) findViewById(R.id.editgelasplastik); editSabut = (EditText) findViewById(R.id.editsabut); editSedotanplastik = (EditText) findViewById(R.id.editsedotanplastik); editPlastikultah = (EditText) findViewById(R.id.editplastikultah); final Button buy = (Button) findViewById(R.id.buy); final Firebase ref = new Firebase("https://buydata-66bfa.firebaseio.com/"); buy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if ( editnama.getText().toString().equals("") | editnotelp.getText().toString().equals("") | editPiringplastik.getText().toString().equals("") | editGelasplastik.getText().toString().equals("") |

BT

Page 73: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

editSedotanplastik.getText().toString().equals("") | editPlastikultah.getText().toString().equals("") ) { Toast.makeText(BuyActivity.this, "Input Text Kosong..Tolong masukan Text", Toast.LENGTH_SHORT).show(); } else { nama = editnama.getText().toString().trim(); notelp = editnotelp.getText().toString().trim(); piringplastik = editPiringplastik.getText().toString().trim(); gelasplastik = editGelasplastik.getText().toString().trim(); sabut = editSabut.getText().toString().trim(); sedotanplastik = editSedotanplastik.getText().toString().trim(); plastikultah = editPlastikultah.getText().toString().trim(); //String tanggal = date; final Firebase detail = ref.child("detailz").push(); detail.child("nama").setValue(nama); detail.child("nomor telepon").setValue(notelp); detail.child("alamat asal").setValue(getIntent().getStringExtra("origin")); detail.child("alamat tujuan").setValue(getIntent().getStringExtra("destination")); detail.child("piringplastik").setValue(piringplastik); detail.child("gelasplastik").setValue(gelasplastik); detail.child("sabut").setValue(sabut); detail.child("sedotanplastik").setValue(sedotanplastik); detail.child("plastikultah").setValue(plastikultah); //detail.child("tanggal").setValue(tanggal); detail.push(); Toast.makeText(getApplicationContext(), "Data Has Been Saved", Toast.LENGTH_LONG).show(); } } }); } public void sendlistView(View view) { Intent intent = new Intent(BuyActivity.this,BuylistActivity.class); startActivity(intent); }}

BU

Page 74: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding BuylistActivity.java

package com.example.maps;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import com.firebase.client.ChildEventListener;import com.firebase.client.DataSnapshot;import com.firebase.client.Firebase;import com.firebase.client.FirebaseError;import com.firebase.client.Query;import com.firebase.client.ValueEventListener;import com.google.firebase.auth.FirebaseAuth;import java.util.ArrayList;public class BuylistActivity extends Activity { private ArrayList<Object> mDetail = new ArrayList<>(); private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_buylist); ListView mValueView = (ListView) findViewById(R.id.valueViewz); Firebase mRef = new Firebase("https://buydata-66bfa.firebaseio.com/detailz"); final Query mref = mRef.orderByChild("nama"); final ArrayAdapter<Object> arrayAdapters = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mDetail); mValueView.setAdapter(arrayAdapters); mref.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { mref.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot){ Object value =dataSnapshot.getValue().toString().replace("{","").replace("}","").replace(",","\n"); mDetail.add(value); arrayAdapters.notifyDataSetChanged();//buat list view real time } @Override public void onCancelled(FirebaseError firebaseError) { } }); } @Override public void onChildChanged(DataSnapshot dataSnapshot, Strings) { }

BV

Page 75: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

@Override public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(FirebaseError firebaseError) { } }); }}

BW

Page 76: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_maps.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.maps.BuyActivity"> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="13dp" android:text="Buy" android:textSize="50sp" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/gelasplastik" android:layout_toEndOf="@+id/gelasplastik" /> <TextView android:id="@+id/piringplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="120dp" android:text="Piring Plastik" android:textSize="20sp" android:layout_below="@+id/textView5" android:layout_toLeftOf="@+id/editpiringplastik" android:layout_toStartOf="@+id/editpiringplastik" /> <TextView android:id="@+id/sabut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="13dp" android:text="Sabut" android:textSize="20sp" android:layout_marginRight="22dp" android:layout_marginEnd="22dp" android:layout_below="@+id/editgelasplastik" android:layout_alignRight="@+id/gelasplastik" android:layout_alignEnd="@+id/gelasplastik" /> <TextView android:id="@+id/plastikultah" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="Plastik Ultah" android:layout_below="@+id/sedotanplastik" android:layout_alignLeft="@+id/sedotanplastik" android:layout_alignStart="@+id/sedotanplastik" android:textSize="20sp" />

BX

Page 77: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<TextView android:id="@+id/sedotanplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="22dp" android:text="Sedotan Plastik" android:textSize="20sp" android:layout_below="@+id/sabut" android:layout_alignLeft="@+id/piringplastik" android:layout_alignStart="@+id/piringplastik" /> <TextView android:id="@+id/gelasplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Gelas Plastik" android:textSize="20sp" android:layout_alignBaseline="@+id/editgelasplastik" android:layout_alignBottom="@+id/editgelasplastik" android:layout_alignRight="@+id/plastikultah" android:layout_alignEnd="@+id/plastikultah" /> <Button android:id="@+id/buy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="56dp" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:text="Buy" /> <EditText android:id="@+id/editpiringplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignTop="@+id/piringplastik" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editgelasplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editpiringplastik" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:ems="10" android:inputType="number" />

BY

Page 78: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<EditText android:id="@+id/editsabut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/sabut" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editsedotanplastik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/sedotanplastik" android:layout_alignLeft="@+id/editplastikultah" android:layout_alignStart="@+id/editplastikultah" android:ems="10" android:inputType="number" /> <EditText android:id="@+id/editplastikultah" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/plastikultah" android:layout_alignBottom="@+id/plastikultah" android:layout_marginLeft="21dp" android:layout_marginStart="21dp" android:layout_toEndOf="@+id/piringplastik" android:layout_toRightOf="@+id/piringplastik" android:ems="10" android:inputType="number" /> <Button android:id="@+id/Buylist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/buy" android:layout_marginLeft="12dp" android:layout_marginStart="12dp" android:layout_toEndOf="@+id/buy" android:layout_toRightOf="@+id/buy" android:onClick="sendlistView" android:text="List Detail" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="18dp" android:text="No.Telepon" android:textSize="20sp" android:layout_above="@+id/editpiringplastik" android:layout_alignLeft="@+id/piringplastik" android:layout_alignStart="@+id/piringplastik" />

BZ

Page 79: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<EditText android:id="@+id/editnotelp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/textView4" android:layout_toEndOf="@+id/gelasplastik" android:layout_toRightOf="@+id/gelasplastik" android:ems="10" android:inputType="phone" /> <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView4" android:layout_alignLeft="@+id/sabut" android:layout_alignStart="@+id/sabut" android:layout_marginBottom="16dp" android:text="Nama" android:textSize="20sp" /> <EditText android:id="@+id/editnama" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignTop="@+id/textView6" android:ems="10" android:inputType="textPersonName" /></RelativeLayout>

Coding activity_buylist.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/valueViewz" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>

Coding activity_courier_emaillist.xml

<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.maps.CourierEmaillistActivity"></android.support.constraint.ConstraintLayout>

CA

Page 80: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_emaillist.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/valueView" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>

Coding activity_list.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/valueView" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>

CB

Page 81: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_main.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.maps.MainActivity"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="34dp" android:text="Welcome To" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_centerHorizontal="true" android:layout_marginTop="9dp" android:text="MyShopz" /> <Button android:id="@+id/buy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView3" android:layout_centerHorizontal="true" android:layout_marginTop="83dp" android:onClick="sendBuy" android:text="Buy" /> <Button android:id="@+id/Map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="44dp" android:onClick="sendMap" android:text="View Map" android:layout_below="@+id/buy" android:layout_alignRight="@+id/buy" android:layout_alignEnd="@+id/buy" /> <Button android:id="@+id/listemail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/Map" android:layout_centerHorizontal="true" android:layout_marginTop="42dp" android:onClick="senduseremail" android:text="User Email" />

CC

Page 82: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/listemail" android:layout_centerHorizontal="true" android:layout_marginTop="36dp" android:onClick="sendcourieremail" android:text="Courier Email" /></RelativeLayout>

CD

Page 83: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding activity_maps.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rel" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#372492" > <!-- The map fragments will go here --> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myapplication.MapsActivity" android:layout_below="@+id/textView" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <Button android:id="@+id/LatList" android:layout_width="wrap_content" android:layout_height="wrap_content" android:elevation="0dp" android:onClick="sendMessage" android:text="LatLongList" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/saveFb" android:layout_toEndOf="@+id/saveFb" android:layout_marginLeft="7dp" android:layout_marginStart="7dp" /> <Button android:id="@+id/saveFb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SaveLocation" android:layout_below="@+id/textView" android:layout_toRightOf="@+id/button" android:layout_toEndOf="@+id/button" /> <EditText android:id="@+id/etOrigin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/LatList" android:ems="10" android:hint="Rute Awal" />

CE

Page 84: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<EditText android:id="@+id/etDestination" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/etOrigin" android:ems="10" android:hint="Rute Tujuan" /> <Button android:id="@+id/btnFindPath" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Find Path" android:layout_marginLeft="10dp" android:layout_marginStart="10dp" android:layout_marginTop="14dp" android:layout_below="@+id/etDestination" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:id="@+id/tvDistance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/etDestination" android:layout_marginBottom="7dp" android:layout_marginLeft="17dp" android:layout_marginStart="17dp" android:layout_toEndOf="@+id/etOrigin" android:layout_toRightOf="@+id/etOrigin" android:text="Jarak" /> <TextView android:id="@+id/tvDuration" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvDistance" android:layout_alignStart="@+id/tvDistance" android:layout_below="@+id/tvDistance" android:layout_marginTop="12dp" android:text="Durasi" /></RelativeLayout>

CF

Page 85: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding GradleMaps

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rel" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#372492" > <!-- The map fragments will go here --> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myapplication.MapsActivity" android:layout_below="@+id/textView" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <Button android:id="@+id/LatList" android:layout_width="wrap_content" android:layout_height="wrap_content" android:elevation="0dp" android:onClick="sendMessage" android:text="LatLongList" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/saveFb" android:layout_toEndOf="@+id/saveFb" android:layout_marginLeft="7dp" android:layout_marginStart="7dp" /> <Button android:id="@+id/saveFb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SaveLocation" android:layout_below="@+id/textView" android:layout_toRightOf="@+id/button" android:layout_toEndOf="@+id/button" /> <EditText android:id="@+id/etOrigin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/LatList" android:ems="10" android:hint="Rute Awal" />

CG

Page 86: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<EditText android:id="@+id/etDestination" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/etOrigin" android:ems="10" android:hint="Rute Tujuan" /> <Button android:id="@+id/btnFindPath" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Find Path" android:layout_marginLeft="10dp" android:layout_marginStart="10dp" android:layout_marginTop="14dp" android:layout_below="@+id/etDestination" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:id="@+id/tvDistance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/etDestination" android:layout_marginBottom="7dp" android:layout_marginLeft="17dp" android:layout_marginStart="17dp" android:layout_toEndOf="@+id/etOrigin" android:layout_toRightOf="@+id/etOrigin" android:text="Jarak" /> <TextView android:id="@+id/tvDuration" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvDistance" android:layout_alignStart="@+id/tvDistance" android:layout_below="@+id/tvDistance" android:layout_marginTop="12dp" android:text="Durasi" /></RelativeLayout>

CH

Page 87: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding appMaps

apply plugin: 'com.android.application'android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.example.maps" minSdkVersion 14 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/ASL2.0' }}dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.google.android.gms:play-services-maps:10.2.6' compile 'com.google.android.gms:play-services-location:10.2.6' compile 'com.firebase:firebase-client-android:2.3.1' compile 'com.google.firebase:firebase-database:10.2.6' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.google.firebase:firebase-auth:10.2.6' testCompile 'junit:junit:4.12'}apply plugin: 'com.google.gms.google-services'

CI

Page 88: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.maps"> <!-- The ACCESS_COARSE/FINE_LOCATION permissions are not required touse Google Maps Android API v2, but you must specify either coarse or fine location permissions for the 'MyLocation' functionality. --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="Admin Myshopz" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <!-- The API key for Google Maps-based APIs is defined as a string resource. (See the file "res/values/google_maps_api.xml"). Note that the API key is linked to the encryption key usedto sign the APK. You need a different API key for each encryption key, including the release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU" /> <activity android:name=".MapsActivity" android:label="@string/title_activity_maps" /> <activity android:name=".ListActivity" android:label="@string/title_activity_maps" /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".BuyActivity" /> <activity android:name=".BuylistActivity" /> <activity android:name=".EmaillistActivity" />

CJ

Page 89: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

<activity android:name=".CourierEmaillistActivity"></activity> </application></manifest>

CK

Page 90: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Modules/DirectionFinder.java

package Modules;import android.os.AsyncTask;import com.google.android.gms.maps.model.LatLng;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.MalformedURLException;import java.net.URL;import java.net.URLEncoder;import java.util.ArrayList;import java.util.List;public class DirectionFinder { private static final String DIRECTION_URL_API = "https://maps.googleapis.com/maps/api/directions/json?"; private static final String GOOGLE_API_KEY = "AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU"; private DirectionFinderListener listener; private String origin; private String destination; public DirectionFinder(DirectionFinderListener listener, String origin, String destination) { this.listener = listener; this.origin = origin; this.destination = destination; } public void execute() throws UnsupportedEncodingException { listener.onDirectionFinderStart(); new DownloadRawData().execute(createUrl()); } private String createUrl() throws UnsupportedEncodingException { String urlOrigin = URLEncoder.encode(origin, "utf-8"); String urlDestination = URLEncoder.encode(destination, "utf-8"); return DIRECTION_URL_API + "origin=" + urlOrigin + "&destination=" + urlDestination + "&key=" + GOOGLE_API_KEY; } private class DownloadRawData extends AsyncTask<String, Void, String>{ @Override protected String doInBackground(String... params) { String link = params[0]; try { URL url = new URL(link); InputStream is = url.openConnection().getInputStream(); StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n");

CL

Page 91: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

} return buffer.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String res) { try { parseJSon(res); } catch (JSONException e) { e.printStackTrace(); } } } private void parseJSon(String data) throws JSONException { if (data == null) return; List<Route> routes = new ArrayList<Route>(); JSONObject jsonData = new JSONObject(data); JSONArray jsonRoutes = jsonData.getJSONArray("routes"); for (int i = 0; i < jsonRoutes.length(); i++) { JSONObject jsonRoute = jsonRoutes.getJSONObject(i); Route route = new Route(); JSONObject overview_polylineJson = jsonRoute.getJSONObject("overview_polyline"); JSONArray jsonLegs = jsonRoute.getJSONArray("legs"); JSONObject jsonLeg = jsonLegs.getJSONObject(0); JSONObject jsonDistance = jsonLeg.getJSONObject("distance"); JSONObject jsonDuration = jsonLeg.getJSONObject("duration"); JSONObject jsonEndLocation = jsonLeg.getJSONObject("end_location"); JSONObject jsonStartLocation = jsonLeg.getJSONObject("start_location"); route.distance = new Distance(jsonDistance.getString("text"), jsonDistance.getInt("value")); route.duration = new Duration(jsonDuration.getString("text"), jsonDuration.getInt("value")); route.endAddress = jsonLeg.getString("end_address"); route.startAddress = jsonLeg.getString("start_address"); route.startLocation = new LatLng(jsonStartLocation.getDouble("lat"), jsonStartLocation.getDouble("lng")); route.endLocation = new LatLng(jsonEndLocation.getDouble("lat"), jsonEndLocation.getDouble("lng")); route.points = decodePolyLine(overview_polylineJson.getString("points")); routes.add(route); } listener.onDirectionFinderSuccess(routes); }

CM

Page 92: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

private List<LatLng> decodePolyLine(final String poly) { int len = poly.length(); int index = 0; List<LatLng> decoded = new ArrayList<LatLng>(); int lat = 0; int lng = 0; while (index < len) { int b; int shift = 0; int result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; decoded.add(new LatLng( lat / 100000d, lng / 100000d )); } return decoded; }}

CN

Page 93: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Modules/DirectionFinderListener.java

package Modules;import android.os.AsyncTask;import com.google.android.gms.maps.model.LatLng;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.MalformedURLException;import java.net.URL;import java.net.URLEncoder;import java.util.ArrayList;import java.util.List;public class DirectionFinder { private static final String DIRECTION_URL_API = "https://maps.googleapis.com/maps/api/directions/json?"; private static final String GOOGLE_API_KEY = "AIzaSyABij_-mb8aCEavgVcc0yM23XgOKI-VKYU"; private DirectionFinderListener listener; private String origin; private String destination; public DirectionFinder(DirectionFinderListener listener, String origin, String destination) { this.listener = listener; this.origin = origin; this.destination = destination; } public void execute() throws UnsupportedEncodingException { listener.onDirectionFinderStart(); new DownloadRawData().execute(createUrl()); } private String createUrl() throws UnsupportedEncodingException { String urlOrigin = URLEncoder.encode(origin, "utf-8"); String urlDestination = URLEncoder.encode(destination, "utf-8"); return DIRECTION_URL_API + "origin=" + urlOrigin + "&destination=" + urlDestination + "&key=" + GOOGLE_API_KEY; } private class DownloadRawData extends AsyncTask<String, Void, String>{ @Override protected String doInBackground(String... params) { String link = params[0]; try { URL url = new URL(link); InputStream is = url.openConnection().getInputStream(); StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line;

CO

Page 94: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } return buffer.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String res) { try { parseJSon(res); } catch (JSONException e) { e.printStackTrace(); } } } private void parseJSon(String data) throws JSONException { if (data == null) return; List<Route> routes = new ArrayList<Route>(); JSONObject jsonData = new JSONObject(data); JSONArray jsonRoutes = jsonData.getJSONArray("routes"); for (int i = 0; i < jsonRoutes.length(); i++) { JSONObject jsonRoute = jsonRoutes.getJSONObject(i); Route route = new Route(); JSONObject overview_polylineJson = jsonRoute.getJSONObject("overview_polyline"); JSONArray jsonLegs = jsonRoute.getJSONArray("legs"); JSONObject jsonLeg = jsonLegs.getJSONObject(0); JSONObject jsonDistance = jsonLeg.getJSONObject("distance"); JSONObject jsonDuration = jsonLeg.getJSONObject("duration"); JSONObject jsonEndLocation = jsonLeg.getJSONObject("end_location"); JSONObject jsonStartLocation = jsonLeg.getJSONObject("start_location"); route.distance = new Distance(jsonDistance.getString("text"), jsonDistance.getInt("value")); route.duration = new Duration(jsonDuration.getString("text"), jsonDuration.getInt("value")); route.endAddress = jsonLeg.getString("end_address"); route.startAddress = jsonLeg.getString("start_address"); route.startLocation = new LatLng(jsonStartLocation.getDouble("lat"), jsonStartLocation.getDouble("lng")); route.endLocation = new LatLng(jsonEndLocation.getDouble("lat"), jsonEndLocation.getDouble("lng")); route.points = decodePolyLine(overview_polylineJson.getString("points")); routes.add(route); }

CP

Page 95: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

listener.onDirectionFinderSuccess(routes); } private List<LatLng> decodePolyLine(final String poly) { int len = poly.length(); int index = 0; List<LatLng> decoded = new ArrayList<LatLng>(); int lat = 0; int lng = 0; while (index < len) { int b; int shift = 0; int result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = poly.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; decoded.add(new LatLng( lat / 100000d, lng / 100000d )); } return decoded; }}

Coding Modules/Distance.java

package Modules;public class Distance { public String text; public int value; public Distance(String text, int value) { this.text = text; this.value = value; }}

CQ

Page 96: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

Coding Modules/Duration.java

package Modules;public class Duration { public String text; public int value; public Duration(String text, int value) { this.text = text; this.value = value; }}

Coding Modules/Route.java

package Modules;import com.google.android.gms.maps.model.LatLng;import java.util.List;public class Route { public Distance distance; public Duration duration; public String endAddress; public LatLng endLocation; public String startAddress; public LatLng startLocation; public List<LatLng> points;}

CR

Page 97: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

CS

Page 98: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

CT

Page 99: PLASTIC & SHEET ORDERING AND SHIPPING SYSTEM ON ANDROID … · android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling

CU