SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxLMW Machine Tool Division
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS Bahzad5
 
Test of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptxTest of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptxHome
 
Power System electrical and electronics .pptx
Power System electrical and electronics .pptxPower System electrical and electronics .pptx
Power System electrical and electronics .pptxMUKULKUMAR210
 
IT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptxIT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptxSAJITHABANUS
 
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchrohitcse52
 
Landsman converter for power factor improvement
Landsman converter for power factor improvementLandsman converter for power factor improvement
Landsman converter for power factor improvementVijayMuni2
 
Design of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxDesign of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxYogeshKumarKJMIT
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...soginsider
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxwendy cai
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Amil baba
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfJulia Kaye
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderjuancarlos286641
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Projectreemakb03
 
Mohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxMohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxKISHAN KUMAR
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxrealme6igamerr
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfNaveenVerma126
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical SensorTanvir Moin
 

Kürzlich hochgeladen (20)

Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
 
Test of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptxTest of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptx
 
Power System electrical and electronics .pptx
Power System electrical and electronics .pptxPower System electrical and electronics .pptx
Power System electrical and electronics .pptx
 
IT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptxIT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptx
 
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
 
Landsman converter for power factor improvement
Landsman converter for power factor improvementLandsman converter for power factor improvement
Landsman converter for power factor improvement
 
Design of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxDesign of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptx
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptx
 
Présentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdfPrésentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdf
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entender
 
Lecture 4 .pdf
Lecture 4                              .pdfLecture 4                              .pdf
Lecture 4 .pdf
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Project
 
Mohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxMohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptx
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical Sensor
 

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