简单的工具类LogUtil、Toast

简单的工具类LogUtil、Toast     粘过去就可以用了

activity调用:

日志打印:ALog.getInstance().i("MainActivity", "我是你要打印的内容");

Toast内容:ALog.getInstance().toast("MainActivity", "我是你要toast的内容");

package com.utils;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class ALog {

	/**
	 * 用法例子 ALog.getInstance().i("MainActivity", "我是你要打印的内容");
	 */

	private static boolean isRelease = true;

	private static class ULog {
		private final static ALog log = new ALog();
	}

	public final static ALog getInstance() {
		return ULog.log;
	}

	public void i(String tag, String msg) {
		if (isRelease && (!isNullEmptyBlank(tag)) && ((!isNullEmptyBlank(msg)))) {
			Log.i(tag, msg);
		}
	}

	public void e(String tag, String msg) {
		if (isRelease && (!isNullEmptyBlank(tag)) && ((!isNullEmptyBlank(msg)))) {
			Log.e(tag, msg);
		}
	}

	public void i(String tag, Object obj) {
		ALog.getInstance().i(tag, String.valueOf(obj));
	}

	public void e(String tag, Object obj) {
		ALog.getInstance().e(tag, String.valueOf(obj));
	}

	/**
	 * 弹出提示框 Toast
	 * 
	 * @param text
	 * @param 内容
	 */
	public void toast(Context context, String text) {
		if (!isNullEmptyBlank(text) && (!isNullEmptyBlank(text))) {
			Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
		}
	}

	public void toast(Context context, Object obj) {
		ALog.getInstance().toast(context, obj);
	}

	private boolean isNullEmptyBlank(String str) {
		if (null == str || "".equals(str) || "".equals(str.trim()))
			return true;
		return false;
	}
}


你可能感兴趣的:(android,tag)