ãã®èšäºã§ã¯ãAndroidçšã®ã¢ããªã±ãŒã·ã§ã³ãäœæããéã®äž»ãªåé¡ã«ã€ããŠèª¬æããŸãã
Androidããã°ã©ãã³ã°ã®åºæ¬æŠå¿µãèæ
®ãããŸãã
ããšãã°ãã
HelloãAndroid-Ed Burnette ããšããæ¬ããæ°ç¬ã²ãŒã ãäœæããããš
ã説æãããŠããŸãã
å€ãã®ã¹ã¯ãªãŒã³ã·ã§ããã«æ³šæããŠãã ããã
1.éçºã®é£ããAndroidã¯ãŠããŒã¯ãªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ãã ã¢ããªã±ãŒã·ã§ã³éçºè
ã¯ãè¯ãçµæãåŸãããã«ããã®æ©èœãšãã¥ã¢ã³ã¹ãç¥ã£ãŠããå¿
èŠããããŸãã éçºæã«èæ
®ãã¹ãããã€ãã®å°é£ããããŸãïŒ
ãã¡ãã®èª¬æãã芧ãã ãã ïŒã ããããç°¡åã«ãªã¹ãããŸãã
1ïŒã¢ããªã±ãŒã·ã§ã³ã¯ãã¢ããªã±ãŒã·ã§ã³ã®å
ã®ãµã€ãºã®2åïŒãŸãã¯4åïŒä»¥äžã®ã¹ããŒã¹ãã€ã³ã¹ããŒã«ããå¿
èŠããããŸãã
2ïŒå
èµãã©ãã·ã¥ãã©ã€ãäžã®ãã¡ã€ã«ã®åŠçé床ã¯ã空ãé åãå°ãªããªããšæ°ååäœäžããŸãã
3ïŒåããã»ã¹ã¯ãæ倧16 MBïŒå Žåã«ãã£ãŠã¯24 MBïŒã®RAMã䜿çšã§ããŸãã
2. Androidçšã®çç£çãªã¢ããªã±ãŒã·ã§ã³ã®éçºã®ååAndroidçšã®çç£çãªã¢ããªã±ãŒã·ã§ã³ãäœæããããã®
æšå¥šäºé
ãããã€ããããŸãã ãããã¯ãEffective Java-Joshua Blochããã³ããã°ã©ãã³ã°ãã©ãããã©ãŒã äžã®ã¢ãã€ã«ããã€ã¹ã®æžç±Net Compact Framework-I. Salmreã«åºã¥ããŠæ¡åŒµããããšãã§ããŸãã
Androidåãã®çç£çãªã¢ããªã±ãŒã·ã§ã³ãéçºããããã®åºæ¬ååããªã¹ãããŸãã
æŠç¥çïŒ1ïŒãªãœãŒã¹ãä¿åããå¿
èŠããããŸãã
2ïŒã¢ã¯ã·ã§ã³ã«å¯ŸããŠå³åº§ã«åå¿ã瀺ãããŠãŒã¶ãŒãšã®ãã£ãŒãããã¯ãç¶æããå¿
èŠããããŸãã
3ïŒã¢ããªã±ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ãäž»ãªç®æšã§ãã ãã®äœæ¥ãåŸã§è¡ãããšãªããéçºããã»ã¹ã§çç£æ§ãåžžã«æé©åããå¿
èŠããããŸãã
4ïŒå®è¡æéã枬å®ããã¢ããªã±ãŒã·ã§ã³ã®é²è¡ç¶æ³ãèšé²ããŠåæããã³ãŒãã®çãã»ã¯ã·ã§ã³ãã€ãã³ãã®çºçãã¡ã¢ãªå²ãåœãŠããªããžã§ã¯ãã®å¯¿åœãèšé²ããå¿
èŠããããŸãã
枬å®ãããªããã®ã¯æé©åã§ããŸããã
æŠè¡ïŒ1ïŒäžèŠãªãªããžã§ã¯ããäœæããªãã§ãã ããã
2ïŒå¯èœã§ããã°ãã¡ãœãããéçã«ããŸãã
3ïŒãããã·ã¡ãœããã®ä»£ããã«çŽæ¥ãã£ãŒã«ãã¢ã¯ã»ã¹ã䜿çšããŸãã
4ïŒå®æ°ã«ã¯éçãã¡ã€ãã«ã䜿çšããŸãã
5ïŒéåžžã®æŽæ°å€æ°ã§ååãªå Žåã¯ãenumã䜿çšããªãã§ãã ããã
3. Androidã®äž»ãªæ©èœAndroidã¯Linuxã«åºã¥ããŠããŸãã ã¢ããªã±ãŒã·ã§ã³ãšã«ãŒãã«ã®éã«ã¯ããã€ãã£ãã³ãŒãã®APIã¬ã€ã€ãŒãšã©ã€ãã©ãªã¬ã€ã€ãŒããããŸãã ã¢ããªã±ãŒã·ã§ã³ã¯Javaä»®æ³ãã·ã³ïŒDalvikä»®æ³ãã·ã³ïŒã§å®è¡ãããŸãã
Androidã§å€ãã®ã¢ããªã±ãŒã·ã§ã³ãå®è¡ã§ããŸãã ãã ãããã®ãã¡ã®1ã€ãã¡ã€ã³ã§ãããç»é¢ãå æããŸãã çŸåšã®ã¢ããªã±ãŒã·ã§ã³ãããåã®ã¢ããªã±ãŒã·ã§ã³ã«ç§»åããããæ°ããã¢ããªã±ãŒã·ã§ã³ãéå§ã§ããŸãã é²èŠ§å±¥æŽã®ãããã©ãŠã¶ã®ããã«èŠããŸãã
åãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ç»é¢ã¯ãã³ãŒãå
ã®ã¢ã¯ãã£ããã£ã¯ã©ã¹ã§è¡šãããŸãã ããŸããŸãªã¢ã¯ãã£ããã£ãããã»ã¹ã«å«ãŸããŠããŸãã ã¢ã¯ãã£ããã£ã¯ããã»ã¹ãããé·ãçããããšãã§ããŸãã å¿
èŠãªãã¹ãŠã®æ
å ±ãä¿åããŠãã¢ã¯ãã£ããã£ãäžæåæ¢ããã³åéã§ããŸãã
Androidã¯ãIntentã«åºã¥ããŠã¢ã¯ã·ã§ã³ãèšè¿°ããããã®ç¹å¥ãªã¡ã«ããºã ã䜿çšããŸãã ã¢ã¯ã·ã§ã³ãå®è¡ããå¿
èŠãããå ŽåïŒé»è©±ãããããæçŽãéãããŠã£ã³ããŠã衚瀺ããïŒãIntentãåŒã³åºãããŸãã
Androidã«ã¯ãããã¯ã°ã©ãŠã³ãã§å¿
èŠãªã¢ã¯ã·ã§ã³ïŒé³æ¥œã®åçãªã©ïŒãå®è¡ããããã®Linuxã®ããŒã¢ã³ã«äŒŒããµãŒãã¹ãå«ãŸããŠããŸãã
ã³ã³ãã³ããããã€ããŒã¯ãã³ã³ãã³ããããã€ããŒã䜿çšããŠã¢ããªã±ãŒã·ã§ã³éã§ããŒã¿ã亀æããŸãã
4.é©çšäŸ-æ°ç¬æ°ç¬ã²ãŒã ã®å®æãããã©ãããæ€èšã
ãŸã ïŒ
Sudokuv4ãã©ã«ãå
ã®å®å
šãªã³ãŒã ïŒã
åäœããã«ã¯Android SDKãšEclipseãå¿
èŠã§ãã ãã¹ãŠãã€ã³ã¹ããŒã«ããŠèµ·åããæ¹æ³ã¯
ããã«æžãããŠã
ãŸã ã
ãããžã§ã¯ããEclipseã«ããŒãããã«ã¯ã次ã®äžé£ã®ã¢ã¯ã·ã§ã³ãå®è¡ããå¿
èŠããããŸãã
1ïŒãããžã§ã¯ããEclipseã¯ãŒã¯ã¹ããŒã¹ã®å¥ã®ãã©ã«ããŒã«è§£åããŸãã
2ïŒã¡ãã¥ãŒé
ç®ããã¡ã€ã«ã->ãæ°èŠã->ãAndroidãããžã§ã¯ãããéžæããŸãã
3ïŒ[æ°ããAndroidãããžã§ã¯ã]ãã€ã¢ãã°ã§ã[æ¢åã®ãœãŒã¹ãããããžã§ã¯ããäœæãã]ãªãã·ã§ã³ãéžæããŸãã
4ïŒ[å Žæ]ãã£ãŒã«ãã§ããããžã§ã¯ããã©ã«ããŒãžã®ãã¹ãæå®ããŸãã 次ãžãã¯ãªãã¯ããŸãã
ããã°ã©ã ã¡ãã¥ãŒã²ãŒã ã¡ãã¥ãŒã¯res / layout / main.xmlã§èª¬æãããŠããŸãã ã€ã³ã¿ãŒãã§ã€ã¹ã®èª¬æã¯ãXMLãŸãã¯èŠèŠåãããã€ã³ã¿ãŒãã§ã€ã¹ãšããŠç·šéã§ããŸãã åãæ¿ããã«ã¯ãã³ã³ãã³ã衚瀺é åã®äžéšã«ããã¿ãã䜿çšããŸãã
éåžžãã³ã³ãããŒã«ã¯ã³ã³ããå
ã«å«ãŸããŸãããã®å ŽåãLinearLayoutã§ãã 圌ã¯ãã¹ãŠã®èŠçŽ ãåäžã®åã«é
眮ããŸãã
è³æºãã¹ãŠã®ããã¹ãã©ãã«ïŒandroidïŒtextïŒã¯ãªãœãŒã¹ããããŒã¿ãååŸããããšã«æ³šæããŠãã ããã ããšãã°ããšã³ããªandroidïŒtext = "@ string / main_title"ã¯ãmain_titleïŒAndroid SudokuïŒãšããååã®ããŒãã®res / values / string.xmlãã¡ã€ã«ã§ããã¹ããæ€çŽ¢ããå¿
èŠãããããšã瀺ããŸãã èæ¯è²ããªãœãŒã¹ïŒandroidïŒbackground = "@ color / background"ïŒã«å«ãŸããŠããŸãããcolor.xmlãã¡ã€ã«ïŒïŒ3500ffffïŒã«å«ãŸããŠããŸãã ãšãã£ã¿ãŒã§ãªãœãŒã¹ãã¡ã€ã«ãéããšããšã©ãŒãçºçããå ŽåããããŸãã ãã ãããã€ã§ãXMLã衚瀺ã§ããŸãã
ã³ãŒãããã¢ã¯ã»ã¹ããå¿
èŠãããã³ã³ãããŒã«ã«ã¯IDãå¿
èŠã§ãã ãã¿ã³ã«ã¯idïŒandroidïŒid = "@ + id / continue_button"ïŒããããããã¯ãªãã¯ãã³ãã©ãŒããã¿ã³ã«ã¢ã¿ããã§ããŸãã ãã©ã¹èšå·ã¯ããã¿ã³ã®å Žåããã¡ã€ã«/gen/org.example.sudoku/R.javaã«èå¥åãäœæããå¿
èŠãããããšã瀺ããŸãïŒpublic static final int continue_button = 0x7f0b000b;ïŒã ãã®ãã¡ã€ã«ã¯èªåçã«çæããããããå€æŽããããšã¯ãå§ãããŸããã ãã®ãã¡ã€ã«ã«ã¯Rã¯ã©ã¹ãå«ãŸããŠããããã®ã¯ã©ã¹ãä»ããŠãä»»æã®ã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ããã®ä»ã®ãªãœãŒã¹ã«ã¢ã¯ã»ã¹ã§ããŸãã
ãŠã£ã³ããŠäœæããã°ã©ã ã«é¢ããæ
å ±ãå«ããŠã£ã³ããŠãäœæããããšãæ€èšããŠãã ããã ãã®ãŠã£ã³ããŠã®ããŒã¯ã¢ããã¯/res/layout/about.xmlãã¡ã€ã«ã«ãããŸãã Activityã¯ã©ã¹ã¯ã/ src / org.example.sudoku / About.javaãã¡ã€ã«ã«èšè¿°ãããŠããŸãã ã¢ã¯ãã£ããã£ã¯ãAndroidManifest.xmlãã¡ã€ã«ã®ããŒã¯ã¢ããã«é¢é£ä»ããããŠããŸãã ãã®ãã¡ã€ã«ã¯ããšãã£ã¿ãŒãŸãã¯XMLãšããŠè¡šç€ºã§ããŸãã ãšãã£ã¿ãŒã®ããŸããŸãªã¿ãã§ããã¡ã€ã«ã®ããŸããŸãªã»ã¯ã·ã§ã³ãéžæã§ããŸãã [ã¢ããªã±ãŒã·ã§ã³]ã»ã¯ã·ã§ã³ã«ã¯ãã¢ã¯ãã£ããã£ãã©ã¡ãŒã¿ããããŸãã ããŒãã¯
android ïŒstyle / Theme.Dialogã«èšå®ãããŠããããšã«æ³šæããŠãã ããã ããã«ããããŠã£ã³ããŠã¹ã¿ã€ã«ã¯ã¢ãŒãã«ãã€ã¢ãã°ã«äŒŒãŠããŸãã
ããã°ã©ã ã«ã€ããŠã®æ
å ±ãå«ããŠã£ã³ããŠã¯ãAboutãã¿ã³ãæŒãããšã§æ°ç¬ã¯ã©ã¹ããåŒã³åºãããŸãã Sudokuã¯ã©ã¹ã¯ãClickã€ãã³ããåŠçããããã«èšè¿°ãããŠããŸãïŒãããªãã¯ã¯ã©ã¹ã®Sudokuã¯ActivityãOnClickListenerãå®è£
ããŸãïŒã public void onClickïŒView vïŒã¡ãœããã¯ãã€ãã³ããããªã¬ãŒãããã¿ã³ã決å®ãã察å¿ããã³ãŒããå®è¡ãããŸãã ããŒãžã§ã³æ
å ±ãŠã£ã³ããŠã衚瀺ããã«ã¯ã察å¿ããã€ã³ãã³ããåŒã³åºãããŸãã
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
ã€ãã³ããã³ãã©ãŒã¯ãç¹å®ã®ã³ã³ãããŒã«ã«ã€ã³ã¹ããŒã«ããããšãã§ããŸãã ããšãã°ãKeypadã¯ã©ã¹ã§ã¯ãsetListenersïŒïŒã¡ãœããã§ã¯ã©ã¹ãäœæãããšãåã
ã®ãã¿ã³ã®ãã³ãã©ãŒãèšå®ãããŸãã
ç°¡åãªå¯Ÿè©±ãŠãŒã¶ãŒã«ã¯ãé£æ床ãéžæããæ©äŒãäžããå¿
èŠããããŸãã ããã¯ãããã€ãã®ãªãã·ã§ã³ã®ãããããéžæããå¿
èŠãããå°ããªãã€ã¢ãã°ã§ãã ãã®ããã«å¥ã®Intentãäœæããå¿
èŠã¯ãªããAlertDialogã¯ã©ã¹ã䜿çšããããšãéåžžã«ããããæããŸãã
æ°ããã²ãŒã ãéå§ããããã»ã¹ãåæããŸãã ãŠãŒã¶ãŒã¯[æ°ããã²ãŒã ]ãã¿ã³ãã¯ãªãã¯ããŸãã ã¯ãªãã¯ãã³ãã©ã¯ãSudokuã¯ã©ã¹ã¡ãœããonClickã§ãã 次ã«ãopenNewGameDialogã¡ãœãããåŒã³åºãããé£æ床éžæãã€ã¢ãã°ã衚瀺ãããéžæããé£æ床ã§ã²ãŒã ãéå§ãããŸãã ãã®ãã€ã¢ãã°ã¯AlertDialogã¯ã©ã¹ã䜿çšããŠæ§ç¯ãããŸãã
private void openNewGameDialog() { new AlertDialog.Builder(this) .setTitle(R.string.new_game_title) .setItems(R.array.difficulty, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { startGame(i); } }) .show(); }
ãã€ã¢ãã°ã®å
容ïŒãã¿ã³ã®ã»ããïŒã¯ãæååã®é
åR.array.difficultyããæ§ç¯ãããããšã«æ³šæããŠãã ããã ãã€ã¢ãã°ã®ãã¿ã³ãã¯ãªãã¯ããããã®ãã³ãã©ãŒãããã«å²ãåœãŠãããæŒããããã¿ã³ã®æ°ã«å¿ããŠãstartGameã¡ãœãããåŒã³åºããŠãæå®ãããã¬ãã«ã®è€éãã§æ°ããã²ãŒã ãèµ·åããŸãã
ã°ã©ãã£ãã¯ã¹ã²ãŒã ã¯ã©ã¹ã¯ãã²ãŒã ããžãã¯ãæ
åœããŸãã ããã§ã¿ã¹ã¯ãããŒããããåã¡ã®æ¡ä»¶ããã§ãã¯ãããŸãã Gameã¯ã©ã¹ã¯Activityã§ãããã€ã³ã¿ãŒãã§ã€ã¹ã¯XMLã§èšè¿°ãããŠããŸããããã³ãŒãã«ãã£ãŠäœæãããŸãã onCreateã¡ãœããã¯ãã¥ãŒãäœæããŸãã
puzzleView = new PuzzleView(this);
setContentView(puzzleView);
puzzleView.requestFocus();
PazzleViewã¯Viewãã掟çããã¯ã©ã¹ã§ã競æå Žãæç»ããã¿ããã€ãã³ãïŒonTouchEventã¡ãœããïŒãšããŒã¹ãããŒã¯ïŒonKeyDownã¡ãœããïŒãåŠçããŸãã
Androidã§ã®æç»ããã»ã¹ãåæããŸãããã æç»ããã«ã¯ãonDrawã¡ãœããããªãŒããŒããŒãããå¿
èŠããããŸãã ã¡ãœããã¯ãæç»ãå®è¡ãããCanvasãªããžã§ã¯ããåãåããŸãã è²ãèšå®ããã«ã¯ãPaintã¯ã©ã¹ã®ãªããžã§ã¯ããäœæããŸãã è²ã¯ARGB圢åŒã§èšå®ãããŸãã è²ã¯ãªãœãŒã¹ïŒcolors.xmlãã¡ã€ã«ïŒãšããŠä¿åããã®ãæé©ã§ãã ãã€ã³ãã¯ãè²æ
å ±ãä¿åããããã®ã¯ã©ã¹ã ãã§ã¯ãããŸããã ããšãã°ãããã¹ããæç»ããå Žåãããã¹ãã®å¡ãæ¹ããã©ã³ããããã³é
眮ã«é¢ããæ
å ±ãå«ãŸããŸãã
Canvasã«ã¯ãã°ã©ãã£ãã¯ã¹ãæç»ããããã®äžé£ã®ã¡ãœããïŒdrawRectãdrawLineãdrawPathãdrawTextãªã©ïŒãå«ãŸããŠããŸãã
ã°ã©ãã£ãã¯ã¹ãæé©åããã«ã¯ãonDrawã¡ãœããå
ã§ãªããžã§ã¯ããšäžèŠãªèšç®ãäœæããªãããã«ããããšããå§ãããŸãïŒã°ã©ãã£ãã¯ã¹å®è£
ã®æ€èšäŸã¯æé©ã§ã¯ãããŸããïŒã
ãã¥ãŒãžãã¯é³æ¥œãåçããã«ã¯ãMediaPlayerã¯ã©ã¹ã䜿çšããŸãã ã²ãŒã ã®é³æ¥œããªãœãŒã¹ã«è¿œå ãããŸããã å¿
èŠãªãã¡ã€ã«ã/ res / rawãã©ã«ããŒïŒWAVãAACãMP3ãWMAãAMRãOGGãMIDI圢åŒïŒã«ã³ããŒããã ãã§ãã
ãŸããMediaPlayerã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããå¿
èŠããããŸãã
mp = MediaPlayer.createïŒã³ã³ããã¹ãããªãœãŒã¹ïŒ;
ããã§ãã³ã³ããã¹ãã¯éåžžââãé³æ¥œã®èµ·åãéå§ããã¯ã©ã¹ã§ããããªãœãŒã¹-é³æ¥œãæã€ãªãœãŒã¹ã®èå¥åã§ãã åçãå¶åŸ¡ããã«ã¯ãstartãstopãããã³releaseã¡ãœããã䜿çšããŸãã
ã²ãŒã ã§ã¯ãé³æ¥œã¯ã¡ã€ã³ã¡ãã¥ãŒïŒæ°ç¬ã¯ã©ã¹ããèµ·åïŒãšã²ãŒã ããã»ã¹ïŒã²ãŒã ã¯ã©ã¹ããèµ·åïŒã§åçãããŸãã åçãå¶åŸ¡ããããã«ãMusicã¯ã©ã¹ãäœæãããŸããã ãã®ã¯ã©ã¹ã«ã¯MediaPlayerã®éçã€ã³ã¹ã¿ã³ã¹ãå«ãŸããŠããããããªãŒãã£ãªãªãœãŒã¹ã®èµ·åããšã«åå¥ã®ãããžã§ã¯ããäœæããå¿
èŠããããŸããã
Sudokuã¯ã©ã¹ãšGameã¯ã©ã¹ã§ã¯ãonResumeã¡ãœãããšonPauseã¡ãœãããåå®çŸ©ãããŸãããã®ã¡ãœããã§ã¯ãã¢ã¯ãã£ããã£ãéå§ãããšé³æ¥œãéå§ããéã¢ã¯ãã£ãã«ãããšé³æ¥œãåæ¢ããŸãã
çµè«ãã®èšäºã§æ€èšãããŠããäŸã¯ããã»ã©è€éã§ã¯ãªããããå€ãã®åŽåããããã«ç解ã§ããŸãã åæã«ãAndroidéçºã®ããŸããŸãªåŽé¢ã«è§ŠããŠããŸãã
PSã³ã¡ã³ãã«ã€ããŠã¯ãŠãŒã¶ãŒ
malkolmã«æè¬ããŸãã