Don't Reinvent The Wheel ~ For All Android Beginners ~

Don't Reinvent The Wheel ~ For All Android Beginners ~

Advice for all Android Development Beginners how to learn themself.

3b36493b4296ebeb219bcd3ffab3aa2b?s=128

Kenju Wagatsuma

November 23, 2015
Tweet

Transcript

  1. Don’t Reinvent The Wheel Kenju Wagatsuma

  2. Agenda: -> ❖ 1m : Introduction ❖ 3m : Main

    part ❖ 1m : Conclusion
  3. /** * Introduce Myself * * @kenjuwagatsuma */

  4. 'me' = { name : 'Kenju Wagatsuma ( KJ )’,

    }
  5. 'me' = { name : 'Kenju Wagatsuma ( KJ )’,

    company : 'Recruit Technologies Co.,LTD.', }
  6. 'me' = { name : 'Kenju Wagatsuma ( KJ )’,

    company : 'Recruit Technologies Co.,LTD.', profession : 'Android Development', }
  7. 'me' = { name : 'Kenju Wagatsuma ( KJ )’,

    company : 'Recruit Technologies Co.,LTD.', profession : 'Android Development', favs : { 'Book' : ‘Soft Skills', 'Music' : ‘The Beatles', 'Hobby' : ‘Acoustic Guitar', 'Sport' : 'Rugby' } }
  8. /** * My Story * * @author me */

  9. ```java /** * Validate user id input from a form

    * * @param String userID */ private void validateUserId(String userId) { // Validate userId } ```
  10. ```java private void validateUserId(String userId) { // Check input field

    here if (userId == null || userId.length() == 0) { return; } // Validate userId } ```
  11. ```java // Utility class public static class UtilClass { public

    static boolean checkStringInput(String str) { if (str == null || str.length() == 0) { return true; } else { return false; } } } // Activity class public void MainActivity extends Activity { private void validateUserId(String userId) { if(UtilClass.checkStringInput(userId)) return; // Validate userId // ... } } ```
  12. /** * @codereview * */

  13. None
  14. None
  15. ```java private void validateUserId(String userId) { // Check input field

    here if (userId == null || userId.length() == 0) { return; } // Validate userId } ```
  16. ```java private void validateUserId(String userId) { // Check input field

    here if (TextUtils.isEmpty(userId)) { return; } // Validate userId } ```
  17. Okay, I’ll look at the source code, sir…

  18. ```java /** * Returns true if the string is null

    or 0-length. * @param str the string to be examined * @return true if str is null or zero length */ public static boolean isEmpty(CharSequence str) { if (str == null || str.length() == 0) return true; else return false; } ```
  19. ……

  20. ……ʮ͍ͬ͠ΐ΍Μ͚wʯ

  21. ```java public static boolean checkStringInput(String str) { if (str ==

    null || str.length() == 0) { return true; } else { return false; } } ``` My Code
  22. ```java public static boolean isEmpty(CharSequence str) { if (str ==

    null || str.length() == 0) return true; else return false; } ``` android.TextUtils
  23. ```java public static boolean checkStringInput(String str) { if (str ==

    null || str.length() == 0) { return true; } else { return false; } } ``` My Code
  24. ```java public static boolean isEmpty(CharSequence str) { if (str ==

    null || str.length() == 0) return true; else return false; } ``` android.TextUtils
  25. ……ʮ͍ͬ͠ΐ΍Μ͚wʯ(࠶)

  26. /** * Why TextUtils? * (not my own code) *

    */
  27. #47 ʮϥΠϒϥϦʔΛ஌Γɺ ϥΠϒϥϦʔΛ࢖͏ʯ “Effective Java” 2nd Edition

  28. #47 ʮϥΠϒϥϦʔΛ஌ΓɺϥΠϒϥϦʔΛ࢖͏ʯ ར఺̍ ❖ ඪ४ϥΠϒϥϦΛ࢖༻͢Δ͜ͱͰɺͦΕΛॻ͍ ͨઐ໳Ոͷ஌ࣝͱɺͦΕΛ͋ͳͨΑΓ΋લʹ࢖༻ ͨ͠ਓʑͷܦݧΛར༻͢Δ͜ͱʹͳΓ·͢ɻ “Effective Java” 2nd

    Edition
  29. #47 ʮϥΠϒϥϦʔΛ஌ΓɺϥΠϒϥϦʔΛ࢖͏ʯ ར఺̎ ❖ ࣗ෼ͷ՝୊ʹগ͠͹͔Γؔ࿈͍ͯ͠Δ໰୊ʹର ͢Δ৔౰ͨΓతͳղܾࡦΛॻ͘͜ͱͰɺ࣌ؒΛແ ବʹ͢Δඞཁ͕ແ͍ɻ “Effective Java” 2nd

    Edition
  30. #47 ʮϥΠϒϥϦʔΛ஌ΓɺϥΠϒϥϦʔΛ࢖͏ʯ ར఺̏ ❖ ࣗ෼Ͱ͸Կ΋͠ͳͯ͘΋ɺଟ͘ͷਓʹΑͬͯ܁ Γฦ͠ॻ͖௚͞ΕΔίʔυ͸ɺ࣌ؒͱڞʹύ ϑΥʔϚϯε͕վળ͞ΕΔʢࣗ෼ͷίʔυͰ͸ͦ ͏͸͍͔ͳ͍ʣɻ “Effective Java”

    2nd Edition
  31. /** * So what? * * @return Conclusion */

  32. #47 ʮϥΠϒϥϦʔΛ஌ΓɺϥΠϒϥϦʔΛ࢖͏ʯ For All Beginners,

  33. 1. Know Android Library 2. Use Library methods 3. See

    & Understand source codes 3 Steps for Learning,
  34. /** * Appendix * */

  35. ❖ android.text.format.DateUtils ❖ android.text.format.Formatter ❖ android.text.TextUtils ❖ android.text.util.Linkify ❖ android.util.Pair<F,

    S> ❖ android.util.SparseArray<E> ❖ android.util.Log ❖ android.util.LruCache ❖ android.graphics.Color ❖ android.media.ThumbnailUtils android.*
  36. android.text.TextUtils ```java /** * ༩͑ΒΕͨจࣈྻ͕͢΂ͯ਺஋͔Ͳ͏͔Λ൑ఆ */ public static boolean isDigitsOnly(CharSequence

    str) { final int len = str.length(); for (int i = 0; i< len; i++) { if (!Character.isDigit(str.charAt(i)) { return false; } } return true; } ```
  37. android.text.TextUtils ```java /** * HTMLΤϯίʔυ */ public static boolean htmlEncode(String

    s) { StringBuilder sb = new StringBuilder(); char c; for (int i = 0; i < s.length(); i++) { c = s.charAt(i); switch(c) { case '<': sb.append("&lt;"); break; //...ͦͷଞͷΤϯίʔυ͢΂͖จࣈ default: sb.append(c); } } return sb.toString(); }
  38. android.text.TextUtils ```java /** * trim()Ͱ࡟আ͞Εۭͨനͷ਺Λฦ͠·͢ */ public static int getTrimmedLength(CharSequence

    s) { int len = s.length(); int start = 0; while (start < len && s.charAt(start) <= ' ') { start++; } int end = 0; while (end > start && s.charAt(end - 1) <= ' ') { end--; } return end - start; } ```
  39. android.database.DatabaseUtils ```java /** * WHERE۟࡞੒ͷϔϧύʔϝιου */ public static String concatenateWhere(String

    a, String b) { if (TextUtils.isEmpty(a)) { return b; } if (TextUtils.isEmpty(b)) { return a; } return "(" + a + ") AND (" + b + ")"; } ```
  40. android.database.DatabaseUtils ```java /** * Cursorͷத਎Λग़ྗ͢Δσόοά༻ϝιου */ public static void dumpCursor(Cursor

    cursor) { dumpCursor(cursor, System.out); } public static void dumpCursor(Cursor cursor, PrintStream stream) { stream.println(">>>>> Dumping cursor " + cursor); if (cursor != null) { int startPos = cursor.getPosition(); cursor.moveToPosition(-1); while (cursor.moveToNext()) { dumpCurrentRow(cursor, stream); } cursor.moveToPosition(startPos); } stream.println("<<<<<"); } ```
  41. android.database.DatabaseUtils ```java /** * CursorͷݱࡏͷߦΛग़ྗ͢Δ */ public static void dumpCurrentRow(Cursor

    cursor, PrintStream stream) { String[] cols = cursor.getColumnNames(); stream.println("" + cursor.getPosition() + " {"); int length = cols.length; for (int i = 0; i < length; i++) { String value; try { value = cursor.getString(i); } catch (SQLiteException e) { value = "<unprintable>"; } stream.println(" " + cols[i] + '=' + value); } stream.println("}"); } ```
  42. /** * And Much More! * * Happy Coding! *

    */