Slide 1

Slide 1 text

Android WAT?!? by Alexey Buzdin

Slide 2

Slide 2 text

Android WAT?!? by Alexey Buzdin *aka 7 things I like about Android

Slide 3

Slide 3 text

Alexey Buzdin

Slide 4

Slide 4 text

WAT Gary Bernhardt @garybernhardt https://www.destroyallsoftware.com/talks/wat 2012 inspired by

Slide 5

Slide 5 text

DISCLAIMER All characters, events, thoughts and ideas used in this presentation — even those based on real life — are entirely fictional and purely subjective to speaker opinion. :)

Slide 6

Slide 6 text

“Writing API is tough, writing good ones is an art” quote: me

Slide 7

Slide 7 text

*Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏ String ๏ ViewGroup ๏ View ๏ Context

Slide 8

Slide 8 text

"Java Code Conventions”: Files longer than 2000 lines are cumbersome and should be avoided.

Slide 9

Slide 9 text

*Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏ String ๏ ViewGroup ๏ View ๏ Context

Slide 10

Slide 10 text

*Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏ String ๏ ViewGroup ๏ View ๏ Context - 2197

Slide 11

Slide 11 text

*Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏ String ๏ ViewGroup ๏ View ๏ Context - 2197

Slide 12

Slide 12 text

*Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏ String - 3154 ๏ ViewGroup ๏ View ๏ Context - 2197

Slide 13

Slide 13 text

*Android SDK 21 ๏ JUnit ๏ TextView - 11536 ๏ Activity ๏ String - 3154 ๏ ViewGroup ๏ View - 14878 ๏ Context - 2197

Slide 14

Slide 14 text

*Android SDK 21 ๏ JUnit - 5756 ๏ TextView - 11536 ๏ Activity - 4658 ๏ String - 3154 ๏ ViewGroup - 5691 ๏ View - 14878 ๏ Context - 2197

Slide 15

Slide 15 text

#01 Android Y U No Generics?

Slide 16

Slide 16 text

ImageView image = (ImageView) findViewById(R.id.image); #01 Android Y U No Generics?

Slide 17

Slide 17 text

ImageView image = (ImageView) findViewById(R.id.image); #01 Android Y U No Generics? Custom wrapper; ButterKnife; Android Data Binding Solved by:

Slide 18

Slide 18 text

How to get Window height/width? #02

Slide 19

Slide 19 text

How to get Window height/width? #02 Display display = getWindowManager().getDefaultDisplay();

Slide 20

Slide 20 text

How to get Window height/width? #02 Display display = getWindowManager().getDefaultDisplay(); display.getWidth(); display.getHeight();

Slide 21

Slide 21 text

How to get Window height/width? #02 Display display = getWindowManager().getDefaultDisplay(); display.getWidth(); // deprecated display.getHeight(); // deprecated

Slide 22

Slide 22 text

How to get Window height/width? #02 Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y;

Slide 23

Slide 23 text

How to get Window height/width? #02 Tuple out parameter srsly? Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y;

Slide 24

Slide 24 text

#03 View state

Slide 25

Slide 25 text

#03 View state to Enable a view use ->

Slide 26

Slide 26 text

public void setEnabled(boolean enabled) #03 View state to Enable a view use ->

Slide 27

Slide 27 text

public void setEnabled(boolean enabled) #03 View state to Enable a view use -> to Hide a view use ->

Slide 28

Slide 28 text

public void setEnabled(boolean enabled) #03 View state to Enable a view use -> public void setVisib…. to Hide a view use ->

Slide 29

Slide 29 text

public void setEnabled(boolean enabled) #03 View state to Enable a view use -> public void setVisibility (int visibility) to Hide a view use ->

Slide 30

Slide 30 text

Enums, what enums? public void setEnabled(boolean enabled) #03 View state to Enable a view use -> public void setVisibility (int visibility) One of VISIBLE, INVISIBLE, or GONE. to Hide a view use ->

Slide 31

Slide 31 text

Who came up with this names? #04

Slide 32

Slide 32 text

Who came up with this names? BoringLayout #04

Slide 33

Slide 33 text

Who came up with this names? ActivityInstrumentationTestCase2 BoringLayout #04

Slide 34

Slide 34 text

Who came up with this names? ActivityInstrumentationTestCase2 Log.wtf() BoringLayout #04

Slide 35

Slide 35 text

Who came up with this names? ActivityInstrumentationTestCase2 Log.wtf() BoringLayout UserManager isUserAGoat #04

Slide 36

Slide 36 text

Who came up with this names? ActivityInstrumentationTestCase2 Log.wtf() BoringLayout UserManager isUserAGoat #04 public static final int removeBeforeMRelease

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Do you like nulls? #05

Slide 39

Slide 39 text

Drawable drw = getResources().getDrawable(R.drawable.btn); btn.setCompoundDrawables(drw, null, null, null); Do you like nulls? #05

Slide 40

Slide 40 text

Drawable drw = getResources().getDrawable(R.drawable.btn); btn.setCompoundDrawables(drw, null, null, null); Do you like nulls? SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CONTACTS, new String[] {KEY_ID, KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",new String[] { String.valueOf(id) }, null, null, null, null); #05 or

Slide 41

Slide 41 text

#06 The Cake is a lie!

Slide 42

Slide 42 text

#06 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(pathToMyPdf)); intent.setType("application/pdf"); startActivity(intent); The Cake is a lie!

Slide 43

Slide 43 text

#06 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(pathToMyPdf)); intent.setType("application/pdf"); startActivity(intent); The Cake is a lie! don’t work… Instead:

Slide 44

Slide 44 text

#06 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(pathToMyPdf)); intent.setType("application/pdf"); startActivity(intent); Intent intent = new Intent(Intent.ACTION_VIEW); intent. setDataAndType(Uri.parse(pathToMyPdf), "application/pdf"); startActivity(intent); The Cake is a lie! don’t work… Instead:

Slide 45

Slide 45 text

#07 My favourite Toast.makeText(this, "hello", 2000);

Slide 46

Slide 46 text

#07 My favourite Toast.makeText(this, "hello", 2000); <- 2 seconds

Slide 47

Slide 47 text

#07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 2000); <- 2 seconds

Slide 48

Slide 48 text

#07 My favourite Toast.makeText(this, "hello", 0); <- 2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds

Slide 49

Slide 49 text

#07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 1); <- 2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds

Slide 50

Slide 50 text

#07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 1); <- 2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds <- 3.5 seconds

Slide 51

Slide 51 text

#07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 1000); Toast.makeText(this, "hello", 1); <- 2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds <- 3.5 seconds

Slide 52

Slide 52 text

#07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 1000); Toast.makeText(this, "hello", 1); <- 2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds <- 2 seconds <- 3.5 seconds

Slide 53

Slide 53 text

#07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 10000); Toast.makeText(this, "hello", 1000); Toast.makeText(this, "hello", 1); <- 2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds <- 2 seconds <- 3.5 seconds

Slide 54

Slide 54 text

#07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 10000); Toast.makeText(this, "hello", 1000); Toast.makeText(this, "hello", 1); <- 2 seconds <- 2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds <- 2 seconds <- 3.5 seconds

Slide 55

Slide 55 text

NotificationManagerService.scheduleTimeoutLocked() { … long delay = r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY; … } private static final int LONG_DELAY = 3500; // 3.5 seconds private static final int SHORT_DELAY = 2000; // 2 seconds public static final int LENGTH_SHORT = 0; public static final int LENGTH_LONG = 1;

Slide 56

Slide 56 text

The END! ››˘›ʣ›ớᵲᴸᵲ