Androidã¢ããªã«Strutsã®ãããªã³ã³ããã¼ã©ãå°å ¥ãï¼ç»é¢å¶å¾¡ããããµã³ãã«ã³ã¼ããï¼ã®è©¦ä½åãããªãã¼ã·ã§ã³ããã¸ãã¹ãã¸ãã¯ã®éª¨çµã¿ï¼
éè¦ãªãç¥ããï¼
ãã®è¨äºã§å ¬éããæ å ±ã¯ï¼Androidã®MVCãã¬ã¼ã ã¯ã¼ã¯ãAndroid-MVCãã®æ©è½ã®ä¸é¨ã¨ãã¦åãè¾¼ã¾ãã¾ããã
ããæ£ç¢ºãªè¨è¨æ å ±ãï¼åä½å¯è½ãªå ¨ã½ã¼ã¹ã³ã¼ããé²è¦§ãããå ´åï¼ãAndroid-MVCãã®å ¬å¼ãã¼ã¸ããæè¡æ å ±ãåç §ãã¦ãã ããã
Androidã®MVCãã¬ã¼ã ã¯ã¼ã¯ - ãAndroid-MVCã
http://code.google.com/p/android-mvc-...
Androidã¢ããªã®è¨è¨ã«ï¼Strutsã®ãããªã¢ã¼ããã¯ãã£ãåãå
¥ããããã¨ããè¨äºã
ãã ãï¼Javaã«ã¤ããã®ã®ãXMLå°çãã¯ï¼å¾¹åºçã«é¿ãããã®ã¨ããã
ããã«ã·ã³ãã«ã«Androidã¢ããªã®ç»é¢å¶å¾¡ã管çãããï¼
Androidã¢ããªã¯ï¼è¤æ°ã®ãActivityãï¼ï¼ç»é¢ï¼ãæã¤ã
ãããActivityã©ããã®éãè¡ãæ¥ããããã«ã¯ï¼Intentãçºè¡ããã
é常ï¼Intentã®çºè¡å¦çã¯ï¼é·ç§»å ã®Activityã®ä¸ã«æ¸ãã¦ãã¾ãã
Activityã®ä¸ã«ï¼é·ç§»å ã¨é·ç§»å ã®æ å ±ãåãè¾¼ã¾ããã®ã ã
ããªãã¼ã·ã§ã³ããã¸ãã¹ãã¸ãã¯ãï¼ä¸¸ãã¨ï¼ã¯ã©ã¹å ã«è©°ãè¾¼ããããããªãã
ããããã¨ï¼ä¸è¨ã®ãããªãå¯ãªçµåããçãã¦ãã¾ãã
ãªãã¨ã網ç®ç¶ã§ï¼ã«ãªã¹ãªçµåç¶æ ã ã
ããã¯ï¼ãªãã¸ã§ã¯ãæåçã«ã¯ãã¡ã§ããã
ãççµåããªã¯ã©ã¹è¨è¨ã«ãªã£ã¦ããªãã
ãããï¼Activityã«ã¯ãããã£ãæ å ±ãåãè¾¼ã¾ãã«ï¼
ç»é¢é·ç§»ã«é¢ãå¦çãéç´ãã¦ï¼ï¼ã¤ã®ãã³ã³ããã¼ã©ãã¯ã©ã¹ã«ä»»ããã
ããã¨ï¼ä¸è¨ã®ãããªãã¹ã¿ã¼ç¶ãã®çµåã«ãªãã
ãã¥ã¼ã¨å¶å¾¡ã®åé¢ã§ããã
ã³ã³ããã¼ã©ã¯ã©ã¹ã¯ï¼å¶å¾¡ã«ã¤ãã¦è²¬ä»»ãè² ããããªãã¼ã·ã§ã³ãªã©ãå¼ãåããã
Activityã¯ï¼åå¥ã®ç»é¢ã«ãããUIæç»ã»ã¤ãã³ãã®ãã³ããªã³ã°ãªã©ã«ã¤ãã¦è²¬ä»»ãè² ãã
ã©ã¡ããããè¨è¨ãï¼
å°è¦æ¨¡ã¢ããªãªãï¼åè ã§äºè¶³ããã
ãããè¦æ¨¡ãè¤éã«ãªã£ã¦ããã¨ï¼ç»é¢å¶å¾¡ã®æ´ãåºãã«è¦å´ãããã®ã ã
ããã¦ï¼æãã¬ã¨ããã«ç»é¢é·ç§»ã®å®è£ æ¼ãã»ä¸æ´åãè¦ã¤ãã£ãããã¦ï¼ãã¹ãå·¥ç¨ã®è² è·ãäºæ³å¤ã«å¢ããã
ã¡ããã©ï¼Strutsãã¬ã¼ã ã¯ã¼ã¯ã§ï¼struts-config.xmlã
ç»é¢é·ç§»ããã©ã¼ã ã®ããªãã¼ã·ã§ã³ã«é¢ããè¨å®ãå¼ãåãã¦ããã®ãæãåºããã
åãããã«ï¼Androidã¢ããªã®ãã³ã³ããã¼ã©å±¤ãã®æ å ±ã®éç´ãè¡ãªããã¨ã§
ã¢ããªéçºã®ä¿å®æ§ã»çç£æ§ã»æ¡å¼µæ§ã»ãã¹ã¿ããªãã£çãåä¸ããããã
ãã®ãããªãµã³ãã«ã³ã¼ããå®æãï¼Androidå®æ©ä¸ã§å®éã«åä½ããã
試ä½åã®ã¬ãã«ã ãï¼ä¸è¨ã§ç´¹ä»ããã
ï¼ï¼ï¼ã³ã³ããã¼ã©å±¤ãç°¡æ½ã«ï¼ã·ã³ãã«ã«ã³ã¼ãã£ã³ã°
DSLãæä¾ããã©ã¤ãã©ãªãç¡è¦ããã¨ï¼ã¦ã¼ã¶ãæã触ããã®ã¯ï¼ããããªéã®ã³ã¼ãã ã
以ä¸ã®ï¼ã¤ã ãã
- ã¢ã¯ãã£ããã£æ¬ä½
- ã³ã³ããã¼ã©
- ããªãã¼ã¿
- ãã¸ãã¹ãã¸ãã¯
ã¾ãï¼Activityå
ã«ç»é¢å¶å¾¡ã®æ
å ±ããã¼ãã³ã¼ãããã®ãããããã
ãµã ããªãIntentãçºè¡ããããªãé¨åã§ï¼ããããã£ã¨ããããã
ãããã«ï¼ãnew Controller().submit( this );ãã¨ããã
MainActivity.java
package controller_test.dayo.activities.func_main; import controller_test.dayo.R; import controller_test.dayo.activities.base.BaseActivity; import controller_test.dayo.controller.Controller; import controller_test.dayo.controller.lib.ActivityParams; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; // ã¡ã¤ã³å¦çãè¡ãç»é¢ã public class MainActivity extends BaseActivity implements OnClickListener{ Button btn; EditText et; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // ãã¿ã³å®ç¾© btn = (Button)findViewById(R.id.btn1); btn.setOnClickListener(this); // å ¥åããã¯ã¹å®ç¾© et = (EditText)findViewById(R.id.editText1); } @Override public void onClick(View v) { // ãã¿ã³æ¼ä¸æ if( v == btn ) { // ã³ã³ããã¼ã©ãå¼ã¶ãâ ãããéè¦ã // ã©ãã®Activityã«é·ç§»ããã®ãï¼ãã®Activityèªä½ã¯ç¥ããªãã new Controller().submit( this ); } } @Override public ActivityParams toParams() { // ããªãã¼ã·ã§ã³ã«æ¸¡ãããã«ï¼ãã®ç»é¢ã®ç¶æ ãä½ããååã return new ActivityParams() .add("input_value", et.getText().toString() ) ; } }
ãã®ç»é¢ã¯ã¨ã¦ãã·ã³ãã«ã
å ¥åããã¯ã¹ã¨ï¼å®è¡ãã¿ã³ãï¼ã¤ãã¤ããã
å ¥åããã¯ã¹ã«å ¥ããæååã¯ï¼ã®ã¡ã®ã¡ããªãã¼ã·ã§ã³ãããã
ãã®ããã«ï¼ã¢ã¯ãã£ããã£ãæ±ãã¦ããæ å ±ã丸ãã¨åå¾ããããã®ãtoParamsãã¨ããã¡ã½ãããæºåããã¦ããï¼ããã¯åºåºã¯ã©ã¹ã§æ½è±¡ã¡ã½ãããªã®ã§ï¼åã¯ã©ã¹ã§å®è£ ãå¼·å¶ãããã
è¿å´å¤ã¯ï¼æããã«è¶³ãããåãªãHashMapã®ã©ããã¼ã§ããã
ãã¦ï¼ä¸è¨ã®ã¢ã¯ãã£ããã£ã¯ãControllerãã¯ã©ã¹ã«å¶å¾¡ããã ãã¦ããã
æ¬é¡ã®ãControllerãã¯ã©ã¹ãè¦ã¦ã¿ããã
package controller_test.dayo.controller; import java.util.HashMap; import android.app.Activity; import controller_test.dayo.activities.func_main.FugaAction; import controller_test.dayo.activities.func_main.FugaActivity; import controller_test.dayo.activities.func_main.HogeActivity; import controller_test.dayo.activities.func_main.MainAction; import controller_test.dayo.activities.func_main.MainActivity; import controller_test.dayo.controller.lib.BaseController; // MVCã®ã³ã³ããã¼ã©å±¤ã«å½ããã¯ã©ã¹ã // ãã¥ã¼ãã渡ãããå¤ã®æ¤è¨¼ãï¼BLã®å¼ã³åºãï¼ç»é¢é·ç§»ã®å¶å¾¡ãªã©ãè¡ãã // ããè¥å¤§åãããï¼ããããããã·ã«ãã¦å¥ã¯ã©ã¹ã«ç´°ååããã public class Controller extends BaseController { // é·ç§»å ã¨ãªãActivityãã¨ã«ï¼submit()ããªã¼ãã¼ãã¼ãããã // ã¡ã¤ã³ç»é¢ããã®é·ç§»æ @SuppressWarnings("serial") public void submit( final MainActivity mainActivity ) { // ã³ã³ããã¼ã«ã®ããã¼ã®è©³ç´°ãè¨è¿°ããã new ControlFlowDetail<MainActivity>( mainActivity ) .describeValidation( new ValidationExecutor(){ @Override protected void validate() { // ããªãã¼ã·ã§ã³å¦ç validation_result = GateChecker.validate( mainActivity ); } }) .describeBL( new BLExecutor(){ @Override protected void doAction() { // BL action_result = new MainAction( mainActivity ).exec(); } }) .onValidationFailed( FugaActivity.class ) // ããªã失ææã®é·ç§»å .onBLExecuted( // BLå®è¡å®äºæã®ã«ã¼ãã£ã³ã°ã»ãã¼ãã«ã // BLå®äºæã®ã«ã¼ãã£ã³ã°èå¥åã¨ï¼é·ç§»å ã®Activityã¯ã©ã¹ãã²ãã¥ãã¦ããã new HashMap<String, Class<? extends Activity>>(){{ put( "success", HogeActivity.class ); // put( "piyo", MugaActivity.class ); // ... }} // NOTE: ããâã®ã©ããã¼ã¯ã©ã¹ãä½ãã°@SuppressWarningsã¢ããã¼ã·ã§ã³ãä¸è¦ã«ãªãã®ã ã // HashMapã®ã©ããã¼ã¯ã©ã¹ã®ä½ãããã®ããã«ï¼ããå æ¸åå°½ããã®ã§ã»ã»ã»ã // http://www.kinopyo.com/blog/java-init-map-with-data ) .startControl(); ; } // å¥ã®ç»é¢ã§ã®ã³ã³ããã¼ã«ããã¼ï¼ããªã失æç»é¢ããã®é·ç§»æï¼ @SuppressWarnings("serial") public void submit(final FugaActivity fugaActivity) { new ControlFlowDetail<FugaActivity>( fugaActivity ) .describeValidation( new ValidationExecutor(){ @Override protected void validate() { validation_result = GateChecker.validate( fugaActivity ); } }) .describeBL( new BLExecutor(){ @Override protected void doAction() { action_result = new FugaAction( fugaActivity ).exec(); } }) .onBLExecuted( new HashMap<String, Class<? extends Activity>>(){{ put( "success", MainActivity.class ); }} ) .startControl(); ; } }
ãã®ã¯ã©ã¹ãï¼Strutsã§ããï¼ããæå³ï¼æªåé«ãï¼ãstruts-config.xmlãã«ç¸å½ããã
ãã ãããã§ã¯è¨å®ãã¡ã¤ã«ã§ã¯ãªãï¼Javaã³ã¼ãã¨ãã¦å®è£ ãã¦ããã
MainActivityç¨ã®å¶å¾¡ããã¼ä¸ã§ã¯ï¼ï¼ã¤ã®ãã¨ããã¦ããã®ããããã
- ControlFlowDetailã¨ãããªãã¸ã§ã¯ãã宣è¨ãã¦ï¼å¶å¾¡ããã¼ã®è©³ç´°ããã®ä¸ã«æ¾ãè¾¼ã¿å§ããã
- ã¾ãã¯ï¼MainActivityã®ã¤ã³ã¹ã¿ã³ã¹ãç»é²ããã
- ããªãã¼ã·ã§ã³å¦çã®å¼ã³åºããå®ç¾©ã
- ããªãã¼ã·ã§ã³ã¨ã©ã¼çºçæã®é·ç§»å ã¯ã©ã¹ãå®ç¾©ã
- ãã¸ãã¹ãã¸ãã¯ã®å¼ã³åºããå®ç¾©ã
- ãã¸ãã¹ãã¸ãã¯å®è¡å®äºå¾ã«ï¼å®è¡çµæãã ãã§åå²å ãè¿ãããã®ã«ã¼ãã£ã³ã°ãã¼ãã«ãå®ç¾©ã
- ãããã®å¶å¾¡ããã¼ãéå§ããã
DSLï¼fluent interfaceï¼ã§è¨è¿°ãã¦ããã®ã§ï¼æ¥µåèªã¿ãããï¼ç解ãããããªã£ã¦ããã
ä½ãèµ·ãã£ãæã«ï¼ã©ãã®Activityã«é·ç§»ããäºã«ãªãã®ãï¼ä¸ç®çç¶ã«éç´ããã¦ããã
ããã³ã³ããã¼ã©ã¯ã©ã¹ãè¥å¤§åãããï¼æ©è½ãã¨ã«ã³ã³ããã¼ã©ã¯ã©ã¹ãåå²ããã®ãè¯ãæãããããªãã
ãã¦ï¼ããªãã¼ã·ã§ã³ãå®è¡ãã¦ããããã ãï¼å®è¡ã¯ã©ã¹ã¯GateCheckerã¨ããååã ã
ãã¨ãã¨ï¼ä¸è¨ã®Controllerã¯ãGateãã¨ããååã®ã¯ã©ã¹ã¨ãã¦éçºãé²ãã¦ããã®ã§ããããå称ã«ãªã£ãã
ã¡ããã©ï¼åActivityããè¦ã¦Gateï¼éï¼ã®å½¹ç®ãããããã ã
ããªãã¼ã·ã§ã³æ å½ã®GateCheckerã¯ä¸è¨ã®ãããªå 容ã
package controller_test.dayo.controller; import java.util.regex.Pattern; import controller_test.dayo.activities.func_main.FugaActivity; import controller_test.dayo.activities.func_main.MainActivity; import controller_test.dayo.controller.lib.ActivityParams; import controller_test.dayo.controller.lib.GateValidationResult; // Activityãã¨ã®ããªãã¼ã·ã§ã³æä½ãè©°ãè¾¼ãã ã¯ã©ã¹ã // ããè¥å¤§åãããï¼ããããããã·ã«ãã¦å¥ã¯ã©ã¹ã«ç´°ååããã public class GateChecker { // Activityãã¨ã«å¼æ°ã®åãå¤ãã¦ãªã¼ãã¼ãã¼ãããã // ã¡ã¤ã³ç»é¢ã®å ¥åå¤ãæ¤è¨¼ public static GateValidationResult validate(MainActivity mainActivity) { // Activityãæ±ãã¦ããå¤æ å ±ãå ¨ã¦åãåºã ActivityParams params = mainActivity.toParams(); GateValidationResult vres = new GateValidationResult(); // 1ã¤ã®å ¥åå¤ã«é¢ãã¦ããªãéå§ String s = (String)params.get("input_value"); // 1æå以ä¸ã§ãããã¨ã // TODO: ã決ã¾ãã®ããªãã¼ã·ã§ã³ãã¸ãã¯ãDSLã§å®åã¡ã½ããåãããã if( ( s == null ) || ( s.length() < 1 ) ) { return vres.err("æ°å¤ãå ¥åããã¦ãã¾ããã"); } // åè§æ°åã®ã¿ã§ãããã¨ããã¤ãã¹ãããªãªãã許å¯ããªãã if( ! Pattern.compile("^[0-9]+$").matcher(s).matches() ) { return vres.err("åè§æ°åã®ã¿ãå ¥åãã¦ãã ããã"); } // ãã¼ã¹ long long_value = Long.parseLong(s); // ãã¼ã¹åå¾ã§ä½è¨ãªå¤åããªããã¨ãå é ã®0ã¨ãã if( ! String.valueOf(long_value ).equals(s) ) { return vres.err("æ´æ°ã®å ¥åå½¢å¼ãä¸æ£ã§ãã"); } // 0ãã大ããã㨠if( long_value < 1 ) { return vres.err("0ãã大ããæ°ãå ¥åãã¦ãã ããã"); } // OK return vres.success(); } // ããªã失æç»é¢ã®å ¥åå¤ãæ¤è¨¼ public static GateValidationResult validate(FugaActivity fugaActivity) { GateValidationResult vres = new GateValidationResult(); // ä½ãæ¤æ»ãã // OK return vres.success(); } }
MainActivityã®ããã®ããªãã¼ã·ã§ã³ã¡ã½ããå
ã§ã¯ï¼GateValidationResultã¨ãããªãã¸ã§ã¯ããä¸å¿ã«è©±ãå±éãã¦ããã
ãã®ãªãã¸ã§ã¯ãã«ï¼ããªãã¼ã·ã§ã³ã®æçµçãªçµæãï¼çºçããã¨ã©ã¼ã¡ãã»ã¼ã¸ãè©°ãè¾¼ãã§ããã®ã§ããã
次ã«ï¼ãã¸ãã¹ãã¸ãã¯ãå®è¡ãããªãã¸ã§ã¯ãã
â»Strutsã¨ç°ãªãï¼ããã§ã¯Actionã¨BLã¨ããèªãã¨ããããå義ã§ç¨ãããã¨ã«ããã
ãã®ãµã³ãã«ã§ã¯ï¼åã«ãã°ãåºåããã ãã®ãã¸ãã¯ãªã®ã ããã
package controller_test.dayo.activities.func_main; import android.app.Activity; import android.util.Log; import android.widget.Toast; import controller_test.dayo.controller.lib.ActionResult; import controller_test.dayo.controller.lib.BaseAction; // ã¡ã¤ã³ã®BLã public class MainAction extends BaseAction { public MainAction(MainActivity fromActivity) { this.activity = fromActivity; } // BLæ¬ä½ãè¨è¿° public ActionResult exec() { // ããããã§ããããªå¦çãããããã // NOTE: ããå¿ è¦ãªãï¼å¼ã³åºãå ã®ActivityãtoParams()ãããã¨ã«ãã£ã¦ // ããªãã¼ã·ã§ã³ééæ¸ã¿ã®å ¥åå¤ãããã§åç §ãï¼DBç»é²ãªã©ã«å©ç¨ã§ããã // NOTE: BLã®ãã®é¨åã¯éåæã¿ã¹ã¯å ã§ã©ããããã¦ããäºã«æ³¨æã // AsyncTaskãæèããªãã§å®è¡ã§ããã // DBæä½ãªããã¯åæçã«è¡ããã // NWå¦çãåæåããããã«ï¼å¦çã®å®äºãwaitããå¿ è¦ãããã Log.d("myapp", "ã¡ã¤ã³ã®BLãå®è¡ãã¾ããã"); // å®è¡çµæãè¿ã return new ActionResult(){ @Override public void onNextActivityStarted(final Activity activity) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText( activity, "ã¡ã¤ã³BLãçµãã£ããã\nboo = " + get("boo"), Toast.LENGTH_LONG ).show(); // NOTE:å¿åã¯ã©ã¹ãå ¥ãåã«ãã¦ãããï¼ã¢ã¦ã¿ã¼ã¯ã©ã¹å.this.getãªãã¦æ¸ã㨠// ãã¨ã³ã¯ãã¼ã¸ã³ã°ã»ã¤ã³ã¹ã¿ã³ã¹ãã¢ã¯ã»ã¹ä¸å¯è½ã§ããã®ã¨ã©ã¼ã«ãªãã } }); } } .setRouteId("success") // ãã®èå¥åãé·ç§»å ã®Activityã¯ã©ã¹ã¨ã²ãã¥ã .add("boo", "BLã®å®è¡çµæã¨ãã¦ã¨ããããæ ¼ç´ããå¤") ; } }
ããã§ï¼å¥¥æ·±ã層ã®ãã¼ã¿å¦çãªã©ãè¡ãªãã
Webã¢ããªã§ããã°ï¼ãµã¼ããµã¤ãã§ã³ã³ããã¼ã©ããã¡ã¤ã³é åã®ã¯ã©ã¹ãå¼ã³åºãå§ããã
ããã¦å¦çãçµãã£ããï¼ãã¸ãã¯ã®å®è¡çµæããã«ã¼ãã£ã³ã°èå¥åãã¨ãã¦è¿ãã
å®è¡çµæã«é¢ããæ å ±ã¯ï¼ActionResultã¨ãããªãã¸ã§ã¯ãã«è©°ãè¾¼ãã§è¿å´ããã
ãã®è¿å´ç¨ã®ãªãã¸ã§ã¯ãã«ãï¼BLå ã§èªç±ã«å¤ãaddãããã¨ãã§ããã
ã¦ã¼ã¶ãæã触ããã®ã¯ï¼ä»¥ä¸ã®ï¼ã¯ã©ã¹ã
ããã ãã§ï¼ç»é¢é·ç§»ããã³ããã«ä¼´ãå種ã®å¦çã«é¢ãè¨è¿°ã¯çµäºã
å®è¡ããã¨ï¼ã¡ããã¨ããªãã¼ã·ã§ã³ã»BLå¼ã³åºãã»ç»é¢é·ç§»ã®å¶å¾¡ãªã©ãã£ã¦ãããã
Androidã¢ããªã¯ï¼è¦æ¨¡ãå°ããç©ãããã
ãªã®ã§ï¼ãã¸ãã¹ãã¸ãã¯ãã³ã³ããã¼ã©ã¨ãã£ãæ¦å¿µãå°å ¥ããã®ã«æµæãæããå ´åããããããããªãã
ãã ã§ããï¼ããã¡ã¤ã³ã¨ã¯ä½ãã«ãã¼ããã®ãããã¢ãã«ã¨ã³ã³ããã¼ã©ã®å¢çç·ã¯ã©ããªã®ããã¨ãã£ã話é¡ã¯æ£è§£ããªãï¼è°è«ãçä¸ããããã
åã«å©ãå°ã¨ãã¦ã³ã¼ããå ¬éããã®ã«ï¼ããã®äººã¯MVCã«ã¤ãã¦ä½ã«ãåãã£ã¦ããªãããã¨ãããããªé ·è©ãåãããã¨ããããã
ãSmallTalk MVCã¨J2EE MVCãæ··åãã¦ãã ãï¼ãã¨ãï¼ããã¡ã¤ã³ã¨ã¢ãã«ã¨DAOã®éããããã£ã½ã£ã¡ãããã£ã¦ãªãããã¨ãâ¦ã
ãããè¦æã®ãã¡ã ã
Androidä¸ã§ç¨æããã¦ããå種åºæ¬ã¯ã©ã¹ãï¼ã©ã®ããã«MVCã®å層ãã«ãã¼ããã®ãï¼ãããã¯ããæã¡ãããªããã°ãªããªãã®ãï¼ãã®å 模索ãã¦ãããã°ãªããªãã®ã ããâ¦ã
ãã®ãµã³ãã«ã¯ï¼å種å¦çã®ãã¹ã¿ã³ãã¼ããªè¨è¿°ãã¸ã·ã§ã³ãã®ä¾ã示ããï¼ã¨ããç¹ã§ä¾¡å¤ãããã¨è¨ããã
ã¾ãï¼Androidã¢ããªã«ã³ã³ããã¼ã©å±¤ã®æ¦å¿µãå°å
¥ããï¼ã¨ããç¹ã ãã§ãã
ï¼ï¼ï¼ãããã®DSLãã³ã¼ãã£ã³ã°å¯è½ã«ããããã®ã©ã¤ãã©ãª
ãã¦ï¼åé ã§åãä¸ãããããªã³ã¼ããå®ç¾å¯è½ã«ããããã«ã¯ï¼ã©ã®ãããªã©ã¤ãã©ãªãæºåãããããã®ãã
ã»ã¨ãã©ã®ã¯ã©ã¹ã¯HashMapã®ã©ããã¼ã«éããªãã®ã§ï¼ããã§ã¯æç²ãã¦
éè¦ãªï¼ã¯ã©ã¹ã ããæ²è¼ããã
ã¾ãï¼ã¦ã¼ã¶ãè¨è¿°ããã³ã³ããã¼ã©ã®åºåºã¯ã©ã¹ã
ã¦ã¼ã¶ãã³ã³ããã¼ã©ä¸ã§å¶å¾¡å¦çãè¨è¿°ããããããããã«åå¨ããã
BaseController.java
package controller_test.dayo.controller.lib; import java.util.HashMap; import android.app.Activity; import controller_test.dayo.controller.task.AsyncTasksRunner; import controller_test.dayo.controller.task.SequentialAsyncTask; // ã³ã³ããã¼ã©ã®åºåºã¯ã©ã¹ã public class BaseController { // ä¸ã¤ã®ã³ã³ããã¼ã«ããã¼å ã§ããªãã¼ã·ã§ã³æä½ãå®è¡ããã¯ã©ã¹ protected abstract class ValidationExecutor { protected abstract void validate(); public GateValidationResult validation_result; } // ä¸ã¤ã®ã³ã³ããã¼ã«ããã¼å ã§BLãå®è¡ããã¯ã©ã¹ protected abstract class BLExecutor { protected abstract void doAction(); public ActionResult action_result; } // NOTE: ãããã®ã¤ã³ãã¼ã¯ã©ã¹ã¯ï¼è¦ªã¯ã©ã¹ã®ã¸ã§ããªã¯ã¹ã§è§£æ±ºã§ããªãã£ãåé¡ã // ãªãã¨ãããããã«ï¼ã¯ãã¼ã¸ã£ã®ä»£ããã¨ãã¦ä»æ¹ãªãæä¾ããã¦ããã // ä¸ã¤ã®ã³ã³ããã¼ã«ããã¼ã®è©³ç´°è¨è¿° protected class ControlFlowDetail<ActivityClass> { protected ActivityClass from_activity; private ValidationExecutor validation_executor; private BLExecutor bl_executor; private Class<? extends Activity> validation_failed_activity; private HashMap<String, Class<? extends Activity>> routingTable; // åæå public ControlFlowDetail(ActivityClass fromActivity) { this.from_activity = fromActivity; } // ããªãã¼ã·ã§ã³å¦çã®è©³ç´°ãã»ãã public ControlFlowDetail<ActivityClass> describeValidation( ValidationExecutor validationExecutor ) { this.validation_executor = validationExecutor; return this; } // ããªãã¼ã·ã§ã³å¤±ææã®é·ç§»å ãã»ãã public ControlFlowDetail<ActivityClass> onValidationFailed( Class<? extends Activity> validation_failed_activity ) { this.validation_failed_activity = validation_failed_activity; return this; } // BLå®è¡ã®è©³ç´°ãã»ãã public ControlFlowDetail<ActivityClass> describeBL( BLExecutor blExecutor ) { this.bl_executor = blExecutor; return this; } // BLå®è¡å®äºæã®ã«ã¼ãã£ã³ã°ãã¼ãã«ãã»ãã public ControlFlowDetail<ActivityClass> onBLExecuted( HashMap<String, Class<? extends Activity>> routingTable ) { this.routingTable = routingTable; return this; } // å¶å¾¡ããã¼ãå®è¡ public void startControl() { new AsyncTasksRunner( new SequentialAsyncTask[]{ // ï¼UIã§æ¸ã¾ãªãã£ãï¼ããªãã¼ã·ã§ã³ãè¡ãªãéåæã¿ã¹ã¯ã // Webã§ãããµã¼ããµã¤ãã»ããªãã¼ã·ã§ã³ã«ç¸å½ new SequentialAsyncTask(){ public boolean main(){ // Activityã®paramsãããªãã¼ã validation_executor.validate(); storeData( "validation_result", validation_executor.validation_result ); // ããªãçµæã®æ¯éã«é¢ããã«ã¼ãã£ã³ã°ã¸é²ãã®ã§å¿ ãtrue return true; } } , // ããå¯è½ãªãBLãè¡ãªãéåæã¿ã¹ã¯ã // DBæä½ãNWéä¿¡ãªã©ãæ³å®ã new SequentialAsyncTask(){ public boolean main(){ // åã®ããªãã¼ã·ã§ã³å¦çã®çµæãåãã ã GateValidationResult vres = (GateValidationResult)getDataFromRunner("validation_result"); // ããããªãçµæãããã¦BLãå®è¡ãã¦ããã®ã§ããã° if( vres.permitsExecitionOfBL() ) { // BLãå®è¡ bl_executor.doAction(); storeData( "action_result", bl_executor.action_result ); } // BLã®å®è¡çµæã®æ¯éã«é¢ããã«ã¼ãã£ã³ã°ã¯ããã®ã§å¿ ãtrue return true; } } , // ã«ã¼ãã£ã³ã°ãè¡ãªãéåæã¿ã¹ã¯ new SequentialAsyncTask(){ public boolean main(){ // ããªãã¼ã·ã§ã³å¦çã®çµæãåãã ã GateValidationResult vres = (GateValidationResult)getDataFromRunner("validation_result"); if( vres.didNotExecuteBL() ) { // ããªãã¼ã·ã§ã³ã§ã¯ããããå ´åã®ã«ã¼ã㸠Router.go( (Activity)from_activity, validation_failed_activity, vres ); } else { // BLãå®è¡ãããå ´å ActionResult ares = (ActionResult)getDataFromRunner("action_result"); // BLå®è¡çµæã«å¿ãã¦é·ç§»å ãåå² Router.switchByActionResult( (Activity)from_activity, ares, routingTable ); } return true; } } }) .withSimpleDialog("å¦çä¸ã»ã»ã»", (Activity)from_activity) // å ¨éåæã¿ã¹ã¯ãçµäºããã¾ã§ãã¤ã¢ãã°ãåºã .begin(); } } }
ãã®ä¸ã§ï¼å¶å¾¡å¦çãé次å®è¡ãã¦ããã
éåæã¿ã¹ã¯ã®é次åã®ããã«ï¼AsyncTasksRunnerã¨ãSequentialAsyncTaskã¨ãã£ãã¯ã©ã¹ãå©ç¨ãã¦ãããï¼ãããã«ã¤ãã¦ã¯ä¸è¨ã®ã¨ã³ããªã§è¿°ã¹ãã
ã¨ã¯ããï¼ä¸è¨è¨äºã«è¼ã£ã¦ããã®ã¯éAndroidåãã®ã¯ã©ã¹ãªã®ã§ï¼ä¸è¨ã®ã³ã¼ãã¯Androidç¨ã«ä½ãæ¿ãããã®ã使ã£ã¦ããã®ã§ãããã
ãã¨ãã°ï¼å ¨ã¦ã®éåæã¿ã¹ã¯ã®é次å®è¡ãå®äºããã¾ã§ã®éï¼ç»é¢ä¸ã«ãã¤ã¢ãã°ã表示ãç¶ããï¼ã¨ãã£ãæ©è½ã追å ãã¦ãããï¼ .withSimpleDialog() ã®é¨åï¼
Javaã®éåæå¦çãï¼ã·ã³ã°ã«ã¹ã¬ããã®ããã«ã·ã³ãã«ã«ã³ã¼ãã£ã³ã°ããããã®è¨è¨ãã¿ã¼ã³ãï¼ä¸¦åå¦çãé次å¦çã«ããï¼
http://language-and-engineering.hatenablog.jp/entry/20120205/p1
ã¡ãªã¿ã«ä¸è¨ã®ã¨ã³ããªã¯ï¼Androidã§ã®å¿ç¨ãç®çã¨ãã¦æ¸ããããä¼ç·ãã ã£ãã®ã ãï¼ä¸éã®äººã ã«ã¯ãªããªãããã£ã¦ï¼åä»ãã¦ï¼ããããªãã£ãã
Androidã§ã¯ï¼AsyncTaskã¦ã¼ãã£ãªãã£ããjava.util.concurrentãããã±ã¼ã¸ãã²ãããé ãºããã¦ããã®ã ã
ãã®äºæ ãç¥ããªãã¨ï¼ããã«ãã¹ã¬ããã®å®çªã¯ã©ã¹ãªãã ããjava.util.concurrent使ããï¼ãã¨ããã¢ããã¤ã¹ãï¼å®¹èµ¦ãªãå¤ãã®æ¹ã ããé ãäºã«ãªãã
platform_frameworks_base / core / java / android / os / AsyncTask.java
https://github.com/android/platform_f...
- ã²ãããimport java.util.concurrentãã¦ãã¦ï¼ãã®ã©ããã¼ã¯ã©ã¹ãAsyncTaskãªã®ã§ããã
ã¾ãï¼ä»æ¹ãªããã¨ã³ããªã®å ¬éæ¦ç¥ã¯ï¼ããã¦ãæå³çã«é ãã¦ããã®ã ãã
話ãæ»ããã
ã¸ã§ããªã¯ã¹ã»å¿åã¯ã©ã¹ã»å é¨ã¯ã©ã¹ãé§ä½¿ããäºã«ããï¼ã³ã³ããã¼ã©å±¤ã®åã¯ã©ã¹ã§ã¦ã¼ã¶ãè¨è¿°ããã³ã¼ãéã¯å¯è½ãªéãæããã
ï¼â»æ¬å½ã¯ãã¹ã¦ã¸ã§ããªã¯ã¹ã§çä»ãã¦ï¼Builderãã¿ã¼ã³ãªãã使ããã«ï¼ãã£ã¨ã¦ã¼ã¶å´ã®è¨è¿°éã®è² æ ãæ¸ããããã£ãããããJavaã§ã¯ããã¯ç¡çã ã£ããä¸ä½ã¬ã¤ã¤ã§ãããããªã¼ãã¼ãã¼ãããã¦ããã¡ã½ãããï¼ã¦ã¼ã¶ã®ã¬ã¤ã¤ããééçã«æ±ãäºãåºæ¥ãªãã£ãã®ã ãã ããã¦ã¼ã¶ãè¨è¿°ããã³ã¼ãã«ã¯ï¼è¬ã®ã³ã¼ãã®æçãï¼è¡ã ãè¨è¿°ãããããã®ã¡ã½ããã©ããã¼ã®ç¡åã¯ã©ã¹ãç»å ´ããäºã«ãªãããã®ç¡åã¯ã©ã¹ã¯ï¼ã¦ã¼ã¶ãæ±ãä¸ä½ã¬ã¤ã¤ããä¸ä½ã¬ã¤ã¤ã«å¯¾ãï¼ã³ã¼ãããæ³¨å ¥ãããåããæã¤ãï¼
æå¾ã«ï¼ä¸è¨ã®ã³ã¼ãã§ãå¼ã³åºããã¦ãããï¼
Intentã®æ±ããã©ãããã¦ããRouterã¨ããã¯ã©ã¹ãæ²è¼ããã
å½åã®ãã³ãã¯ï¼Ruby on Railsã®routingï¼config/routes.rbï¼ããå¾ãã
package controller_test.dayo.controller.lib; import java.util.HashMap; import android.app.Activity; import android.content.Intent; // ç»é¢é·ç§»ãå®è¡ããã¯ã©ã¹ã public class Router { // ããªã失ææã®ç»é¢é·ç§» public static void go( Activity from_activity, Class<? extends Activity> to_activity, GateValidationResult vres ) { Intent intent = new Intent( from_activity.getApplicationContext(), to_activity ); from_activity.startActivity(intent); // ããªã失æãæ°ç»é¢ä¸ã§éç¥ vres.onFailedActivityStarted(from_activity); } // BLå®è¡æã®ç»é¢é·ç§»ã // ã¢ã¯ã·ã§ã³å®è¡çµæãã¨ã®ã«ã¼ãã£ã³ã°èå¥åã«ãã£ã¦åå²ã public static void switchByActionResult( Activity from_activity, ActionResult ares, HashMap<String, Class<? extends Activity>> routingTable ) { // ã«ã¼ãã£ã³ã°èå¥åãåå¾ String route_id = ares.getRouteId(); // é·ç§»å ã®Activityã®ã¯ã©ã¹ãåå¾ Class<? extends Activity> to_activity = routingTable.get(route_id); // é·ç§»ãå®è¡ Intent intent = new Intent( from_activity.getApplicationContext(), to_activity ); from_activity.startActivity(intent); // TODO: ActionResultãputExtraãã¦ï¼é·ç§»å ã®ç»é¢ã§åç §ã§ããããã«ããã // BLå®è¡å®äºãæ°ç»é¢ä¸ã§éç¥ ares.onNextActivityStarted(from_activity); } }
ããæ¬ç¨¿ã§ç´¹ä»ããå種ã¯ã©ã¹ã®å°å ¥ãé¢åãªå ´åï¼ãã®ãããªãIntentã®ããã¼ã¸ã£ãã ãã§ãä½ã£ã¦ããã¨ï¼ã³ã¼ãéãæ¸ã£ã¦å©ããã ããã
ã§ããã ãä¸ä½ã¬ã¤ã¤ã®APIãé ãºããï¼ã¦ã¼ã¶ã«ã¯ã¢ããªã®ä»æ§ã«é¢ãè¨è¿°ã®ã³ã¼ãã£ã³ã°ã«å°å¿µãããã
ãããã£ã¦çç£æ§ãåä¸ããããã¨ãçãã ã
è£è¶³
ããã¾ã§ã§ï¼è©¦ä½åã®è¨è¨æ¹éã¨ï¼ãµã³ãã«ãå®éã«åä½ããæ¨ã®å ±åãè¿°ã¹ãã
ããããå ï¼ã¾ã ããäºãæ®ã£ã¦ããã
ç¾å¨ï¼Androidã¢ããªéçºã«ãããã³ã³ããã¼ã©å±¤ãæ´ç·´ããããã®TODOã¨ãã¦ï¼
- ä»ã¢ããªã¨ã®é£æºæ©è½ãå
å®ããããã¨ããããAndroidã®å¼·ã¿ã ãã
- Controllerã¯ã©ã¹ã¯å®è³ªçã«ãIntentããã¼ã¸ã£ãã¿ãããªãã®ãªã®ã§ï¼ã¬ã·ã¼ãï¼ã¤ã³ãã³ããã£ã«ã¿ãªãããèæ ®ããæèã§ï¼ã³ã³ããã¼ã©å±¤ã®è¨è¨ãæ¡å¼µããå¿ è¦ãããã
- ããªãã¼ã¿ããã£ã¨æ¥½ã«è¨è¿°ã§ããããã«ï¼ããªãã¼ã·ã§ã³ãã¸ãã¯ãè±å¯ã«åããããããã¨ã
- ã¾ãã§JUnitãRSpecãQUnitã§ãã¹ãã³ã¼ããæ¸ããã®ããã«ï¼ããªãã¼ã·ã§ã³ãã¸ãã¯ãè¨è¿°ã§ãããï¼ããããã¤ã¹ã§é¢ç½ãã¨æããªããï¼assertEqual() ã¨ãï¼ããããã
- Controllerä¸ã«ã¦ã¼ã¶ãè¨è¿°ããã³ã¼ããï¼ã¸ã§ããªã¯ã¹çã®ãã¥ã¢Javaã®è¨æ³ãé§ä½¿ãã¦ï¼ããã«ããã«ã·ã³ãã«ã«ã§ããªããã®ããæ¬ç¨¿ã§æ²è¼ããã³ã¼ãã¯ï¼ç§ãå½åæå¾
ãã¦ããã³ã¼ããããåé·ãªå§¿ãªã®ã ã
- ã§ããã°ï¼ãyamlã¿ããã ãã©åå®å ¨ãªJavaã³ã¼ãããæ¸ãã¦ãã£ã¦ï¼ãããåããã¨ãã姿ããã¹ããªãã ãã©ï¼ããã¯åå°ï¼ç¡çã ãGroovyã§Androidã¢ããªãä½ããããã«ãªããªãã¾ã ããããã¨ãã£ã¦ï¼è¨å®ãã¡ã¤ã«å°çã¯ãããã ãã
- å æ¥ã®ãjQueryã£ã½ãã¬ã¤ã¢ã¦ããè¨è¿°ãããã®è¨äºã§ã¯å¤ãã¦ãããã®ã ãï¼Silverlightã¨ãRIAä¸çã§ã®ãMVVMãã¿ã¼ã³ãããã£ã¨èæ ®ããå¿ è¦ãããããã¤ã³ãã£ã³ã°æ©æ§ã¨ãå°å ¥ããã°ï¼ããªãã¼ã·ã§ã³ã®æ¦å¿µãå¤ããã¯ãã ã
ãã¹ãå¯è½ãªUIè¨è¨ãã¿ã¼ã³ – 第ï¼å Androidãã¹ãç¥ã çºè¡¨è³æ
http://ugaya40.net/architecture/andro...
- UIå´ã®è¨è¨ãççµåã«ãã¦ï¼åä½ãã¹ããããããã
MVVMãã¿ã¼ã³ã¨ã¯ï¼ – ãããã¾åçæ±äº¬åå¼·ä¼ #60 ã»ãã·ã§ã³è³æ
http://ugaya40.net/mvvm/what_is_mvvm....
- ã¯ã©ã¹ã®ç¸äºä¾åã§åä¸è²¬ä»»ã®ååã«åããã¨NGãéçºæã®ä½æ¥åæ ããã¥ãããããããã®ä¾åæ§ãæé¤ããå¿ è¦ãã
- 責åã«é¢é£ããã°ã¤ã³ã¿ãã§ã¼ã¹ã¯ãããé¢é£èããã°Observerãã¯ããã
- WPFãªããã¼ã¿ãã¤ã³ãã
Androidã¢ããªã®ç»é¢ã¬ã¤ã¢ã¦ããï¼ã¾ãã§jQueryã®ãããªã³ã¼ãã§åçæ§ç¯ã§ããã©ã¤ãã©ãªãï¼ã®è©¦ä½åãUIã³ã¼ãã£ã³ã°ã®ããã®DSLï¼
http://language-and-engineering.hatenablog.jp/entry/20120210/p1
ãAndroidã¨MVCã¢ããªã±ã¼ã·ã§ã³ã¢ã¼ããã¯ãã£ã
http://www.android-group.jp/index.php...
- 2008å¹´ã®æ å ±
ãªãï¼ããªãã¼ã·ã§ã³ã®åé¡ã¨ãã¦ã¯ï¼
ä»åã¯Controllerä¸ã§ã®ããªãã¼ã·ã§ã³ã ã£ãã®ã§ï¼ãã³ã³ããªãã®åå°ãå®è£ ãããã¨ããäºã«ãªãã
ãã¾ãç¥ããã¦ããªãï¼Webã¢ããªéçºæã®ï¼ï¼ã®ç¥èª ï¼ä¾æã¤ãï¼
http://language-and-engineering.hatenablog.jp/entry/20101102/p1
- ã¯ã©ããªãï¼ã¯ã©ã¤ã¢ã³ããµã¤ãã»ããªãã¼ã·ã§ã³ï¼
- ã¢ãããªãï¼ã¢ãã«ã¯ã©ã¹ã«ããããªãã¼ã·ã§ã³ï¼
- ã³ã³ããªãï¼ã³ã³ããã¼ã©ã¯ã©ã¹ã«ããããªãã¼ã·ã§ã³ï¼
ãã¾ãã§ï¼Strutsã触ã£ããã¨ãç¡ã人ã®ããã«ã
Strutsã®MVCã¢ã¼ããã¯ãã£ã®åºç¤ã«ã¤ãã¦ã¯ï¼ä¸è¨ãã¼ã¸ã®å³è¡¨ãªã©ãåç §ã
Strutsã®ç¥èãåºã«ãRuby on Railsãå¦ã¶
http://jibun.atmarkit.co.jp/lskill01/...
é¢é£ã¨ã³ããªï¼
ãããªãã¼ã·ã§ã³ãAPIã¨ãåä½ãã¹ããAPIã®é¡ä¼¼æ§ï¼ããã³ãã®ã¹ã¿ã¤ã«ãæ代ã¨å ±ã«æ´ç·´ãããéç¨ã®æ¦è¦³
http://language-and-engineering.hatenablog.jp/entry/20120320/p1
Androidã¢ããªéçºç¨ã®MVCãã¬ã¼ã ã¯ã¼ã¯ ãAndroid-MVCã ver0.2ããªãªã¼ã¹
http://language-and-engineering.hatenablog.jp/entry/20120323/p1
ã