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. 5.

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

    company : 'Recruit Technologies Co.,LTD.', }
  2. 6.

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

    company : 'Recruit Technologies Co.,LTD.', profession : 'Android Development', }
  3. 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' } }
  4. 9.

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

    * * @param String userID */ private void validateUserId(String userId) { // Validate userId } ```
  5. 10.

    ```java private void validateUserId(String userId) { // Check input field

    here if (userId == null || userId.length() == 0) { return; } // Validate userId } ```
  6. 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 // ... } } ```
  7. 13.
  8. 14.
  9. 15.

    ```java private void validateUserId(String userId) { // Check input field

    here if (userId == null || userId.length() == 0) { return; } // Validate userId } ```
  10. 16.

    ```java private void validateUserId(String userId) { // Check input field

    here if (TextUtils.isEmpty(userId)) { return; } // Validate userId } ```
  11. 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; } ```
  12. 19.
  13. 21.

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

    null || str.length() == 0) { return true; } else { return false; } } ``` My Code
  14. 22.

    ```java public static boolean isEmpty(CharSequence str) { if (str ==

    null || str.length() == 0) return true; else return false; } ``` android.TextUtils
  15. 23.

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

    null || str.length() == 0) { return true; } else { return false; } } ``` My Code
  16. 24.

    ```java public static boolean isEmpty(CharSequence str) { if (str ==

    null || str.length() == 0) return true; else return false; } ``` android.TextUtils
  17. 33.

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

    & Understand source codes 3 Steps for Learning,
  18. 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.*
  19. 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; } ```
  20. 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(); }
  21. 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; } ```
  22. 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 + ")"; } ```
  23. 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("<<<<<"); } ```
  24. 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("}"); } ```