Slide 1

Slide 1 text

Don’t Reinvent The Wheel Kenju Wagatsuma

Slide 2

Slide 2 text

Agenda: -> ❖ 1m : Introduction ❖ 3m : Main part ❖ 1m : Conclusion

Slide 3

Slide 3 text

/** * Introduce Myself * * @kenjuwagatsuma */

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

'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' } }

Slide 8

Slide 8 text

/** * My Story * * @author me */

Slide 9

Slide 9 text

```java /** * Validate user id input from a form * * @param String userID */ private void validateUserId(String userId) { // Validate userId } ```

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

```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 // ... } } ```

Slide 12

Slide 12 text

/** * @codereview * */

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

```java private void validateUserId(String userId) { // Check input field here if (TextUtils.isEmpty(userId)) { return; } // Validate userId } ```

Slide 17

Slide 17 text

Okay, I’ll look at the source code, sir…

Slide 18

Slide 18 text

```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; } ```

Slide 19

Slide 19 text

……

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

……ʮ͍ͬ͠ΐ΍Μ͚wʯ(࠶)

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

/** * So what? * * @return Conclusion */

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

1. Know Android Library 2. Use Library methods 3. See & Understand source codes 3 Steps for Learning,

Slide 34

Slide 34 text

/** * Appendix * */

Slide 35

Slide 35 text

❖ android.text.format.DateUtils ❖ android.text.format.Formatter ❖ android.text.TextUtils ❖ android.text.util.Linkify ❖ android.util.Pair ❖ android.util.SparseArray ❖ android.util.Log ❖ android.util.LruCache ❖ android.graphics.Color ❖ android.media.ThumbnailUtils android.*

Slide 36

Slide 36 text

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; } ```

Slide 37

Slide 37 text

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("<"); break; //...ͦͷଞͷΤϯίʔυ͢΂͖จࣈ default: sb.append(c); } } return sb.toString(); }

Slide 38

Slide 38 text

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; } ```

Slide 39

Slide 39 text

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 + ")"; } ```

Slide 40

Slide 40 text

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("<<<<<"); } ```

Slide 41

Slide 41 text

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 = ""; } stream.println(" " + cols[i] + '=' + value); } stream.println("}"); } ```

Slide 42

Slide 42 text

/** * And Much More! * * Happy Coding! * */