/** * create the prefix with the current time, it is create only if the last message was received * more than PAUSE_DETECTION_TIME_MS ms ago * * @param append if true force to create the prefix string * @return prefix string with the current time */ private String appendDateTime(Boolean append) { String str = ""; Date now = new Date(); if (append || (now.getTime() - mLastMessageReceived.getTime() > PAUSE_DETECTION_TIME_MS)) { str += "\n[" + DATE_FORMAT.format(now) + mTargetConsole.getPrefix() + "]"; } mLastMessageReceived = now; return str; } // appendDateTime
/** * append the message to the console * * @param message message to add * @param std console to use for add the string */ private void appendMessage(String message, ConsoleType std) { boolean forceAppendPrefix = (mTargetConsole != std); mTargetConsole = std; final SpannableStringBuilder displayText = new SpannableStringBuilder(); displayText.append(appendDateTime(forceAppendPrefix)); displayText.append(message); displayText.setSpan( new ForegroundColorSpan(getResources().getColor(mTargetConsole.getColorID())), 0, displayText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); DebugConsoleActivity.this.runOnUiThread( new Runnable() { @Override public void run() { mConsole.append(displayText); mConsoleView.fullScroll(View.FOCUS_DOWN); } // run }); } // appendMessage