Grupo04 Proyecto Final

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 64

FACULTAD DE INGENIERÍA INDUSTRIAL, SISTEMAS E INFORMÁTICA

ESCUELA PROFESIONAL DE INGENIERÍA DE SISTEMAS

PROYECTO

APLICACIÓN GLANCY

AUTORES:

GUARDALES COLLANTES, CRISTINA

GIRALDO HIDALGO, GINA

HERBOZO RUBIO, ARTURO

RUIZ TRUJILLO, YOCHET

VELARDE VARGAS, NURIA

DOCENTE

LONCAN

HUACHO – PERÚ
2019
PROPÓSITO

La aplicación de transporte compartido GLANCY es una empresa cuya finalidad principal es la de


ayudar a la gente a obtener un servicio de taxi seguro a cualquier hora del día y en cualquier
lugar que se encuentre, la aplicación GLANCY es muy fácil de usar, además está comprometido
con el cliente a llegar a donde quieran ir, desde opciones de navegación claras hasta pagos sin
efectivo, la app está diseñada para ayudar a las personas a llegar a sus destinos a precios bajos
en todos los tipos de viaje, desde los traslados diarios hasta las salidas nocturnas.
GLANCY acepta a personas que quieran sumarse a esta empresa como conductor, por lo que
tiene un área de la aplicación en la cual pueden registrar sus datos y del vehículo, para que de
esta manera pueda ser seleccionado por la empresa, además, el conductor tendrá horario libre
de trabajo, esto quiere decir que podrá elegir a qué hora trabajar.

CÓMO VIAJAR CON GLANCY

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:

En esta pantalla se seleccionará el tipo de ingreso a la aplicación ya sea como cliente o


como conductor.

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:

En esta pantalla se podrá registrar el cliente, se ingresará sus datos y se confirmará la


información.
4. LOGIN CONDUCTOR:

En esta pantalla se podrá ingresar a la aplicación como conductor, si aún no estamos


registrados daremos en el botón registrar, que nos llevará a otra pantalla.
5. CONFIGURACIÓN CONDUCTOR

En esta pantalla el conductor se registra y coloca la información sobre sus datos


personales y del vehículo, además de seleccionar el tipo de servicio que brindará.

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.

GLANCYXL: Permite al usuario obtener viajes económicos hasta de 6 personas.


ANEXOS

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;

public class BienvenidoActivity extends AppCompatActivity {

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;

public class Cliente_Configuracion extends AppCompatActivity {

private EditText mNameField, mPhoneField;

private Button mBack, mConfirm;

private ImageView mProfileImage;

private FirebaseAuth mAuth;


private DatabaseReference mCustomerDatabase;

private String userID;


private String mName;
private String mPhone;
private String mProfileImageUrl;

private Uri resultUri;

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

mNameField = (EditText) findViewById(R.id.name);


mPhoneField = (EditText) findViewById(R.id.phone);

mProfileImage = (ImageView) findViewById(R.id.profileImage);

mBack = (Button) findViewById(R.id.back);


mConfirm = (Button) findViewById(R.id.confirm);

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) {
}
});
}

private void saveUserInformation() {


mName = mNameField.getText().toString();
mPhone = mPhoneField.getText().toString();

Map userInfo = new HashMap();


userInfo.put("name", mName);
userInfo.put("phone", mPhone);
mCustomerDatabase.updateChildren(userInfo);

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();
}

ByteArrayOutputStream baos = new ByteArrayOutputStream();


bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = filePath.putBytes(data);

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();

Map newImage = new HashMap();


newImage.put("profileImageUrl",
downloadUrl.toString());
mCustomerDatabase.updateChildren(newImage);

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;

public class Cliente_login_registar extends AppCompatActivity {

private EditText mEmail, mPassword;


private Button mLogin, mRegistration;

private FirebaseAuth mAuth;


private FirebaseAuth.AuthStateListener firebaseAuthListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cliente_login_registar);

mAuth = FirebaseAuth.getInstance();

firebaseAuthListener = new FirebaseAuth.AuthStateListener() {


@Override
public void onAuthStateChanged(@NonNull FirebaseAuth
firebaseAuth) {
FirebaseUser user =
FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){
Intent intent = new
Intent(Cliente_login_registar.this, ClienteMapActivity.class);
startActivity(intent);
finish();
return;
}
}
};

mEmail = (EditText) findViewById(R.id.tv_email);


mPassword = (EditText) findViewById(R.id.tv_password);
mLogin = (Button) findViewById(R.id.btn_ingresar);
mRegistration = (Button) findViewById(R.id.btn_registrarse);

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()){

Toast.makeText(Cliente_login_registar.this, "sign up error",


Toast.LENGTH_SHORT).show();
}else{
String user_id =
mAuth.getCurrentUser().getUid();
DatabaseReference current_user_db =
FirebaseDatabase.getInstance().getReference().child("Users").child("Cu
stomers").child(user_id);
current_user_db.setValue(true);
}
}
});
}
});

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()){

Toast.makeText(Cliente_login_registar.this, "sign in error",


Toast.LENGTH_SHORT).show();
}
}
});

}
});
}

@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;

public class ClienteMapActivity extends AppCompatActivity implements


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

private GoogleMap mMap;


GoogleApiClient mGoogleApiClient;
Location mLastLocation;
LocationRequest mLocationRequest;

private Button mLogout, mRequest, mSettings, mHistory;

private LatLng pickupLocation;

private Boolean requestBol = false;

private Marker pickupMarker;

private SupportMapFragment mapFragment;

private String destination, requestService;

private LatLng destinationLatLng;

private LinearLayout mDriverInfo;

private ImageView mDriverProfileImage;

private TextView mDriverName, mDriverPhone, mDriverCar;

private RadioGroup mRadioGroup;

private RatingBar mRatingBar;

@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);
}

destinationLatLng = new LatLng(0.0,0.0);

mDriverInfo = (LinearLayout) findViewById(R.id.driverInfo);

mDriverProfileImage = (ImageView)
findViewById(R.id.driverProfileImage);
mDriverName = (TextView) findViewById(R.id.driverName);
mDriverPhone = (TextView) findViewById(R.id.driverPhone);
mDriverCar = (TextView) findViewById(R.id.driverCar);

mRatingBar = (RatingBar) findViewById(R.id.ratingBar);

mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup);


mRadioGroup.check(R.id.UberX);

mLogout = (Button) findViewById(R.id.logout);


mRequest = (Button) findViewById(R.id.request);
mSettings = (Button) findViewById(R.id.settings);
mHistory = (Button) findViewById(R.id.history);

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();

final RadioButton radioButton = (RadioButton)


findViewById(selectId);

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)))
;

mRequest.setText("Getting your Driver....");

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"
);

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){
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) {

}
});
}

/*-------------------------------------------- Map specific


functions -----
| Function(s) getDriverLocation
|
| Purpose: Get's most updated driver location and it's always
checking for movements.
|
| Note:
| Even tho we used geofire to push the location of the driver
we can use a normal
| Listener to get it's location with no problem.
|
| 0 -> Latitude
| 1 -> Longitude
|
*-----------------------------------------------------------------
--*/
private Marker mDriverMarker;
private DatabaseReference driverLocationRef;
private ValueEventListener driverLocationRefListener;
private void getDriverLocation(){
driverLocationRef =
FirebaseDatabase.getInstance().getReference().child("driversWorking").
child(driverFoundID).child("l");
driverLocationRefListener =
driverLocationRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() && requestBol){
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());
}
LatLng driverLatLng = new
LatLng(locationLat,locationLng);
if(mDriverMarker != null){
mDriverMarker.remove();
}
Location loc1 = new Location("");
loc1.setLatitude(pickupLocation.latitude);
loc1.setLongitude(pickupLocation.longitude);

Location loc2 = new Location("");


loc2.setLatitude(driverLatLng.latitude);
loc2.setLongitude(driverLatLng.longitude);

float distance = loc1.distanceTo(loc2);

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) {
}
});

/*-------------------------------------------- getDriverInfo -----


| Function(s) getDriverInfo
|
| Purpose: Get all the user information that we can get from the
user's database.
|
| Note: --
|
*-----------------------------------------------------------------
--*/
private void getDriverInfo(){
mDriverInfo.setVisibility(View.VISIBLE);
DatabaseReference mCustomerDatabase =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(driverFoundID);
mCustomerDatabase.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() &&
dataSnapshot.getChildrenCount()>0){
if(dataSnapshot.child("name")!=null){

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) {
}
});
}

private DatabaseReference driveHasEndedRef;


private ValueEventListener driveHasEndedRefListener;
private void getHasRideEnded(){
driveHasEndedRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(driverFoundID).child("customerRequest").child("customerR
ideId");
driveHasEndedRefListener =
driveHasEndedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){

}else{
endRide();
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

private void endRide(){


requestBol = false;
geoQuery.removeAllListeners();

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);
}

/*-------------------------------------------- Map specific


functions -----
| Function(s) onMapReady, buildGoogleApiClient,
onLocationChanged, onConnected
|
| Purpose: Find and update user's location.
|
| Note:
| The update interval is set to 1000Ms and the accuracy is set
to PRIORITY_HIGH_ACCURACY,
| If you're having trouble with battery draining too fast
then change these to lower values
|
|
*-----------------------------------------------------------------
--*/
@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) {
ActivityCompat.requestPermissions(ClienteMapActivity.this,
new String[]{android.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) {
if(getApplicationContext()!=null){
mLastLocation = location;

LatLng latLng = new


LatLng(location.getLatitude(),location.getLongitude());

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;

public class Conductor_configuracion extends AppCompatActivity {

private EditText mNameField, mPhoneField, mCarField;

private Button mBack, mConfirm;

private ImageView mProfileImage;

private FirebaseAuth mAuth;


private DatabaseReference mDriverDatabase;

private String userID;


private String mName;
private String mPhone;
private String mCar;
private String mService;
private String mProfileImageUrl;

private Uri resultUri;

private RadioGroup mRadioGroup;

@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);

mProfileImage = (ImageView) findViewById(R.id.profileImage);

mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup);

mBack = (Button) findViewById(R.id.back);


mConfirm = (Button) findViewById(R.id.confirm);

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) {
}
});
}

private void saveUserInformation() {


mName = mNameField.getText().toString();
mPhone = mPhoneField.getText().toString();
mCar = mCarField.getText().toString();

int selectId = mRadioGroup.getCheckedRadioButtonId();

final RadioButton radioButton = (RadioButton)


findViewById(selectId);

if (radioButton.getText() == null){
return;
}

mService = radioButton.getText().toString();

Map userInfo = new HashMap();


userInfo.put("name", mName);
userInfo.put("phone", mPhone);
userInfo.put("car", mCar);
userInfo.put("service", mService);
mDriverDatabase.updateChildren(userInfo);

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();
}

ByteArrayOutputStream baos = new ByteArrayOutputStream();


bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = filePath.putBytes(data);

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();

Map newImage = new HashMap();


newImage.put("profileImageUrl",
downloadUrl.toString());
mDriverDatabase.updateChildren(newImage);

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;

public class conductor_login_registar extends AppCompatActivity


{

private EditText tv_email,tv_password;


private Button btn_ingresar,btn_registar;

private FirebaseAuth Auth;


private FirebaseAuth.AuthStateListener firebaseAuthListener;

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

Auth= FirebaseAuth.getInstance();

firebaseAuthListener= new FirebaseAuth.AuthStateListener() {


@Override
public void onAuthStateChanged(@NonNull FirebaseAuth
firebaseAuth) {
FirebaseUser user =
FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){
Intent intent= new
Intent(conductor_login_registar.this,ConductorMapsActivity.class);
startActivity(intent);
finish();
return;

}
}

};

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) {

final String email = tv_email.getText().toString();


final String password =
tv_password.getText().toString();

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;

public class ConductorMapsActivity extends FragmentActivity implements


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

private GoogleMap mMap;


GoogleApiClient mGoogleApiClient;
Location mLastLocation;
LocationRequest mLocationRequest;

private Button mLogout, mSettings, mRideStatus;

private Switch mWorkingSwitch;

private int status = 0;

private String customerId = "", destination;


private LatLng destinationLatLng, pickupLatLng;
private float rideDistance;

private Boolean isLoggingOut = false;

private SupportMapFragment mapFragment;

private LinearLayout mCustomerInfo;

private ImageView mCustomerProfileImage;

private TextView mCustomerName, mCustomerPhone,


mCustomerDestination;

@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);

mCustomerName = (TextView) findViewById(R.id.customerName);


mCustomerPhone = (TextView) findViewById(R.id.customerPhone);
mCustomerDestination = (TextView)
findViewById(R.id.customerDestination);

mWorkingSwitch = (Switch) findViewById(R.id.workingSwitch);


mWorkingSwitch.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked){
connectDriver();
}else{
disconnectDriver();
}
}
});

mSettings = (Button) findViewById(R.id.settings);


mLogout = (Button) findViewById(R.id.logout);
mRideStatus = (Button) findViewById(R.id.rideStatus);
mRideStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch(status){
case 1:
status=2;
erasePolylines();
if(destinationLatLng.latitude!=0.0 &&
destinationLatLng.longitude!=0.0){
getRouteToMarker(destinationLatLng);
}
mRideStatus.setText("drive completed");

break;
case 2:
recordRide();
endRide();
break;
}
}
});

mLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isLoggingOut = true;

disconnectDriver();

FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(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();
}

private void getAssignedCustomer(){


String driverId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(driverId).child("customerRequest").child("customerRideId
");
assignedCustomerRef.addValueEventListener(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
status = 1;
customerId = dataSnapshot.getValue().toString();
getAssignedCustomerPickupLocation();
getAssignedCustomerDestination();
getAssignedCustomerInfo();
}else{
endRide();
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

Marker pickupMarker;
private DatabaseReference assignedCustomerPickupLocationRef;
private ValueEventListener
assignedCustomerPickupLocationRefListener;
private void getAssignedCustomerPickupLocation(){
assignedCustomerPickupLocationRef =
FirebaseDatabase.getInstance().getReference().child("customerRequest")
.child(customerId).child("l");
assignedCustomerPickupLocationRefListener =
assignedCustomerPickupLocationRef.addValueEventListener(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() && !customerId.equals("")){
List<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) {
}
});
}

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(){


String driverId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(driverId).child("customerRequest");
assignedCustomerRef.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
Map<String, Object> map = (Map<String, Object>)
dataSnapshot.getValue();
if(map.get("destination")!=null){
destination =
map.get("destination").toString();
mCustomerDestination.setText("Destination: " +
destination);
}
else{
mCustomerDestination.setText("Destination: --
");
}
Double destinationLat = 0.0;
Double destinationLng = 0.0;
if(map.get("destinationLat") != null){
destinationLat =
Double.valueOf(map.get("destinationLat").toString());
}
if(map.get("destinationLng") != null){
destinationLng =
Double.valueOf(map.get("destinationLng").toString());
destinationLatLng = new LatLng(destinationLat,
destinationLng);
}

}
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

private void getAssignedCustomerInfo(){


mCustomerInfo.setVisibility(View.VISIBLE);
DatabaseReference mCustomerDatabase =
FirebaseDatabase.getInstance().getReference().child("Users").child("Cu
stomers").child(customerId);
mCustomerDatabase.addListenerForSingleValueEvent(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){

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) {
}
});
}

private void endRide(){


mRideStatus.setText("picked customer");
erasePolylines();

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);
}

private void recordRide(){


String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference driverRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(userId).child("history");
DatabaseReference customerRef =
FirebaseDatabase.getInstance().getReference().child("Users").child("Cu
stomers").child(customerId).child("history");
DatabaseReference historyRef =
FirebaseDatabase.getInstance().getReference().child("history");
String requestId = historyRef.push().getKey();
driverRef.child(requestId).setValue(true);
customerRef.child(requestId).setValue(true);

HashMap map = new HashMap();


map.put("driver", userId);
map.put("customer", customerId);
map.put("rating", 0);
map.put("timestamp", getCurrentTimestamp());
map.put("destination", destination);
map.put("location/from/lat", pickupLatLng.latitude);
map.put("location/from/lng", pickupLatLng.longitude);
map.put("location/to/lat", destinationLatLng.latitude);
map.put("location/to/lng", destinationLatLng.longitude);
map.put("distance", rideDistance);
historyRef.child(requestId).updateChildren(map);
}
private Long getCurrentTimestamp() {
Long timestamp = System.currentTimeMillis()/1000;
return timestamp;
}

@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);
}

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) {
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) {
}

private void connectDriver(){


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);
}

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiCli
ent, mLocationRequest, this);
}

private void disconnectDriver(){

LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClie
nt, this);
String userId =
FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("driversAvailable");

GeoFire geoFire = new GeoFire(ref);


geoFire.removeLocation(userId);
}

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(getApplicationContext(), "Please
provide the permission", Toast.LENGTH_LONG).show();
}
break;
}
}
}

private List<Polyline> polylines;


private static final int[] COLORS = new
int[]{R.color.primary_dark_material_light};
@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
shortestRouteIndex) {
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();
}
}

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;

public class HistoryActivity extends AppCompatActivity {


private String customerOrDriver, userId;

private RecyclerView mHistoryRecyclerView;


private RecyclerView.Adapter mHistoryAdapter;
private RecyclerView.LayoutManager mHistoryLayoutManager;

@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();
}

private void getUserHistoryIds() {


DatabaseReference userHistoryDatabase =
FirebaseDatabase.getInstance().getReference().child("Users").child(cus
tomerOrDriver).child(userId).child("history");
userHistoryDatabase.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
for(DataSnapshot history :
dataSnapshot.getChildren()){
FetchRideInformation(history.getKey());
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

private void FetchRideInformation(String rideKey) {


DatabaseReference historyDatabase =
FirebaseDatabase.getInstance().getReference().child("history").child(r
ideKey);
historyDatabase.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
String rideId = dataSnapshot.getKey();
Long timestamp = 0L;
for(DataSnapshot child :
dataSnapshot.getChildren()){
if (child.getKey().equals("timestamp")){
timestamp =
Long.valueOf(child.getValue().toString());
}
}
HistoryObject obj = new HistoryObject(rideId,
getDate(timestamp));
resultsHistory.add(obj);
mHistoryAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private String getDate(Long time) {
Calendar cal = Calendar.getInstance(Locale.getDefault());
cal.setTimeInMillis(time*1000);
String date = DateFormat.format("MM-dd-yyyy hh:mm",
cal).toString();
return date;
}

private ArrayList resultsHistory = new ArrayList<HistoryObject>();


private ArrayList<HistoryObject> getDataSetHistory() {
return resultsHistory;
}
}

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;

public class HistorySingleActivity extends AppCompatActivity


implements OnMapReadyCallback, RoutingListener {
private String rideId, currentUserId, customerId, driverId,
userDriverOrCustomer;

private TextView rideLocation;


private TextView rideDistance;
private TextView rideDate;
private TextView userName;
private TextView userPhone;

private ImageView userImage;

private RatingBar mRatingBar;

private Button mPay;

private DatabaseReference historyRideInfoDb;

private LatLng destinationLatLng, pickupLatLng;


private String distance;
private Double ridePrice;

private GoogleMap mMap;


private SupportMapFragment mMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_single);

Intent intent = new Intent(this, PayPalService.class);


intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,
config);
startService(intent);

polylines = new ArrayList<>();

rideId = getIntent().getExtras().getString("rideId");

mMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);

rideLocation = (TextView) findViewById(R.id.rideLocation);


rideDistance = (TextView) findViewById(R.id.rideDistance);
rideDate = (TextView) findViewById(R.id.rideDate);
userName = (TextView) findViewById(R.id.userName);
userPhone = (TextView) findViewById(R.id.userPhone);

userImage = (ImageView) findViewById(R.id.userImage);

mRatingBar = (RatingBar) findViewById(R.id.ratingBar);


mPay = findViewById(R.id.pay);

currentUserId =
FirebaseAuth.getInstance().getCurrentUser().getUid();

historyRideInfoDb =
FirebaseDatabase.getInstance().getReference().child("history").child(r
ideId);
getRideInformation();

private void getRideInformation() {


historyRideInfoDb.addListenerForSingleValueEvent(new
ValueEventListener() {
@SuppressLint("SetTextI18n")
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
for (DataSnapshot
child:dataSnapshot.getChildren()){
if (child.getKey().equals("customer")){
customerId = child.getValue().toString();
if(!customerId.equals(currentUserId)){
userDriverOrCustomer = "Drivers";
getUserInformation("Customers",
customerId);
}
}
if (child.getKey().equals("driver")){
driverId = child.getValue().toString();
if(!driverId.equals(currentUserId)){
userDriverOrCustomer = "Customers";
getUserInformation("Drivers",
driverId);
displayCustomerRelatedObjects();
}
}
if (child.getKey().equals("timestamp")){

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) {
}
});
}

private void displayCustomerRelatedObjects() {


mRatingBar.setVisibility(View.VISIBLE);
mPay.setVisibility(View.VISIBLE);
mRatingBar.setOnRatingBarChangeListener(new
RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float
rating, boolean fromUser) {
historyRideInfoDb.child("rating").setValue(rating);
DatabaseReference mDriverRatingDb =
FirebaseDatabase.getInstance().getReference().child("Users").child("Dr
ivers").child(driverId).child("rating");
mDriverRatingDb.child(rideId).setValue(rating);
}
});
mPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
payPalPayment();
}
});
}

private int PAYPAL_REQUEST_CODE = 1;


private static PayPalConfiguration config = new
PayPalConfiguration()
.environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
.clientId(PayPalConfig.PAYPAL_CLIENT_ID);

private void payPalPayment() {


PayPalPayment payment = new PayPalPayment(new
BigDecimal(ridePrice), "USD", "Uber Ride",
PayPalPayment.PAYMENT_INTENT_SALE);

Intent intent = new Intent(this, PaymentActivity.class);

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();
}

private void getUserInformation(String otherUserDriverOrCustomer,


String otherUserId) {
DatabaseReference mOtherUserDB =
FirebaseDatabase.getInstance().getReference().child("Users").child(oth
erUserDriverOrCustomer).child(otherUserId);
mOtherUserDB.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
Map<String, Object> map = (Map<String, Object>)
dataSnapshot.getValue();
if(map.get("name") != null){
userName.setText(map.get("name").toString());
}
if(map.get("phone") != null){

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) {
}
});
}

private String getDate(Long time) {


Calendar cal = Calendar.getInstance(Locale.getDefault());
cal.setTimeInMillis(time*1000);
String date = DateFormat.format("MM-dd-yyyy hh:mm",
cal).toString();
return date;
}
private void getRouteToMarker() {
Routing routing = new Routing.Builder()
.travelMode(AbstractRouting.TravelMode.DRIVING)
.withListener(this)
.alternativeRoutes(false)
.waypoints(pickupLatLng, destinationLatLng)
.build();
routing.execute();
}

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

private List<Polyline> polylines;


private static final int[] COLORS = new
int[]{R.color.primary_dark_material_light};
@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
shortestRouteIndex) {

LatLngBounds.Builder builder = new LatLngBounds.Builder();


builder.include(pickupLatLng);
builder.include(destinationLatLng);
LatLngBounds bounds = builder.build();

int width = getResources().getDisplayMetrics().widthPixels;


int padding = (int) (width*0.2);

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();
}
}

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();
}

10. MAIN_ACTIVITY
package com.unjfsc.transporte_glancy;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

Thread thread = new Thread()


{
@Override
public void run()
{
try
{
sleep(1000);
}

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;

public class onAppKilled extends Service {


@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

@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.
*/

public class PayPalConfig {


public static final String PAYPAL_CLIENT_ID = "AXGlZJ-
6rLnwBMhHMkuaQSpdbKyBIbcwWiIUJvBeCO7qEvdUI2DiM_b2biBZzydhXski8KUkpF55z
COl";
}

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.
*/

public class HistoryAdapter extends


RecyclerView.Adapter<HistoryViewHolders> {

private List<HistoryObject> itemList;


private Context context;

public HistoryAdapter(List<HistoryObject> itemList, Context


context) {
this.itemList = itemList;
this.context = context;
}

@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.
*/

public class HistoryObject {


private String rideId;
private String time;

public HistoryObject(String rideId, String time){


this.rideId = rideId;
this.time = time;
}

public String getRideId(){return rideId;}


public void setRideId(String rideId) {
this.rideId = rideId;
}

public String getTime(){return time;}


public void setTime(String time) {
this.time = time;
}
}

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.
*/

public class HistoryViewHolders extends RecyclerView.ViewHolder


implements View.OnClickListener{

public TextView rideId;


public TextView time;
public HistoryViewHolders(View itemView) {
super(itemView);
itemView.setOnClickListener(this);

rideId = (TextView) itemView.findViewById(R.id.rideId);


time = (TextView) itemView.findViewById(R.id.time);
}

@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);
}
}

También podría gustarte