対象èªè
- Javaçµé¨è ï¼åå¿è å¯ï¼
- RxJavaæªçµé¨è
- ãªã¢ã¯ãã£ãããã°ã©ãã³ã°æªçµé¨è
RxJavaã¨ã¯
ãRxJavaã¯ãJavaã§ãªã¢ã¯ãã£ãããã°ã©ãã³ã°ãè¡ãããã®ã©ã¤ãã©ãªã§ãããã®ã©ã¤ãã©ãªã¯è»½éã§ãããã¾ããä»ã®ã©ã¤ãã©ãªã«å¯¾ããä¾åããªãã®ã§RxJavaã®jarããã¹ã«éãã ãã§ä½¿ããããã«ãªãã¾ãã対å¿ãã¦ããJavaã®ãã¼ã¸ã§ã³ã¯6ããã§ãããã«Androidããã¼ã¸ã§ã³2.3ï¼Gingerbreadï¼ãããµãã¼ããã¦ãã¾ãã
ãããã¦ãRxJavaã¯å³å¯ã«ã¯é¢æ°åãªã¢ã¯ãã£ãããã°ã©ãã³ã°ï¼Functional Reactive Programmingï¼ã§ã¯ãªãã®ã§ãããå¼æ°ã«é¢æ°åã¤ã³ã¿ã¼ãã§ã¼ã¹ãåãåãã¡ã½ããã使ã£ã¦ããã®ã§ãé¢æ°åããã°ã©ãã³ã°ã®ããã«é¢æ°ãçµã¿åããã¦ãããã¨ã§ããã¼ã¿ã®å¤æããã£ã«ã¿ãªã©ãæè»ã«çµã¿ç«ã¦ããããã«ãªã£ã¦ãã¾ãã
ãªã¢ã¯ãã£ãããã°ã©ãã³ã°ã¨ã¯
ããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã¨ã¯ããã¼ã¿ãæµããããã«æ¥ããã¨ï¼ã¹ããªã¼ã ï¼ã«çç®ãããã¼ã¿ãåãåããã³ã«é¢é£ããããã°ã©ã ãåå¿ï¼ãªã¢ã¯ã·ã§ã³ï¼ãã¦å¦çãè¡ãããã«ããããã°ã©ãã³ã°ã®èãæ¹ã§ãã
ããã®ãã¼ã¿ã®ã¹ããªã¼ã ã¨ã¯ãä¾ãã°GPSãå©ç¨ãã¦ä½ç½®æ å ±ãå¤ãããã³ã«éä¿¡ããããã¼ã¿ã®æµããã¤ã¡ã¼ã¸ãã¦ãããã¨åãããããããããã¾ããã移åãä½ç½®æ å ±ãå¤ãããã³ã«ãã¼ã¿ãéä¿¡ãããç«ã¡æ¢ã¾ãã°ãã¼ã¿ã®éä¿¡ãæ¢ã¾ãããã«ãçæããããã¼ã¿ããã¹ã¦ã¾ã¨ãã¦éä¿¡ããã®ã§ã¯ãªããåã ã®ãã¼ã¿ãçæããã度ã«é ã«éä¿¡ãã¦ããã¾ãããã®ãããªãã¼ã¿ã®æµãã®ãã¨ããã¼ã¿ã¹ããªã¼ã ã¨è¨ãã¾ãã
ããã®ãã¼ã¿ã¹ããªã¼ã ã¯ã¤ãã³ãã¨ãé¢é£ãã¦ãã¦ãæååãå ¥åããã¨ããè¡çºã¯ãå ¥åãããã¼ã¿ãé ã«çæããã¦ããã¨ã¿ããã¨ãã§ãã¾ããä¾ãã°ãabcãã¨ããå ¥åã¯ãå ¥åã®ã¤ãã³ããçºçãããã³ã«
- ãaã
- ãabã
- ãabcã
ã¨ããã¼ã¿ãçºçãã¦ããã¨è¦ãªããã¨ãã§ãã¾ããåæ§ã«ãã¿ã³ãæ¼ãè¡çºã«é¢ãã¦ããå ·ä½çãªãã¼ã¿ããªãã¦ãããã¿ã³ãæ¼ãããã¨ãããã¼ã¿ãçæããã¦ããã¨è¦ãªããã¨ãå¯è½ã§ãããã¿ã³ãè¤æ°åæ¼ããå ´åããã®æ¼ããæ°ã ãããã¿ã³ãæ¼ãããã¨ãããã¼ã¿ãçæããã¦ãããã¨ã«ãªãã¾ããã¤ã¾ãã¤ãã³ãããçºçãããã³ã«ãã¼ã¿ãçºä¿¡ãããã¼ã¿ã¹ããªã¼ã ã¨ãã¦æ±ããã¨ãå¯è½ã«ãªãã¾ãã
ããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã§ã¯ããã®ãããªãã¼ã¿ã¹ããªã¼ã ããæµãã¦ãããã¼ã¿ã«å¯¾ãããã®ãã¼ã¿ãåãåã£ãããã°ã©ã ãããã®ãã³ã«å¦çããã¦ããä½ãã«ãªã£ã¦ãã¾ããã¤ã¾ããããã°ã©ã ãå¿ è¦ãªãã¼ã¿ãèªåããåå¾ãå¦çãããã®ã§ã¯ãªããéããã¦ãããã¼ã¿ãåãåããã³ã«åå¿ãã¦å¦çãããï¼ãªã¢ã¯ãã£ããªå¦çãããï¼ãããªããã°ã©ã ã«ãããã¨ããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã«ãªãã¾ãã
ãä¾ãã°ãååä¾¡æ ¼ã¨ç¨çããç¨é¡ãè¨ç®ããããã°ã©ã ããã£ãã¨ãã¾ãããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã§ãªãå ´åãååä¾¡æ ¼ã¨ç¨çã®å¤ãåå¾ããã ãã§ã¯ä½ãèµ·ããã¾ãããå¤ãåå¾ããå¾ã«ãç¨é¡ã®è¨ç®å¦çãè¡ããã¨ããã¢ã¯ã·ã§ã³ãå®è¡ããã¦åãã¦ç¨é¡ãç®åºããã¾ããããã¦ãç¨é¡ãè¨ç®ããå¾ã«ååä¾¡æ ¼ã®å¤ãå¤ãã£ãã¨ãã¦ããåã³è¨ç®å¦çã®ã¢ã¯ã·ã§ã³ãå®è¡ãããªãéãç¨é¡ã®å¤ã¯å¤ããã¾ããã
ãããããããããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã®å ´åãååä¾¡æ ¼ã®å¤ãå¤åãããã³ã«ç¨é¡ãè¨ç®ãã表示ãããããã«ãªãã¾ããããã¯ååä¾¡æ ¼ã®å¤ãå¤åãããã³ã«ç¨é¡ãè¨ç®ããããã°ã©ã ã«å¤ãéä¿¡ãããããã°ã©ã ãå¤ãåãåãã¨ç¨é¡ã®è¨ç®å¦çãè¡ãããã®è¨ç®çµæãç¨é¡ã«åæ ãããããã§ãããã®ãããååä¾¡æ ¼ã®å¤ãå¤ãããã³ã«ååä¾¡æ ¼ãéç¥ãããç¨é¡ãèªåçã«ç®åºãããããã«ãªãã¾ãã
ãããã ãã ã¨ãååä¾¡æ ¼ã«Listenerãã¤ãã¦èªåã§è¨ç®ã§ããããã«ããããã°ã©ã ã¨ã©ãéãã®ãçåã«æãããããããã¾ããããã®å ´åããªã¢ã¯ãã£ãããã°ã©ãã³ã°ãªã®ãã©ããã¯ãä½ãå¦çãè¡ãã®ãã®æèã®éãã«ãªããã¨èãããã¾ããä¾ãã°ãååä¾¡æ ¼ãå¤æ´ããListenerãåå¿ãã¦ãååä¾¡æ ¼ãç¨é¡ãè¨ç®ãã¦å¤ãåæ ãã¦ããã¨ããæèã®å ´åã¯ããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã®èãæ¹ã«ã¯ãªãã¾ããã
ããããListenerãåå¿ãããã¨ã«ãã£ã¦ãç¨é¡ã«æ°ããªååä¾¡æ ¼ã渡ãããç¨é¡ã«ã¦è¨ç®ã®ããã°ã©ã ãå®è¡ããã¦ããã®çµæãç¨é¡èªèº«ã«åæ ãã¦ããã¨æèãã¦ããå ´åã¯ããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã®èãæ¹ã«ãªãã¾ãã
ããã®ãããä»åã®ãããªç°¡åãªããã°ã©ã ã®å ´åã¯ãåè ãå¾è ãã½ã¼ã¹ã³ã¼ãä¸ã§ã¯ã¾ã£ããåãã«ãªãå¯è½æ§ã¯ããã¾ãããããããã®ããã°ã©ãã³ã°ä¸ã®èãæ¹ã®éãã«ãã£ã¦ãã©ã®ããã°ã©ã ãä½ãããã®ãã®ç¯å²ãå¤ãã£ã¦ãã¾ããè¡ãã¹ãå¦çãè¤éã«ãªã£ã¦ããããååä¾¡æ ¼ã®å¤æ´ã«ãã£ã¦å¤ãå¤ããé ç®ãå¢ãã¦ãããããã«ã¤ããã©ãã§å¦çãè¡ãã®ãã®æ¯éãå¤ãããã½ã¼ã¹ã³ã¼ãä¸ã«ãéããç¾ãã¦ããã§ãããã
ããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã§ã¯ããã¼ã¿ã®çç£å´ï¼ä»åã®ä¾ã§ã¯ååä¾¡æ ¼ï¼ã¯ãã¼ã¿ã渡ãã¨ããã¾ã§ãèªèº«ã®è²¬ä»»ã«ãªãã¾ãããã®ããããã¼ã¿ã®çç£å´ã¯ãã¼ã¿ã®æ¶è²»å´ï¼ä»åã®ä¾ã§ã¯ç¨é¡ï¼ã®å¦çã«ã¤ãã¦ã¯ãã®ãã¼ã¿ã使ã£ã¦ä½ããã¦ããã®ããæèããªãã¦ããããªãã¾ããããã¦ãã®ãã¨ã¯ããã¼ã¿ã®çç£å´ã¯æ¶è²»å´ã§ä½ããã¦ããã®ãã¯é¢ä¿ããªããªããæ¶è²»å´ã®å¦çãå¾ ã¤å¿ è¦ããªããªãã®ã§ããã¼ã¿ã®éç¥ãããå¾ã«ãæ¶è²»å´ã®å¦çãéä¸ã§ãã£ã¦ããããã«çç£å´ã®æ¬¡ã®å¦çãè¡ãã¾ãããããããã¨ã§éåæå¦çã容æã«å®ç¾ã§ããããã«ãªãã¾ãã
ãã¾ããã·ã¹ãã ã®æ§ç¯ã¨ããç¹ã§è¦ã¦ãããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã®èãæ¹ã¯ãã¤ã¯ããµã¼ãã¹ãªã©ã®åæ£ã·ã¹ãã ã§ç¨¼åããããã°ã©ã ã«ãåãã¦ãããç¾å¨å¤§ããªæ³¨ç®ãæµ´ã³ã¦ããããã°ã©ãã³ã°ææ³ã®ä¸ã¤ã«ãªã£ã¦ãã¾ãã
ããã ããç´ãããããã¨ã«ãããªã¢ã¯ãã£ãã·ã¹ãã ãã¨è¨ã£ãå ´åãããªã¢ã¯ãã£ãããã°ã©ãã³ã°ã§å®è£ ãããã·ã¹ãã ãã®ãã¨ã表ããªããã¨ã«æ³¨æããªãã¨ããã¾ããããªã¢ã¯ãã£ãã·ã¹ãã ã¨ã¯ãç°¡åã«èª¬æããã¨ãã¡ãã»ã¼ã¸ãéããã¨ã§å¦çãè¡ããç¶æ³ã«å¿ãã¦ã¹ã±ã¼ã«ã¢ã¦ããã¹ã±ã¼ã«ã¤ã³ãèªåã§è¡ãããé害ã®èæ§ãé«ãããã¨ã«ãã£ã¦ã常ã«è¿ éãªå¿çãå¾ããã¨ãã§ããã·ã¹ãã ã®ãã¨ãè¨ãã¾ãããã®ããããã®ãªã¢ã¯ãã£ãã·ã¹ãã ã¯ããã°ã©ã ã ãã§ã¯ãªãã¤ã³ãã©ã®æ¡ä»¶ãå¿ è¦ã¨ãªãã¾ããããã¦åãµã¼ãã¹ã«å¯¾ãã¦ã¯å¥ã«ãªã¢ã¯ãã£ãããã°ã©ãã³ã°ã§å®è£ ãã¦ããªãã¦ãããªã¢ã¯ãã£ãã·ã¹ãã ã®æ§ç¯ã¯å¯è½ã§ãããã¾ãã