SlideShare a Scribd company logo
1 of 14
Download to read offline
Creating an Uber Clone - Part XX
We’ll continue the search UI implementation as we step into the CompletionContainer class
public class CompletionContainer {
private Container result;
private boolean completionUsed;
private final EventDispatcher dispatcher = new EventDispatcher();
void updateCompletion(String text, AutoCompleteAddressInput dest) {
SearchService.suggestLocations(text,
LocationService.getCurrentLocation(), resultList -> {
if(resultList != null && resultList.size() > 0) {
result.removeAll();
completionUsed = true;
for(SearchService.SuggestionResult r : resultList) {
MultiButton mb = createEntry(FontImage.MATERIAL_PLACE,
r.getMainText(), r.getSecondaryText());
result.add(mb);
mb.addActionListener(e -> {
dest.setTextNoEvent(r.getFullText());
r.getLocation(l -> {
dest.setCurrentLocation(l);
dispatcher.fireActionEvent(e);
});
});
}
CompletionContainer
The CompletionContainer tries to coordinate the two instances of the AutoCompleteAddressInput class by providing a single class that handles the completion UI. Most
of the code in this class should be very familiar as some of it is refactored code from the MapForm while other code relates to the suggestLocations API we implemented
earlier... 

The name of the class is misleading. CompletionContainer is not a Container. Here instead of deriving I encapsulated the UI logic and tried to expose only the business
logic
public class CompletionContainer {
private Container result;
private boolean completionUsed;
private final EventDispatcher dispatcher = new EventDispatcher();
void updateCompletion(String text, AutoCompleteAddressInput dest) {
SearchService.suggestLocations(text,
LocationService.getCurrentLocation(), resultList -> {
if(resultList != null && resultList.size() > 0) {
result.removeAll();
completionUsed = true;
for(SearchService.SuggestionResult r : resultList) {
MultiButton mb = createEntry(FontImage.MATERIAL_PLACE,
r.getMainText(), r.getSecondaryText());
result.add(mb);
mb.addActionListener(e -> {
dest.setTextNoEvent(r.getFullText());
r.getLocation(l -> {
dest.setCurrentLocation(l);
dispatcher.fireActionEvent(e);
});
});
}
CompletionContainer
Event dispatchers allow us to broadcast events using the add/removeListener observer style API. We use this dispatcher to broadcast an event when a user presses a
completion button
public class CompletionContainer {
private Container result;
private boolean completionUsed;
private final EventDispatcher dispatcher = new EventDispatcher();
void updateCompletion(String text, AutoCompleteAddressInput dest) {
SearchService.suggestLocations(text,
LocationService.getCurrentLocation(), resultList -> {
if(resultList != null && resultList.size() > 0) {
result.removeAll();
completionUsed = true;
for(SearchService.SuggestionResult r : resultList) {
MultiButton mb = createEntry(FontImage.MATERIAL_PLACE,
r.getMainText(), r.getSecondaryText());
result.add(mb);
mb.addActionListener(e -> {
dest.setTextNoEvent(r.getFullText());
r.getLocation(l -> {
dest.setCurrentLocation(l);
dispatcher.fireActionEvent(e);
});
});
}
CompletionContainer
This method is invoked when completion is in progress it invokes the WebService call to request completion suggestions for the given string
public class CompletionContainer {
private Container result;
private boolean completionUsed;
private final EventDispatcher dispatcher = new EventDispatcher();
void updateCompletion(String text, AutoCompleteAddressInput dest) {
SearchService.suggestLocations(text,
LocationService.getCurrentLocation(), resultList -> {
if(resultList != null && resultList.size() > 0) {
result.removeAll();
completionUsed = true;
for(SearchService.SuggestionResult r : resultList) {
MultiButton mb = createEntry(FontImage.MATERIAL_PLACE,
r.getMainText(), r.getSecondaryText());
result.add(mb);
mb.addActionListener(e -> {
dest.setTextNoEvent(r.getFullText());
r.getLocation(l -> {
dest.setCurrentLocation(l);
dispatcher.fireActionEvent(e);
});
});
}
CompletionContainer
We fill up the container with buttons if one of the buttons is pressed we fetch the location from the webservice and fill it into the AutoCompleteAddressInput. We then fire
the event dispatcher to process the actual selection in the UI
result.animateLayout(150);
}
});
}
private MultiButton createEntry(char icon, String title) {
MultiButton b = new MultiButton(title);
b.setUIID("Container");
b.setUIIDLine1("WhereToButtonLine1");
b.setIconUIID("WhereToButtonIcon");
FontImage.setMaterialIcon(b, icon);
return b;
}
private MultiButton createEntry(char icon, String title, String subtitle) {
MultiButton b = new MultiButton(title);
b.setTextLine2(subtitle);
b.setUIID("Container");
b.setUIIDLine1("WhereToButtonLineNoBorder");
b.setUIIDLine2("WhereToButtonLine2");
b.setIconUIID("WhereToButtonIcon");
FontImage.setMaterialIcon(b, icon);
return b;
CompletionContainer
We have two types of entries here, one with only one line of text and one with two lines of text. This is mostly in place to fit the UIID's correctly with the right underline
behavior
b.setUIIDLine2("WhereToButtonLine2");
b.setIconUIID("WhereToButtonIcon");
FontImage.setMaterialIcon(b, icon);
return b;
}
public void initCompletionBar() {
if(!completionUsed) {
return;
}
completionUsed = false;
result.removeAll();
initCompletionBarImpl();
}
private void initCompletionBarImpl() {
MultiButton addHome = createEntry(FontImage.MATERIAL_HOME,
"Add Home");
MultiButton addWork = createEntry(FontImage.MATERIAL_WORK,
"Add Work");
MultiButton savedPlaces = createEntry(
FontImage.MATERIAL_NAVIGATE_NEXT, "Saved Places");
savedPlaces.setUIIDLine1("WhereToButtonLineNoBorder");
savedPlaces.setEmblemUIID("WhereToButtonLineNoBorder");
savedPlaces.setEmblem(FontImage.createMaterial(
CompletionContainer
This method is invoked externally to clear up the content of the completion UI and show the "clean" set of initial options
savedPlaces.setUIIDLine1("WhereToButtonLineNoBorder");
savedPlaces.setEmblemUIID("WhereToButtonLineNoBorder");
savedPlaces.setEmblem(FontImage.createMaterial(
FontImage.MATERIAL_NAVIGATE_NEXT,
savedPlaces.getIconComponent().getUnselectedStyle()));
Label whereSeparator = new Label("", "WhereSeparator");
whereSeparator.setShowEvenIfBlank(true);
result.addAll(addHome, addWork, savedPlaces, whereSeparator);
addHistoryToCompletionBar();
}
private void addHistoryToCompletionBar() {
MultiButton history1 = createEntry(FontImage.MATERIAL_HISTORY,
"Mikve Yisrael Str...");
result.add(history1);
}
public void showCompletionBar(Container parentLayer) {
result = new Container(BoxLayout.y());
initCompletionBarImpl();
CompletionContainer
History is positioned here so we could later on fill this with actual search history etc.
private void addHistoryToCompletionBar() {
MultiButton history1 = createEntry(FontImage.MATERIAL_HISTORY,
"Mikve Yisrael Str...");
result.add(history1);
}
public void showCompletionBar(Container parentLayer) {
result = new Container(BoxLayout.y());
initCompletionBarImpl();
result.setUIID("Form");
result.setScrollableY(true);
result.setScrollVisible(false);
Container enclose = BorderLayout.center(result);
enclose.setY(getDisplayHeight());
enclose.setWidth(getDisplayWidth());
enclose.setHeight(result.getPreferredH());
parentLayer.add(CENTER, enclose);
parentLayer.animateLayout(200);
}
public void addCompletionListener(ActionListener<ActionEvent> a) {
dispatcher.addListener(a);
CompletionContainer
This method constructs and animates the completion UI into place. Notice that we place the content in a Container which we wrap up in a BorderLayout this allows us to
manipulate the preferred size without breaking the scrolling behavior of the child Container
WhereToButtonLine2
© Codename One 2017 all rights reserved
In order to accomplish the design for the buttons I had to add the WhereToButtonLine2 UIID. It uses gray text on a transparent background
WhereToButtonLine2
© Codename One 2017 all rights reserved
Padding aligns with the text above, we keep the top padding to 0 so it won’t drift away from the first line in the where to button
WhereToButtonLine2
© Codename One 2017 all rights reserved
Margin is zero as usual
WhereToButtonLine2
© Codename One 2017 all rights reserved
We have an underline here instead of the underline of the first line of text
WhereToButtonLine2
© Codename One 2017 all rights reserved
We use a slightly smaller font but the standard main light font

More Related Content

Similar to Creating an Uber Clone - Part XX - Transcript.pdf

properties-how-do-i.pdf
properties-how-do-i.pdfproperties-how-do-i.pdf
properties-how-do-i.pdfShaiAlmog1
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfShaiAlmog1
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseHeiko Behrens
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptkvangork
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
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.pdfShaiAlmog1
 
Functionality Focused Code Organization
Functionality Focused Code OrganizationFunctionality Focused Code Organization
Functionality Focused Code OrganizationRebecca Murphey
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#Rainer Stropek
 
Creating a Facebook Clone - Part XXXIII - Transcript.pdf
Creating a Facebook Clone - Part XXXIII - Transcript.pdfCreating a Facebook Clone - Part XXXIII - Transcript.pdf
Creating a Facebook Clone - Part XXXIII - Transcript.pdfShaiAlmog1
 
MVVM e Caliburn Micro for Windows Phone applications
MVVM e Caliburn Micro for Windows Phone applicationsMVVM e Caliburn Micro for Windows Phone applications
MVVM e Caliburn Micro for Windows Phone applicationsMatteo Pagani
 
Enterprise workflow with Apps Script
Enterprise workflow with Apps ScriptEnterprise workflow with Apps Script
Enterprise workflow with Apps Scriptccherubino
 
Creating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdfCreating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdfShaiAlmog1
 

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

properties-how-do-i.pdf
properties-how-do-i.pdfproperties-how-do-i.pdf
properties-how-do-i.pdf
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdf
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
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
 
Functionality Focused Code Organization
Functionality Focused Code OrganizationFunctionality Focused Code Organization
Functionality Focused Code Organization
 
JavaScript Lessons 2023
JavaScript Lessons 2023JavaScript Lessons 2023
JavaScript Lessons 2023
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Creating a Facebook Clone - Part XXXIII - Transcript.pdf
Creating a Facebook Clone - Part XXXIII - Transcript.pdfCreating a Facebook Clone - Part XXXIII - Transcript.pdf
Creating a Facebook Clone - Part XXXIII - Transcript.pdf
 
mobl
moblmobl
mobl
 
16 18
16 1816 18
16 18
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
MVVM e Caliburn Micro for Windows Phone applications
MVVM e Caliburn Micro for Windows Phone applicationsMVVM e Caliburn Micro for Windows Phone applications
MVVM e Caliburn Micro for Windows Phone applications
 
Enterprise workflow with Apps Script
Enterprise workflow with Apps ScriptEnterprise workflow with Apps Script
Enterprise workflow with Apps Script
 
Creating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdfCreating an Uber Clone - Part XVIII - Transcript.pdf
Creating an Uber Clone - Part XVIII - Transcript.pdf
 

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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfShaiAlmog1
 

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 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
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 

Creating an Uber Clone - Part XX - Transcript.pdf

  • 1. Creating an Uber Clone - Part XX We’ll continue the search UI implementation as we step into the CompletionContainer class
  • 2. public class CompletionContainer { private Container result; private boolean completionUsed; private final EventDispatcher dispatcher = new EventDispatcher(); void updateCompletion(String text, AutoCompleteAddressInput dest) { SearchService.suggestLocations(text, LocationService.getCurrentLocation(), resultList -> { if(resultList != null && resultList.size() > 0) { result.removeAll(); completionUsed = true; for(SearchService.SuggestionResult r : resultList) { MultiButton mb = createEntry(FontImage.MATERIAL_PLACE, r.getMainText(), r.getSecondaryText()); result.add(mb); mb.addActionListener(e -> { dest.setTextNoEvent(r.getFullText()); r.getLocation(l -> { dest.setCurrentLocation(l); dispatcher.fireActionEvent(e); }); }); } CompletionContainer The CompletionContainer tries to coordinate the two instances of the AutoCompleteAddressInput class by providing a single class that handles the completion UI. Most of the code in this class should be very familiar as some of it is refactored code from the MapForm while other code relates to the suggestLocations API we implemented earlier... The name of the class is misleading. CompletionContainer is not a Container. Here instead of deriving I encapsulated the UI logic and tried to expose only the business logic
  • 3. public class CompletionContainer { private Container result; private boolean completionUsed; private final EventDispatcher dispatcher = new EventDispatcher(); void updateCompletion(String text, AutoCompleteAddressInput dest) { SearchService.suggestLocations(text, LocationService.getCurrentLocation(), resultList -> { if(resultList != null && resultList.size() > 0) { result.removeAll(); completionUsed = true; for(SearchService.SuggestionResult r : resultList) { MultiButton mb = createEntry(FontImage.MATERIAL_PLACE, r.getMainText(), r.getSecondaryText()); result.add(mb); mb.addActionListener(e -> { dest.setTextNoEvent(r.getFullText()); r.getLocation(l -> { dest.setCurrentLocation(l); dispatcher.fireActionEvent(e); }); }); } CompletionContainer Event dispatchers allow us to broadcast events using the add/removeListener observer style API. We use this dispatcher to broadcast an event when a user presses a completion button
  • 4. public class CompletionContainer { private Container result; private boolean completionUsed; private final EventDispatcher dispatcher = new EventDispatcher(); void updateCompletion(String text, AutoCompleteAddressInput dest) { SearchService.suggestLocations(text, LocationService.getCurrentLocation(), resultList -> { if(resultList != null && resultList.size() > 0) { result.removeAll(); completionUsed = true; for(SearchService.SuggestionResult r : resultList) { MultiButton mb = createEntry(FontImage.MATERIAL_PLACE, r.getMainText(), r.getSecondaryText()); result.add(mb); mb.addActionListener(e -> { dest.setTextNoEvent(r.getFullText()); r.getLocation(l -> { dest.setCurrentLocation(l); dispatcher.fireActionEvent(e); }); }); } CompletionContainer This method is invoked when completion is in progress it invokes the WebService call to request completion suggestions for the given string
  • 5. public class CompletionContainer { private Container result; private boolean completionUsed; private final EventDispatcher dispatcher = new EventDispatcher(); void updateCompletion(String text, AutoCompleteAddressInput dest) { SearchService.suggestLocations(text, LocationService.getCurrentLocation(), resultList -> { if(resultList != null && resultList.size() > 0) { result.removeAll(); completionUsed = true; for(SearchService.SuggestionResult r : resultList) { MultiButton mb = createEntry(FontImage.MATERIAL_PLACE, r.getMainText(), r.getSecondaryText()); result.add(mb); mb.addActionListener(e -> { dest.setTextNoEvent(r.getFullText()); r.getLocation(l -> { dest.setCurrentLocation(l); dispatcher.fireActionEvent(e); }); }); } CompletionContainer We fill up the container with buttons if one of the buttons is pressed we fetch the location from the webservice and fill it into the AutoCompleteAddressInput. We then fire the event dispatcher to process the actual selection in the UI
  • 6. result.animateLayout(150); } }); } private MultiButton createEntry(char icon, String title) { MultiButton b = new MultiButton(title); b.setUIID("Container"); b.setUIIDLine1("WhereToButtonLine1"); b.setIconUIID("WhereToButtonIcon"); FontImage.setMaterialIcon(b, icon); return b; } private MultiButton createEntry(char icon, String title, String subtitle) { MultiButton b = new MultiButton(title); b.setTextLine2(subtitle); b.setUIID("Container"); b.setUIIDLine1("WhereToButtonLineNoBorder"); b.setUIIDLine2("WhereToButtonLine2"); b.setIconUIID("WhereToButtonIcon"); FontImage.setMaterialIcon(b, icon); return b; CompletionContainer We have two types of entries here, one with only one line of text and one with two lines of text. This is mostly in place to fit the UIID's correctly with the right underline behavior
  • 7. b.setUIIDLine2("WhereToButtonLine2"); b.setIconUIID("WhereToButtonIcon"); FontImage.setMaterialIcon(b, icon); return b; } public void initCompletionBar() { if(!completionUsed) { return; } completionUsed = false; result.removeAll(); initCompletionBarImpl(); } private void initCompletionBarImpl() { MultiButton addHome = createEntry(FontImage.MATERIAL_HOME, "Add Home"); MultiButton addWork = createEntry(FontImage.MATERIAL_WORK, "Add Work"); MultiButton savedPlaces = createEntry( FontImage.MATERIAL_NAVIGATE_NEXT, "Saved Places"); savedPlaces.setUIIDLine1("WhereToButtonLineNoBorder"); savedPlaces.setEmblemUIID("WhereToButtonLineNoBorder"); savedPlaces.setEmblem(FontImage.createMaterial( CompletionContainer This method is invoked externally to clear up the content of the completion UI and show the "clean" set of initial options
  • 8. savedPlaces.setUIIDLine1("WhereToButtonLineNoBorder"); savedPlaces.setEmblemUIID("WhereToButtonLineNoBorder"); savedPlaces.setEmblem(FontImage.createMaterial( FontImage.MATERIAL_NAVIGATE_NEXT, savedPlaces.getIconComponent().getUnselectedStyle())); Label whereSeparator = new Label("", "WhereSeparator"); whereSeparator.setShowEvenIfBlank(true); result.addAll(addHome, addWork, savedPlaces, whereSeparator); addHistoryToCompletionBar(); } private void addHistoryToCompletionBar() { MultiButton history1 = createEntry(FontImage.MATERIAL_HISTORY, "Mikve Yisrael Str..."); result.add(history1); } public void showCompletionBar(Container parentLayer) { result = new Container(BoxLayout.y()); initCompletionBarImpl(); CompletionContainer History is positioned here so we could later on fill this with actual search history etc.
  • 9. private void addHistoryToCompletionBar() { MultiButton history1 = createEntry(FontImage.MATERIAL_HISTORY, "Mikve Yisrael Str..."); result.add(history1); } public void showCompletionBar(Container parentLayer) { result = new Container(BoxLayout.y()); initCompletionBarImpl(); result.setUIID("Form"); result.setScrollableY(true); result.setScrollVisible(false); Container enclose = BorderLayout.center(result); enclose.setY(getDisplayHeight()); enclose.setWidth(getDisplayWidth()); enclose.setHeight(result.getPreferredH()); parentLayer.add(CENTER, enclose); parentLayer.animateLayout(200); } public void addCompletionListener(ActionListener<ActionEvent> a) { dispatcher.addListener(a); CompletionContainer This method constructs and animates the completion UI into place. Notice that we place the content in a Container which we wrap up in a BorderLayout this allows us to manipulate the preferred size without breaking the scrolling behavior of the child Container
  • 10. WhereToButtonLine2 © Codename One 2017 all rights reserved In order to accomplish the design for the buttons I had to add the WhereToButtonLine2 UIID. It uses gray text on a transparent background
  • 11. WhereToButtonLine2 © Codename One 2017 all rights reserved Padding aligns with the text above, we keep the top padding to 0 so it won’t drift away from the first line in the where to button
  • 12. WhereToButtonLine2 © Codename One 2017 all rights reserved Margin is zero as usual
  • 13. WhereToButtonLine2 © Codename One 2017 all rights reserved We have an underline here instead of the underline of the first line of text
  • 14. WhereToButtonLine2 © Codename One 2017 all rights reserved We use a slightly smaller font but the standard main light font