12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package com.feemers.android.fftdrawer.SignalProcessing;
-
- import android.app.Activity;
- import android.util.Log;
- import android.widget.TextView;
-
- import java.io.PrintWriter;
- import java.io.StringWriter;
-
- public class Logger
- {
- private TextView textView;
- private StringBuffer sb = new StringBuffer();
- private String tag;
- private Activity activity;
-
- public Logger(String tag, String logInitText)
- {
- this.activity = null;
- this.tag = tag;
- sb.append(logInitText);
- }
-
- public Logger(Activity activity, String tag, TextView textView, String logInitText)
- {
- this.activity = activity;
- this.tag = tag;
- this.textView = textView;
- sb.append(logInitText);
- }
-
- public void log(String s)
- {
- Log.d(tag, s);
- sb.append(s).append("\n");
- if (textView != null)
- {
- if(activity !=null)
- {
- activity.runOnUiThread(new Runnable()
- {
- @Override
- public void run()
- {
- textView.setText(sb.toString());
- }
- });
- }
- else
- {
- textView.setText(sb.toString());
- }
- }
- }
-
- public void log(Exception e)
- {
- StringWriter sw = new StringWriter();
- e.printStackTrace(new PrintWriter(sw));
- log(sw.toString());
- }
-
- public void clearLog()
- {
- sb.setLength(0);
- if (textView != null)
- {
- textView.setText("");
- }
- }
-
- public String getLoggedText()
- {
- return sb.toString();
- }
- }
|