0% found this document useful (0 votes)
12 views

Coding

Coding file

Uploaded by

Boopathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Coding

Coding file

Uploaded by

Boopathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

DRIVER MAP Activity:

package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

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.location.LocationRequest;
import com.google.android.gms.common.ConnectionResult;
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.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.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;

private Button profile;

private SupportMapFragment mapFragment;

private String CustomerId = "";


private Boolean isLoggingOut =false;

GoogleApiClient mGoogleApiClient;
Location mLastLocation;
LocationRequest mLocationRequest;
private String mCustomerDestination;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_driver_map);
polylines = new ArrayList<>();

// Obtain the SupportMapFragment and get notified when the map is


ready to be used.
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);

if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,
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);
}

profile = (Button) findViewById(R.id.profile);


Button logout = (Button) findViewById(R.id.logout);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isLoggingOut = true;
disconnectDriver();
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(DriverMapActivity.this,
DriverLoginActivity.class);
startActivity(intent);
finish();
}
});
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(DriverMapActivity.this,
DriverProfileActivity.class);
startActivity(intent);
}
});

getAssignedCustomer();
}

private void getAssignedCustomer() {

if (FirebaseAuth.getInstance().getCurrentUser() == null) {

}
else{
String driverId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef =
FirebaseDatabase.getInstance().getReference().child("Customer").child("Driver"
).child(driverId);
assignedCustomerRef.addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists()){
CustomerId =
Objects.requireNonNull(snapshot.getValue()).toString();
getAssignedCustomerPickupLocation();
}
else{
erasePolyLines();
CustomerId = "";
if(pickupMarker!=null){
pickupMarker.remove();
}
if(assignedCustomerPickupLocationRefListener!=null){

assignedCustomerPickupLocationRef.removeEventListener(assignedCustomerPickupLo
cationRefListener);
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});

}
Marker pickupMarker;
DatabaseReference assignedCustomerPickupLocationRef;
private ValueEventListener assignedCustomerPickupLocationRefListener;
private void getAssignedCustomerPickupLocation() {
assignedCustomerPickupLocationRef =
FirebaseDatabase.getInstance().getReference().child("CustomerRequest").child(C
ustomerId).child("l");
assignedCustomerPickupLocationRef.addValueEventListener(new
ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists() && !CustomerId.equals("")){
List<Object> map = (List<Object>) snapshot.getValue();
double locationLat = 0;
double locationLng = 0;

if(map.get(0) != null){

locationLat =
Double.parseDouble(map.get(0).toString());

}
if(map.get(1) != null) {

locationLng =
Double.parseDouble(map.get(1).toString());
}
LatLng pickupLatLng = new LatLng(locationLat,
locationLng);

pickupMarker=mMap.addMarker(new
MarkerOptions().position(pickupLatLng).title("pickup
Location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pickup)));
getRouteToMarker(pickupLatLng);
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});

private void getRouteToMarker(LatLng pickupLatLng) {


Routing routing = new Routing.Builder()
.travelMode(AbstractRouting.TravelMode.DRIVING)
.withListener(this)
.alternativeRoutes(false)
.waypoints(new LatLng(mLastLocation.getLatitude(),
mLastLocation.getLongitude()), pickupLatLng)
.build();
routing.execute();
}
/**private void getAssignedCustomerDestination(){
if (FirebaseAuth.getInstance().getCurrentUser() == null) {

}
else{
String driverId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef =
FirebaseDatabase.getInstance().getReference().child("Customer").child("Driver"
).child(driverId);
assignedCustomerRef.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists()){
String destination = snapshot.getValue().toString();

}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}

}*/
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
mMap = googleMap;

if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(DriverMapActivity.this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);

}
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);

protected synchronized void buildGoogleApiClient() {

mGoogleApiClient = new GoogleApiClient.Builder(this)


.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();

mGoogleApiClient.connect();
}
@Override
public void onLocationChanged(@NonNull Location location) {

if(getApplicationContext() != null) {
mLastLocation = location;
LatLng latLng = new LatLng(location.getLatitude(),
location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(26));

if (FirebaseAuth.getInstance().getCurrentUser() == null) {

}
else {
String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();

DatabaseReference refAvailable =
FirebaseDatabase.getInstance().getReference("DriversAvailable");
DatabaseReference refWorking =
FirebaseDatabase.getInstance().getReference("driversWorking");

GeoFire geoFireAvailable = new GeoFire(refAvailable);


GeoFire geoFireWorking = new GeoFire(refWorking);

switch (CustomerId){
case "":
geoFireWorking.removeLocation(userId);
geoFireAvailable.setLocation(userId, new
GeoLocation(location.getLatitude(), location.getLongitude()));
break;

default:
geoFireAvailable.removeLocation(userId);
geoFireWorking.setLocation(userId, new
GeoLocation(location.getLatitude(), location.getLongitude()));
break;
}

@Override
public void onConnected(@Nullable Bundle bundle) {

mLocationRequest = new LocationRequest();


mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(DriverMapActivity.this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);
}

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, (com.google.android.gms.location.LocationListener) this);

@Override
public void onConnectionSuspended(int i) {

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult)
{

}
final int LOCATION_REQUEST_CODE = 1;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
switch (requestCode){
case LOCATION_REQUEST_CODE:{
if (grantResults.length>0 && grantResults[0]==
PackageManager.PERMISSION_GRANTED){
mapFragment.getMapAsync(this);
}
else{
Toast.makeText(this, "Please Provide Permission",
Toast.LENGTH_LONG).show();
}
break;
}

}
}

private void disconnectDriver(){


if (FirebaseAuth.getInstance().getCurrentUser() == null) {

}
else{
String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("DriversAvailable");

GeoFire geoFire = new GeoFire(ref);


geoFire.removeLocation(userId);
}
}

@Override
protected void onStop() {
super.onStop();
if(!isLoggingOut){
disconnectDriver();

}
private List<Polyline> polylines;
private static final int[] COLORS = new int[]{R.color.Grey};

@Override
public void onRoutingFailure(RouteException e) {
if(e != null) {
Toast.makeText(this, "Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}else {
Toast.makeText(this, "Something went wrong, Try again",
Toast.LENGTH_SHORT).show();
}

@Override
public void onRoutingStart() {

@Override
public void onRoutingSuccess(ArrayList<Route> route, int routeIndex) {

if(polylines.size()>0) {
for (Polyline poly : polylines) {
poly.remove();
}
}

polylines = new ArrayList<>();


//add route(s) to the map.
for (int i = 0; i <route.size(); i++) {

//In case of more than 5 alternative routes


int colorIndex = i % COLORS.length;

PolylineOptions polyOptions = new PolylineOptions();


polyOptions.color(getResources().getColor(COLORS[colorIndex]));
polyOptions.width(10 + i * 3);
polyOptions.addAll(route.get(i).getPoints());
Polyline polyline = mMap.addPolyline(polyOptions);
polylines.add(polyline);
Toast.makeText(getApplicationContext(),"Route "+ (i+1) +":
distance - "+ route.get(i).getDistanceValue()+": duration - "+
route.get(i).getDurationValue(),Toast.LENGTH_SHORT).show();
}

@Override
public void onRoutingCancelled() {
}

private void erasePolyLines(){


for(Polyline line: polylines){
line.remove();
}
polylines.clear();
}
}

User Map Activity:

package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.firebase.geofire.GeoFire;
import com.firebase.geofire.GeoLocation;
import com.firebase.geofire.GeoQuery;
import com.firebase.geofire.GeoQueryEventListener;
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.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.HashMap;
import java.util.List;
import java.util.Objects;

public class UserMapActivity extends FragmentActivity implements


OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
com.google.android.gms.location.LocationListener {

private GoogleMap mMap;

private Button request;


private LatLng pickUpLocation;
private Boolean requestBol=false;
private Marker pickupMarker;

private SupportMapFragment mapFragment;


GoogleApiClient mGoogleApiClient;
Location mLastLocation;
LocationRequest mLocationRequest;

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

// Obtain the SupportMapFragment and get notified when the map is


ready to be used.
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);

if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(UserMapActivity.this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);
}
else{
mapFragment.getMapAsync(this);
}
Button logout = (Button) findViewById(R.id.logout2);
request = (Button) findViewById(R.id.request);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(UserMapActivity.this,
HomeActivity.class);
startActivity(intent);

}
});

request.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(requestBol){
requestBol = false;
geoQuery.removeAllListeners();

driverLocationRef.removeEventListener(driverLocationRefListener);
if(driverFoundID != null){
DatabaseReference driverRef =
FirebaseDatabase.getInstance().getReference().child("Customer").child("Driver"
).child(driverFoundID);
driverRef.setValue(true);
driverFoundID = null;
}
driverFound = false;
radius = 1;
String userId =
Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid();

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("CustomerRequest");
GeoFire geoFire = new GeoFire(reference);
geoFire.removeLocation(userId);

if(pickupMarker != null){
pickupMarker.remove();
}
request.setText("call Driver");
}
else{
requestBol = true;

String userId =
Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid();
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("CustomerRequest");
GeoFire geoFire = new GeoFire(ref);
geoFire.setLocation(userId, new
GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()));
pickUpLocation = new LatLng(mLastLocation.getLatitude(),
mLastLocation.getLongitude());
pickupMarker = mMap.addMarker(new
MarkerOptions().position(pickUpLocation).title("pickup
here").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_auto)));

request.setText("Getting Driver....");

getClosestDriver();

}
}
});

private int radius = 1;


private Boolean driverFound = false;
private String driverFoundID;
GeoQuery geoQuery;
private void getClosestDriver() {

DatabaseReference driverLocation =
FirebaseDatabase.getInstance().getReference().child("DriversAvailable");
GeoFire geoFire = new GeoFire(driverLocation);
geoQuery = geoFire.queryAtLocation(new
GeoLocation(pickUpLocation.latitude, pickUpLocation.longitude), radius);
geoQuery.removeAllListeners();

geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {

if(!driverFound && requestBol) {


driverFound = true;
driverFoundID = key;

DatabaseReference driverRef =
FirebaseDatabase.getInstance().getReference().child("Customer").child("Driver"
).child(driverFoundID);
String customerId =
Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid();
HashMap map = new HashMap();
map.put("customerRideId", customerId);
driverRef.updateChildren(map);

getDriverLocation();
request.setText("Looking for Driver Location....");
}

@Override
public void onKeyExited(String key) {

@Override
public void onKeyMoved(String key, GeoLocation location) {
}

@Override
public void onGeoQueryReady() {

if(!driverFound)
{
radius++;
getClosestDriver();
}

@Override
public void onGeoQueryError(DatabaseError error) {

}
});
}

private Marker DriverMarker;


private DatabaseReference driverLocationRef;
private ValueEventListener driverLocationRefListener;
private void getDriverLocation() {

driverLocationRef = FirebaseDatabase.getInstance()
.getReference().child("driversWorking").child(driverFoundID).c
hild("l");

driverLocationRef.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {

if(snapshot.exists()&& requestBol){
List<Object> map = (List<Object>) snapshot.getValue();

double locationLat = 0;
double locationLng = 0;

request.setText("Driver Found");

if(map.get(0) != null){

locationLat =
Double.parseDouble(map.get(0).toString());

}
if(map.get(1) != null) {

locationLng =
Double.parseDouble(map.get(1).toString());
}
LatLng driverLatLng = new LatLng(locationLat,
locationLng);
if(DriverMarker != null){
DriverMarker.remove();
}
Location locl = new Location("");
locl.setLatitude(driverLatLng.latitude);
locl.setLongitude(driverLatLng.longitude);

float distance = locl.distanceTo(locl);

if (distance<100){
request.setText("driver is here");
}
else{
request.setText("Driver Found:" +
String.valueOf(distance));
}
DriverMarker = mMap.addMarker(new
MarkerOptions().position(driverLatLng).title("your
Driver").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_auto)));
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}

@Override
public void onMapReady(@NonNull 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) {
ActivityCompat.requestPermissions(UserMapActivity.this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);

}
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);

protected synchronized void buildGoogleApiClient() {

mGoogleApiClient = new GoogleApiClient.Builder(this)


.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}

@Override
public void onLocationChanged(Location location) {

mLastLocation = location;

LatLng latLng = new LatLng(location.getLatitude(),


location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(30));

@Override
public void onConnected(@Nullable Bundle bundle) {

mLocationRequest = new LocationRequest();


mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(UserMapActivity.this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, (com.google.android.gms.location.LocationListener) this);

@Override
public void onConnectionSuspended(int i) {

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult)
{

final int LOCATION_REQUEST_CODE = 1;


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
switch (requestCode){
case LOCATION_REQUEST_CODE:{
if (grantResults.length>0 && grantResults[0]==
PackageManager.PERMISSION_GRANTED){
mapFragment.getMapAsync(this);
}
else{
Toast.makeText(this, "Please Provide Permission",
Toast.LENGTH_LONG).show();
}
break;
}

}
}

@Override
protected void onStop() {
super.onStop();

}
}

Main Activity:

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

public class MainActivity extends AppCompatActivity {

private TextView animateText;


private ImageView siren;

Animation animateNow;

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

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this,
LoginActivity.class);
startActivity(intent);
finish();
}
}, 5000);

init();
}
private void init(){

animateText = (TextView) findViewById(R.id.textView2);


siren = (ImageView) findViewById(R.id.imageView);
animateNow =
AnimationUtils.loadAnimation(getApplicationContext(),R.anim.up_animation);
animateText.setAnimation(animateNow);

Glide.with(this).load(R.drawable.siren).into(siren);
}
}

Home Activity:

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

import com.firebase.geofire.GeoFire;
import com.firebase.geofire.GeoLocation;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class HomeActivity extends AppCompatActivity {

private ProgressBar progressBar;


private Button Emergency;

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

Emergency = (Button) findViewById(R.id.emergency);


progressBar = (ProgressBar) findViewById(R.id.ProgressBar12);
progressBar.setVisibility(View.GONE);
Emergency.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressBar.setVisibility(View.VISIBLE);

Intent intent = new Intent(HomeActivity.this,


UserMapActivity.class);
startActivity(intent);

}
});

activity main xml:

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.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"
android:background="@drawable/app"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
android:fontFamily="times"
android:text="Emerlo"
android:textColor="@color/colorPrimaryDark"
android:textSize="48sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.987" />

<ImageView
android:id="@+id/imageView"
android:layout_width="83dp"
android:layout_height="112dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.95"
app:srcCompat="@drawable/siren" />

</androidx.constraintlayout.widget.ConstraintLayout>

Activity driver map xml:

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="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=".DriverMapActivity">

<Button
android:id="@+id/logout"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:text="Logout"
android:textStyle="bold"/>

<Button
android:id="@+id/profile"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:text="Profile"
android:textStyle="bold" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/sceneform_ux_fragment_layout" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id ="@+id/driverInfo"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="@color/black"
android:visibility="gone">

<ImageView
android:layout_height="100sp"
android:layout_width ="100sp"
android:id="@+id/driverProfile"
android:src="@mipmap/ic_profile"
android:padding="20sp" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="40sp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/driverName"
android:paddingBottom="10sp"
android:paddingTop="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/driverPhone"
android:paddingBottom="10sp"
android:paddingTop="20sp"/>

</LinearLayout>
</LinearLayout>

</FrameLayout>

Activity user map xml:

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="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=".UserMapActivity">
<Button
android:id="@+id/logout2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:text="Logout"
android:textStyle="bold" />

<Button
android:id="@+id/request"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Call Driver"
android:layout_gravity="bottom"
/>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/sceneform_ux_fragment_layout" />

</FrameLayout>

Actvity Home xml:

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.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"
android:background="@color/white"
tools:context=".HomeActivity">

<Button
android:id="@+id/emergency"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/emergency_tab"
android:text="!"
android:textSize="50sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ProgressBar
android:id="@+id/ProgressBar12"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:indeterminate="true"
android:progressTint="@color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="12dp"
android:text="Click the Button to Search for Nearest Auto"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/emergency"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Gradle. module app:

plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
namespace 'com.example.myapplication'
compileSdk 33

defaultConfig {
applicationId "com.example.myapplication"
minSdk 26
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.google.firebase:firebase-auth:22.0.0'
implementation 'com.google.firebase:firebase-database:20.2.1'
implementation 'com.google.firebase:firebase-storage:20.2.0'
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation "com.google.android.gms:play-services-maps:18.1.0"
implementation "com.google.android.gms:play-services-nearby:18.5.0"
implementation "com.google.android.gms:play-services-auth:20.5.0"
implementation "com.google.android.gms:play-services-identity:18.0.1"
implementation "com.google.android.gms:play-services-auth-api-
phone:18.0.1"
implementation "com.google.android.gms:play-services-base:18.2.0"
annotationProcessor 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.firebase:geofire-android:3.2.0'
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.17.1'
implementation 'com.firebase:geofire-android-common:3.2.0'
implementation 'com.github.jd-alexander:library:1.1.0'
implementation 'com.hbb20:ccp:2.5.0'
implementation 'com.github.mohammadatif:Animatoo:master'
implementation 'androidx.browser:browser:1.5.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'io.github.chaosleung:pinview:1.4.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

You might also like