Grupo04 Proyecto Final
Grupo04 Proyecto Final
Grupo04 Proyecto Final
PROYECTO
APLICACIÓN GLANCY
AUTORES:
DOCENTE
LONCAN
HUACHO – PERÚ
2019
PROPÓSITO
1. Pide un viaje: Abre la app e ingresa tu destino en la casilla ¿A dónde vas?. Una vez que
confirmes que el punto de partida y el destino son correctos, selecciona el tipo de
servicio que desee en la parte inferior de la pantalla. Luego, toca Confirmar. Cuando se
te asigne un conductor compatible podrás hacer un seguimiento de su llegada en el
mapa.
2. Viaja: El conductor conoce tu destino y las indicaciones para llegar de la manera más
rápida, pero siempre puedes solicitarle que siga una ruta específica.
3. Sal del vehículo: Para que puedas salir del auto apenas llegues, se te cobrará el viaje de
manera automática a tu método de pago. Recuerda calificar al conductor para ayudar
a que Uber sea seguro y agradable para todos.
PANTALLAS
1. PANTALLA CONDUCTOR/CLIENTE:
2. LOGIN CLIENTE:
En esta pantalla llenaremos nuestros datos como cliente, si ya estamos registrados sólo
se incia sesión, de lo contrario se tendrá que registrar.
3. CONFIGURACIÓN DE CLIENTE:
GLANCYX: Permite a los usuarios compartir el taxi, por lo que el costo del viaje será
mucho menor.
GLANCYBLACK: Permite a los usuarios acceder a autos negros premium, los cuales son
perfectos para noches de citas o negocios.
CÓDIGOS
PANTALLAS
1. BIENVENIDO
<?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=".BienvenidoActivity">
<Button
android:id="@+id/btn_Cliente"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_marginBottom="131dp"
android:background="@drawable/button_roundel_border"
android:text="Cliente"
android:textAllCaps="false"
android:textSize="22sp"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/btn_Conductor" />
<Button
android:id="@+id/btn_Conductor"
android:layout_width="250dp"
android:layout_height="60dp"
android:background="@drawable/button_roundel"
android:text="Conductor"
android:textAllCaps="false"
android:textSize="22sp"
android:layout_above="@+id/btn_Cliente"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="149dp"
android:layout_height="168dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
app:srcCompat="@drawable/logo" />
</RelativeLayout>
2. CLIENTE CONFIGURACIÓN
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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=".Cliente_Configuracion"
android:orientation="vertical"
android:padding="20sp">
<ImageView
android:layout_width="100sp"
android:layout_height="100sp"
android:id="@+id/profileImage"
android:src="@mipmap/ic_default_user"
android:layout_marginBottom="20sp"/>
<EditText
android:id="@+id/nombre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="Nombre"
android:layout_marginBottom="20sp"/>
<EditText
android:id="@+id/telefono"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="telefono"
android:layout_marginBottom="20sp"
android:inputType="number"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/confirm"
android:layout_marginTop="36dp"
android:text="confirma"
android:background="@drawable/button_roundel"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/back"
android:text="atras"
android:layout_marginTop="44dp"
android:background="@drawable/button_roundel_border"/>
</LinearLayout>
3. CLIENTE LOGIN
<?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=".Cliente_login_registar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/id_logo"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo"
android:layout_gravity="center"/>
<EditText
android:id="@+id/tv_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_logo"
android:backgroundTint="@color/colorPrimary"
android:drawableLeft="@drawable/ic_action_name"/>
<EditText
android:id="@+id/tv_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_email"
android:backgroundTint="@color/colorPrimary"
android:drawableLeft="@drawable/ic_action_pass"/>
<Button
android:id="@+id/btn_ingresar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="@drawable/button_roundel"
android:text="INICIAR SESION"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_password" />
<Button
android:id="@+id/btn_registrarse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="@drawable/button_roundel_border"
android:text="REGISTRARSE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_email" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center">
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/button_social"
android:scaleType="fitCenter"
app:layout_constraintEnd_toStartOf="@+id/imageButton2"
app:layout_constraintTop_toBottomOf="@+id/btn_registrarse"
app:srcCompat="@drawable/google" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/button_social"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_registrarse"
app:srcCompat="@drawable/fb" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
4. CLIENTE MAP
<FrameLayout
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=".Cliente_login_registar" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/logout"
android:text="logout"/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="call Uber"
android:id="@+id/request"
android:layout_gravity="bottom"/>
</FrameLayout>
5. CONDUCTOR CONFIGURACIÓN
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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=".Conductor_configuracion"
android:orientation="vertical"
android:padding="20sp">
<ImageView
android:layout_width="100sp"
android:layout_height="100sp"
android:id="@+id/profileImage"
android:src="@mipmap/ic_default_user"
android:layout_marginBottom="20sp"/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="Nombre"
android:layout_marginBottom="20sp"/>
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="telefono"
android:layout_marginBottom="20sp"
android:inputType="number"/>
<EditText
android:id="@+id/car"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="Carro"
android:layout_marginBottom="20sp"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radioGroup"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UberX"
android:id="@+id/UberX"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UberBlack"
android:id="@+id/UberBlack"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UberXl"
android:id="@+id/UberXl"/>
</RadioGroup>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/confirm"
android:layout_marginTop="36dp"
android:text="confirma"
android:background="@drawable/button_roundel"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/back"
android:text="atras"
android:layout_marginTop="44dp"
android:background="@drawable/button_roundel_border"/>
</LinearLayout>
6. LOGIN CONDUCTOR
<?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=".conductor_login_registar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/id_logo"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo"
android:layout_gravity="center"/>
<EditText
android:id="@+id/tv_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_logo"
android:backgroundTint="@color/colorPrimary"
android:drawableLeft="@drawable/ic_action_name"/>
<EditText
android:id="@+id/tv_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_usuario"
android:backgroundTint="@color/colorPrimary"
android:drawableLeft="@drawable/ic_action_pass"/>
<Button
android:id="@+id/btn_ingresar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="@drawable/button_roundel"
android:text="INICIAR SESION"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_password" />
<Button
android:id="@+id/btn_registrarse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="@drawable/button_roundel_border"
android:text="REGISTRARSE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_usuario" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center">
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/button_social"
android:scaleType="fitCenter"
app:layout_constraintEnd_toStartOf="@+id/imageButton2"
app:layout_constraintTop_toBottomOf="@+id/btn_registrarse"
app:srcCompat="@drawable/google" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/button_social"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_registrarse"
app:srcCompat="@drawable/fb" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
7. CONDUCTOR MAPS
<FrameLayout
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=".conductor_login_registar" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/logout"
android:text="logout"/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="call Uber"
android:id="@+id/request"
android:layout_gravity="bottom"/>
</FrameLayout>
8. HISTORY
<?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.simcoder.uber.HistoryActivity"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="vertical"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/historyRecyclerView"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
9. HISTORY SINGLE
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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.simcoder.uber.HistorySingleActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<fragment
android:layout_width="match_parent"
android:layout_height="200dp"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="From - To"
android:layout_marginBottom="20sp"
android:id="@+id/rideLocation"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="distance"
android:layout_marginBottom="20sp"
android:id="@+id/rideDistance"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="date"
android:layout_marginBottom="20sp"
android:id="@+id/rideDate"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/userImage"
android:src="@mipmap/ic_default_user"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginTop="20sp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="name"
android:layout_marginBottom="20sp"
android:id="@+id/userName"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="phone"
android:layout_marginBottom="20sp"
android:id="@+id/userPhone"/>
</LinearLayout>
</LinearLayout>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_gravity="center"
android:numStars="5"
android:stepSize="1"
android:visibility="gone"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pay"
android:text="Pay Here"
android:visibility="gone"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
CÓDIGO DE LAS CLASES
1. ACTIVITY BIENVENIDO
package com.unjfsc.transporte_glancy;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Button btn_cliente,btn_conductor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bienvenido);
btn_cliente= (Button)findViewById(R.id.btn_Cliente);
btn_conductor=(Button)findViewById(R.id.btn_Conductor);
btn_conductor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new
Intent(BienvenidoActivity.this,conductor_login_registar.class);
startActivity(intent);
finish();
return;
}
});
btn_cliente.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new
Intent(BienvenidoActivity.this,Cliente_login_registar.class);
startActivity(intent);
finish();
return;
}
});
}
}
2. CLIENTE CONFIGURACION
package com.unjfsc.transporte_glancy;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
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.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cliente__configuracion);
mAuth = FirebaseAuth.getInstance();
userID = mAuth.getCurrentUser().getUid();
mCustomerDatabase =
FirebaseDatabase.getInstance().getReference().child("Users").child("Cu
stomers").child(userID);
getUserInfo();
mProfileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, 1);
}
});
mConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveUserInformation();
}
});
mBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
return;
}
});
}
private void getUserInfo(){
mCustomerDatabase.addValueEventListener(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() &&
dataSnapshot.getChildrenCount()>0){
Map<String, Object> map = (Map<String, Object>)
dataSnapshot.getValue();
if(map.get("name")!=null){
mName = map.get("name").toString();
mNameField.setText(mName);
}
if(map.get("phone")!=null){
mPhone = map.get("phone").toString();
mPhoneField.setText(mPhone);
}
if(map.get("profileImageUrl")!=null){
mProfileImageUrl =
map.get("profileImageUrl").toString();
Glide.with(getApplication()).load(mProfileImageUrl).into(mProfileImage
);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
if(resultUri != null) {
StorageReference filePath =
FirebaseStorage.getInstance().getReference().child("profile_images").c
hild(userID);
Bitmap bitmap = null;
try {
bitmap =
MediaStore.Images.Media.getBitmap(getApplication().getContentResolver(
), resultUri);
} catch (IOException e) {
e.printStackTrace();
}
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
finish();
return;
}
});
uploadTask.addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot
taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
finish();
return;
}
});
}else{
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1 && resultCode == Activity.RESULT_OK){
final Uri imageUri = data.getData();
resultUri = imageUri;
mProfileImage.setImageURI(resultUri);
}
}
}
3. CLIENTE_LOGIN_REGISTRAR
package com.unjfsc.transporte_glancy;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
mAuth = FirebaseAuth.getInstance();
mRegistration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String email = mEmail.getText().toString();
final String password =
mPassword.getText().toString();
mAuth.createUserWithEmailAndPassword(email,
password).addOnCompleteListener(Cliente_login_registar.this, new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult>
task) {
if(!task.isSuccessful()){
mLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String email = mEmail.getText().toString();
final String password =
mPassword.getText().toString();
mAuth.signInWithEmailAndPassword(email,
password).addOnCompleteListener(Cliente_login_registar.this, new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult>
task) {
if(!task.isSuccessful()){
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(firebaseAuthListener);
}
@Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(firebaseAuthListener);
}
}
4. CLIENTE_MAP_ACTIVITY
package com.unjfsc.transporte_glancy;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.TextView;
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.common.api.Status;
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.Map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cliente_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,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(ClienteMapActivity.this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
LOCATION_REQUEST_CODE);
}else{
mapFragment.getMapAsync(this);
}
mDriverProfileImage = (ImageView)
findViewById(R.id.driverProfileImage);
mDriverName = (TextView) findViewById(R.id.driverName);
mDriverPhone = (TextView) findViewById(R.id.driverPhone);
mDriverCar = (TextView) findViewById(R.id.driverCar);
mLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(ClienteMapActivity.this,
MainActivity.class);
startActivity(intent);
finish();
return;
}
});
mRequest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (requestBol){
endRide();
}else{
int selectId =
mRadioGroup.getCheckedRadioButtonId();
if (radioButton.getText() == null){
return;
}
requestService = radioButton.getText().toString();
requestBol = true;
String userId =
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_pickup)))
;
getClosestDriver();
}
}
});
mSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ClienteMapActivity.this,
CustomerSettingsActivity.class);
startActivity(intent);
return;
}
});
mHistory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ClienteMapActivity.this,
HistoryActivity.class);
intent.putExtra("customerOrDriver", "Customers");
startActivity(intent);
return;
}
});
PlaceAutocompleteFragment autocompleteFragment =
(PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment
);
autocompleteFragment.setOnPlaceSelectedListener(new
PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
destination = place.getName().toString();
destinationLatLng = place.getLatLng();
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
}
});
}
private int radius = 1;
private Boolean driverFound = false;
private String driverFoundID;
GeoQuery geoQuery;
private void getClosestDriver(){
DatabaseReference driverLocation =
FirebaseDatabase.getInstance().getReference().child("driversAvailable"
);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener()
{
@Override
public void onKeyEntered(String key, GeoLocation location)
{
if (!driverFound && requestBol){
DatabaseReference mCustomerDatabase =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(key);
mCustomerDatabase.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot
dataSnapshot) {
if (dataSnapshot.exists() &&
dataSnapshot.getChildrenCount()>0){
Map<String, Object> driverMap =
(Map<String, Object>) dataSnapshot.getValue();
if (driverFound){
return;
}
if(driverMap.get("service").equals(requestService)){
driverFound = true;
driverFoundID =
dataSnapshot.getKey();
DatabaseReference driverRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(driverFoundID).child("customerRequest");
String customerId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
HashMap map = new HashMap();
map.put("customerRideId",
customerId);
map.put("destination",
destination);
map.put("destinationLat",
destinationLatLng.latitude);
map.put("destinationLng",
destinationLatLng.longitude);
driverRef.updateChildren(map);
getDriverLocation();
getDriverInfo();
getHasRideEnded();
mRequest.setText("Looking for
Driver Location....");
}
}
}
@Override
public void onCancelled(DatabaseError
databaseError) {
}
});
}
}
@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) {
}
});
}
if (distance<100){
mRequest.setText("Driver's Here");
}else{
mRequest.setText("Driver Found: " +
String.valueOf(distance));
}
mDriverMarker = mMap.addMarker(new
MarkerOptions().position(driverLatLng).title("your
driver").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_car)));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
mDriverName.setText(dataSnapshot.child("name").getValue().toString());
}
if(dataSnapshot.child("phone")!=null){
mDriverPhone.setText(dataSnapshot.child("phone").getValue().toString()
);
}
if(dataSnapshot.child("car")!=null){
mDriverCar.setText(dataSnapshot.child("car").getValue().toString());
}
if(dataSnapshot.child("profileImageUrl")!=null){
Glide.with(getApplication()).load(dataSnapshot.child("profileImageUrl"
).getValue().toString()).into(mDriverProfileImage);
}
int ratingSum = 0;
float ratingsTotal = 0;
float ratingsAvg = 0;
for (DataSnapshot child :
dataSnapshot.child("rating").getChildren()){
ratingSum = ratingSum +
Integer.valueOf(child.getValue().toString());
ratingsTotal++;
}
if(ratingsTotal!= 0){
ratingsAvg = ratingSum/ratingsTotal;
mRatingBar.setRating(ratingsAvg);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}else{
endRide();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
driverLocationRef.removeEventListener(driverLocationRefListener);
driveHasEndedRef.removeEventListener(driveHasEndedRefListener);
if (driverFoundID != null){
DatabaseReference driverRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(driverFoundID).child("customerRequest");
driverRef.removeValue();
driverFoundID = null;
}
driverFound = false;
radius = 1;
String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("customerRequest");
GeoFire geoFire = new GeoFire(ref);
geoFire.removeLocation(userId);
if(pickupMarker != null){
pickupMarker.remove();
}
if (mDriverMarker != null){
mDriverMarker.remove();
}
mRequest.setText("call Uber");
mDriverInfo.setVisibility(View.GONE);
mDriverName.setText("");
mDriverPhone.setText("");
mDriverCar.setText("Destination: --");
mDriverProfileImage.setImageResource(R.mipmap.ic_default_user);
}
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(ClienteMapActivity.this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
LOCATION_REQUEST_CODE);
}
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
@Override
public void onLocationChanged(Location location) {
if(getApplicationContext()!=null){
mLastLocation = location;
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
}
}
@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,
android.Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(ClienteMapActivity.this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
LOCATION_REQUEST_CODE);
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiCli
ent, mLocationRequest, this);
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult
connectionResult) {
}
/*--------------------------------------------
onRequestPermissionsResult -----
| Function onRequestPermissionsResult
|
| Purpose: Get permissions for our app if they didn't previously
exist.
|
| Note:
| requestCode: the nubmer assigned to the request that we've
made. Each
| request has it's own unique request code.
|
*-----------------------------------------------------------------
--*/
final int LOCATION_REQUEST_CODE = 1;
public void onRequestPermissionsResult(int requestCode, String
permissions[], int[] grantResults) {
switch (requestCode) {
case LOCATION_REQUEST_CODE: {
// If request is cancelled, the result arrays are
empty.
if (grantResults.length > 0
&& grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
mapFragment.getMapAsync(this);
} else {
Toast.makeText(getApplicationContext(), "Please
provide the permission", Toast.LENGTH_LONG).show();
}
break;
}
}
}
}
5. CONDUCTOR_CONFIGURACION
package com.unjfsc.transporte_glancy;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
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.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conductor_configuracion);
mNameField = (EditText) findViewById(R.id.name);
mPhoneField = (EditText) findViewById(R.id.phone);
mCarField = (EditText) findViewById(R.id.car);
mAuth = FirebaseAuth.getInstance();
userID = mAuth.getCurrentUser().getUid();
mDriverDatabase =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(userID);
getUserInfo();
mProfileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, 1);
}
});
mConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveUserInformation();
}
});
mBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
return;
}
});
}
private void getUserInfo(){
mDriverDatabase.addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() &&
dataSnapshot.getChildrenCount()>0){
Map<String, Object> map = (Map<String, Object>)
dataSnapshot.getValue();
if(map.get("name")!=null){
mName = map.get("name").toString();
mNameField.setText(mName);
}
if(map.get("phone")!=null){
mPhone = map.get("phone").toString();
mPhoneField.setText(mPhone);
}
if(map.get("car")!=null){
mCar = map.get("car").toString();
mCarField.setText(mCar);
}
if(map.get("service")!=null){
mService = map.get("service").toString();
switch (mService){
case"UberX":
mRadioGroup.check(R.id.UberX);
break;
case"UberBlack":
mRadioGroup.check(R.id.UberBlack);
break;
case"UberXl":
mRadioGroup.check(R.id.UberXl);
break;
}
}
if(map.get("profileImageUrl")!=null){
mProfileImageUrl =
map.get("profileImageUrl").toString();
Glide.with(getApplication()).load(mProfileImageUrl).into(mProfileImage
);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
if (radioButton.getText() == null){
return;
}
mService = radioButton.getText().toString();
if(resultUri != null) {
StorageReference filePath =
FirebaseStorage.getInstance().getReference().child("profile_images").c
hild(userID);
Bitmap bitmap = null;
try {
bitmap =
MediaStore.Images.Media.getBitmap(getApplication().getContentResolver(
), resultUri);
} catch (IOException e) {
e.printStackTrace();
}
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
finish();
return;
}
});
uploadTask.addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot
taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
finish();
return;
}
});
}else{
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1 && resultCode == Activity.RESULT_OK){
final Uri imageUri = data.getData();
resultUri = imageUri;
mProfileImage.setImageURI(resultUri);
}
}
}
6. CONDUCTOR_LOGIN_REGISTRAR
package com.unjfsc.transporte_glancy;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conductor_login_registar);
Auth= FirebaseAuth.getInstance();
}
}
};
tv_email = (EditText)findViewById(R.id.tv_email);
tv_password = (EditText) findViewById(R.id.tv_password);
btn_ingresar = (Button)findViewById(R.id.btn_ingresar);
btn_registar = (Button)findViewById(R.id.btn_registrarse);
btn_registar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String email = tv_email.getText().toString();
final String password =
tv_password.getText().toString();
Auth.createUserWithEmailAndPassword(email,password).addOnCompleteListe
ner(conductor_login_registar.this,
new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult>
task) {
if(!task.isSuccessful()){
Toast.makeText(conductor_login_registar.this,"Error al registarte",
Toast.LENGTH_SHORT).show();
}else {
String user_id=
Auth.getCurrentUser().getUid();
DatabaseReference corrent_user_db =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(user_id);
corrent_user_db.setValue(true);
}
});
}
});
btn_ingresar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Auth.signInWithEmailAndPassword(email,password).addOnCompleteListener(
conductor_login_registar.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult>
task) {
if(!task.isSuccessful()){
Toast.makeText(conductor_login_registar.this,"Error al registarte",
Toast.LENGTH_SHORT).show();
}
}
});
}
});
@Override
protected void onStart() {
super.onStart();
Auth.addAuthStateListener(firebaseAuthListener);
}
@Override
protected void onStop() {
super.onStop();
Auth.removeAuthStateListener(firebaseAuthListener);
}
}
7. CONDUCTOR_MAPS_ACTIVITY
package com.unjfsc.transporte_glancy;
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.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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conductor_maps);
// 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(ConductorMapsActivity.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);
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(ConductorMapsActivity.this,
MainActivity.class);
startActivity(intent);
finish();
return;
}
});
mSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ConductorMapsActivity.this,
DriverSettingsActivity.class);
startActivity(intent);
return;
}
});
getAssignedCustomer();
}
@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<Object> map = (List<Object>)
dataSnapshot.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());
}
pickupLatLng = new
LatLng(locationLat,locationLng);
pickupMarker = mMap.addMarker(new
MarkerOptions().position(pickupLatLng).title("pickup
location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_picku
p)));
getRouteToMarker(pickupLatLng);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
mCustomerName.setText(map.get("name").toString());
}
if(map.get("phone")!=null){
mCustomerPhone.setText(map.get("phone").toString());
}
if(map.get("profileImageUrl")!=null){
Glide.with(getApplication()).load(map.get("profileImageUrl").toString(
)).into(mCustomerProfileImage);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference driverRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(userId).child("customerRequest");
driverRef.removeValue();
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("customerRequest");
GeoFire geoFire = new GeoFire(ref);
geoFire.removeLocation(customerId);
customerId="";
rideDistance = 0;
if(pickupMarker != null){
pickupMarker.remove();
}
if (assignedCustomerPickupLocationRefListener != null){
assignedCustomerPickupLocationRef.removeEventListener(assignedCustomer
PickupLocationRefListener);
}
mCustomerInfo.setVisibility(View.GONE);
mCustomerName.setText("");
mCustomerPhone.setText("");
mCustomerDestination.setText("Destination: --");
mCustomerProfileImage.setImageResource(R.mipmap.ic_default_user);
}
@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) {
return;
}
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
@Override
public void onLocationChanged(Location location) {
if(getApplicationContext()!=null){
if(!customerId.equals("")){
rideDistance +=
mLastLocation.distanceTo(location)/1000;
}
mLastLocation = location;
LatLng latLng = new
LatLng(location.getLatitude(),location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
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);
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult
connectionResult) {
}
ActivityCompat.requestPermissions(ConductorMapsActivity.this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION},
LOCATION_REQUEST_CODE);
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiCli
ent, mLocationRequest, this);
}
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClie
nt, this);
String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("driversAvailable");
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();
}
}
8. HISTORY_ACTIVITY
package com.unjfsc.transporte_glancy;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.format.DateFormat;
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 com.simcoder.uber.historyRecyclerView.HistoryAdapter;
import com.simcoder.uber.historyRecyclerView.HistoryObject;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
mHistoryRecyclerView = (RecyclerView)
findViewById(R.id.historyRecyclerView);
mHistoryRecyclerView.setNestedScrollingEnabled(false);
mHistoryRecyclerView.setHasFixedSize(true);
mHistoryLayoutManager = new
LinearLayoutManager(HistoryActivity.this);
mHistoryRecyclerView.setLayoutManager(mHistoryLayoutManager);
mHistoryAdapter = new HistoryAdapter(getDataSetHistory(),
HistoryActivity.this);
mHistoryRecyclerView.setAdapter(mHistoryAdapter);
customerOrDriver =
getIntent().getExtras().getString("customerOrDriver");
userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
getUserHistoryIds();
}
9. HISTORY_SINGLE_ACTIVITY
package com.unjfsc.transporte_glancy;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
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.google.android.gms.maps.CameraUpdate;
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.LatLngBounds;
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 com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
rideId = getIntent().getExtras().getString("rideId");
mMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);
currentUserId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
historyRideInfoDb =
FirebaseDatabase.getInstance().getReference().child("history").child(r
ideId);
getRideInformation();
rideDate.setText(getDate(Long.valueOf(child.getValue().toString())));
}
if (child.getKey().equals("rating")){
mRatingBar.setRating(Integer.valueOf(child.getValue().toString()));
}
if (child.getKey().equals("distance")){
distance = child.getValue().toString();
rideDistance.setText(distance.substring(0,
Math.min(distance.length(), 5)) + " km");
ridePrice = Double.valueOf(distance) *
0.5;
}
if (child.getKey().equals("destination")){
rideLocation.setText(child.getValue().toString());
}
if (child.getKey().equals("location")){
pickupLatLng = new
LatLng(Double.valueOf(child.child("from").child("lat").getValue().toSt
ring()),
Double.valueOf(child.child("from").child("lng").getValue().toString())
);
destinationLatLng = new
LatLng(Double.valueOf(child.child("to").child("lat").getValue().toStri
ng()),
Double.valueOf(child.child("to").child("lng").getValue().toString()));
if(destinationLatLng != new LatLng(0,0)){
getRouteToMarker();
}
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,
config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, PAYPAL_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PAYPAL_REQUEST_CODE){
if(resultCode == Activity.RESULT_OK){
}else{
Toast.makeText(getApplicationContext(), "Payment
unsuccessful", Toast.LENGTH_LONG).show();
}
}
}
@Override
protected void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
userPhone.setText(map.get("phone").toString());
}
if(map.get("profileImageUrl") != null){
Glide.with(getApplication()).load(map.get("profileImageUrl").toString(
)).into(userImage);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap=googleMap;
}
CameraUpdate cameraUpdate =
CameraUpdateFactory.newLatLngBounds(bounds, padding);
mMap.animateCamera(cameraUpdate);
mMap.addMarker(new
MarkerOptions().position(pickupLatLng).title("pickup
location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_picku
p)));
mMap.addMarker(new
MarkerOptions().position(destinationLatLng).title("destination"));
if(polylines.size()>0) {
for (Polyline poly : polylines) {
poly.remove();
}
}
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);
}
@Override
public void onRoutingCancelled() {
}
private void erasePolylines(){
for(Polyline line : polylines){
line.remove();
}
polylines.clear();
}
10. MAIN_ACTIVITY
package com.unjfsc.transporte_glancy;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
catch(Exception e)
{
e.printStackTrace();
}
finally
{
Intent mainIntent = new Intent(MainActivity.this,
BienvenidoActivity.class);
startActivity(mainIntent);
}
}
};
thread.start();
@Override
protected void onPause()
{
super.onPause();
finish();
}
ON_APP_KILLED
package com.unjfsc.transporte_glancy;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import com.firebase.geofire.GeoFire;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
@Override
public void onTaskRemoved(Intent rootIntent) {
super.onTaskRemoved(rootIntent);
String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("driversAvailable");
GeoFire geoFire = new GeoFire(ref);
geoFire.removeLocation(userId);
}
}
11. PAY_PAL_CONFIG
package com.unjfsc.transporte_glancy;
/**
* Created by manel on 11/14/2017.
*/
12. HISTORY_ADAPTER
package com.unjfsc.transporte_glancy.historyRecyclerView;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.simcoder.uber.R;
import java.util.List;
/**
* Created by manel on 03/04/2017.
*/
@Override
public HistoryViewHolders onCreateViewHolder(ViewGroup parent, int
viewType) {
View layoutView =
LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history
, null, false);
RecyclerView.LayoutParams lp = new
RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutView.setLayoutParams(lp);
HistoryViewHolders rcv = new HistoryViewHolders(layoutView);
return rcv;
}
@Override
public void onBindViewHolder(HistoryViewHolders holder, final int
position) {
holder.rideId.setText(itemList.get(position).getRideId());
if(itemList.get(position).getTime()!=null){
holder.time.setText(itemList.get(position).getTime());
}
}
@Override
public int getItemCount() {
return this.itemList.size();
}
13. HISTORY_OBJECT
package com.unjfsc.transporte_glancy.historyRecyclerView;
/**
* Created by manel on 10/10/2017.
*/
14. HISTORY_VIEW_HOLDERS
package com.unjfsc.transporte_glancy.historyRecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.simcoder.uber.HistorySingleActivity;
import com.simcoder.uber.R;
/**
* Created by manel on 10/10/2017.
*/
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),
HistorySingleActivity.class);
Bundle b = new Bundle();
b.putString("rideId", rideId.getText().toString());
intent.putExtras(b);
v.getContext().startActivity(intent);
}
}