ThinkAndroid框架

来源:互联网 发布:广播电台广告投放数据 编辑:程序博客网 时间:2024/06/08 08:58

1.简介

http://www.oschina.net/p/thinkandroid

2.数据存储

UserEntity.java

package com.gst.user.application;import java.io.Serializable;/** * Created by user on 2/15/16. */public class UserEntity implements Serializable{    private String username;    private String passward;    public UserEntity(String username, String passward) {        this.username = username;        this.passward = passward;    }    public UserEntity() {    }    public String getUsername() {        return username;    }    public void setUsername(String username) {        this.username = username;    }    public String getPassward() {        return passward;    }    public void setPassward(String passward) {        this.passward = passward;    }}


    private void read() {        TAIConfig config=taApplication.getConfig(TAApplication.PREFERENCECONFIG);        UserEntity userEntity=config.getConfig(UserEntity.class);        Log.d(TAG,userEntity.getUsername()+":"+userEntity.getPassward());    }    private void write() {        UserEntity userEntity=new UserEntity();        userEntity.setUsername("fsg");        userEntity.setPassward("123");        //保存        TAIConfig config=taApplication.getConfig(TAApplication.PREFERENCECONFIG);        config.setConfig(userEntity);        config.close();    }


3.数据库操作

package com.gst.user.application;import com.ta.TAApplication;import com.ta.util.db.TASQLiteDatabase;import java.util.List;/** * Created by user on 2/16/16. */public class UserDao {    TAApplication taApplication;    public UserDao(TAApplication taApplication) {        this.taApplication = taApplication;        TASQLiteDatabase database=taApplication.getSQLiteDatabasePool().getSQLiteDatabase();        if (!database.hasTable(UserEntity.class)){            database.creatTable(UserEntity.class);        }        taApplication.getSQLiteDatabasePool().releaseSQLiteDatabase(database);    }    public void insert(UserEntity userEntity){        TASQLiteDatabase database=taApplication.getSQLiteDatabasePool().getSQLiteDatabase();        database.insert(userEntity);        taApplication.getSQLiteDatabasePool().releaseSQLiteDatabase(database);    }    public List<UserEntity> query(){        List<UserEntity> userEntityList=null;        TASQLiteDatabase database=taApplication.getSQLiteDatabasePool().getSQLiteDatabase();        userEntityList=database.query(UserEntity.class, true, null, null, null, null, null);        taApplication.getSQLiteDatabasePool().releaseSQLiteDatabase(database);        return userEntityList;    }}
4.MVC模式

  • model
    package com.gst.user.application;import com.ta.mvc.command.TACommand;/** * Created by user on 2/16/16. */public class LoginBin extends TACommand {    @Override    protected void executeCommand() {        UserEntity userEntity= (UserEntity) getRequest().getData();        if ("fsg".equals(userEntity.getUsername()) &&"123".equals(userEntity.getPassward())){          sendSuccessMessage("success");        }    }}
  • view
    package com.gst.user.application;import android.os.Bundle;import android.util.Log;import com.ta.TAActivity;import com.ta.TAApplication;import com.ta.mvc.common.TAIResponseListener;import com.ta.mvc.common.TARequest;import com.ta.mvc.common.TAResponse;import com.ta.util.config.TAIConfig;public class TempActivity extends TAActivity {    TAApplication taApplication;    private static final String TAG = "TempActivity";    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.content_temp);        taApplication=getTAApplication();        //发消息        //发给model的数据        final TARequest request=new TARequest();        UserEntity userEntity=new UserEntity();        userEntity.setUsername("fsg");        userEntity.setPassward("123");        request.setData(userEntity);        final TAIResponseListener listener=new TAIResponseListener() {            @Override            public void onStart() {            }            @Override            public void onSuccess(TAResponse taResponse) {                Log.d(TAG, "mvc" + taResponse.getData());            }            @Override            public void onRuning(TAResponse taResponse) {            }            @Override            public void onFailure(TAResponse taResponse) {            }            @Override            public void onFinish() {            }        };        //处理model返回的结果        taApplication.doCommand("login",request,listener,true,true);    }}

  • control
    package com.gst.user.application;import com.easemob.chat.EMChat;import com.ta.TAApplication;/** * Created by user on 2/15/16. */public class MyApplication extends TAApplication {    @Override    public void onCreate() {        super.onCreate();        EMChat.getInstance().init(getApplicationContext());        EMChat.getInstance().setDebugMode(true);        registerCommand("login",LoginBin.class);    }}

0 0
原创粉丝点击