Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android WAT?!?

Android WAT?!?

Android is a great piece of machinery as a platform, but one thing it which it fails hard is its API. In his short talk Alexey will nag about some brain exploading APIs that he stumble upon during his experience with Android. Expect some brain teasers, quizes and fun trivia.

12d6ff93ca25d366161efccadd81bbb2?s=128

Alexey Buzdin

July 07, 2015
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

  1. Android WAT?!? by Alexey Buzdin

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

    about Android
  3. Alexey Buzdin

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

  5. 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. :)
  6. “Writing API is tough, writing good ones is an art”

    quote: me
  7. *Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏

    String ๏ ViewGroup ๏ View ๏ Context
  8. "Java Code Conventions”: Files longer than 2000 lines are cumbersome

    and should be avoided.
  9. *Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏

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

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

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

    String - 3154 ๏ ViewGroup ๏ View ๏ Context - 2197
  13. *Android SDK 21 ๏ JUnit ๏ TextView - 11536 ๏

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

    11536 ๏ Activity - 4658 ๏ String - 3154 ๏ ViewGroup - 5691 ๏ View - 14878 ๏ Context - 2197
  15. #01 Android Y U No Generics?

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

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

    Generics? Custom wrapper; ButterKnife; Android Data Binding Solved by:
  18. How to get Window height/width? #02

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

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

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

    display.getWidth(); // deprecated display.getHeight(); // deprecated
  22. 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;
  23. 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;
  24. #03 View state

  25. #03 View state to Enable a view use ->

  26. public void setEnabled(boolean enabled) #03 View state to Enable a

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

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

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

    view use -> public void setVisibility (int visibility) to Hide a view use ->
  30. 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 ->
  31. Who came up with this names? #04

  32. Who came up with this names? BoringLayout #04

  33. Who came up with this names? ActivityInstrumentationTestCase2 BoringLayout #04

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

  35. Who came up with this names? ActivityInstrumentationTestCase2 Log.wtf() BoringLayout UserManager

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

    isUserAGoat #04 public static final int removeBeforeMRelease
  37. None
  38. Do you like nulls? #05

  39. Drawable drw = getResources().getDrawable(R.drawable.btn); btn.setCompoundDrawables(drw, null, null, null); Do you

    like nulls? #05
  40. 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
  41. #06 The Cake is a lie!

  42. #06 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(pathToMyPdf)); intent.setType("application/pdf"); startActivity(intent); The

    Cake is a lie!
  43. #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:
  44. #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:
  45. #07 My favourite Toast.makeText(this, "hello", 2000);

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

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

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

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

    2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds
  50. #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
  51. #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
  52. #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
  53. #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
  54. #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
  55. 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;
  56. The END! ››˘›ʣ›ớᵲᴸᵲ