(原创)分享自己写的几个工具类(三)Toast和Log管理类
2017-04-17 17:52
453 查看
平常开发中测试代码,toast和log用的比较多
好处是代码简介方便,一行即可
但这样的代码写的多了,有时候也不易查找
而且影响可读性
于是自己封装了一个Debug管理工具类,
下面直接贴代码:
这个工具类实现了Toast的弹出和log的打印
同时适配了自定义事件的toast
log打印的话只写了logd,读者可以自己加上其他log
好处是代码简介方便,一行即可
但这样的代码写的多了,有时候也不易查找
而且影响可读性
于是自己封装了一个Debug管理工具类,
下面直接贴代码:
/** * Created by Administrator on 2017/4/14 0014. * 管理toast和log打印的工具类 */ public class DebugUtil { public static final String TAG = "print"; private DebugUtil() { } /** * 管理log打印 * * @param str */ public static void logD(String str) { if (str != null) { Log.d(TAG, str); } else { Log.d(TAG, "打印参数为空,请检查后再打印执行"); } } //短toast public static void toastShort(Context context, String str) { if (context != null && str != null) { Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); } else if (str == null) { Toast.makeText(context, "输入参数为空值,请检查后重新输入", Toast.LENGTH_SHORT).show(); } } //长toast public static void toastLong(Context context, String str) { if (context != null && str != null) { Toast.makeText(context, str, Toast.LENGTH_LONG).show(); } else if (str == null) { Toast.makeText(context, "输入参数为空值,请检查后重新输入", Toast.LENGTH_SHORT).show(); } } //自定义时间 public static void toastTimer(Context context, String str, int durantion) { if (context != null && str != null) { Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); } else if (str == null) { Toast.makeText(context, "输入参数为空值,请检查后重新输入", durantion).show(); } } }
这个工具类实现了Toast的弹出和log的打印
同时适配了自定义事件的toast
log打印的话只写了logd,读者可以自己加上其他log
相关文章推荐
- (原创)分享自己写的几个工具类(五)时间计算工具类
- (原创)分享自己写的几个工具类(一)防止重复点击工具类
- (原创)分享自己写的几个工具类(四)BigDecimal精确计算
- (原创)分享自己写的几个工具类(二)共享参数工具类
- 编程乐趣:分享几个自己常用的工具
- 分享一个小工具,提供源码,以便根据自己需要进行修改
- 分享一个小巧简单的基金查询工具(自己写的)
- 分享一个自己做的简易敏捷开发管理工具——AgileLite
- 分享一个Windows Mobile下自己写的联系人备份工具
- 分享一款自己开发的小工具[网页一键转PDF]
- 如何在自己的网站或博客或空间加上社交分享按钮,猜你喜欢工具,社会化评论框
- 和大家分享下,自己写的一个截图小工具
- 定义自己的Log管理类
- 分享自己写的一个小工具RGB转十六进制(高手勿喷)
- 新手分享自己使用的在线UML画图工具
- 分享几个iOS游戏开发的有利工具
- 分享一个自己写的字符串工具:字符串格式化拼接
- 分享几个iOS游戏开发的有利工具
- 分享自己做的一个系统工具--CME [友情转载]
- 【绝对原创】BACnet MS/TP开发经验分享系列-001 工具篇