SlideShare a Scribd company logo
Creating an Uber Clone - Part XXX
User/Driver Flow
✦User: Confirm Hailing - Server Responds
✦User: Sends push messages
✦Driver: Shown push, if he clicks he’s shown ride details
✦Driver: Accepts route, notifies server
✦User: Receives WebSocket message of acceptance
✦Driver: Shown Dialog to indicate pickup
✦Driver: Shown dialog to finish the ride. Location
updates set the route of the ride
© Codename One 2017 all rights reserved
public void showRide(long userId) {
InteractionDialog id = new InteractionDialog(new BorderLayout());
id.setTitle("Loading Ride Details");
id.add(CENTER, new InfiniteProgress());
id.show(getHeight() - id.getPreferredH(), 0, 0, 0);
DriverService.fetchRideDetails(userId, ride -> {
id.setTitle("Building Ride Path");
final Coord[] locations = new Coord[2];
if(ride.from.get() == null) {
id.dispose();
ToastBar.showErrorMessage("Ride no longer available...");
return;
}
SearchService.findLocation(ride.from.get(), fromLocation -> {
locations[0] = fromLocation;
onShowRideResponse(id, ride, locations);
});
SearchService.findLocation(ride.destination.get(), toLocation -> {
locations[1] = toLocation;
onShowRideResponse(id, ride, locations);
});
});
}
showRide
public void showRide(long userId) {
InteractionDialog id = new InteractionDialog(new BorderLayout());
id.setTitle("Loading Ride Details");
id.add(CENTER, new InfiniteProgress());
id.show(getHeight() - id.getPreferredH(), 0, 0, 0);
DriverService.fetchRideDetails(userId, ride -> {
id.setTitle("Building Ride Path");
final Coord[] locations = new Coord[2];
if(ride.from.get() == null) {
id.dispose();
ToastBar.showErrorMessage("Ride no longer available...");
return;
}
SearchService.findLocation(ride.from.get(), fromLocation -> {
locations[0] = fromLocation;
onShowRideResponse(id, ride, locations);
});
SearchService.findLocation(ride.destination.get(), toLocation -> {
locations[1] = toLocation;
onShowRideResponse(id, ride, locations);
});
});
}
showRide
public void showRide(long userId) {
InteractionDialog id = new InteractionDialog(new BorderLayout());
id.setTitle("Loading Ride Details");
id.add(CENTER, new InfiniteProgress());
id.show(getHeight() - id.getPreferredH(), 0, 0, 0);
DriverService.fetchRideDetails(userId, ride -> {
id.setTitle("Building Ride Path");
final Coord[] locations = new Coord[2];
if(ride.from.get() == null) {
id.dispose();
ToastBar.showErrorMessage("Ride no longer available...");
return;
}
SearchService.findLocation(ride.from.get(), fromLocation -> {
locations[0] = fromLocation;
onShowRideResponse(id, ride, locations);
});
SearchService.findLocation(ride.destination.get(), toLocation -> {
locations[1] = toLocation;
onShowRideResponse(id, ride, locations);
});
});
}
showRide
void onShowRideResponse(InteractionDialog dlg, Ride ride,
Coord[] locations) {
if(locations[0] == null || locations[1] == null) {
return;
}
SearchService.directions(toLocation(locations[0]), toLocation(locations[1]),
(path, duration, distance) -> {
dlg.dispose();
String from = ride.from.get();
String to = ride.destination.get();
Component fromComponent = createNavigationTag(
trimmedString(from), duration / 60);
Component toComponent = createNavigationTag(trimmedString(to), -1);
MapContainer.MapObject pathObject = addPath(path,
fromComponent, toComponent, duration);
InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y());
id.add(new Label(ride.name.get(), "RideTitle"));
Button acceptButton = new Button("Accept", "BlackButton");
Button cancelButton = new Button("Cancel", "BlackButton");
id.setAnimateShow(false);
id.add(acceptButton);
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
onShowRideResponse
void onShowRideResponse(InteractionDialog dlg, Ride ride,
Coord[] locations) {
if(locations[0] == null || locations[1] == null) {
return;
}
SearchService.directions(toLocation(locations[0]), toLocation(locations[1]),
(path, duration, distance) -> {
dlg.dispose();
String from = ride.from.get();
String to = ride.destination.get();
Component fromComponent = createNavigationTag(
trimmedString(from), duration / 60);
Component toComponent = createNavigationTag(trimmedString(to), -1);
MapContainer.MapObject pathObject = addPath(path,
fromComponent, toComponent, duration);
InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y());
id.add(new Label(ride.name.get(), "RideTitle"));
Button acceptButton = new Button("Accept", "BlackButton");
Button cancelButton = new Button("Cancel", "BlackButton");
id.setAnimateShow(false);
id.add(acceptButton);
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
onShowRideResponse
void onShowRideResponse(InteractionDialog dlg, Ride ride,
Coord[] locations) {
if(locations[0] == null || locations[1] == null) {
return;
}
SearchService.directions(toLocation(locations[0]), toLocation(locations[1]),
(path, duration, distance) -> {
dlg.dispose();
String from = ride.from.get();
String to = ride.destination.get();
Component fromComponent = createNavigationTag(
trimmedString(from), duration / 60);
Component toComponent = createNavigationTag(trimmedString(to), -1);
MapContainer.MapObject pathObject = addPath(path,
fromComponent, toComponent, duration);
InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y());
id.add(new Label(ride.name.get(), "RideTitle"));
Button acceptButton = new Button("Accept", "BlackButton");
Button cancelButton = new Button("Cancel", "BlackButton");
id.setAnimateShow(false);
id.add(acceptButton);
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
onShowRideResponse
void onShowRideResponse(InteractionDialog dlg, Ride ride,
Coord[] locations) {
if(locations[0] == null || locations[1] == null) {
return;
}
SearchService.directions(toLocation(locations[0]), toLocation(locations[1]),
(path, duration, distance) -> {
dlg.dispose();
String from = ride.from.get();
String to = ride.destination.get();
Component fromComponent = createNavigationTag(
trimmedString(from), duration / 60);
Component toComponent = createNavigationTag(trimmedString(to), -1);
MapContainer.MapObject pathObject = addPath(path,
fromComponent, toComponent, duration);
InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y());
id.add(new Label(ride.name.get(), "RideTitle"));
Button acceptButton = new Button("Accept", "BlackButton");
Button cancelButton = new Button("Cancel", "BlackButton");
id.setAnimateShow(false);
id.add(acceptButton);
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
onShowRideResponse
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
id.dispose();
});
acceptButton.addActionListener(e -> {
boolean accept = DriverService.acceptRide(ride.userId.getLong());
callSerially(() -> {
if(accept) {
id.dispose();
pickUpPassenger(pathObject, ride, fromComponent,
toComponent);
} else {
id.dispose();
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
getAnimationManager().flushAnimation(() ->
ToastBar.showErrorMessage("Failed to grab ride"));
}
});
});
id.show(getHeight() - id.getPreferredH(), 0, 0, 0);
onShowRideResponse
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
id.dispose();
});
acceptButton.addActionListener(e -> {
boolean accept = DriverService.acceptRide(ride.userId.getLong());
callSerially(() -> {
if(accept) {
id.dispose();
pickUpPassenger(pathObject, ride, fromComponent,
toComponent);
} else {
id.dispose();
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
getAnimationManager().flushAnimation(() ->
ToastBar.showErrorMessage("Failed to grab ride"));
}
});
});
id.show(getHeight() - id.getPreferredH(), 0, 0, 0);
onShowRideResponse
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
id.dispose();
});
acceptButton.addActionListener(e -> {
boolean accept = DriverService.acceptRide(ride.userId.getLong());
callSerially(() -> {
if(accept) {
id.dispose();
pickUpPassenger(pathObject, ride, fromComponent,
toComponent);
} else {
id.dispose();
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
getAnimationManager().flushAnimation(() ->
ToastBar.showErrorMessage("Failed to grab ride"));
}
});
});
id.show(getHeight() - id.getPreferredH(), 0, 0, 0);
onShowRideResponse
id.add(cancelButton);
cancelButton.addActionListener(e -> {
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
id.dispose();
});
acceptButton.addActionListener(e -> {
boolean accept = DriverService.acceptRide(ride.userId.getLong());
callSerially(() -> {
if(accept) {
id.dispose();
pickUpPassenger(pathObject, ride, fromComponent,
toComponent);
} else {
id.dispose();
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
getAnimationManager().flushAnimation(() ->
ToastBar.showErrorMessage("Failed to grab ride"));
}
});
});
id.show(getHeight() - id.getPreferredH(), 0, 0, 0);
onShowRideResponse
private Location toLocation(Coord crd) {
return new Location(crd.getLatitude(), crd.getLongitude());
}
toLocation
public void pickUpPassenger(MapContainer.MapObject pathObject,
Ride ride,
Component fromComponent, Component toComponent) {
InteractionDialog id = new InteractionDialog("Pick Up", BoxLayout.y());
id.add(new Label(ride.name.get(), "RideTitle"));
Button acceptButton = new Button("Picked Up", "BlackButton");
Button cancelButton = new Button("Cancel", "BlackButton");
id.add(acceptButton);
id.add(cancelButton);
acceptButton.addActionListener(e -> {
DriverService.startRide();
id.dispose();
InteractionDialog dlg = new InteractionDialog("Driving...", BoxLayout.y());
dlg.add(new Label(ride.name.get(), "RideTitle"));
Button finishButton = new Button("Finished Ride", "BlackButton");
dlg.add(finishButton);
finishButton.addActionListener(ee -> {
DriverService.finishRide();
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
dlg.dispose();
});
dlg.show(getHeight() - dlg.getPreferredH(), 0, 0, 0);
});
cancelButton.addActionListener(e -> {
fromComponent.remove();
pickUpPassenger
public void pickUpPassenger(MapContainer.MapObject pathObject,
Ride ride,
Component fromComponent, Component toComponent) {
InteractionDialog id = new InteractionDialog("Pick Up", BoxLayout.y());
id.add(new Label(ride.name.get(), "RideTitle"));
Button acceptButton = new Button("Picked Up", "BlackButton");
Button cancelButton = new Button("Cancel", "BlackButton");
id.add(acceptButton);
id.add(cancelButton);
acceptButton.addActionListener(e -> {
DriverService.startRide();
id.dispose();
InteractionDialog dlg = new InteractionDialog("Driving...", BoxLayout.y());
dlg.add(new Label(ride.name.get(), "RideTitle"));
Button finishButton = new Button("Finished Ride", "BlackButton");
dlg.add(finishButton);
finishButton.addActionListener(ee -> {
DriverService.finishRide();
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
dlg.dispose();
});
dlg.show(getHeight() - dlg.getPreferredH(), 0, 0, 0);
});
cancelButton.addActionListener(e -> {
fromComponent.remove();
pickUpPassenger
public void pickUpPassenger(MapContainer.MapObject pathObject,
Ride ride,
Component fromComponent, Component toComponent) {
InteractionDialog id = new InteractionDialog("Pick Up", BoxLayout.y());
id.add(new Label(ride.name.get(), "RideTitle"));
Button acceptButton = new Button("Picked Up", "BlackButton");
Button cancelButton = new Button("Cancel", "BlackButton");
id.add(acceptButton);
id.add(cancelButton);
acceptButton.addActionListener(e -> {
DriverService.startRide();
id.dispose();
InteractionDialog dlg = new InteractionDialog("Driving...", BoxLayout.y());
dlg.add(new Label(ride.name.get(), "RideTitle"));
Button finishButton = new Button("Finished Ride", "BlackButton");
dlg.add(finishButton);
finishButton.addActionListener(ee -> {
DriverService.finishRide();
fromComponent.remove();
toComponent.remove();
mc.removeMapObject(pathObject);
dlg.dispose();
});
dlg.show(getHeight() - dlg.getPreferredH(), 0, 0, 0);
});
cancelButton.addActionListener(e -> {
fromComponent.remove();
pickUpPassenger
private MapContainer.MapObject addPath(List<Coord> path,
Component fromComponent, Component toComponent, int duration) {
Coord[] pathCoords = new Coord[path.size()];
path.toArray(pathCoords);
MapContainer.MapObject pathObject = mc.addPath(pathCoords);
BoundingBox bb = BoundingBox.create(pathCoords).
extend(new BoundingBox(pathCoords[0], 0.01, 0.01)).
extend(new BoundingBox(pathCoords[pathCoords.length-1], 0.01, 0.01));
mc.fitBounds(bb);
MapLayout.setHorizontalAlignment(fromComponent,
MapLayout.HALIGN.RIGHT);
mapLayer.add(pathCoords[0], fromComponent);
mapLayer.add(pathCoords[pathCoords.length - 1], toComponent);
return pathObject;
}
addPath
private void hailRideImpl(User car, final Container pinLayer) {
pinLayer.getUnselectedStyle().setBgTransparency(0);
pinLayer.removeAll();
String driverName = car.givenName.get();
String carBrand = car.car.get();
SpanLabel driver = new SpanLabel("Driver found " + driverName + "n" + carBrand);
Container stars = new Container(new FlowLayout(CENTER));
for(int iter = 0 ; iter < 5 ; iter++) {
if(iter + 1 >= car.currentRating.getFloat()) {
Label fullStar = new Label("", "Star");
FontImage.setMaterialIcon(fullStar, FontImage.MATERIAL_STAR);
stars.add(fullStar);
} else {
if(iter + 1 >= Math.round(car.currentRating.getFloat())) {
Label halfStar = new Label("", "Star");
FontImage.setMaterialIcon(halfStar, FontImage.MATERIAL_STAR_HALF);
stars.add(halfStar);
} else {
break;
}
}
}
Button ok = new Button("OK", "BlackButton");
Container dialog = BoxLayout.encloseY(driver, stars, ok);
dialog.setUIID("SearchingDialog");
pinLayer.add(SOUTH, dialog);
revalidate();
hailRideImpl
private void hailRideImpl(User car, final Container pinLayer) {
pinLayer.getUnselectedStyle().setBgTransparency(0);
pinLayer.removeAll();
String driverName = car.givenName.get();
String carBrand = car.car.get();
SpanLabel driver = new SpanLabel("Driver found " + driverName + "n" + carBrand);
Container stars = new Container(new FlowLayout(CENTER));
for(int iter = 0 ; iter < 5 ; iter++) {
if(iter + 1 >= car.currentRating.getFloat()) {
Label fullStar = new Label("", "Star");
FontImage.setMaterialIcon(fullStar, FontImage.MATERIAL_STAR);
stars.add(fullStar);
} else {
if(iter + 1 >= Math.round(car.currentRating.getFloat())) {
Label halfStar = new Label("", "Star");
FontImage.setMaterialIcon(halfStar, FontImage.MATERIAL_STAR_HALF);
stars.add(halfStar);
} else {
break;
}
}
}
Button ok = new Button("OK", "BlackButton");
Container dialog = BoxLayout.encloseY(driver, stars, ok);
dialog.setUIID("SearchingDialog");
pinLayer.add(SOUTH, dialog);
revalidate();
hailRideImpl
private void hailRideImpl(User car, final Container pinLayer) {
pinLayer.getUnselectedStyle().setBgTransparency(0);
pinLayer.removeAll();
String driverName = car.givenName.get();
String carBrand = car.car.get();
SpanLabel driver = new SpanLabel("Driver found " + driverName + "n" + carBrand);
Container stars = new Container(new FlowLayout(CENTER));
for(int iter = 0 ; iter < 5 ; iter++) {
if(iter + 1 >= car.currentRating.getFloat()) {
Label fullStar = new Label("", "Star");
FontImage.setMaterialIcon(fullStar, FontImage.MATERIAL_STAR);
stars.add(fullStar);
} else {
if(iter + 1 >= Math.round(car.currentRating.getFloat())) {
Label halfStar = new Label("", "Star");
FontImage.setMaterialIcon(halfStar, FontImage.MATERIAL_STAR_HALF);
stars.add(halfStar);
} else {
break;
}
}
}
Button ok = new Button("OK", "BlackButton");
Container dialog = BoxLayout.encloseY(driver, stars, ok);
dialog.setUIID("SearchingDialog");
pinLayer.add(SOUTH, dialog);
revalidate();
hailRideImpl
Star
© Codename One 2017 all rights reserved
Star
© Codename One 2017 all rights reserved
Star
© Codename One 2017 all rights reserved
Star
© Codename One 2017 all rights reserved

More Related Content

PDF
Creating an Uber Clone - Part XXX - Transcript.pdf
PDF
Creating an Uber Clone - Part XXIX.pdf
PDF
Creating an Uber Clone - Part XXVII - Transcript.pdf
PDF
Creating an Uber Clone - Part XXIX - Transcript.pdf
PDF
Creating an Uber Clone - Part XXVI.pdf
PDF
Google Maps API - DevFest Karlsruhe
PDF
Creating an Uber Clone - Part XXIII.pdf
PDF
Creating an Uber Clone - Part XXIII - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXIX.pdf
Creating an Uber Clone - Part XXVII - Transcript.pdf
Creating an Uber Clone - Part XXIX - Transcript.pdf
Creating an Uber Clone - Part XXVI.pdf
Google Maps API - DevFest Karlsruhe
Creating an Uber Clone - Part XXIII.pdf
Creating an Uber Clone - Part XXIII - Transcript.pdf

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

PDF
Creating an Uber Clone - Part XVII.pdf
PDF
Creating an Uber Clone - Part XXVI - Transcript.pdf
PDF
Creating an Uber Clone - Part XXIV.pdf
PDF
Creating an Uber Clone - Part XVI.pdf
PDF
Creating an Uber Clone - Part XVIII - Transcript.pdf
PDF
Creating an Uber Clone - Part XXIV - Transcript.pdf
PDF
Creating an Uber Clone - Part XVII - Transcript.pdf
PDF
You will learn RxJS in 2017
PPTX
Django GeoTracker
PDF
Geolocation on Rails
PDF
Creating an Uber Clone - Part XV.pdf
PDF
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
PDF
Migrating from Flux to Redux. Why and how.
KEY
How Quick Can We Be? Data Visualization Techniques for Engineers.
PDF
Creating an Uber Clone - Part XXI.pdf
PDF
Background Life with Android O and beyond - Yonatan Levin, KolGene
PDF
Please finish the codes in Graph.h class.#################### Vert.pdf
PDF
Creating an Uber Clone - Part XX - Transcript.pdf
PDF
Creating an Uber Clone - Part XXXI.pdf
PDF
Google Maps Api
Creating an Uber Clone - Part XVII.pdf
Creating an Uber Clone - Part XXVI - Transcript.pdf
Creating an Uber Clone - Part XXIV.pdf
Creating an Uber Clone - Part XVI.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XVII - Transcript.pdf
You will learn RxJS in 2017
Django GeoTracker
Geolocation on Rails
Creating an Uber Clone - Part XV.pdf
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
Migrating from Flux to Redux. Why and how.
How Quick Can We Be? Data Visualization Techniques for Engineers.
Creating an Uber Clone - Part XXI.pdf
Background Life with Android O and beyond - Yonatan Levin, KolGene
Please finish the codes in Graph.h class.#################### Vert.pdf
Creating an Uber Clone - Part XX - Transcript.pdf
Creating an Uber Clone - Part XXXI.pdf
Google Maps Api
Ad

More from ShaiAlmog1 (20)

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

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
KodekX | Application Modernization Development
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
The AUB Centre for AI in Media Proposal.docx
MIND Revenue Release Quarter 2 2025 Press Release
KodekX | Application Modernization Development
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
Advanced methodologies resolving dimensionality complications for autism neur...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Programs and apps: productivity, graphics, security and other tools
Cloud computing and distributed systems.

Creating an Uber Clone - Part XXX.pdf

  • 1. Creating an Uber Clone - Part XXX
  • 2. User/Driver Flow ✦User: Confirm Hailing - Server Responds ✦User: Sends push messages ✦Driver: Shown push, if he clicks he’s shown ride details ✦Driver: Accepts route, notifies server ✦User: Receives WebSocket message of acceptance ✦Driver: Shown Dialog to indicate pickup ✦Driver: Shown dialog to finish the ride. Location updates set the route of the ride © Codename One 2017 all rights reserved
  • 3. public void showRide(long userId) { InteractionDialog id = new InteractionDialog(new BorderLayout()); id.setTitle("Loading Ride Details"); id.add(CENTER, new InfiniteProgress()); id.show(getHeight() - id.getPreferredH(), 0, 0, 0); DriverService.fetchRideDetails(userId, ride -> { id.setTitle("Building Ride Path"); final Coord[] locations = new Coord[2]; if(ride.from.get() == null) { id.dispose(); ToastBar.showErrorMessage("Ride no longer available..."); return; } SearchService.findLocation(ride.from.get(), fromLocation -> { locations[0] = fromLocation; onShowRideResponse(id, ride, locations); }); SearchService.findLocation(ride.destination.get(), toLocation -> { locations[1] = toLocation; onShowRideResponse(id, ride, locations); }); }); } showRide
  • 4. public void showRide(long userId) { InteractionDialog id = new InteractionDialog(new BorderLayout()); id.setTitle("Loading Ride Details"); id.add(CENTER, new InfiniteProgress()); id.show(getHeight() - id.getPreferredH(), 0, 0, 0); DriverService.fetchRideDetails(userId, ride -> { id.setTitle("Building Ride Path"); final Coord[] locations = new Coord[2]; if(ride.from.get() == null) { id.dispose(); ToastBar.showErrorMessage("Ride no longer available..."); return; } SearchService.findLocation(ride.from.get(), fromLocation -> { locations[0] = fromLocation; onShowRideResponse(id, ride, locations); }); SearchService.findLocation(ride.destination.get(), toLocation -> { locations[1] = toLocation; onShowRideResponse(id, ride, locations); }); }); } showRide
  • 5. public void showRide(long userId) { InteractionDialog id = new InteractionDialog(new BorderLayout()); id.setTitle("Loading Ride Details"); id.add(CENTER, new InfiniteProgress()); id.show(getHeight() - id.getPreferredH(), 0, 0, 0); DriverService.fetchRideDetails(userId, ride -> { id.setTitle("Building Ride Path"); final Coord[] locations = new Coord[2]; if(ride.from.get() == null) { id.dispose(); ToastBar.showErrorMessage("Ride no longer available..."); return; } SearchService.findLocation(ride.from.get(), fromLocation -> { locations[0] = fromLocation; onShowRideResponse(id, ride, locations); }); SearchService.findLocation(ride.destination.get(), toLocation -> { locations[1] = toLocation; onShowRideResponse(id, ride, locations); }); }); } showRide
  • 6. void onShowRideResponse(InteractionDialog dlg, Ride ride, Coord[] locations) { if(locations[0] == null || locations[1] == null) { return; } SearchService.directions(toLocation(locations[0]), toLocation(locations[1]), (path, duration, distance) -> { dlg.dispose(); String from = ride.from.get(); String to = ride.destination.get(); Component fromComponent = createNavigationTag( trimmedString(from), duration / 60); Component toComponent = createNavigationTag(trimmedString(to), -1); MapContainer.MapObject pathObject = addPath(path, fromComponent, toComponent, duration); InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y()); id.add(new Label(ride.name.get(), "RideTitle")); Button acceptButton = new Button("Accept", "BlackButton"); Button cancelButton = new Button("Cancel", "BlackButton"); id.setAnimateShow(false); id.add(acceptButton); id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); onShowRideResponse
  • 7. void onShowRideResponse(InteractionDialog dlg, Ride ride, Coord[] locations) { if(locations[0] == null || locations[1] == null) { return; } SearchService.directions(toLocation(locations[0]), toLocation(locations[1]), (path, duration, distance) -> { dlg.dispose(); String from = ride.from.get(); String to = ride.destination.get(); Component fromComponent = createNavigationTag( trimmedString(from), duration / 60); Component toComponent = createNavigationTag(trimmedString(to), -1); MapContainer.MapObject pathObject = addPath(path, fromComponent, toComponent, duration); InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y()); id.add(new Label(ride.name.get(), "RideTitle")); Button acceptButton = new Button("Accept", "BlackButton"); Button cancelButton = new Button("Cancel", "BlackButton"); id.setAnimateShow(false); id.add(acceptButton); id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); onShowRideResponse
  • 8. void onShowRideResponse(InteractionDialog dlg, Ride ride, Coord[] locations) { if(locations[0] == null || locations[1] == null) { return; } SearchService.directions(toLocation(locations[0]), toLocation(locations[1]), (path, duration, distance) -> { dlg.dispose(); String from = ride.from.get(); String to = ride.destination.get(); Component fromComponent = createNavigationTag( trimmedString(from), duration / 60); Component toComponent = createNavigationTag(trimmedString(to), -1); MapContainer.MapObject pathObject = addPath(path, fromComponent, toComponent, duration); InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y()); id.add(new Label(ride.name.get(), "RideTitle")); Button acceptButton = new Button("Accept", "BlackButton"); Button cancelButton = new Button("Cancel", "BlackButton"); id.setAnimateShow(false); id.add(acceptButton); id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); onShowRideResponse
  • 9. void onShowRideResponse(InteractionDialog dlg, Ride ride, Coord[] locations) { if(locations[0] == null || locations[1] == null) { return; } SearchService.directions(toLocation(locations[0]), toLocation(locations[1]), (path, duration, distance) -> { dlg.dispose(); String from = ride.from.get(); String to = ride.destination.get(); Component fromComponent = createNavigationTag( trimmedString(from), duration / 60); Component toComponent = createNavigationTag(trimmedString(to), -1); MapContainer.MapObject pathObject = addPath(path, fromComponent, toComponent, duration); InteractionDialog id = new InteractionDialog("Ride", BoxLayout.y()); id.add(new Label(ride.name.get(), "RideTitle")); Button acceptButton = new Button("Accept", "BlackButton"); Button cancelButton = new Button("Cancel", "BlackButton"); id.setAnimateShow(false); id.add(acceptButton); id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); onShowRideResponse
  • 10. id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); id.dispose(); }); acceptButton.addActionListener(e -> { boolean accept = DriverService.acceptRide(ride.userId.getLong()); callSerially(() -> { if(accept) { id.dispose(); pickUpPassenger(pathObject, ride, fromComponent, toComponent); } else { id.dispose(); fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); getAnimationManager().flushAnimation(() -> ToastBar.showErrorMessage("Failed to grab ride")); } }); }); id.show(getHeight() - id.getPreferredH(), 0, 0, 0); onShowRideResponse
  • 11. id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); id.dispose(); }); acceptButton.addActionListener(e -> { boolean accept = DriverService.acceptRide(ride.userId.getLong()); callSerially(() -> { if(accept) { id.dispose(); pickUpPassenger(pathObject, ride, fromComponent, toComponent); } else { id.dispose(); fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); getAnimationManager().flushAnimation(() -> ToastBar.showErrorMessage("Failed to grab ride")); } }); }); id.show(getHeight() - id.getPreferredH(), 0, 0, 0); onShowRideResponse
  • 12. id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); id.dispose(); }); acceptButton.addActionListener(e -> { boolean accept = DriverService.acceptRide(ride.userId.getLong()); callSerially(() -> { if(accept) { id.dispose(); pickUpPassenger(pathObject, ride, fromComponent, toComponent); } else { id.dispose(); fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); getAnimationManager().flushAnimation(() -> ToastBar.showErrorMessage("Failed to grab ride")); } }); }); id.show(getHeight() - id.getPreferredH(), 0, 0, 0); onShowRideResponse
  • 13. id.add(cancelButton); cancelButton.addActionListener(e -> { fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); id.dispose(); }); acceptButton.addActionListener(e -> { boolean accept = DriverService.acceptRide(ride.userId.getLong()); callSerially(() -> { if(accept) { id.dispose(); pickUpPassenger(pathObject, ride, fromComponent, toComponent); } else { id.dispose(); fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); getAnimationManager().flushAnimation(() -> ToastBar.showErrorMessage("Failed to grab ride")); } }); }); id.show(getHeight() - id.getPreferredH(), 0, 0, 0); onShowRideResponse
  • 14. private Location toLocation(Coord crd) { return new Location(crd.getLatitude(), crd.getLongitude()); } toLocation
  • 15. public void pickUpPassenger(MapContainer.MapObject pathObject, Ride ride, Component fromComponent, Component toComponent) { InteractionDialog id = new InteractionDialog("Pick Up", BoxLayout.y()); id.add(new Label(ride.name.get(), "RideTitle")); Button acceptButton = new Button("Picked Up", "BlackButton"); Button cancelButton = new Button("Cancel", "BlackButton"); id.add(acceptButton); id.add(cancelButton); acceptButton.addActionListener(e -> { DriverService.startRide(); id.dispose(); InteractionDialog dlg = new InteractionDialog("Driving...", BoxLayout.y()); dlg.add(new Label(ride.name.get(), "RideTitle")); Button finishButton = new Button("Finished Ride", "BlackButton"); dlg.add(finishButton); finishButton.addActionListener(ee -> { DriverService.finishRide(); fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); dlg.dispose(); }); dlg.show(getHeight() - dlg.getPreferredH(), 0, 0, 0); }); cancelButton.addActionListener(e -> { fromComponent.remove(); pickUpPassenger
  • 16. public void pickUpPassenger(MapContainer.MapObject pathObject, Ride ride, Component fromComponent, Component toComponent) { InteractionDialog id = new InteractionDialog("Pick Up", BoxLayout.y()); id.add(new Label(ride.name.get(), "RideTitle")); Button acceptButton = new Button("Picked Up", "BlackButton"); Button cancelButton = new Button("Cancel", "BlackButton"); id.add(acceptButton); id.add(cancelButton); acceptButton.addActionListener(e -> { DriverService.startRide(); id.dispose(); InteractionDialog dlg = new InteractionDialog("Driving...", BoxLayout.y()); dlg.add(new Label(ride.name.get(), "RideTitle")); Button finishButton = new Button("Finished Ride", "BlackButton"); dlg.add(finishButton); finishButton.addActionListener(ee -> { DriverService.finishRide(); fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); dlg.dispose(); }); dlg.show(getHeight() - dlg.getPreferredH(), 0, 0, 0); }); cancelButton.addActionListener(e -> { fromComponent.remove(); pickUpPassenger
  • 17. public void pickUpPassenger(MapContainer.MapObject pathObject, Ride ride, Component fromComponent, Component toComponent) { InteractionDialog id = new InteractionDialog("Pick Up", BoxLayout.y()); id.add(new Label(ride.name.get(), "RideTitle")); Button acceptButton = new Button("Picked Up", "BlackButton"); Button cancelButton = new Button("Cancel", "BlackButton"); id.add(acceptButton); id.add(cancelButton); acceptButton.addActionListener(e -> { DriverService.startRide(); id.dispose(); InteractionDialog dlg = new InteractionDialog("Driving...", BoxLayout.y()); dlg.add(new Label(ride.name.get(), "RideTitle")); Button finishButton = new Button("Finished Ride", "BlackButton"); dlg.add(finishButton); finishButton.addActionListener(ee -> { DriverService.finishRide(); fromComponent.remove(); toComponent.remove(); mc.removeMapObject(pathObject); dlg.dispose(); }); dlg.show(getHeight() - dlg.getPreferredH(), 0, 0, 0); }); cancelButton.addActionListener(e -> { fromComponent.remove(); pickUpPassenger
  • 18. private MapContainer.MapObject addPath(List<Coord> path, Component fromComponent, Component toComponent, int duration) { Coord[] pathCoords = new Coord[path.size()]; path.toArray(pathCoords); MapContainer.MapObject pathObject = mc.addPath(pathCoords); BoundingBox bb = BoundingBox.create(pathCoords). extend(new BoundingBox(pathCoords[0], 0.01, 0.01)). extend(new BoundingBox(pathCoords[pathCoords.length-1], 0.01, 0.01)); mc.fitBounds(bb); MapLayout.setHorizontalAlignment(fromComponent, MapLayout.HALIGN.RIGHT); mapLayer.add(pathCoords[0], fromComponent); mapLayer.add(pathCoords[pathCoords.length - 1], toComponent); return pathObject; } addPath
  • 19. private void hailRideImpl(User car, final Container pinLayer) { pinLayer.getUnselectedStyle().setBgTransparency(0); pinLayer.removeAll(); String driverName = car.givenName.get(); String carBrand = car.car.get(); SpanLabel driver = new SpanLabel("Driver found " + driverName + "n" + carBrand); Container stars = new Container(new FlowLayout(CENTER)); for(int iter = 0 ; iter < 5 ; iter++) { if(iter + 1 >= car.currentRating.getFloat()) { Label fullStar = new Label("", "Star"); FontImage.setMaterialIcon(fullStar, FontImage.MATERIAL_STAR); stars.add(fullStar); } else { if(iter + 1 >= Math.round(car.currentRating.getFloat())) { Label halfStar = new Label("", "Star"); FontImage.setMaterialIcon(halfStar, FontImage.MATERIAL_STAR_HALF); stars.add(halfStar); } else { break; } } } Button ok = new Button("OK", "BlackButton"); Container dialog = BoxLayout.encloseY(driver, stars, ok); dialog.setUIID("SearchingDialog"); pinLayer.add(SOUTH, dialog); revalidate(); hailRideImpl
  • 20. private void hailRideImpl(User car, final Container pinLayer) { pinLayer.getUnselectedStyle().setBgTransparency(0); pinLayer.removeAll(); String driverName = car.givenName.get(); String carBrand = car.car.get(); SpanLabel driver = new SpanLabel("Driver found " + driverName + "n" + carBrand); Container stars = new Container(new FlowLayout(CENTER)); for(int iter = 0 ; iter < 5 ; iter++) { if(iter + 1 >= car.currentRating.getFloat()) { Label fullStar = new Label("", "Star"); FontImage.setMaterialIcon(fullStar, FontImage.MATERIAL_STAR); stars.add(fullStar); } else { if(iter + 1 >= Math.round(car.currentRating.getFloat())) { Label halfStar = new Label("", "Star"); FontImage.setMaterialIcon(halfStar, FontImage.MATERIAL_STAR_HALF); stars.add(halfStar); } else { break; } } } Button ok = new Button("OK", "BlackButton"); Container dialog = BoxLayout.encloseY(driver, stars, ok); dialog.setUIID("SearchingDialog"); pinLayer.add(SOUTH, dialog); revalidate(); hailRideImpl
  • 21. private void hailRideImpl(User car, final Container pinLayer) { pinLayer.getUnselectedStyle().setBgTransparency(0); pinLayer.removeAll(); String driverName = car.givenName.get(); String carBrand = car.car.get(); SpanLabel driver = new SpanLabel("Driver found " + driverName + "n" + carBrand); Container stars = new Container(new FlowLayout(CENTER)); for(int iter = 0 ; iter < 5 ; iter++) { if(iter + 1 >= car.currentRating.getFloat()) { Label fullStar = new Label("", "Star"); FontImage.setMaterialIcon(fullStar, FontImage.MATERIAL_STAR); stars.add(fullStar); } else { if(iter + 1 >= Math.round(car.currentRating.getFloat())) { Label halfStar = new Label("", "Star"); FontImage.setMaterialIcon(halfStar, FontImage.MATERIAL_STAR_HALF); stars.add(halfStar); } else { break; } } } Button ok = new Button("OK", "BlackButton"); Container dialog = BoxLayout.encloseY(driver, stars, ok); dialog.setUIID("SearchingDialog"); pinLayer.add(SOUTH, dialog); revalidate(); hailRideImpl
  • 22. Star © Codename One 2017 all rights reserved
  • 23. Star © Codename One 2017 all rights reserved
  • 24. Star © Codename One 2017 all rights reserved
  • 25. Star © Codename One 2017 all rights reserved