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.

Alexey Buzdin

July 07, 2015
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

  1. 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. :)
  2. *Android SDK 21 ๏ JUnit ๏ TextView ๏ Activity ๏

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

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

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

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

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

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

    11536 ๏ Activity - 4658 ๏ String - 3154 ๏ ViewGroup - 5691 ๏ View - 14878 ๏ Context - 2197
  9. ImageView image = (ImageView) findViewById(R.id.image); #01 Android Y U No

    Generics? Custom wrapper; ButterKnife; Android Data Binding Solved by:
  10. How to get Window height/width? #02 Display display = getWindowManager().getDefaultDisplay();

    display.getWidth(); // deprecated display.getHeight(); // deprecated
  11. 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;
  12. 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;
  13. public void setEnabled(boolean enabled) #03 View state to Enable a

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

    view use -> public void setVisibility (int visibility) to Hide a view use ->
  15. 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 ->
  16. Who came up with this names? ActivityInstrumentationTestCase2 Log.wtf() BoringLayout UserManager

    isUserAGoat #04 public static final int removeBeforeMRelease
  17. 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
  18. #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:
  19. #07 My favourite Toast.makeText(this, "hello", 0); Toast.makeText(this, "hello", 1); <-

    2 seconds Toast.makeText(this, "hello", 2000); <- 2 seconds
  20. #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
  21. #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
  22. #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
  23. #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
  24. #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
  25. 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;