Slide 1

Slide 1 text

Kickstart your Android development DINO KOVAČ ANDROID TEAM LEAD

Slide 2

Slide 2 text

ABOUT INFINUM • independent design and development agency • 90 employees • 15 Android Engineers • hundreds of projects

Slide 3

Slide 3 text

01 ANDROID STUDIO 2.0

Slide 4

Slide 4 text

SHORTCUTS • CTRL + SHIFT + A → find action • SHIFT + F6 → rename • ALT + F7 → find usages • CTRL + SHIFT + O → open file

Slide 5

Slide 5 text

DEBUGGER

Slide 6

Slide 6 text

EVALUATE EXPRESSION

Slide 7

Slide 7 text

PROFILING TOOLS • find bottlenecks in the app • identify memory leaks

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

02 ANDROID EMULATOR 2.0

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

03 DEBUGGING LAYOUTS

Slide 13

Slide 13 text

DEVELOPER TOOLS ON DEVICE • to enable press build number 7 times (Settings - About phone) • you get a bunch of useful options

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

HIERARCHY VIEWER • inspect your view hierarchy at runtime • profile measure/layout/draw and find bottlenecks • comes with Android SDK

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

04 LIBRARIES

Slide 19

Slide 19 text

GLIDE • simple image loading library • built-in caching • animated gifs! • https://github.com/bumptech/glide Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);

Slide 20

Slide 20 text

OKHTTP • fast, well-tested and maintained http client • many features (spdy and http/2 support, websockets, …) • nice API (as opposed to HttpURLConnection) • http://square.github.io/okhttp/

Slide 21

Slide 21 text

GSON • JSON (de)serialization library from Google • Java objects <=> JSON string

Slide 22

Slide 22 text

{
 "id": "2GC3t5Un6d1BEF5a6BTYo05jYCfv7OYcLvAJqxwRGPxT8xH1oY9ivM7uBFoY5Cvf",
 "ttl": 1209600,
 "userId": "565dc7fe6ebcd2f77e040728"
 }

Slide 23

Slide 23 text

public class LoginResponse implements Serializable {
 
 @SerializedName("id")
 private String accessToken;
 
 @SerializedName("userId")
 private String userId;
 
 @SerializedName("ttl")
 private int timeToLive;
 
 public String getAccessToken() {
 return accessToken;
 }
 
 public String getUserId() {
 return userId;
 }
 
 public int getTimeToLive() {
 return timeToLive;
 }
 }

Slide 24

Slide 24 text

RETROFIT • ‘turns your HTTP API into a Java interface’ • http://square.github.io/retrofit/

Slide 25

Slide 25 text

public interface ApiService {
 
 @POST("/api/users/login")
 Call authenticateUser(@Body LoginRequest loginRequest);
 
 @POST("/api/users")
 Call registerUser(@Body RegisterRequest registerRequest);
 
 @GET("/api/users/{userId}/timezones")
 Call> getTimezones(@Path("userId") String userId);
 
 @DELETE("/api/users/{userId}/timezones/{timezoneId}")
 Call deleteTimezone(@Path("userId") String userId, @Path("timezoneId") String timezoneId);
 
 @POST("/api/users/{userId}/timezones")
 Call createTimezone(@Path("userId") String userId, @Body Timezone timezone);
 
 @GET("/api/users")
 Call> getUsers();
 
 @PUT("/api/users/{userId}")
 Call updateUser(@Path("userId") String userId, @Body User user);
 
 @DELETE("/api/users/{userId}")
 Call deleteUser(@Path("userId") String userId);
 
 @GET("/api/users/{userId}/roles")
 Call> getUserRoles(@Path("userId") String userId); }

Slide 26

Slide 26 text

BUTTERKNIFE • reduces boilerplate code to get view references • generates similar code to what you would write • also does resource binding (strings, drawables, colors, …) • http://jakewharton.github.io/butterknife/

Slide 27

Slide 27 text

WITHOUT BUTTERKNIFE TextView helloText;
 TextView secondHelloText;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main); secondHelloText = (TextView) findViewById(R.id.text_hello2);
 secondHelloText.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 // TODO
 }
 }); helloText = (TextView) findViewById(R.id.text_hello); // TODO
 }

Slide 28

Slide 28 text

WITH BUTTERKNIFE // build.gradle compile 'com.jakewharton:butterknife:7.0.1' // MainActivity.java @Bind(R.id.text_hello2)
 TextView secondHelloText;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 ButterKnife.bind(this); // TODO
 }
 
 @OnClick(R.id.text_hello)
 protected void onHelloClicked() {
 // TODO
 }

Slide 29

Slide 29 text

HUGO • Annotation-triggered method call logging • https://github.com/JakeWharton/hugo @DebugLog
 public String getName() {
 return name;
 } V/EXAMPLE: ⇢ GETNAME() V/EXAMPLE: ⇠ GETNAME [0MS] = "JAKE WHARTON"

Slide 30

Slide 30 text

DBFLOW • ORM library with annotation processing • generates code for interaction with SQLite databases so you don’t have to write it by hand

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

DBINSPECTOR • adds additional launcher icon for viewing db contents and schema • great for debugging db issues • https://github.com/infinum/android_dbinspector/

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

THREETEN-ABP • backport of the new Date API introduced in Java 8 (JSR-310) • https://github.com/JakeWharton/ThreeTenABP

Slide 35

Slide 35 text

LEAK CANARY • automatically detect common classes of memory leaks • https://github.com/square/leakcanary

Slide 36

Slide 36 text

MAGIC VIEWS • easily use custom fonts in your app • https://github.com/ikocijan/MagicViews

Slide 37

Slide 37 text

05 STAYING UP TO DATE

Slide 38

Slide 38 text

• Jake Wharton • Reto Meier • Cyril Mottier • Dan Lew • Chris Banes • Mark Murphy • Mark Allison PEOPLE TO FOLLOW

Slide 39

Slide 39 text

NEWSLETTERS TO READ • https://androidsweets.ongoodbits.com/ • http://androidweekly.net/

Slide 40

Slide 40 text

Use the source, Luke!

Slide 41

Slide 41 text

INFINUM ANDROID TALKS • http://www.meetup.com/Infinum-Android-Talks-Zagreb/ • new libs • practical tips • a place to ask for advice • next event: 7.4.2016. at 18h CET (Strojarska 22)

Slide 42

Slide 42 text

REFERENCES • http://developer.android.com/sdk/installing/studio- tips.html • http://stackoverflow.com/questions/294167/what-are- the-most-useful-intellij-idea-keyboard-shortcuts • http://developer.android.com/tools/debugging/ debugging-ui.html

Slide 43

Slide 43 text

Any questions? [email protected] @DINO_BLACKSMITH Visit infinum.co or find us on social networks: infinum.co infinumco infinumco infinum