編輯:關於Android編程
在寫項目的時候,我們是避免不了用到安卓裡面的Log打印工具的,但是當代碼越寫越多的時候我們這加個Log 那加個Log,當我們項目要上線的時候,我們總會忘記哪有Log,很麻煩啊,當時殺人的心都有了,現在封裝一個Log工具,只需要定義boolean就可以一鍵實現打印和不打印功能,直接復制過去拿到項目裡面用就行!
不要感謝我,請叫我雷鋒
package com.example.qlog;
import java.util.Calendar;
public final class QLog {
public static final boolean DEBUG = true;//是否打印
/**
* Send a {@link #VERBOSE} log message.
*
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param msg The message you would like logged.
*/
public static int v(String tag, String format, Object... args) {
if (DEBUG) {
if (args == null || args.length == 0) {
return android.util.Log.v(tag, format);
}
return android.util.Log.v(tag, String.format(format, args));
}
return 0;
}
/**
* Send a {@link #DEBUG} log message.
*
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param msg The message you would like logged.
*/
public static int d(String tag, String format, Object... args) {
if (DEBUG) {
if (args == null || args.length == 0) {
return android.util.Log.d(tag, format);
}
return android.util.Log.d(tag, String.format(format, args));
}
return 0;
}
/**
* Send an {@link #INFO} log message.
*
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param msg The message you would like logged.
*/
public static int i(String tag, String format, Object... args) {
if (DEBUG) {
if (args == null || args.length == 0) {
return android.util.Log.i(tag, format);
}
return android.util.Log.i(tag, String.format(format, args));
}
return 0;
}
/**
* Send a {@link #WARN} log message.
*
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param msg The message you would like logged.
*/
public static int w(String tag, String format, Object... args) {
if (DEBUG) {
if (args == null || args.length == 0) {
return android.util.Log.w(tag, format);
}
return android.util.Log.w(tag, String.format(format, args));
}
return 0;
}
/**
* Send a {@link #WARN} log message and log the exception.
*
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param tr An exception to log
*/
public static int w(String tag, Throwable tr) {
if (DEBUG) {
return android.util.Log.w(tag, tr);
}
return 0;
}
/**
* Send an {@link #ERROR} log message.
*
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param msg The message you would like logged.
*/
public static int e(String tag, String msg, Throwable e) {
if (DEBUG) {
return android.util.Log.e(tag, msg, e);
}
return 0;
}
/**
* Send an {@link #ERROR} log message.
*
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param msg The message you would like logged.
*/
public static int e(String tag, String msg) {
if (DEBUG) {
return android.util.Log.e(tag, msg);
}
return 0;
}
/**
* Low-level logging call.
*
* @param priority The priority/type of this log message
* @param tag Used to identify the source of a log message. It usually identifies the class or activity where the
* log call occurs.
* @param msg The message you would like logged.
* @return The number of bytes written.
*/
public static int println(int priority, String tag, String msg) {
if (DEBUG) {
return android.util.Log.println(priority, tag, msg);
}
return 0;
}
/**
* 打印調用時間
*
* @param cur ????的時??
* @return 調用時間
*/
public static long debugDuration(long cur) {
long sec = System.currentTimeMillis();
StackTraceElement elem = Thread.currentThread().getStackTrace()[3];
d("Performance", elem.getFileName() + "_" + elem.getLineNumber() + ":" + (sec - cur));
return sec;
}
/**
* 打印當前調用的位置: 文件 行號 方法
*
* @param tag
* @return
*/
public static int printLogPos(String tag) {
StackTraceElement elem = Thread.currentThread().getStackTrace()[3];
return d(tag, elem.getClassName() + ":" + elem.getLineNumber() + "::" + elem.getMethodName());
}
/**
* 獲得當前調用位置??類名
*
* @param depth 堆棧深度
* @return
*/
public static String getLogPos(int depth) {
StackTraceElement elem = Thread.currentThread().getStackTrace()[depth];
return elem.getClassName();
}
/**
* depth = 4
*
* @see #getLogPos(int)
* @return
*/
public static String getLogPos() {
return getLogPos(4);
}
/**
* 獲得當前??code>from????的秒?? *
* @param from
* @return
*/
public static long getSecond(Calendar from) {
return (System.currentTimeMillis() - from.getTimeInMillis()) / 1000;
}
private static final Calendar _20120101 = Calendar.getInstance();
static {
_20120101.set(2012, 0, 0, 0, 0, 0);
}
/**
* from = 20120101
*
* @see #getSecond(Calendar)
* @return
*/
public static long getSecond() {
return getSecond(_20120101);
}
}
Android WebView簡要介紹和學習計劃
我們通常會在App的UI中嵌入WebView,用來實現某些功能的動態更新。在4.4版本之前,Android WebView基於WebKit實現。不過,在4.4版本之後,A
Android For JNI(二)——C語言中的數據類型,輸出,輸入函數以及操作內存地址,內存修改器
Android For JNI(二)——C語言中的數據類型,輸出,輸入函數以及操作內存地址,內存修改器 當我們把Hello World寫完之後,我
Android Notification(通知)
通知基本用法通知的必要屬性一個通知必須包含以下三項屬性:小圖標,對應 setSmallIcon()通知標題,對應 setContentTitle()詳細信息,對應 set
TankWar 單機(JAVA版)版本2.2 超級炮彈
既然我們能夠實現一個方向的發子彈,那麼根據同樣的道理 也能夠實現八個方向的發子彈。首先在Tank類的KeyPress方法裡面加上按鍵A的事件 // 我方坦克的