SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
Snow White and the
Seven Dwarfs
Murat Yener
@yenerm
Android
who am I?
-Java, Android, web
-Android Dev @Intel
-Conference Speaker (JavaOne, Devoxx…)
-GDG Istanbul Organizer
-Book Author
-Java Champion
-GDE on Android
40%
discount with promo
code
VBK43
when ordering
through
wiley.com
valid until end of
December 2015
Once upon a time…
the princess…
well, the Android
had some problems
after eating an… apple
while waiting for the
prince charming…
can Seven Dwarfs help?
Butterknife
Dagger
Volley / OkHttp / Retrofit
GreenBus / Otto
GreenDAO / Schematic
Priority JobQueue
Timber / Hugo
Butterknife
Dependency Injection for views and actions
Cleaner code
Simple annotation based usage
Use Nullable to avoid exceptions
Based on compile time code generation
compile ‘com.jakewharton:butterknife:7.0.1’
class ExampleActivity extends Activity {
@Bind(R.id.title) TextView title;
@Bind(R.id.subtitle) TextView subtitle;
@Bind(R.id.footer) TextView footer;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields...
}
}
@Nullable @Bind(R.id.might_not_be_there) TextView mightNotBeThere;
@Nullable @OnClick(R.id.maybe_missing) void onMaybeMissingClicked() {
// TODO ...
}
//Simple listener injection
@OnClick(R.id.submit)
public void submit(View view) {
// TODO submit data to server...
}
//Multi listener
@OnClick({ R.id.door1, R.id.door2, R.id.door3 })
public void pickDoor(DoorView door) {
if (door.hasPrizeBehind()) {
Toast.makeText(this, "You win!", LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Try again", LENGTH_SHORT).show();
}
}
ProGuard Configuration
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
Dagger
Fast dependency injection
Standard javax.inject (JSR 330)
Make your code easy to test
Compile time code generation (No reflection)
Complicated
Hard to do for ongoing project
compile 'com.google.dagger:dagger:2.0'
apt 'com.google.dagger:dagger-compiler:2.0'
@Module + @Provides: mechanism for providing
dependencies.
@Inject: mechanism for requesting dependencies.
@Component: bridge between modules and
injections


class CoffeeMaker {

@Inject Heater heater;

@Inject Pump pump;

...

}



@Module

class DripCoffeeModule {

@Provides Heater provideHeater() {

return new ElectricHeater();

}



@Provides Pump providePump(Thermosiphon pump) {

return pump;

}

}
@Component(modules = DripCoffeeModule.class)

interface CoffeeShop {

CoffeeMaker maker();

}
public @interface Component {

Class<?>[] modules() default {};

Class<?>[] dependencies() default {};

}
public @interface Module {

Class<?>[] includes() default { };

}


public @interface Provides {

}

public @interface MapKey {

boolean unwrapValue();

}
public interface Lazy<T> {

T get();

}
ProGuard Configuration
NONE
OkHttp
Widely used, simple fix for HttpClient
Internal cache
HTTP2 and SPDY support
Uses GZIP
Manual handling of background execution
compile 'com.squareup.okhttp:okhttp:2.5.0'
//Client

OkHttpClient client = new OkHttpClient();

//Get URL

String run(String url) throws IOException {

Request request = new Request.Builder()

.url(url)

.build();



Response response = client.newCall(request).execute();

return response.body().string();

}

//Post URL
public static final MediaType JSON

= MediaType.parse("application/json; charset=utf-8");



String post(String url, String json) throws IOException {

RequestBody body = RequestBody.create(JSON, json);

Request request = new Request.Builder()

.url(url)

.post(body)

.build();

Response response = client.newCall(request).execute();

return response.body().string();

}
ProGuard Configuration
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
Volley
Simplest HttpClient fix for Android
Internal Queue
Internal Cache
Runs in a separate thread
Not good for large downloads
compile ‘com.mcxiaoke.volley:library-aar:1/0/0’
RequestQueue queue = Volley.newRequestQueue(this);


StringRequest stringRequest = new StringRequest(Request.Method.GET, url,

new Response.Listener<String>() {

@Override

public void onResponse(String response) {

//..

}

}, new Response.ErrorListener() {

@Override

public void onErrorResponse(VolleyError error) {

//..

}

});



queue.add(stringRequest);
//Cancel requests
queue.cancelAll(TAG);
ProGuard Configuration
NONE
Retrofit
REST Client for Java
Generates an implementation of the API
Uses annotation to describe URLs, query params
Object conversion to JSON request body
Multipart request body and file upload
Only good for REST APIs
compile 'com.squareup.retrofit:retrofit:1.9.0'




public interface GitHubService {



@Headers("Cache-Control: max-age=640000")

@GET("/users/{user}/repos")

List<Repo> listRepos(@Path("user") String user);



@POST("/users/new")

void createUser(@Body User user, Callback<User> cb);

}


RestAdapter restAdapter = new RestAdapter.Builder()

.setEndpoint("https://api.github.com")

.build();



GitHubService service = restAdapter.create(GitHubService.class);



List<Repo> repos = service.listRepos("octocat");
-keep class com.squareup.okhttp.** { *; }

-keep interface com.squareup.okhttp.** { *; }

-dontwarn com.squareup.okhttp.**
-dontwarn rx.**

-dontwarn retrofit.**

-dontwarn okio.**

-keep class retrofit.** { *; }
-keepclasseswithmembers class * {

@retrofit.http.* <methods>;

}
GreenRobot EventBus
Dispatches events through a bus
Event Driven
Very easy and clean implementation
Easily transfer data between components
Uses reflection on runtime
compile 'de.greenrobot:eventbus:2.4.0'
//Custom Event Object
public class SampleEvent {
private String message;
public SampleEvent(String message){
this.message=message;
}
}
//Caller
//geteventbus
eventBus.post(new SampleEvent(“An event”);
//callee
//geteventbus
eventBus.register(this);
public void onEvent(SampleEvent event) {
textField.setText(event.getMessage());
};
ProGuard Configuration
-keepclassmembers class ** {
public void onEvent*(**);
}
# Only required if you use AsyncExecutor
-keepclassmembers class * extends
de.greenrobot.event.util.ThrowableFailureEvent {
public <init>(java.lang.Throwable);
}
# Don't warn for missing support classes
-dontwarn de.greenrobot.event.util.*$Support
-dontwarn de.greenrobot.event.util.*$SupportManagerFragment
Otto
Event bus
decouple different parts of your application
Communication between components
Uses reflection
compile 'com.squareup:otto:1.3.8'


Bus bus = new Bus();

bus.post(new AnswerAvailableEvent(42));

bus.register(this);



@Subscribe

public void answerAvailable(AnswerAvailableEvent event) {

// TODO: React to the event somehow!

}
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
GreenDao
from the creators of GreenRobot EventBus
Standard SqLite
No create table… etc
Uses code generation for model and dao
compile 'de.greenrobot:greendao'
new DaoMaster.DevOpenHelper(this, "notes-db", null);
daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();
noteDao = daoSession.getNoteDao();
Note note = new Note(null, noteText, comment, new Date());
noteDao.insert(note);
-keepclassmembers class * extends de.greenrobot.dao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
Schematic
Automatically generate ContentProviders
Backed by SQLite Database
Can be used w/ Android System
Loaders, SyncAdapter, Permissions
Harder to use (deal w/ Cursors)
apt ‘net.simonvt.schematic:schematic-compiler:0.6.0’
compile ‘net.simonvt.schematic:schematic:0.6.0’


public interface ListColumns {



@DataType(INTEGER) @PrimaryKey @AutoIncrement String _ID = "_id";



@DataType(TEXT) @NotNull String TITLE = "title";

}



@Database(version = NotesDatabase.VERSION)

public final class NotesDatabase {



public static final int VERSION = 1;



@Table(ListColumns.class) public static final String LISTS = "lists";

}



@ContentProvider(authority = NotesProvider.AUTHORITY, database = NotesDatabase.class)

public final class NotesProvider {



public static final String AUTHORITY = "net.simonvt.schematic.sample.NotesProvider";



@TableEndpoint(table = NotesDatabase.LISTS)

public static class Lists {



@ContentUri(

path = Path.LISTS,

type = "vnd.android.cursor.dir/list",

defaultSort = ListColumns.TITLE + " ASC")

public static final Uri LISTS = Uri.parse("content://" + AUTHORITY + "/lists")

}

}
ProGuard Configuration
NONE
Priority JobQueue
Persistent queue for scheduling jobs
Easy to prioritize
Delay job execution
Group jobs for batch execution
Not really needed above 5.0
compile 'com.path:android-priority-jobqueue:1.1.2'
public class PostTweetJob extends Job {

public static final int PRIORITY = 1;



public PostTweetJob(String text) {

super(new Params(PRIORITY).requireNetwork().persist());

}


@Override

public void onAdded() {}


@Override

public void onRun() throws Throwable {

webservice.postTweet(text);

}


@Override

protected boolean shouldReRunOnThrowable(Throwable throwable) {

}

}
ProGuard Configuration
NONE
Timber
Logger with a small, extensible API
Default behavior: Nothing
Behavior is added through Tree instances.
Install instance by calling Timber.plant()
DebugTree: output logs for debug builds and auto
tag generation
compile 'com.jakewharton.timber:timber:4.1.0'


/** A tree which logs important information for crash reporting. */

private static class CrashReportingTree extends Timber.Tree {

@Override protected void log(int priority, String tag, 

String message, Throwable t) {


if (priority == Log.VERBOSE || priority == Log.DEBUG) {

return;

}



FakeCrashLibrary.log(priority, tag, message);



if (t != null) {

if (priority == Log.ERROR) {

FakeCrashLibrary.logError(t);

} else if (priority == Log.WARN) {

FakeCrashLibrary.logWarning(t);

}

}

}

}


public void greetingClicked(Button button) {


Timber.i("A button with ID %s was clicked.", button.getId());

//Do stuff

}
ProGuard Configuration
NONE
Hugo
Annotation-triggered method call logging
Generates logging code
Zero effect on non-debug builds.
see next slide
buildscript {

repositories {

mavenCentral()

}



dependencies {

classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'

}

}



apply plugin: 'com.android.application'

apply plugin: 'com.jakewharton.hugo'


@DebugLog

public String getName(String first, String last) {

SystemClock.sleep(15); // Don't ever really do this!

return first + " " + last;

}


V/Example: ⇢ getName(first="Jake", last="Wharton")

V/Example: ⇠ getName [16ms] = "Jake Wharton"
ProGuard Configuration
NONE
BONUS
The Prince Charming:
Lambdas on Android
wait, Java 8?!?
Android 5.0 and above use Java 7
but not invokeDynamic
so no Lambdas…
Retrolambda
lambda expressions
method references
try-with-resources statements
limited support for backporting default methods
and static methods on interfaces
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
}
}
// Required because retrolambda is on maven central
repositories {
mavenCentral()
}
apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: ‘me.tatarka.retrolambda'
OR
plugins {
id "me.tatarka.retrolambda" version "3.2.3"
}
PROGUARD
-dontwarn java.lang.invoke.*
Android Studio
build.gradle
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Libraries fix things…
Use them only when you have a (exprected)
problem…
and don’t overuse them…
Conclusion…
@yenerm
murat@muratyener.com
-the end
questions?

Más contenido relacionado

La actualidad más candente

Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-SideReza Rahman
 
Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Reza Rahman
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Hirofumi Iwasaki
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guidePankaj Singh
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Ryan Cuprak
 
50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutesArun Gupta
 
Java EE 8: On the Horizon
Java EE 8:  On the HorizonJava EE 8:  On the Horizon
Java EE 8: On the HorizonJosh Juneau
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
JSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworksJSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworksDmitry Kornilov
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer ReferenceMuthuselvam RS
 
Java interview questions
Java interview questionsJava interview questions
Java interview questionsSoba Arjun
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOPHitesh-Java
 
Dao pattern
Dao patternDao pattern
Dao patternciriako
 

La actualidad más candente (17)

Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
 
Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Have You Seen Java EE Lately?
Have You Seen Java EE Lately?
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
 
50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes
 
Java EE 6 & Spring: A Lover's Quarrel
Java EE 6 & Spring: A Lover's QuarrelJava EE 6 & Spring: A Lover's Quarrel
Java EE 6 & Spring: A Lover's Quarrel
 
Java EE 8: On the Horizon
Java EE 8:  On the HorizonJava EE 8:  On the Horizon
Java EE 8: On the Horizon
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
JSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworksJSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworks
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
Jdbc
JdbcJdbc
Jdbc
 
Hibernate3 q&a
Hibernate3 q&aHibernate3 q&a
Hibernate3 q&a
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Dao pattern
Dao patternDao pattern
Dao pattern
 

Similar a Android and the Seven Dwarfs from Devox'15

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsMatteo Manchi
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android JetpackAhmad Arif Faizin
 
Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsHassan Abid
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slideshelenmga
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP formatForest Mars
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Filippo Matteo Riggio
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS InternalEyal Vardi
 
Data binding в массы!
Data binding в массы!Data binding в массы!
Data binding в массы!Artjoker
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 

Similar a Android and the Seven Dwarfs from Devox'15 (20)

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Green dao
Green daoGreen dao
Green dao
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
 
Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture Components
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slides
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP format
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Scripting GeoServer
Scripting GeoServerScripting GeoServer
Scripting GeoServer
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Data binding в массы!
Data binding в массы!Data binding в массы!
Data binding в массы!
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 

Más de Murat Yener

Design patterns with Kotlin
Design patterns with KotlinDesign patterns with Kotlin
Design patterns with KotlinMurat Yener
 
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)Murat Yener
 
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)Murat Yener
 
Android WebView, The Fifth Element
Android WebView, The Fifth ElementAndroid WebView, The Fifth Element
Android WebView, The Fifth ElementMurat Yener
 
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse LibraJavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse LibraMurat Yener
 
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)Murat Yener
 
Eclipsist2009 Rich Client Roundup
Eclipsist2009 Rich Client RoundupEclipsist2009 Rich Client Roundup
Eclipsist2009 Rich Client RoundupMurat Yener
 

Más de Murat Yener (7)

Design patterns with Kotlin
Design patterns with KotlinDesign patterns with Kotlin
Design patterns with Kotlin
 
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
 
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
 
Android WebView, The Fifth Element
Android WebView, The Fifth ElementAndroid WebView, The Fifth Element
Android WebView, The Fifth Element
 
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse LibraJavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
 
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
 
Eclipsist2009 Rich Client Roundup
Eclipsist2009 Rich Client RoundupEclipsist2009 Rich Client Roundup
Eclipsist2009 Rich Client Roundup
 

Último

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Último (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Android and the Seven Dwarfs from Devox'15

  • 1. Snow White and the Seven Dwarfs Murat Yener @yenerm Android
  • 2. who am I? -Java, Android, web -Android Dev @Intel -Conference Speaker (JavaOne, Devoxx…) -GDG Istanbul Organizer -Book Author -Java Champion -GDE on Android
  • 3. 40% discount with promo code VBK43 when ordering through wiley.com valid until end of December 2015
  • 4. Once upon a time…
  • 5. the princess… well, the Android had some problems after eating an… apple while waiting for the prince charming…
  • 6. can Seven Dwarfs help? Butterknife Dagger Volley / OkHttp / Retrofit GreenBus / Otto GreenDAO / Schematic Priority JobQueue Timber / Hugo
  • 7. Butterknife Dependency Injection for views and actions Cleaner code Simple annotation based usage Use Nullable to avoid exceptions Based on compile time code generation compile ‘com.jakewharton:butterknife:7.0.1’
  • 8. class ExampleActivity extends Activity { @Bind(R.id.title) TextView title; @Bind(R.id.subtitle) TextView subtitle; @Bind(R.id.footer) TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.bind(this); // TODO Use fields... } }
  • 9. @Nullable @Bind(R.id.might_not_be_there) TextView mightNotBeThere; @Nullable @OnClick(R.id.maybe_missing) void onMaybeMissingClicked() { // TODO ... }
  • 10. //Simple listener injection @OnClick(R.id.submit) public void submit(View view) { // TODO submit data to server... } //Multi listener @OnClick({ R.id.door1, R.id.door2, R.id.door3 }) public void pickDoor(DoorView door) { if (door.hasPrizeBehind()) { Toast.makeText(this, "You win!", LENGTH_SHORT).show(); } else { Toast.makeText(this, "Try again", LENGTH_SHORT).show(); } }
  • 11. ProGuard Configuration -keep class butterknife.** { *; } -dontwarn butterknife.internal.** -keep class **$$ViewInjector { *; } -keepclasseswithmembernames class * { @butterknife.* <fields>; } -keepclasseswithmembernames class * { @butterknife.* <methods>; }
  • 12. Dagger Fast dependency injection Standard javax.inject (JSR 330) Make your code easy to test Compile time code generation (No reflection) Complicated Hard to do for ongoing project compile 'com.google.dagger:dagger:2.0' apt 'com.google.dagger:dagger-compiler:2.0'
  • 13. @Module + @Provides: mechanism for providing dependencies. @Inject: mechanism for requesting dependencies. @Component: bridge between modules and injections
  • 14. 
 class CoffeeMaker {
 @Inject Heater heater;
 @Inject Pump pump;
 ...
 }
 
 @Module
 class DripCoffeeModule {
 @Provides Heater provideHeater() {
 return new ElectricHeater();
 }
 
 @Provides Pump providePump(Thermosiphon pump) {
 return pump;
 }
 } @Component(modules = DripCoffeeModule.class)
 interface CoffeeShop {
 CoffeeMaker maker();
 }
  • 15. public @interface Component {
 Class<?>[] modules() default {};
 Class<?>[] dependencies() default {};
 } public @interface Module {
 Class<?>[] includes() default { };
 } 
 public @interface Provides {
 }
 public @interface MapKey {
 boolean unwrapValue();
 } public interface Lazy<T> {
 T get();
 }
  • 17. OkHttp Widely used, simple fix for HttpClient Internal cache HTTP2 and SPDY support Uses GZIP Manual handling of background execution compile 'com.squareup.okhttp:okhttp:2.5.0'
  • 18. //Client
 OkHttpClient client = new OkHttpClient();
 //Get URL
 String run(String url) throws IOException {
 Request request = new Request.Builder()
 .url(url)
 .build();
 
 Response response = client.newCall(request).execute();
 return response.body().string();
 }
 //Post URL public static final MediaType JSON
 = MediaType.parse("application/json; charset=utf-8");
 
 String post(String url, String json) throws IOException {
 RequestBody body = RequestBody.create(JSON, json);
 Request request = new Request.Builder()
 .url(url)
 .post(body)
 .build();
 Response response = client.newCall(request).execute();
 return response.body().string();
 }
  • 19. ProGuard Configuration -keepattributes Signature -keepattributes *Annotation* -keep class com.squareup.okhttp.** { *; } -keep interface com.squareup.okhttp.** { *; } -dontwarn com.squareup.okhttp.**
  • 20. Volley Simplest HttpClient fix for Android Internal Queue Internal Cache Runs in a separate thread Not good for large downloads compile ‘com.mcxiaoke.volley:library-aar:1/0/0’
  • 21. RequestQueue queue = Volley.newRequestQueue(this); 
 StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
 new Response.Listener<String>() {
 @Override
 public void onResponse(String response) {
 //..
 }
 }, new Response.ErrorListener() {
 @Override
 public void onErrorResponse(VolleyError error) {
 //..
 }
 });
 
 queue.add(stringRequest); //Cancel requests queue.cancelAll(TAG);
  • 23. Retrofit REST Client for Java Generates an implementation of the API Uses annotation to describe URLs, query params Object conversion to JSON request body Multipart request body and file upload Only good for REST APIs compile 'com.squareup.retrofit:retrofit:1.9.0'
  • 24. 
 
 public interface GitHubService {
 
 @Headers("Cache-Control: max-age=640000")
 @GET("/users/{user}/repos")
 List<Repo> listRepos(@Path("user") String user);
 
 @POST("/users/new")
 void createUser(@Body User user, Callback<User> cb);
 } 
 RestAdapter restAdapter = new RestAdapter.Builder()
 .setEndpoint("https://api.github.com")
 .build();
 
 GitHubService service = restAdapter.create(GitHubService.class);
 
 List<Repo> repos = service.listRepos("octocat");
  • 25. -keep class com.squareup.okhttp.** { *; }
 -keep interface com.squareup.okhttp.** { *; }
 -dontwarn com.squareup.okhttp.** -dontwarn rx.**
 -dontwarn retrofit.**
 -dontwarn okio.**
 -keep class retrofit.** { *; } -keepclasseswithmembers class * {
 @retrofit.http.* <methods>;
 }
  • 26. GreenRobot EventBus Dispatches events through a bus Event Driven Very easy and clean implementation Easily transfer data between components Uses reflection on runtime compile 'de.greenrobot:eventbus:2.4.0'
  • 27. //Custom Event Object public class SampleEvent { private String message; public SampleEvent(String message){ this.message=message; } } //Caller //geteventbus eventBus.post(new SampleEvent(“An event”);
  • 28. //callee //geteventbus eventBus.register(this); public void onEvent(SampleEvent event) { textField.setText(event.getMessage()); };
  • 29. ProGuard Configuration -keepclassmembers class ** { public void onEvent*(**); } # Only required if you use AsyncExecutor -keepclassmembers class * extends de.greenrobot.event.util.ThrowableFailureEvent { public <init>(java.lang.Throwable); } # Don't warn for missing support classes -dontwarn de.greenrobot.event.util.*$Support -dontwarn de.greenrobot.event.util.*$SupportManagerFragment
  • 30. Otto Event bus decouple different parts of your application Communication between components Uses reflection compile 'com.squareup:otto:1.3.8'
  • 31. 
 Bus bus = new Bus();
 bus.post(new AnswerAvailableEvent(42));
 bus.register(this);
 
 @Subscribe
 public void answerAvailable(AnswerAvailableEvent event) {
 // TODO: React to the event somehow!
 }
  • 32. -keepclassmembers class ** { @com.squareup.otto.Subscribe public *; @com.squareup.otto.Produce public *; }
  • 33. GreenDao from the creators of GreenRobot EventBus Standard SqLite No create table… etc Uses code generation for model and dao compile 'de.greenrobot:greendao'
  • 34. new DaoMaster.DevOpenHelper(this, "notes-db", null); daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); noteDao = daoSession.getNoteDao(); Note note = new Note(null, noteText, comment, new Date()); noteDao.insert(note);
  • 35. -keepclassmembers class * extends de.greenrobot.dao.AbstractDao { public static java.lang.String TABLENAME; } -keep class **$Properties
  • 36. Schematic Automatically generate ContentProviders Backed by SQLite Database Can be used w/ Android System Loaders, SyncAdapter, Permissions Harder to use (deal w/ Cursors) apt ‘net.simonvt.schematic:schematic-compiler:0.6.0’ compile ‘net.simonvt.schematic:schematic:0.6.0’
  • 37. 
 public interface ListColumns {
 
 @DataType(INTEGER) @PrimaryKey @AutoIncrement String _ID = "_id";
 
 @DataType(TEXT) @NotNull String TITLE = "title";
 }
 
 @Database(version = NotesDatabase.VERSION)
 public final class NotesDatabase {
 
 public static final int VERSION = 1;
 
 @Table(ListColumns.class) public static final String LISTS = "lists";
 }
 
 @ContentProvider(authority = NotesProvider.AUTHORITY, database = NotesDatabase.class)
 public final class NotesProvider {
 
 public static final String AUTHORITY = "net.simonvt.schematic.sample.NotesProvider";
 
 @TableEndpoint(table = NotesDatabase.LISTS)
 public static class Lists {
 
 @ContentUri(
 path = Path.LISTS,
 type = "vnd.android.cursor.dir/list",
 defaultSort = ListColumns.TITLE + " ASC")
 public static final Uri LISTS = Uri.parse("content://" + AUTHORITY + "/lists")
 }
 }
  • 39. Priority JobQueue Persistent queue for scheduling jobs Easy to prioritize Delay job execution Group jobs for batch execution Not really needed above 5.0 compile 'com.path:android-priority-jobqueue:1.1.2'
  • 40. public class PostTweetJob extends Job {
 public static final int PRIORITY = 1;
 
 public PostTweetJob(String text) {
 super(new Params(PRIORITY).requireNetwork().persist());
 } 
 @Override
 public void onAdded() {} 
 @Override
 public void onRun() throws Throwable {
 webservice.postTweet(text);
 } 
 @Override
 protected boolean shouldReRunOnThrowable(Throwable throwable) {
 }
 }
  • 42. Timber Logger with a small, extensible API Default behavior: Nothing Behavior is added through Tree instances. Install instance by calling Timber.plant() DebugTree: output logs for debug builds and auto tag generation compile 'com.jakewharton.timber:timber:4.1.0'
  • 43. 
 /** A tree which logs important information for crash reporting. */
 private static class CrashReportingTree extends Timber.Tree {
 @Override protected void log(int priority, String tag, 
 String message, Throwable t) { 
 if (priority == Log.VERBOSE || priority == Log.DEBUG) {
 return;
 }
 
 FakeCrashLibrary.log(priority, tag, message);
 
 if (t != null) {
 if (priority == Log.ERROR) {
 FakeCrashLibrary.logError(t);
 } else if (priority == Log.WARN) {
 FakeCrashLibrary.logWarning(t);
 }
 }
 }
 }
  • 44. 
 public void greetingClicked(Button button) { 
 Timber.i("A button with ID %s was clicked.", button.getId());
 //Do stuff
 }
  • 46. Hugo Annotation-triggered method call logging Generates logging code Zero effect on non-debug builds. see next slide
  • 47. buildscript {
 repositories {
 mavenCentral()
 }
 
 dependencies {
 classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
 }
 }
 
 apply plugin: 'com.android.application'
 apply plugin: 'com.jakewharton.hugo'
  • 48. 
 @DebugLog
 public String getName(String first, String last) {
 SystemClock.sleep(15); // Don't ever really do this!
 return first + " " + last;
 } 
 V/Example: ⇢ getName(first="Jake", last="Wharton")
 V/Example: ⇠ getName [16ms] = "Jake Wharton"
  • 51. wait, Java 8?!? Android 5.0 and above use Java 7 but not invokeDynamic so no Lambdas…
  • 52. Retrolambda lambda expressions method references try-with-resources statements limited support for backporting default methods and static methods on interfaces
  • 53. buildscript { repositories { mavenCentral() } dependencies { classpath 'me.tatarka:gradle-retrolambda:3.2.3' } } // Required because retrolambda is on maven central repositories { mavenCentral() } apply plugin: 'com.android.application' //or apply plugin: 'java' apply plugin: ‘me.tatarka.retrolambda' OR plugins { id "me.tatarka.retrolambda" version "3.2.3" }
  • 54. PROGUARD -dontwarn java.lang.invoke.* Android Studio build.gradle android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
  • 55. Libraries fix things… Use them only when you have a (exprected) problem… and don’t overuse them… Conclusion…