【FastDev4Android框架開發】Android快速開發框架介紹(一)

轉載請標明出處:

http://www.lxweimin.com/p/67dffeedc6ad

本文出自:【江清清博客-代號獨狼】

? ? ? ? 本項目是Android快速開發框架,采用AndroidStudio進行開發。 隨著公司項目的不斷深入,也相信每個公司都有自己的項目開發框架,同時也在不斷的完善,本人在工作中也在不斷總結,喜歡技術,熱愛開源,也樂于和各種技術牛人一起交流。同時一直有一個想法可以做一套相對快速的開發框架用于工作中。所以就有了下面這個項目,各種工具方法都會再接下來的時間中慢慢加入進入,也非常歡迎和我同樣想法的牛人加入進來,一起把這個項目完善好~Thankyou

項目地址:https://github.com/jiangqqlmj/FastDev4Android

文章主頁地址:http://blog.csdn.net/developer_jiangqq

(一):初步想法集成如下:

1:開發工具類;

2:ORM;

3:網絡請求(HTTPClint,Volley,OkHttps);

4:數據解析;

5:依賴注入;

6:xutils;

7:圖片異步加載;

8:二維碼掃描;

9:自定義控件;

10:傳感器相關功能等等 后續會進行逐步添加。

模塊詳解如下:

(二):V1.0_001版本功能如下:

一.Utils工具類加入(1.DataUtils 時間日期處理

2.GuideUtils 是否啟動引導處理標志管理

3.IoUtils 網絡請求工具類【特別注意】這邊采用HTTPClient 由于Android 6.0已經刪除該類,

這邊libs目錄需要加入org.apache.http.legcy.jar依賴包

4.JudgeNetWorker 網絡狀態判斷工具類

5.Log 日志自定義管理

6.ManagerActivity Activity管理工具類

7.StrUtils 字符串相關處理工具類,系統信息獲取工具類)

二.sperferences加入SharePerferences加入封裝工具可以快速使用SP進行數據保存配置文件

三.Activity基類簡單封裝BaseActivity和BaseFrameActivity 暫時主要為Toast,LayoutInFlater,打開指定的Activity工具類封裝

(三):實例代碼

1:SharedPerference模塊封裝類:

SharedPreferencesHelper.java

package com.chinaztt.fda.spreference;

import android.content.Context;

import android.content.SharedPreferences;

/**

* 當前類注釋:當前為SharedPerferences進行封裝基本的方法,SharedPerferences已經封裝成單例模式

* 可以通過SharedPreferences sp=SharedPreferencesHelper.getInstances(FDApplication.getInstance())進行獲取當前對象

* sp.putStringValue(key,value)進行使用

* 項目名:FastDev4Android

* 包名:com.chinaztt.fda.spreference

* 作者:江清清 on 15/10/22 09:25

* 郵箱:jiangqqlmj@163.com

* QQ: 781931404

* 公司:江蘇中天科技軟件技術有限公司

*/

public class SharedPreferencesHelper {

private static final String SHARED_PATH = "fda_shared";

private static SharedPreferencesHelper instance;

private SharedPreferences sp;

private SharedPreferences.Editor editor;

public static SharedPreferencesHelper getInstance(Context context) {

if (instance == null && context != null) {

instance = new SharedPreferencesHelper(context);

}

return instance;

}

private SharedPreferencesHelper(Context context) {

sp = context.getSharedPreferences(SHARED_PATH, Context.MODE_PRIVATE);

editor = sp.edit();

}

public long getLongValue(String key) {

if (key != null && !key.equals("")) {

return sp.getLong(key, 0);

}

return 0;

}

public String getStringValue(String key) {

if (key != null && !key.equals("")) {

return sp.getString(key, null);

}

return null;

}

public int getIntValue(String key) {

if (key != null && !key.equals("")) {

return sp.getInt(key, 0);

}

return 0;

}

public int getIntValueByDefault(String key)

{

if (key != null && !key.equals("")) {

return sp.getInt(key, 0);

}

return 0;

}

public boolean getBooleanValue(String key) {

if (key != null && !key.equals("")) {

return sp.getBoolean(key, false);

}

return true;

}

public float getFloatValue(String key) {

if (key != null && !key.equals("")) {

return sp.getFloat(key, 0);

}

return 0;

}

public void putStringValue(String key, String value) {

if (key != null && !key.equals("")) {

editor = sp.edit();

editor.putString(key, value);

editor.commit();

}

}

public void putIntValue(String key, int value) {

if (key != null && !key.equals("")) {

editor = sp.edit();

editor.putInt(key, value);

editor.commit();

}

}

public void putBooleanValue(String key, boolean value) {

if (key != null && !key.equals("")) {

editor = sp.edit();

editor.putBoolean(key, value);

editor.commit();

}

}

public void putLongValue(String key, long value) {

if (key != null && !key.equals("")) {

editor = sp.edit();

editor.putLong(key, value);

editor.commit();

}

}

public void putFloatValue(String key, Float value) {

if (key != null && !key.equals("")) {

editor = sp.edit();

editor.putFloat(key, value);

editor.commit();

}

}

}

SharedPerferencesTag.java

package com.chinaztt.fda.spreference;

/**

* 當前類注釋:當前類用戶SharedPreferences進行save的時候 配置key常量

* 項目名:FastDev4Android

* 包名:com.chinaztt.fda.spreference

* 作者:江清清 on 15/10/22 09:26

* 郵箱:jiangqqlmj@163.com

* QQ: 781931404

* 公司:江蘇中天科技軟件技術有限公司

*/

public class SharedPreferencesTag {

public static final String DEMO_KEY="demo_key";

}

2.日志管理類封裝

package com.chinaztt.fda.utils;

/**

* 當前類注釋:重寫系統日志管理類

* 使用方法:還是和平時Log.v(key,value)這樣使用,需要導入當前類,該類會打印比系統更多的日志信息,

* 例如:類名稱,當前運行的方法,行數,和日志信息

* 項目名:FastDev4Android

* 包名:com.chinaztt.fda.utils

* 作者:江清清 on 15/10/22 09:35

* 郵箱:jiangqqlmj@163.com

* QQ: 781931404

* 公司:江蘇中天科技軟件技術有限公司

*/

public class Log {

public static boolean mIsShow=true;

/**

* 設置是否打開log日志開關

* @param pIsShow

*/

public static void setShow(boolean pIsShow)

{

mIsShow=pIsShow;

}

/**

* 根據tag打印相關v信息

* @param tag

* @param msg

*/

public static void v(String tag,String msg)

{

if(mIsShow){

StackTraceElement ste = new Throwable().getStackTrace()[1];

String traceInfo = ste.getClassName() + "::";

traceInfo += ste.getMethodName();

traceInfo += "@" + ste.getLineNumber() + ">>>";

android.util.Log.v(tag, traceInfo+msg);}

}

/**

* 根據tag打印v信息,包括Throwable的信息

* * @param tag

* @param msg

* @param tr

*/

public static void v(String tag,String msg,Throwable tr)

{

if(mIsShow){

android.util.Log.v(tag, msg, tr);

}

}

/**

* 根據tag打印輸出debug信息

* @param tag

* @param msg

*/

public static void d(String tag,String msg)

{

if(mIsShow){

StackTraceElement ste = new Throwable().getStackTrace()[1];

String traceInfo = ste.getClassName() + "::";

traceInfo += ste.getMethodName();

traceInfo += "@" + ste.getLineNumber() + ">>>";

android.util.Log.d(tag, traceInfo+msg);

}}

/**

* 根據tag打印輸出debug信息 包括Throwable的信息

* * @param tag

* @param msg

* @param tr

*/

public static void d(String tag,String msg,Throwable tr)

{

if(mIsShow){

android.util.Log.d(tag, msg, tr);

}}

/**

* 根據tag打印輸出info的信息

* * @param tag

* @param msg

*/

public static void i(String tag,String msg)

{

if(mIsShow){

StackTraceElement ste = new Throwable().getStackTrace()[1];

String traceInfo = ste.getClassName() + "::";

traceInfo += ste.getMethodName();

traceInfo += "@" + ste.getLineNumber() + ">>>";

android.util.Log.i(tag, traceInfo+msg);

}}

/**

* 根據tag打印輸出info信息 包括Throwable的信息

* @param tag

* @param msg

* @param tr

*/

public static void i(String tag,String msg,Throwable tr)

{

if(mIsShow){

android.util.Log.i(tag, msg, tr);

}}

/**

* 根據tag打印輸出error信息

* @param tag

* @param msg

*/

public static void e(String tag,String msg)

{

if(mIsShow){

StackTraceElement ste = new Throwable().getStackTrace()[1];

String traceInfo = ste.getClassName() + "::";

traceInfo += ste.getMethodName();

traceInfo += "@" + ste.getLineNumber() + ">>>";

android.util.Log.e(tag, traceInfo+msg);

}}

/**

* 根據tag打印輸出的error信息 包括Throwable的信息

* @param tag

* @param msg

* @param tr

*/

public static void e(String tag,String msg,Throwable tr)

{

if(mIsShow){

android.util.Log.e(tag, msg, tr);

}}

}

以上是部分工具類封裝模塊,有興趣的童鞋可以去(https://github.com/jiangqqlmj/FastDev4Android)進行clone,也同時歡迎大家star或者fork一下哈,項目會不斷更新,同時如果有興趣一起完善項目的小伙伴聯系我哈~博客資料有聯系方式!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容