SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Bolts + RetroLambda
2015.11.26
• Bolts-Android
• Design API Based On Bolts
• Retrolabmda
• Refactor
Why use ?
• spec.
member func() {
Serialize Asynchronous
Tasks
callback {
callback {
callback{
}
then {
then {
then {
} } } }
member func() {
}
}
}
• Bolts-Android
• Design API Based On Bolts
• Retrolabmda
• Refactor
Example
show dialog
press
“YES” button Cancel
Do
something
NO
YES
Example 1/4
public class RunnableCB implements Runnable {

public void run() {

this.run();

}

}




private AlertDialog simpleAlertDialog(String message, final
RunnableCB cb) {

if (cb == null) {

final RunnableCB emptyCallback= new RunnableCB() {

public void run() {

}

};

return buildDialog(message, "OK", emptyCallback);

} else {

return buildDialog(message, "OK", cb);

}

}



Example 2/4




private AlertDialog buildDialog(String message,

String cb1Option, final RunnableCB cb1)
{



AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage(message);

builder.setPositiveButton(cb1Option, new
DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

cb1.run();

}

});



return builder.create();

}
Example 3/4


final RunnableCB cbSwitchOff = new RunnableCB() {

public void run() {

((CompoundButton) bleSwitch).setChecked(false);

}

};


String str =
getResources().getString(R.string.no_ble_device_available);


simpleAlertDialog(str, cbSwitchOff).show();


Example 4/4
Refactor with Bolts
public class Dialog {

static Task<Integer> dlg(String msg, String opt1, String opt2) {

final Task<Integer>.TaskCompletionSource tcs = Task.create();

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

builder.setMessage(msg);

if (opt1 != null && !opt1.isEmpty()) {

builder.setPositiveButton(opt1, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

tcs.setResult(0);

}

});

}

if (opt2 != null && !opt2.isEmpty()) {

builder.setPositiveButton(opt2, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

tcs.setResult(1);

}

});

}

AlertDialog d = builder.create();

d.show();

return tcs.getTask();

}

}


String str = getResources().getString(R.string.no_ble_device_available);


mDialog.show(str, "OK", null).continueWith(new Continuation<Integer, Void>() {

@Override

public Void then(Task<Integer> task) throws Exception {

((CompoundButton) bleSwitch).setChecked(false);

return null;

}

});


Calling API we made
RunnableCB
,
they !! ( Java)
• Bolts-Android
• Design API Based On Bolts
• Retrolabmda
• Refactor
What’s Retrolambda
• Back port Java8 to Java 7, 6, 5
• Syntax Sugar ( )
• Good introduction : Ingram Chen http://
ingramchen.io/blog/2014/10/retromlambda.html
Retrolambda Limitation
• Does not back port Java 8 APIs

https://docs.oracle.com/javase/8/docs/api/java/
util/function/package-summary.html
gradle
•
• https://github.com/evant/gradle-retrolambda
// defined in the SDK
interface OnClickListener {
public void onClick(View v);
}
// your code
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do something here
}
});
syntax sugar 1/2
mButton.setOnClickListener((View v) -> {
// do something here
});
syntax sugar 2/2
• Bolts-Android
• Design API Based On Bolts
• Code Example
• Retrolabmda
• Refactor
public class Dialog {

static Task<Integer> dlg(String msg, String opt1, String opt2) {

final Task<Integer>.TaskCompletionSource tcs = Task.create();

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

builder.setMessage(msg);

if (opt1 != null && !opt1.isEmpty()) {

builder.setPositiveButton(opt1, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

tcs.setResult(0);

}

});

}

if (opt2 != null && !opt2.isEmpty()) {

builder.setPositiveButton(opt2, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

tcs.setResult(1);

}

});

}

AlertDialog d = builder.create();

d.show();

return tcs.getTask();

}

}
->
->


String str = getResources().getString(R.string.no_ble_device_available);


mDialog.show(str, "OK", null).continueWith(new Continuation<Integer, Void>() {

@Override

public Void then(Task<Integer> task) throws Exception {

((CompoundButton) bleSwitch).setChecked(false);

return null;

}

});


->
public Task<Integer> show(String msg, String opt1, String opt2) {

final Task.TaskCompletionSource tcs = Task.create();

final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

builder.setMessage(msg);

if (opt1 != null && !opt1.isEmpty()) {

builder.setPositiveButton(opt1, (DialogInterface dialog, int which) -> {

tcs.setResult(0);

});

}

if (opt2 != null && !opt2.isEmpty()) {

builder.setNegativeButton(opt2, (DialogInterface dialog, int which) -> {

tcs.setResult(1);

});

}



AlertDialog d = builder.create();

d.show();


return tcs.getTask();

}
Result 1/2
mDialog.show1(R.string.no_ble_device_available).continueWith(task -> {

((CompoundButton) bleSwitch).setChecked(false);

gotoScanPage();

return null;

});
Result 2/2
Retrolambda+bolts

Mais conteúdo relacionado

Mais procurados

Eclipse Mars News @JUG HH
Eclipse Mars News @JUG HHEclipse Mars News @JUG HH
Eclipse Mars News @JUG HHsimonscholz
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...Fwdays
 
Виталий Редько "React + Redux: performance & scalability"
Виталий Редько "React + Redux: performance & scalability"Виталий Редько "React + Redux: performance & scalability"
Виталий Редько "React + Redux: performance & scalability"Fwdays
 
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений" Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений" Fwdays
 
Супер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOSСупер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOSSQALab
 
vienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentationvienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentationRouven Weßling
 
Continuous Integration for your Android projects
Continuous Integration for your Android projectsContinuous Integration for your Android projects
Continuous Integration for your Android projectsSergii Zhuk
 
java8-patterns
java8-patternsjava8-patterns
java8-patternsJustin Lin
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Fwdays
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Fwdays
 
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Florent BENOIT
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION APIGavin Pickin
 
Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014Chen-en Lu
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017Ortus Solutions, Corp
 
Use React Patterns to Build Large Scalable App
Use React Patterns to Build Large Scalable App Use React Patterns to Build Large Scalable App
Use React Patterns to Build Large Scalable App Yao Nien Chung
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Annie Huang
 

Mais procurados (20)

Eclipse Mars News @JUG HH
Eclipse Mars News @JUG HHEclipse Mars News @JUG HH
Eclipse Mars News @JUG HH
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
 
Виталий Редько "React + Redux: performance & scalability"
Виталий Редько "React + Redux: performance & scalability"Виталий Редько "React + Redux: performance & scalability"
Виталий Редько "React + Redux: performance & scalability"
 
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений" Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
 
Супер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOSСупер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOS
 
vienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentationvienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentation
 
Continuous Integration for your Android projects
Continuous Integration for your Android projectsContinuous Integration for your Android projects
Continuous Integration for your Android projects
 
Rest, sockets em golang
Rest, sockets em golangRest, sockets em golang
Rest, sockets em golang
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
java8-patterns
java8-patternsjava8-patterns
java8-patterns
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
Introducing spring
Introducing springIntroducing spring
Introducing spring
 
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
Use React Patterns to Build Large Scalable App
Use React Patterns to Build Large Scalable App Use React Patterns to Build Large Scalable App
Use React Patterns to Build Large Scalable App
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
Testing in go
Testing in goTesting in go
Testing in go
 

Semelhante a Retrolambda+bolts

Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentSchalk Cronjé
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissAndres Almiray
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionSchalk Cronjé
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinJava User Group Latvia
 
Cool JVM Tools to Help You Test
Cool JVM Tools to Help You TestCool JVM Tools to Help You Test
Cool JVM Tools to Help You TestSchalk Cronjé
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF SummitOrtus Solutions, Corp
 
Eclipse Buildship JUG Hamburg
Eclipse Buildship JUG HamburgEclipse Buildship JUG Hamburg
Eclipse Buildship JUG Hamburgsimonscholz
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineRoman Kirillov
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - Ortus Solutions, Corp
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Anton Arhipov
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGuillaume Laforge
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For ManagersAgileThought
 

Semelhante a Retrolambda+bolts (20)

Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM Development
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
testing.pdf
testing.pdftesting.pdf
testing.pdf
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
 
Cool JVM Tools to Help You Test
Cool JVM Tools to Help You TestCool JVM Tools to Help You Test
Cool JVM Tools to Help You Test
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 
Enter the gradle
Enter the gradleEnter the gradle
Enter the gradle
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Eclipse Buildship JUG Hamburg
Eclipse Buildship JUG HamburgEclipse Buildship JUG Hamburg
Eclipse Buildship JUG Hamburg
 
Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
How to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDKHow to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDK
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 

Mais de Tom Sun

Cloud radio 閃電秀
Cloud radio 閃電秀Cloud radio 閃電秀
Cloud radio 閃電秀Tom Sun
 
健康報告:德國飲食
健康報告:德國飲食健康報告:德國飲食
健康報告:德國飲食Tom Sun
 
Linux usb2ether
Linux usb2etherLinux usb2ether
Linux usb2etherTom Sun
 
iOs app 101
iOs app 101iOs app 101
iOs app 101Tom Sun
 
Whos Fault
Whos FaultWhos Fault
Whos FaultTom Sun
 
小巫婆麗特拉
小巫婆麗特拉小巫婆麗特拉
小巫婆麗特拉Tom Sun
 
Serial Pnp
Serial PnpSerial Pnp
Serial PnpTom Sun
 

Mais de Tom Sun (8)

Pioc
PiocPioc
Pioc
 
Cloud radio 閃電秀
Cloud radio 閃電秀Cloud radio 閃電秀
Cloud radio 閃電秀
 
健康報告:德國飲食
健康報告:德國飲食健康報告:德國飲食
健康報告:德國飲食
 
Linux usb2ether
Linux usb2etherLinux usb2ether
Linux usb2ether
 
iOs app 101
iOs app 101iOs app 101
iOs app 101
 
Whos Fault
Whos FaultWhos Fault
Whos Fault
 
小巫婆麗特拉
小巫婆麗特拉小巫婆麗特拉
小巫婆麗特拉
 
Serial Pnp
Serial PnpSerial Pnp
Serial Pnp
 

Último

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 

Último (20)

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 

Retrolambda+bolts

  • 2. • Bolts-Android • Design API Based On Bolts • Retrolabmda • Refactor
  • 4. member func() { Serialize Asynchronous Tasks callback { callback { callback{ } then { then { then { } } } } member func() { } } }
  • 5. • Bolts-Android • Design API Based On Bolts • Retrolabmda • Refactor
  • 6. Example show dialog press “YES” button Cancel Do something NO YES
  • 7. Example 1/4 public class RunnableCB implements Runnable {
 public void run() {
 this.run();
 }
 } 
 

  • 8. private AlertDialog simpleAlertDialog(String message, final RunnableCB cb) {
 if (cb == null) {
 final RunnableCB emptyCallback= new RunnableCB() {
 public void run() {
 }
 };
 return buildDialog(message, "OK", emptyCallback);
 } else {
 return buildDialog(message, "OK", cb);
 }
 }
 
 Example 2/4
  • 9. 
 
 private AlertDialog buildDialog(String message,
 String cb1Option, final RunnableCB cb1) {
 
 AlertDialog.Builder builder = new AlertDialog.Builder(this);
 builder.setMessage(message);
 builder.setPositiveButton(cb1Option, new DialogInterface.OnClickListener() {
 @Override
 public void onClick(DialogInterface dialog, int which) {
 dialog.dismiss();
 cb1.run();
 }
 });
 
 return builder.create();
 } Example 3/4
  • 10. 
 final RunnableCB cbSwitchOff = new RunnableCB() {
 public void run() {
 ((CompoundButton) bleSwitch).setChecked(false);
 }
 }; 
 String str = getResources().getString(R.string.no_ble_device_available); 
 simpleAlertDialog(str, cbSwitchOff).show(); 
 Example 4/4
  • 11. Refactor with Bolts public class Dialog {
 static Task<Integer> dlg(String msg, String opt1, String opt2) {
 final Task<Integer>.TaskCompletionSource tcs = Task.create();
 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
 builder.setMessage(msg);
 if (opt1 != null && !opt1.isEmpty()) {
 builder.setPositiveButton(opt1, new DialogInterface.OnClickListener() {
 @Override
 public void onClick(DialogInterface dialog, int which) {
 tcs.setResult(0);
 }
 });
 }
 if (opt2 != null && !opt2.isEmpty()) {
 builder.setPositiveButton(opt2, new DialogInterface.OnClickListener() {
 @Override
 public void onClick(DialogInterface dialog, int which) {
 tcs.setResult(1);
 }
 });
 }
 AlertDialog d = builder.create();
 d.show();
 return tcs.getTask();
 }
 }
  • 12. 
 String str = getResources().getString(R.string.no_ble_device_available); 
 mDialog.show(str, "OK", null).continueWith(new Continuation<Integer, Void>() {
 @Override
 public Void then(Task<Integer> task) throws Exception {
 ((CompoundButton) bleSwitch).setChecked(false);
 return null;
 }
 }); 
 Calling API we made RunnableCB
  • 13. , they !! ( Java)
  • 14. • Bolts-Android • Design API Based On Bolts • Retrolabmda • Refactor
  • 15. What’s Retrolambda • Back port Java8 to Java 7, 6, 5 • Syntax Sugar ( ) • Good introduction : Ingram Chen http:// ingramchen.io/blog/2014/10/retromlambda.html
  • 16. Retrolambda Limitation • Does not back port Java 8 APIs
 https://docs.oracle.com/javase/8/docs/api/java/ util/function/package-summary.html
  • 18. // defined in the SDK interface OnClickListener { public void onClick(View v); } // your code mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // do something here } }); syntax sugar 1/2
  • 19. mButton.setOnClickListener((View v) -> { // do something here }); syntax sugar 2/2
  • 20. • Bolts-Android • Design API Based On Bolts • Code Example • Retrolabmda • Refactor
  • 21. public class Dialog {
 static Task<Integer> dlg(String msg, String opt1, String opt2) {
 final Task<Integer>.TaskCompletionSource tcs = Task.create();
 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
 builder.setMessage(msg);
 if (opt1 != null && !opt1.isEmpty()) {
 builder.setPositiveButton(opt1, new DialogInterface.OnClickListener() {
 @Override
 public void onClick(DialogInterface dialog, int which) {
 tcs.setResult(0);
 }
 });
 }
 if (opt2 != null && !opt2.isEmpty()) {
 builder.setPositiveButton(opt2, new DialogInterface.OnClickListener() {
 @Override
 public void onClick(DialogInterface dialog, int which) {
 tcs.setResult(1);
 }
 });
 }
 AlertDialog d = builder.create();
 d.show();
 return tcs.getTask();
 }
 } -> ->
  • 22. 
 String str = getResources().getString(R.string.no_ble_device_available); 
 mDialog.show(str, "OK", null).continueWith(new Continuation<Integer, Void>() {
 @Override
 public Void then(Task<Integer> task) throws Exception {
 ((CompoundButton) bleSwitch).setChecked(false);
 return null;
 }
 }); 
 ->
  • 23. public Task<Integer> show(String msg, String opt1, String opt2) {
 final Task.TaskCompletionSource tcs = Task.create();
 final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
 builder.setMessage(msg);
 if (opt1 != null && !opt1.isEmpty()) {
 builder.setPositiveButton(opt1, (DialogInterface dialog, int which) -> {
 tcs.setResult(0);
 });
 }
 if (opt2 != null && !opt2.isEmpty()) {
 builder.setNegativeButton(opt2, (DialogInterface dialog, int which) -> {
 tcs.setResult(1);
 });
 }
 
 AlertDialog d = builder.create();
 d.show(); 
 return tcs.getTask();
 } Result 1/2
  • 24. mDialog.show1(R.string.no_ble_device_available).continueWith(task -> {
 ((CompoundButton) bleSwitch).setChecked(false);
 gotoScanPage();
 return null;
 }); Result 2/2