SlideShare a Scribd company logo
Creating an Uber Clone - Part XXV
LocationService
✦Mark hailing in websocket code
✦Server checks available area
✦Send push notifications to available drivers
✦Expand the circle of search
© Codename One 2017 all rights reserved
public static final String CODENAME_ONE_PUSH_KEY = "----";
public static final String GOOGLE_PUSH_AUTH_KEY = "----";
public static final String APNS_DEV_PUSH_CERT = "----";
public static final String APNS_PROD_PUSH_CERT = "----";
public static final String APNS_DEV_PUSH_PASS = "----";
public static final String APNS_PROD_PUSH_PASS = "----";
public static final boolean APNS_PRODUCTION = false;
Globals
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
private static final short MESSAGE_TYPE_DRIVER_FOUND = 4;
private static final short HAILING_OFF = 0;
private static final short HAILING_ON = 1;
private static final short HAILING_TURN_OFF = 2;
private static LocationService instance;
private int hailing;
private Motion halingRadius;
private String from;
private String to;
private List<String> notificationList;
private long driverId;
private CarAdded driverFound;
LocationService
if(ll == lon && lt == lat && dir == direction && hailing == HAILING_OFF) {
// no need to do an update
return;
}
sendLocationUpdate
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
if(hailing == HAILING_ON) {
dos.writeDouble(((double)halingRadius.getValue()) / 1000.0);
dos.writeByte(HAILING_ON);
byte[] fromBytes = from.getBytes("UTF-8");
byte[] toBytes = to.getBytes("UTF-8");
dos.writeShort(fromBytes.length);
dos.write(fromBytes);
dos.writeShort(toBytes.length);
dos.write(toBytes);
} else {
dos.writeDouble(1);
dos.writeByte(hailing);
if(hailing == HAILING_TURN_OFF) {
hailing = HAILING_OFF;
}
}
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
sendLocationUpdate
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
if(hailing == HAILING_ON) {
dos.writeDouble(((double)halingRadius.getValue()) / 1000.0);
dos.writeByte(HAILING_ON);
byte[] fromBytes = from.getBytes("UTF-8");
byte[] toBytes = to.getBytes("UTF-8");
dos.writeShort(fromBytes.length);
dos.write(fromBytes);
dos.writeShort(toBytes.length);
dos.write(toBytes);
} else {
dos.writeDouble(1);
dos.writeByte(hailing);
if(hailing == HAILING_TURN_OFF) {
hailing = HAILING_OFF;
}
}
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
sendLocationUpdate
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
if(hailing == HAILING_ON) {
dos.writeDouble(((double)halingRadius.getValue()) / 1000.0);
dos.writeByte(HAILING_ON);
byte[] fromBytes = from.getBytes("UTF-8");
byte[] toBytes = to.getBytes("UTF-8");
dos.writeShort(fromBytes.length);
dos.write(fromBytes);
dos.writeShort(toBytes.length);
dos.write(toBytes);
} else {
dos.writeDouble(1);
dos.writeByte(hailing);
if(hailing == HAILING_TURN_OFF) {
hailing = HAILING_OFF;
}
}
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
sendLocationUpdate
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
if(hailing == HAILING_ON) {
dos.writeDouble(((double)halingRadius.getValue()) / 1000.0);
dos.writeByte(HAILING_ON);
byte[] fromBytes = from.getBytes("UTF-8");
byte[] toBytes = to.getBytes("UTF-8");
dos.writeShort(fromBytes.length);
dos.write(fromBytes);
dos.writeShort(toBytes.length);
dos.write(toBytes);
} else {
dos.writeDouble(1);
dos.writeByte(hailing);
if(hailing == HAILING_TURN_OFF) {
hailing = HAILING_OFF;
}
}
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
sendLocationUpdate
dos.writeDouble(lat);
dos.writeDouble(lon);
dos.writeFloat(dir);
if(hailing == HAILING_ON) {
dos.writeDouble(((double)halingRadius.getValue()) / 1000.0);
dos.writeByte(HAILING_ON);
byte[] fromBytes = from.getBytes("UTF-8");
byte[] toBytes = to.getBytes("UTF-8");
dos.writeShort(fromBytes.length);
dos.write(fromBytes);
dos.writeShort(toBytes.length);
dos.write(toBytes);
} else {
dos.writeDouble(1);
dos.writeByte(hailing);
if(hailing == HAILING_TURN_OFF) {
hailing = HAILING_OFF;
}
}
dos.flush();
send(bos.toByteArray());
} catch(IOException err) {
Log.e(err);
}
sendLocationUpdate
@Override
protected void onMessage(byte[] bytes) {
try {
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes));
short response = dis.readShort();
if(response == MESSAGE_TYPE_DRIVER_FOUND) {
driverId = dis.readLong();
User u = cars.get(driverId);
if(u == null) {
u = new User().id.set(driverId);
cars.put(driverId, u);
}
u.car.set(dis.readUTF()).
givenName.set(dis.readUTF()).
surname.set(dis.readUTF()).
currentRating.set(dis.readFloat());
final User finalUser = u;
callSerially(() -> driverFound.carAdded(finalUser));
return;
}
int size = dis.readInt();
List<String> sendPush = null;
for(int iter = 0 ; iter < size ; iter++) {
onMessage
@Override
protected void onMessage(byte[] bytes) {
try {
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes));
short response = dis.readShort();
if(response == MESSAGE_TYPE_DRIVER_FOUND) {
driverId = dis.readLong();
User u = cars.get(driverId);
if(u == null) {
u = new User().id.set(driverId);
cars.put(driverId, u);
}
u.car.set(dis.readUTF()).
givenName.set(dis.readUTF()).
surname.set(dis.readUTF()).
currentRating.set(dis.readFloat());
final User finalUser = u;
callSerially(() -> driverFound.carAdded(finalUser));
return;
}
int size = dis.readInt();
List<String> sendPush = null;
for(int iter = 0 ; iter < size ; iter++) {
onMessage
List<String> sendPush = null;
for(int iter = 0 ; iter < size ; iter++) {
long id = dis.readLong();
User car = cars.get(id);
if(car == null) {
car = new User().
id.set(id).
latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat()).
pushToken.set(dis.readUTF());
cars.put(id, car);
User finalCar = car;
callSerially(() -> carCallback.carAdded(finalCar));
} else {
car.latitude.set(dis.readDouble()).
longitude.set(dis.readDouble()).
direction.set(dis.readFloat()).
pushToken.set(dis.readUTF());
}
if(hailing==HAILING_ON && response==MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS){
if(!notificationList.contains(car.pushToken.get())) {
notificationList.add(car.pushToken.get());
onMessage
if(hailing==HAILING_ON && response==MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS){
if(!notificationList.contains(car.pushToken.get())) {
notificationList.add(car.pushToken.get());
if(sendPush == null) {
sendPush = new ArrayList<>();
}
sendPush.add(car.pushToken.get());
}
}
}
if(sendPush != null) {
String[] devices = new String[sendPush.size()];
sendPush.toArray(devices);
String apnsCert = APNS_DEV_PUSH_CERT;
String apnsPass = APNS_DEV_PUSH_PASS;
if(APNS_PRODUCTION) {
apnsCert = APNS_PROD_PUSH_CERT;
apnsPass = APNS_PROD_PUSH_PASS;
}
new Push(CODENAME_ONE_PUSH_KEY,
"#" + UserService.getUser().id.getLong() +
";Ride pending from: " + from + " to: " + to,
devices).
onMessage
if(hailing==HAILING_ON && response==MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS){
if(!notificationList.contains(car.pushToken.get())) {
notificationList.add(car.pushToken.get());
if(sendPush == null) {
sendPush = new ArrayList<>();
}
sendPush.add(car.pushToken.get());
}
}
}
if(sendPush != null) {
String[] devices = new String[sendPush.size()];
sendPush.toArray(devices);
String apnsCert = APNS_DEV_PUSH_CERT;
String apnsPass = APNS_DEV_PUSH_PASS;
if(APNS_PRODUCTION) {
apnsCert = APNS_PROD_PUSH_CERT;
apnsPass = APNS_PROD_PUSH_PASS;
}
new Push(CODENAME_ONE_PUSH_KEY,
"#" + UserService.getUser().id.getLong() +
";Ride pending from: " + from + " to: " + to,
devices).
onMessage
}
}
if(sendPush != null) {
String[] devices = new String[sendPush.size()];
sendPush.toArray(devices);
String apnsCert = APNS_DEV_PUSH_CERT;
String apnsPass = APNS_DEV_PUSH_PASS;
if(APNS_PRODUCTION) {
apnsCert = APNS_PROD_PUSH_CERT;
apnsPass = APNS_PROD_PUSH_PASS;
}
new Push(CODENAME_ONE_PUSH_KEY,
"#" + UserService.getUser().id.getLong() +
";Ride pending from: " + from + " to: " + to,
devices).
pushType(3).
apnsAuth(apnsCert, apnsPass, APNS_PRODUCTION).
gcmAuth(GOOGLE_PUSH_AUTH_KEY).sendAsync();
}
} catch(IOException err) {
Log.e(err);
}
}
onMessage
public final Property<String, User> pushToken = new Property<>("pushToken");
private final PropertyIndex idx = new PropertyIndex(this, "User", id, givenName,
surname, phone, email, facebookId, googleId, driver, car, currentRating,
latitude, longitude, direction, authToken, password, pushToken);
User
public static void hailRide(String from, String to, CarAdded callback) {
instance.driverFound = callback;
instance.from = from;
instance.to = to;
instance.notificationList = new ArrayList<>();
instance.halingRadius = Motion.createLinearMotion(500, 2000, 30000);
instance.halingRadius.start();
instance.hailing = HAILING_ON;
instance.server.sendLocationUpdate();
}
hailRide

More Related Content

Similar to Creating an Uber Clone - Part XXV.pdf

How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
Masahiro Nagano
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Creating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdfCreating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdf
ShaiAlmog1
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h
SilvaGraf83
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h
MoseStaton39
 
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
ajay1317
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
2600Hz
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
Daniel-Constantin Mierla
 
FOSDEM 2017 - RTC Services With Lua and Kamailio
FOSDEM 2017 - RTC Services With Lua and KamailioFOSDEM 2017 - RTC Services With Lua and Kamailio
FOSDEM 2017 - RTC Services With Lua and Kamailio
Daniel-Constantin Mierla
 
Creating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdfCreating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdf
ShaiAlmog1
 
Smart Contracts. Pierwsze starcie
Smart Contracts. Pierwsze starcieSmart Contracts. Pierwsze starcie
Smart Contracts. Pierwsze starcie
The Software House
 
Creating an Uber Clone - Part XXXI.pdf
Creating an Uber Clone - Part XXXI.pdfCreating an Uber Clone - Part XXXI.pdf
Creating an Uber Clone - Part XXXI.pdf
ShaiAlmog1
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
 
East Bay Ruby Tropo presentation
East Bay Ruby Tropo presentationEast Bay Ruby Tropo presentation
East Bay Ruby Tropo presentation
Adam Kalsey
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Testing Services Effectively
Testing Services Effectively Testing Services Effectively
Testing Services Effectively
Alberto Leal
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Bart Uelen
 
PHP and COM
PHP and COMPHP and COM
PHP and COM
Wez Furlong
 
COMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdfCOMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdf
fazalenterprises
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
✅ William Pinaud
 

Similar to Creating an Uber Clone - Part XXV.pdf (20)

How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Creating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdfCreating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdf
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h
 
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
 
FOSDEM 2017 - RTC Services With Lua and Kamailio
FOSDEM 2017 - RTC Services With Lua and KamailioFOSDEM 2017 - RTC Services With Lua and Kamailio
FOSDEM 2017 - RTC Services With Lua and Kamailio
 
Creating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdfCreating an Uber Clone - Part XII.pdf
Creating an Uber Clone - Part XII.pdf
 
Smart Contracts. Pierwsze starcie
Smart Contracts. Pierwsze starcieSmart Contracts. Pierwsze starcie
Smart Contracts. Pierwsze starcie
 
Creating an Uber Clone - Part XXXI.pdf
Creating an Uber Clone - Part XXXI.pdfCreating an Uber Clone - Part XXXI.pdf
Creating an Uber Clone - Part XXXI.pdf
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
East Bay Ruby Tropo presentation
East Bay Ruby Tropo presentationEast Bay Ruby Tropo presentation
East Bay Ruby Tropo presentation
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Testing Services Effectively
Testing Services Effectively Testing Services Effectively
Testing Services Effectively
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
 
PHP and COM
PHP and COMPHP and COM
PHP and COM
 
COMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdfCOMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdf
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

Creating an Uber Clone - Part XXV.pdf

  • 1. Creating an Uber Clone - Part XXV
  • 2. LocationService ✦Mark hailing in websocket code ✦Server checks available area ✦Send push notifications to available drivers ✦Expand the circle of search © Codename One 2017 all rights reserved
  • 3. public static final String CODENAME_ONE_PUSH_KEY = "----"; public static final String GOOGLE_PUSH_AUTH_KEY = "----"; public static final String APNS_DEV_PUSH_CERT = "----"; public static final String APNS_PROD_PUSH_CERT = "----"; public static final String APNS_DEV_PUSH_PASS = "----"; public static final String APNS_PROD_PUSH_PASS = "----"; public static final boolean APNS_PRODUCTION = false; Globals
  • 4. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 5. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 6. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 7. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 8. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 9. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 10. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 11. private static final short MESSAGE_TYPE_DRIVER_FOUND = 4; private static final short HAILING_OFF = 0; private static final short HAILING_ON = 1; private static final short HAILING_TURN_OFF = 2; private static LocationService instance; private int hailing; private Motion halingRadius; private String from; private String to; private List<String> notificationList; private long driverId; private CarAdded driverFound; LocationService
  • 12. if(ll == lon && lt == lat && dir == direction && hailing == HAILING_OFF) { // no need to do an update return; } sendLocationUpdate
  • 13. dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); if(hailing == HAILING_ON) { dos.writeDouble(((double)halingRadius.getValue()) / 1000.0); dos.writeByte(HAILING_ON); byte[] fromBytes = from.getBytes("UTF-8"); byte[] toBytes = to.getBytes("UTF-8"); dos.writeShort(fromBytes.length); dos.write(fromBytes); dos.writeShort(toBytes.length); dos.write(toBytes); } else { dos.writeDouble(1); dos.writeByte(hailing); if(hailing == HAILING_TURN_OFF) { hailing = HAILING_OFF; } } dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } sendLocationUpdate
  • 14. dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); if(hailing == HAILING_ON) { dos.writeDouble(((double)halingRadius.getValue()) / 1000.0); dos.writeByte(HAILING_ON); byte[] fromBytes = from.getBytes("UTF-8"); byte[] toBytes = to.getBytes("UTF-8"); dos.writeShort(fromBytes.length); dos.write(fromBytes); dos.writeShort(toBytes.length); dos.write(toBytes); } else { dos.writeDouble(1); dos.writeByte(hailing); if(hailing == HAILING_TURN_OFF) { hailing = HAILING_OFF; } } dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } sendLocationUpdate
  • 15. dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); if(hailing == HAILING_ON) { dos.writeDouble(((double)halingRadius.getValue()) / 1000.0); dos.writeByte(HAILING_ON); byte[] fromBytes = from.getBytes("UTF-8"); byte[] toBytes = to.getBytes("UTF-8"); dos.writeShort(fromBytes.length); dos.write(fromBytes); dos.writeShort(toBytes.length); dos.write(toBytes); } else { dos.writeDouble(1); dos.writeByte(hailing); if(hailing == HAILING_TURN_OFF) { hailing = HAILING_OFF; } } dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } sendLocationUpdate
  • 16. dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); if(hailing == HAILING_ON) { dos.writeDouble(((double)halingRadius.getValue()) / 1000.0); dos.writeByte(HAILING_ON); byte[] fromBytes = from.getBytes("UTF-8"); byte[] toBytes = to.getBytes("UTF-8"); dos.writeShort(fromBytes.length); dos.write(fromBytes); dos.writeShort(toBytes.length); dos.write(toBytes); } else { dos.writeDouble(1); dos.writeByte(hailing); if(hailing == HAILING_TURN_OFF) { hailing = HAILING_OFF; } } dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } sendLocationUpdate
  • 17. dos.writeDouble(lat); dos.writeDouble(lon); dos.writeFloat(dir); if(hailing == HAILING_ON) { dos.writeDouble(((double)halingRadius.getValue()) / 1000.0); dos.writeByte(HAILING_ON); byte[] fromBytes = from.getBytes("UTF-8"); byte[] toBytes = to.getBytes("UTF-8"); dos.writeShort(fromBytes.length); dos.write(fromBytes); dos.writeShort(toBytes.length); dos.write(toBytes); } else { dos.writeDouble(1); dos.writeByte(hailing); if(hailing == HAILING_TURN_OFF) { hailing = HAILING_OFF; } } dos.flush(); send(bos.toByteArray()); } catch(IOException err) { Log.e(err); } sendLocationUpdate
  • 18. @Override protected void onMessage(byte[] bytes) { try { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); short response = dis.readShort(); if(response == MESSAGE_TYPE_DRIVER_FOUND) { driverId = dis.readLong(); User u = cars.get(driverId); if(u == null) { u = new User().id.set(driverId); cars.put(driverId, u); } u.car.set(dis.readUTF()). givenName.set(dis.readUTF()). surname.set(dis.readUTF()). currentRating.set(dis.readFloat()); final User finalUser = u; callSerially(() -> driverFound.carAdded(finalUser)); return; } int size = dis.readInt(); List<String> sendPush = null; for(int iter = 0 ; iter < size ; iter++) { onMessage
  • 19. @Override protected void onMessage(byte[] bytes) { try { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); short response = dis.readShort(); if(response == MESSAGE_TYPE_DRIVER_FOUND) { driverId = dis.readLong(); User u = cars.get(driverId); if(u == null) { u = new User().id.set(driverId); cars.put(driverId, u); } u.car.set(dis.readUTF()). givenName.set(dis.readUTF()). surname.set(dis.readUTF()). currentRating.set(dis.readFloat()); final User finalUser = u; callSerially(() -> driverFound.carAdded(finalUser)); return; } int size = dis.readInt(); List<String> sendPush = null; for(int iter = 0 ; iter < size ; iter++) { onMessage
  • 20. List<String> sendPush = null; for(int iter = 0 ; iter < size ; iter++) { long id = dis.readLong(); User car = cars.get(id); if(car == null) { car = new User(). id.set(id). latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()). pushToken.set(dis.readUTF()); cars.put(id, car); User finalCar = car; callSerially(() -> carCallback.carAdded(finalCar)); } else { car.latitude.set(dis.readDouble()). longitude.set(dis.readDouble()). direction.set(dis.readFloat()). pushToken.set(dis.readUTF()); } if(hailing==HAILING_ON && response==MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS){ if(!notificationList.contains(car.pushToken.get())) { notificationList.add(car.pushToken.get()); onMessage
  • 21. if(hailing==HAILING_ON && response==MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS){ if(!notificationList.contains(car.pushToken.get())) { notificationList.add(car.pushToken.get()); if(sendPush == null) { sendPush = new ArrayList<>(); } sendPush.add(car.pushToken.get()); } } } if(sendPush != null) { String[] devices = new String[sendPush.size()]; sendPush.toArray(devices); String apnsCert = APNS_DEV_PUSH_CERT; String apnsPass = APNS_DEV_PUSH_PASS; if(APNS_PRODUCTION) { apnsCert = APNS_PROD_PUSH_CERT; apnsPass = APNS_PROD_PUSH_PASS; } new Push(CODENAME_ONE_PUSH_KEY, "#" + UserService.getUser().id.getLong() + ";Ride pending from: " + from + " to: " + to, devices). onMessage
  • 22. if(hailing==HAILING_ON && response==MESSAGE_TYPE_AVAILBLE_DRIVER_POSITIONS){ if(!notificationList.contains(car.pushToken.get())) { notificationList.add(car.pushToken.get()); if(sendPush == null) { sendPush = new ArrayList<>(); } sendPush.add(car.pushToken.get()); } } } if(sendPush != null) { String[] devices = new String[sendPush.size()]; sendPush.toArray(devices); String apnsCert = APNS_DEV_PUSH_CERT; String apnsPass = APNS_DEV_PUSH_PASS; if(APNS_PRODUCTION) { apnsCert = APNS_PROD_PUSH_CERT; apnsPass = APNS_PROD_PUSH_PASS; } new Push(CODENAME_ONE_PUSH_KEY, "#" + UserService.getUser().id.getLong() + ";Ride pending from: " + from + " to: " + to, devices). onMessage
  • 23. } } if(sendPush != null) { String[] devices = new String[sendPush.size()]; sendPush.toArray(devices); String apnsCert = APNS_DEV_PUSH_CERT; String apnsPass = APNS_DEV_PUSH_PASS; if(APNS_PRODUCTION) { apnsCert = APNS_PROD_PUSH_CERT; apnsPass = APNS_PROD_PUSH_PASS; } new Push(CODENAME_ONE_PUSH_KEY, "#" + UserService.getUser().id.getLong() + ";Ride pending from: " + from + " to: " + to, devices). pushType(3). apnsAuth(apnsCert, apnsPass, APNS_PRODUCTION). gcmAuth(GOOGLE_PUSH_AUTH_KEY).sendAsync(); } } catch(IOException err) { Log.e(err); } } onMessage
  • 24. public final Property<String, User> pushToken = new Property<>("pushToken"); private final PropertyIndex idx = new PropertyIndex(this, "User", id, givenName, surname, phone, email, facebookId, googleId, driver, car, currentRating, latitude, longitude, direction, authToken, password, pushToken); User
  • 25. public static void hailRide(String from, String to, CarAdded callback) { instance.driverFound = callback; instance.from = from; instance.to = to; instance.notificationList = new ArrayList<>(); instance.halingRadius = Motion.createLinearMotion(500, 2000, 30000); instance.halingRadius.start(); instance.hailing = HAILING_ON; instance.server.sendLocationUpdate(); } hailRide