(原创)分享自己写的几个工具类(三)Toast和Log管理类

平常开发中测试代码,toast和log用的比较多

好处是代码简介方便,一行即可

但这样的代码写的多了,有时候也不易查找

而且影响可读性

于是自己封装了一个Debug管理工具类,

下面直接贴代码:

/**
 * Created by Administrator on 2017/4/14 0014.
 * 管理toastlog打印的工具类
 */
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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值