您好,登錄后才能下訂單哦!
ThinkAndroid是一個免費的開源的、簡易的、遵循Apache2開源協(xié)議發(fā)布的Android開發(fā)框架,其開發(fā)宗旨是簡單、快速的進(jìn)行 Android應(yīng)用程序的開發(fā),包含Android mvc、簡易sqlite orm、ioc模塊、封裝Android httpclitent的http模塊, 具有快速構(gòu)建文件緩存功能,無需考慮緩存文件的格式,都可以非常輕松的實現(xiàn)緩存,它還基于文件緩存模塊實現(xiàn)了圖片緩存功能, 在android中加載的圖片的時候,對oom的問題,和對加載圖片錯位的問題都輕易解決。他還包括了一個手機(jī)開發(fā)中經(jīng)常應(yīng)用的實用工具類, 如日志管理,配置文件管理,android下載器模塊,網(wǎng)絡(luò)切換檢測等等工具。
MVC模塊:實現(xiàn)視圖與模型的分離。
ioc模塊:android中的ioc模塊,完全注解方式就可以進(jìn)行UI綁定、res中的資源的讀取、以及對象的初始化。
數(shù)據(jù)庫模塊:android中的orm框架,使用了線程池對sqlite進(jìn)行操作。
http模塊:通過httpclient進(jìn)行封裝http數(shù)據(jù)請求,支持異步及同步方式加載。
緩存模塊:通過簡單的配置及設(shè)計可以很好的實現(xiàn)緩存,對緩存可以隨意的配置
圖片緩存模塊:p_w_picpathview加載圖片的時候無需考慮圖片加載過程中出現(xiàn)的oom和android容器快速滑動時候出現(xiàn)的圖片錯位等現(xiàn)象。
配置器模塊:可以對簡易的實現(xiàn)配對配置的操作,目前配置文件可以支持Preference、Properties對配置進(jìn)行存取。
日志打印模塊:可以較快的輕易的是實現(xiàn)日志打印,支持日志打印的擴(kuò)展,目前支持對sdcard寫入本地打印、以及控制臺打印
下載器模塊:可以簡單的實現(xiàn)多線程下載、后臺下載、斷點續(xù)傳、對下載進(jìn)行控制、如開始、暫停、刪除等等。
網(wǎng)絡(luò)狀態(tài)檢測模塊:當(dāng)網(wǎng)絡(luò)狀態(tài)改變時,對其進(jìn)行檢測。
<!-- 訪問互聯(lián)網(wǎng)權(quán)限 根據(jù)需要添加--><uses-permission android:name="android.permission.INTERNET" /><!-- SDCARD讀寫權(quán)限 根據(jù)需要添加 --><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!-- 網(wǎng)絡(luò)狀態(tài)檢測權(quán)限 根據(jù)需要添加--><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /><uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 配置: <receiver android:name="com.ta.util.netstate.TANetworkStateReceiver" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> <application android:name="com.ta.TAApplication" > application必須配置以上格式
MVC模塊:實現(xiàn)視圖與模型的分離。
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); } }}
完全注解方式就可以進(jìn)行UI綁定、res中的資源的讀取、以及對象的初始化。
public class ThinkAndroidDemoActivity extends TAActivity { @TAInject Entity entity; //目前只能對無參構(gòu)造函數(shù)進(jìn)行初始化 @@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進(jìn)行操作。
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); // 上傳數(shù)據(jù)流 params.put("profile_picture3", new ByteArrayInputStream(bytes)); // 提交字節(jié)流 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(); } }); }
支持?jǐn)帱c續(xù)傳,隨時停止下載任務(wù) 或者 開始任務(wù)
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加載圖片的時候無需考慮圖片加載過程中出現(xiàn)的oom和android容器快速滑動時候出現(xiàn)的圖片錯位等現(xiàn)象。
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);
很簡單的實現(xiàn)緩存,以一個簡單的文件緩存為例
下載處理類
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"; //這里對數(shù)據(jù)進(jìn)行處理,如下載東西等等,轉(zhuǎn)換為byte[]以供緩存存儲使用 return mynameString.getBytes(); }}
緩存結(jié)果返回操作類
package com.test.file;import android.widget.TextView;import com.ta.util.cache.TACallBackHandler;public class TAStringCallBackHandler extends TACallBackHandler<TextView>{ @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); }}
程序調(diào)用
TAFileCacheWork<TextView> taFileCacheWork=new TAFileCacheWork<TextView>(); taFileCacheWork.setFileCache(getTAApplication().getFileCache()); taFileCacheWork.setCallBackHandler(new TAStringCallBackHandler()); taFileCacheWork.setProcessDataHandler(new TAProcessStringHandler()); taFileCacheWork.loadFormCache("http://www.baidu.com", textView);
可以較快的輕易的是實現(xiàn)日志打印,支持日志打印的擴(kuò)展,目前支持對sdcard寫入本地打印、以及控制臺打印 添加打印器 TALogger.addLogger(new TAPrintToFileLogger()); 調(diào)用打印 TALogger.addLogger(new TAPrintToFileLogger()); TALogger.d(TestActivity.this, "test");
可以簡單的實現(xiàn)多線程下載、后臺下載、斷點續(xù)傳、對下載進(jìn)行控制、如開始、暫停、刪除等等。
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); //繼續(xù) 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; } }; //添加任務(wù) downloadService.addTask(url) //暫停任務(wù) downloadService.pauseTask(url) //繼續(xù)任務(wù) downloadService.continueTask(url) //刪除任務(wù) downloadService.deleteTask(url)
可以對簡易的實現(xiàn)配對配置的操作,目前配置文件可以支持Preference、Properties對配置進(jìn)行存取
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());
當(dāng)網(wǎng)絡(luò)狀態(tài)改變時,對其進(jìn)行監(jiān)測。
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(); } }); 需要開啟權(quán)限 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 配置: <receiver android:name="com.ta.util.netstate.TANetworkStateReceiver" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。