Commits

littledot5566 committed b22507c

New Log level ASSERT, new Cursor dumper.

  • Participants
  • Parent commits 7855d19

Comments (0)

Files changed (2)

File src/nctuw/littledot/util/Echo.java

 
 public class Echo {
 	public static void i(Context context, String msg) {
-		Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+		Toast.makeText(context, Leg.e(msg), Toast.LENGTH_SHORT).show();
 		Leg.i(msg);
 	}
 
 	public static void d(Context context, String msg) {
-		Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+		Toast.makeText(context, Leg.e(msg), Toast.LENGTH_SHORT).show();
 		Leg.d(msg);
 	}
 
 	public static void w(Context context, String msg) {
-		Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+		Toast.makeText(context, Leg.e(msg), Toast.LENGTH_SHORT).show();
 		Leg.w(msg);
 	}
 
 	public static void e(Context context, String msg) {
-		Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
-		Leg.e(msg);
+		Toast.makeText(context, Leg.e(msg), Toast.LENGTH_SHORT).show();
+
+	}
+
+	public static void a(Context context, String msg) {
+		Toast.makeText(context, Leg.a(msg), Toast.LENGTH_SHORT).show();
 	}
 }

File src/nctuw/littledot/util/Leg.java

  * 
  */
 
+import android.database.Cursor;
 import android.util.Log;
 
 /**
 	private static final byte	DEBUG_DBUG	= 2;
 	private static final byte	DEBUG_WARN	= 3;
 	private static final byte	DEBUG_EROR	= 4;
+	private static final byte	DEBUG_ASRT	= 5;
 
 	public static String i(String msg) {
 		return log(DEBUG_INFO, msg);
 		return log(DEBUG_EROR, msg);
 	}
 
+	public static String a(String msg) {
+		return log(DEBUG_ASRT, msg);
+	}
+
 	private static String log(byte level, String msg) {
 		/* 
 		for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
 			case DEBUG_EROR:
 				Log.e(tag, str);
 				break;
+			case DEBUG_ASRT:
+				Log.println(Log.ASSERT, tag, str);
+				break;
 		}
 		return str;
 	}
+
+	public static void dumpCursor(Cursor cur) {
+		if (!cur.moveToFirst()) {
+			Leg.a("Cursor is empty.");
+			return;
+		}
+
+		int pos = cur.getPosition();
+
+		// dump column name
+		String log = "";
+		String cols[] = cur.getColumnNames();
+		int colNum = cols.length;
+
+		for (int i = 0; i < colNum; i++) {
+			log += cols[i] + "/";
+		}
+		Leg.a("columns=" + log);
+
+		// dump data
+		while (!cur.isAfterLast()) {
+			log = "";
+			for (int i = 0; i < colNum; i++) {
+				log += cur.getString(i) + "/";
+			}
+			Leg.a(log);
+			cur.moveToNext();
+		}
+		cur.moveToPosition(pos);
+	}
 }