2011年11月23日 星期三

Amazing-Runtime-Platform(ARP) for Android 動手做做看

聽了這麼多是不是有這麼一點不踏實呢? 動手玩玩看我們 ARP for Android 吧!以下是我們自行寫成的 .jar檔。
將這兩個檔案下載後,加到專案中的 Library 就可以使用囉。
至於要怎麼加到 Library 之中呢?右鍵點選專案--> Build Path --> Configure Build Path --> Add External Jar ,就可以將我們的 ARP 加進 Library 之中囉。
既然已經將 Library 放進來了,馬上就讓我們試試 Front Controler 吧,首先來試試我們的 change view 的功能吧,
首先 create new Android project ,project name : SamepleActivity,SampleActivity 裡面還使用了兩個 method ,分別是 MainLayoutAction and Layout1Action
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.notonly.android.core.AmazingActivity;

public class SampleActivity extends AmazingActivity {

private static String TAG = SampleActivity.TAG + "." + SampleActivity.class.getName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
         
        super.onCreate(savedInstanceState);
         
        Log.i(TAG, "onCreate");
         
        addAction(new MainLayoutAction(this, R.layout.main));
        addAction(new Layout1Action(this, R.layout.layout1));
     
        selectView(R.layout.main);
    }
 
    @Override
    protected void onDestroy() {
         
        super.onDestroy();
    }
 
    @Override
    public void doReceive(int arg0, Intent arg1) {
         
    }
}
MainLayoutAction:
這個 method 繼承 AmazingAction ,並且實做 doBind 的部份
import android.view.View;
import android.widget.Button;

import com.notonly.android.core.AmazingAction;
import com.notonly.android.core.AmazingActivity;

public class MainLayoutAction extends AmazingAction{
 
    Button bChange;
     
    public MainLayoutAction(AmazingActivity activity, int targetViewId) {
        super(activity, targetViewId);
        // TODO Auto-generated constructor stub
    }
    @Override
    protected void doBind() {
        bChange = (Button) findViewById(R.id.bchange);
         
        bChange.setOnClickListener(new Button.OnClickListener(){
 
            @Override
            public void onClick(View v) {
                selectView(R.layout.layout1);
                 
            }
             
        });
         
    }
}
Layout1Action :
import android.view.View;
import android.widget.Button;

import com.notonly.android.core.AmazingAction;
import com.notonly.android.core.AmazingActivity;

public class Layout1Action extends AmazingAction{
     
    Button bBcak;
     
    public Layout1Action(AmazingActivity activity, int targetViewId) {
        super(activity, targetViewId);
        // TODO Auto-generated constructor stub
    }
 
    @Override
    protected void doBind() {
        bBcak = (Button) findViewById(R.id.bback);
         
        bBcak.setOnClickListener(new Button.OnClickListener(){
 
            @Override
            public void onClick(View v) {
                selectView(R.layout.main);
                 
            }           
        });     
    }
}
xml的部份
main:
< ?xml version="1.0" encoding="utf-8"?>


    
     

    
layout1:


    

    
趕緊動手試試我們的 Amazing-Runtime-Platform 吧!讓你的 Activity 乾乾淨淨不再受雜亂的程式碼污染啦!
張貼留言