package com.example.hamza.hamari_sawari;import android.*;import android.Manifest;import android.content.Intent;import android.content.pm.PackageManager;import android.location.Location;import android.location.LocationListener;import android.support.annotation.NonNull;import android.support.annotation.Nullable;import android.support.v4.app.ActivityCompat;import android.support.v4.app.FragmentActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.CompoundButton;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.Switch;import android.widget.TextView;import android.widget.Toast;import com.bumptech.glide.Glide;import com.directions.route.AbstractRouting;import com.directions.route.Route;import com.directions.route.RouteException;import com.directions.route.Routing;import com.directions.route.RoutingListener;import com.firebase.geofire.GeoFire;import com.firebase.geofire.GeoLocation;import com.google.android.gms.common.ConnectionResult;import com.google.android.gms.common.api.GoogleApiClient;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.LatLng;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 com.google.firebase.auth.FirebaseAuth;import com.google.firebase.database.DataSnapshot;import com.google.firebase.database.DatabaseError;import com.google.firebase.database.DatabaseReference;import com.google.firebase.database.FirebaseDatabase;import com.google.firebase.database.ValueEventListener;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Objects;public class DriverMapActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener, RoutingListener { private GoogleMap mMap; GoogleApiClient mGoogleApiClient; Location mLastLocation; LocationRequest mLocationRequest; private Button mLogout, mSettings, mRideStatus; private Switch mWorkingSwitch; private int status = 0; private String customerId = “”, destination; private LatLng destinationLatLng; private Boolean isLoggingOut = false; private SupportMapFragment mapFragment; private LinearLayout mCustomerInfo; private ImageView mCustomerProfileImage; private TextView mCustomerName, mCustomerPhone, mCustomerDestination; @Override protected void onCreate(Bundle savedInstanceState) { //first state of the activity super.onCreate(savedInstanceState); setContentView(R.layout.activity_driver_map); // Obtain the SupportMapFragment and get notified when the map is ready to be used. polylines = new ArrayList<>(); mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); 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) { ActivityCompat.requestPermissions(DriverMapActivity.this, new String{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE); }else{ mapFragment.getMapAsync(this); } mCustomerInfo = (LinearLayout) findViewById(R.id.customerInfo); mCustomerProfileImage = (ImageView) findViewById(R.id.customerProfileImage); mCustomerName = (TextView) findViewById(R.id.customerName); mCustomerPhone = (TextView) findViewById(R.id.customerPhone); mCustomerDestination = (TextView) findViewById(R.id.customerDestination); mWorkingSwitch = (Switch) findViewById(R.id.workingSwitch); mWorkingSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { //checks switch of working of driver if (b){ connectDriver(); }else { disconnectDriver(); } } }); mSettings = (Button) findViewById(R.id.settings); mLogout = (Button) findViewById(R.id.logout); mRideStatus = (Button) findViewById(R.id.rideStatus); mRideStatus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //new ride initiated by customer switch(status){ case 1: status=2; erasePolylines(); if(destinationLatLng.latitude!=0.0 && destinationLatLng.longitude!=0.0){ getRouteToMarker(destinationLatLng); } mRideStatus.setText(“drive completed”); break; case 2: recordRide(); endRide(); break; } } }); mLogout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { isLoggingOut = true; disconnectDriver(); FirebaseAuth.getInstance().signOut(); Intent intent = new Intent(DriverMapActivity.this, MainActivity.class); startActivity(intent); finish(); return; } }); mSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(DriverMapActivity.this, DriverSettingsActivity.class); startActivity(intent); return; } }); getAssignedCustomer(); } private void getAssignedCustomer(){ //get customer from firebase and give it to driver String driverId = FirebaseAuth.getInstance().getCurrentUser().getUid(); DatabaseReference assignedCustomerRef = FirebaseDatabase.getInstance().getReference().child(“Users”).child(“Drivers”).child(driverId).child(“customerRequest”).child(“customerRideId”); assignedCustomerRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(dataSnapshot.exists()){ status = 1; customerId = dataSnapshot.getValue().toString(); getAssignedCustomerPickupLocation(); getAssignedCustomerDestination(); getAssignedCustomerInfo(); }else{ endRide(); } } @Override public void onCancelled(DatabaseError databaseError) { } }); } Marker pickupMarker; private DatabaseReference assignedCustomerPickupLocationRef; private ValueEventListener assignedCustomerPickupLocationRefListener; private void getAssignedCustomerPickupLocation(){ assignedCustomerPickupLocationRef = FirebaseDatabase.getInstance().getReference().child(“customerRequest”).child(customerId).child(“l”); assignedCustomerPickupLocationRefListener = assignedCustomerPickupLocationRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(dataSnapshot.exists() && !customerId.equals(“”)){ List