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

Don't Reinvent The Wheel ~ For All Android Begi...

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

Advice for all Android Development Beginners how to learn themself.

Avatar for Ken Wagatsuma

Ken Wagatsuma

November 23, 2015
Tweet

More Decks by Ken Wagatsuma

Other Decks in Programming

Transcript

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

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

    company : 'Recruit Technologies Co.,LTD.', profession : 'Android Development', }
  3. '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. ```java /** * Validate user id input from a form

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

    here if (userId == null || userId.length() == 0) { return; } // Validate userId } ```
  6. ```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. ```java private void validateUserId(String userId) { // Check input field

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

    here if (TextUtils.isEmpty(userId)) { return; } // Validate userId } ```
  9. ```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; } ```
  10. ```java public static boolean checkStringInput(String str) { if (str ==

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

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

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

    null || str.length() == 0) return true; else return false; } ``` android.TextUtils
  14. 1. Know Android Library 2. Use Library methods 3. See

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