ThinkAndroid是一个免费的开源的、简易的、遵循Apache2开源协议发布的Android开发框架,其开发宗旨是简单、快速的进行 Android应用程序的开发,包含Android mvc、简易sqlite orm、ioc模块、封装Android httpclitent的http模块, 具有快速构建文件缓存功能,无需考虑缓存文件的格式,都可以非常轻松的实现缓存,它还基于文件缓存模块实现了图片缓存功能, 在android中加载的图片的时候,对oom的问题,和对加载图片错位的问题都轻易解决。他还包括了一个手机开发中经常应用的实用工具类, 如日志管理,配置文件管理,android下载器模块,网络切换检测等等工具。
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的秦皇岛网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
MVC模块:实现视图与模型的分离。
ioc模块:android中的ioc模块,完全注解方式就可以进行UI绑定、res中的资源的读取、以及对象的初始化。
数据库模块:android中的orm框架,使用了线程池对sqlite进行操作。
http模块:通过httpclient进行封装http数据请求,支持异步及同步方式加载。
缓存模块:通过简单的配置及设计可以很好的实现缓存,对缓存可以随意的配置
图片缓存模块:p_w_picpathview加载图片的时候无需考虑图片加载过程中出现的oom和android容器快速滑动时候出现的图片错位等现象。
配置器模块:可以对简易的实现配对配置的操作,目前配置文件可以支持Preference、Properties对配置进行存取。
日志打印模块:可以较快的轻易的是实现日志打印,支持日志打印的扩展,目前支持对sdcard写入本地打印、以及控制台打印
下载器模块:可以简单的实现多线程下载、后台下载、断点续传、对下载进行控制、如开始、暂停、删除等等。
网络状态检测模块:当网络状态改变时,对其进行检测。
配置: application必须配置以上格式
MVC模块:实现视图与模型的分离。
getTAApplication().registerCommand(R.string.comand, TAIdentityCommand.class); getTAApplication().registerCommand(R.string.comand, TAIdentityCommand.class); TALogger.addLogger(new TAPrintToFileLogger()); TARequest request = new TARequest(); doCommand(R.string.comand, request, new TAIResponseListener() { @Override public void onStart(TAResponse response) { // TODO Auto-generated method stub } @Override public void onSuccess(TAResponse response) { // TODO Auto-generated method stub } @Override public void onRuning(TAResponse response) { // TODO Auto-generated method stub } @Override public void onFailure(TAResponse response) { // TODO Auto-generated method stub } }, false, true, true);package com.ta.mvc.command;import com.ta.mvc.common.TAIResponseListener;import com.ta.mvc.common.TARequest;import com.ta.mvc.common.TAResponse;public class TAIdentityCommand extends TACommand{ @Override protected void executeCommand() { // TODO Auto-generated method stub TARequest request = getRequest(); TAResponse response = new TAResponse(); response.setTag(request.getTag()); response.setData(request.getData()); response.setActivityKey((String) request.getActivityKey()); response.setActivityKeyResID(request.getActivityKeyResID()); setResponse(response); notifyListener(true); } protected void notifyListener(boolean success) { TAIResponseListener responseListener = getResponseListener(); if (responseListener != null) { onComandUpdate(command_success); } }}
完全注解方式就可以进行UI绑定、res中的资源的读取、以及对象的初始化。
public class ThinkAndroidDemoActivity extends TAActivity { @TAInject Entity entity; //目前只能对无参构造函数进行初始化 @@TAInject(id=R.string.app_name) String appNameString; @TAInjectResource(id=R.attr.test) int[] test; @TAInjectView(id=R.id.add); Button addButton;}
android中的orm框架,使用了线程池对sqlite进行操作。
public class ThinkAndroidDemoActivity extends TAActivity { TASQLiteDatabasePool sqlitePool = getTAApplication() .getSQLiteDatabasePool(); TASQLiteDatabase sqliteDatabase=sqlitePool.getSQLiteDatabase(); //使用中 sqliteDatabase.insert(entity); sqlitePool.returnSQLiteDatabase(sqliteDatabase); }
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.thinkandroid.cn/", new AsyncHttpResponseHandler() { @Override public void onSuccess(String content) { // TODO Auto-generated method stub super.onSuccess(content); TALogger.d(LoginActivity.this, content); } @Override public void onStart() { // TODO Auto-generated method stub super.onStart(); } @Override public void onFailure(Throwable error) { // TODO Auto-generated method stub super.onFailure(error); } @Override public void onFinish() { // TODO Auto-generated method stub super.onFinish(); } });
TASyncHttpClient client = new TASyncHttpClient(); client.get("http://www.thinkandroid.cn/", new AsyncHttpResponseHandler() { @Override public void onSuccess(String content) { // TODO Auto-generated method stub super.onSuccess(content); TALogger.d(LoginActivity.this, content); } @Override public void onStart() { // TODO Auto-generated method stub super.onStart(); } @Override public void onFailure(Throwable error) { // TODO Auto-generated method stub super.onFailure(error); } @Override public void onFinish() { // TODO Auto-generated method stub super.onFinish(); } });
RequestParams params = new RequestParams(); params.put("username", "white_cat"); params.put("password", "123456"); params.put("email", "2640017581@qq.com"); params.put("profile_picture", new File("/mnt/sdcard/testpic.jpg")); // 上传文件 params.put("profile_picture2", inputStream); // 上传数据流 params.put("profile_picture3", new ByteArrayInputStream(bytes)); // 提交字节流 client.post("http://www.thinkandroid.cn/", new AsyncHttpResponseHandler() { @Override public void onSuccess(String content) { // TODO Auto-generated method stub super.onSuccess(content); TALogger.d(LoginActivity.this, content); } @Override public void onStart() { // TODO Auto-generated method stub super.onStart(); } @Override public void onFailure(Throwable error) { // TODO Auto-generated method stub super.onFailure(error); } @Override public void onFinish() { // TODO Auto-generated method stub super.onFinish(); } }); }
支持断点续传,随时停止下载任务 或者 开始任务
AsyncHttpClient syncHttpClient = new AsyncHttpClient(); FileHttpResponseHandler fHandler = new FileHttpResponseHandler( TAExternalOverFroyoUtils.getDiskCacheDir(TestActivity.this, "sdfsdfsdf").getAbsolutePath()) { @Override public void onProgress(String speed, String progress) { //TODO Auto-generated method stub super.onProgress(speed, progress); TALogger.v(TestActivity.this, progress + "--------" + speed); } @Override public void onFailure(Throwable error) { // TODOAuto-generated method stub super.onFailure(error); } @Override public void onSuccess(byte[] binaryData) { // TODOAuto-generated method stub super.onSuccess(binaryData); TALogger.d(TestActivity.this, "kaishi8了"); } }; syncHttpClient .download( "http://static.qiyi.com/ext/common/iQIYI/QIYImedia_4_01.exe", fHandler); //停止 fHandler.setInterrupt(interrupt);
p_w_picpathview加载图片的时候无需考虑图片加载过程中出现的oom和android容器快速滑动时候出现的图片错位等现象。
package com.test;import com.ta.TAApplication;import com.ta.util.bitmap.TABitmapCacheWork;import com.ta.util.bitmap.TADownloadBitmapHandler;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;public class Adapter extends BaseAdapter{ TABitmapCacheWork p_w_picpathFetcher; Context mContext; public Adapter(Context context, TAApplication application) { TADownloadBitmapHandler downloadBitmapFetcher = new TADownloadBitmapHandler( context, 100); p_w_picpathFetcher = new TABitmapCacheWork(context); p_w_picpathFetcher.setProcessDataHandler(downloadBitmapFetcher); p_w_picpathFetcher.setFileCache(application.getFileCache()); this.mContext = context; } @Override public int getCount() { // TODO Auto-generated method stub return Images.p_w_picpathThumbUrls.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return Images.p_w_picpathThumbUrls[position]; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View baseView = inflater.inflate(R.layout.login_adapter, null); final ImageView p_w_picpathView = (ImageView) baseView .findViewById(R.id.p_w_picpathView); //加载图片 p_w_picpathFetcher.loadFormCache(getItem(position), p_w_picpathView); return baseView; }}使用 @TAInjectView(id = R.id.gridView) GridView gridView; Adapter adapter = new Adapter(this, getTAApplication()); gridView.setAdapter(adapter);
很简单的实现缓存,以一个简单的文件缓存为例
下载处理类
package com.test.file;import com.ta.util.cache.TAProcessDataHandler;//下载处理类public class TAProcessStringHandler extends TAProcessDataHandler{ @Override public byte[] processData(Object data) { // TODO Auto-generated method stub String mynameString="white_cat"; //这里对数据进行处理,如下载东西等等,转换为byte[]以供缓存存储使用 return mynameString.getBytes(); }}
缓存结果返回操作类
package com.test.file;import android.widget.TextView;import com.ta.util.cache.TACallBackHandler;public class TAStringCallBackHandler extends TACallBackHandler{ @Override public void onStart(TextView t, Object data) { // TODO Auto-generated method stub super.onStart(t, data); } @Override public void onSuccess(TextView t, Object data, byte[] buffer) { // TODO Auto-generated method stub super.onSuccess(t, data, buffer); } @Override public void onFailure(TextView t, Object data) { // TODO Auto-generated method stub super.onFailure(t, data); }}
程序调用
TAFileCacheWorktaFileCacheWork=new TAFileCacheWork (); taFileCacheWork.setFileCache(getTAApplication().getFileCache()); taFileCacheWork.setCallBackHandler(new TAStringCallBackHandler()); taFileCacheWork.setProcessDataHandler(new TAProcessStringHandler()); taFileCacheWork.loadFormCache("http://www.baidu.com", textView);
可以较快的轻易的是实现日志打印,支持日志打印的扩展,目前支持对sdcard写入本地打印、以及控制台打印 添加打印器 TALogger.addLogger(new TAPrintToFileLogger()); 调用打印 TALogger.addLogger(new TAPrintToFileLogger()); TALogger.d(TestActivity.this, "test");
可以简单的实现多线程下载、后台下载、断点续传、对下载进行控制、如开始、暂停、删除等等。
private DownloadManager downloadManager;downloadManager = DownloadManager.getDownloadManager(); downloadManager.setDownLoadCallback(new DownLoadCallback() { @Override public void onSuccess(String url) { } @Override public void onLoading(String url, String speed, String progress) { // TODO Auto-generated method stub } }); //添加 downloadManager.addHandler(url); //继续 downloadManager.continueHandler(url); //暂停 downloadManager.pauseHandler(url); //删除 downloadManager.deleteHandler(url); //
后台下载
private IDownloadService downloadService; ServiceConnection serviceConnection=new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { // TODO Auto-generated method stub } @Override public void onServiceConnected(ComponentName name, IBinder service) { // TODO Auto-generated method stub downloadService=(IDownloadService)service; } }; //添加任务 downloadService.addTask(url) //暂停任务 downloadService.pauseTask(url) //继续任务 downloadService.continueTask(url) //删除任务 downloadService.deleteTask(url)
可以对简易的实现配对配置的操作,目前配置文件可以支持Preference、Properties对配置进行存取
TAIConfig config = application .getConfig(TAApplication.PROPERTIESCONFIG); Entity entity = new Entity(); entity.setB(false); entity.setD(10); entity.setI(1); entity.setF(1f); config.setConfig(entity); Entity cEntity = config.getConfig(Entity.class); textView.setText(cEntity.toString());
当网络状态改变时,对其进行监测。
TANetworkStateReceiver.registerObserver(new TANetChangeObserver() { @Override public void onConnect(netType type) { // TODO Auto-generated method stub super.onConnect(type); Toast.makeText(TestActivity.this, "onConnect", Toast.LENGTH_SHORT).show(); } @Override public void onDisConnect() { // TODO Auto-generated method stub super.onDisConnect(); Toast.makeText(TestActivity.this, "onDisConnect", Toast.LENGTH_SHORT).show(); } }); 需要开启权限配置: