Back to project page android-mvc-framework.
The source code is released under:
Apache License
If you think the Android project android-mvc-framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.android_mvc.framework.common; //from www . j av a 2 s . c om import com.android_mvc.framework.annotations.SuppressDebugLog; import android.util.Log; /** * ??????????? * @author id:language_and_engineering * */ public class BaseUtil { // ?????????????????????????????????? private static final int DEBUG_STACK_INDEX = 5; // ?????????????????????????????????? private static final int SUPPRESS_STACK_INDEX = 5; /** * ??????????????????????????????????????????????????? */ protected static String APP_TAG = "TODO:"; /** * ?????????? */ protected static boolean DEBUGGING_FLAG; /** * ???????????????????????????? */ protected static boolean FORGET_PREFS_ON_DEBUG; /** * ?????????RDB???????????? */ protected static boolean FORGET_RDB_ON_DEBUG; // ----------------- ???? /** * ????????????? */ private static String getAppTag() { return APP_TAG; }; // http://okwave.jp/qa/q3705267.html /** * ???????????? */ private static void setAppTag( String s ) { APP_TAG = s; } /** * ???????????FW?????????????????????????????? */ public static void initAppTag( String s ) { setAppTag( s ); } // ----------------- ???? /** * Log.d?????? */ public static void d( String s ) { // ???????????????????????????????????????????????????? if( mustSuppressDebugLogByAnnotation() ) { // ?? return; } // TODO: ???????????????????????????????????????????????????????????????????? // ????????? String output = ""; // ??????????????????????????????????? if( isDebuggingMode() ) { // NOTE: ???????????????????????????????LogCat??????????????????????????????? output += getCallerMethodInfoAsString() + " : \n "; } output += s; Log.d( getAppTag(), output ); } /** * ????????????????????????????????? */ private static boolean mustSuppressDebugLogByAnnotation() { // ?????????? Class<?> target_class = null; try { target_class = Class.forName( getTraceInfoByIndex( SUPPRESS_STACK_INDEX ).getClassName() ); } catch (ClassNotFoundException e) { // ??????????? } // ???????????????????????? SuppressDebugLog ann = target_class.getAnnotation(SuppressDebugLog.class); if( ( ann != null ) && ann.value() ) // ???????????????true???????????????? { return true; } else { return false; } // NOTE: ???????????????????????????????Android?????????????????????? // @see http://d.hatena.ne.jp/Kazzz/20100110/p1 } /** * Log.w?????? */ public static void w( String s ) { Log.w( getAppTag(), s ); } /** * Log.e?????? */ public static void e( String s ) { Log.e( getAppTag(), s ); } /** * ????????????????????????????? */ private static String getCallerMethodInfoAsString() { StackTraceElement trace = getTraceInfoByIndex( DEBUG_STACK_INDEX ); String class_name = trace.getClassName(); // FIXED:??????????????????????????????????? String method_name = trace.getMethodName(); // @see http://koteitan.seesaa.net/article/171393826.html // http://okwave.jp/qa/q6341313.html return class_name + "#" + method_name; } /** * ???????????????????????????? */ private static StackTraceElement getTraceInfoByIndex( int index ) { return Thread.currentThread().getStackTrace()[ index ]; } // ----------------- ??????? /** * ???????????????????????????????? */ public static void initDebuggingMode( boolean b ) { DEBUGGING_FLAG = b; } /** * ???????????????????????????????? */ public static boolean isDebuggingMode() { return DEBUGGING_FLAG; } /** * ???????????????????? */ public static void setForgetPrefOnDebug( boolean b ) { FORGET_PREFS_ON_DEBUG = b; } /** * ????????????????????? */ private static boolean mustForgetPrefIfDebug() { return FORGET_PREFS_ON_DEBUG; } /** * ?????????????????????????????????????????? */ public static boolean mustClearPrefsForDebug() { d("isDebuggingMode = " + isDebuggingMode() + ", mustForgetPrefIfDebug = " + mustForgetPrefIfDebug() ); return isDebuggingMode() && mustForgetPrefIfDebug(); } /** * ???RDB??????????? */ public static boolean mustForgetRdbIfDebug() { return FORGET_RDB_ON_DEBUG; } /** * ???RDB????????? */ public static void setForgetRdbOnDebug( boolean b ) { FORGET_RDB_ON_DEBUG = b; } /** * ???????????RDB???????????????????????? */ public static boolean mustClearRdbForDebug() { return isDebuggingMode() && mustForgetRdbIfDebug(); } }