Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / csdk / connectivity / samples / android / sample_service / src / org / iotivity / ca / service / DLog.java
1
2 package org.iotivity.ca.service;
3
4 import android.os.Handler;
5 import android.widget.TextView;
6
7 public final class DLog {
8
9     private final static String MAIN_TAG = "Sample_Service : DLog";
10
11     private static TextView mLogView = null;
12
13     private static Handler mHandler = null;
14
15     public static void setTextView(Handler handler, TextView logView) {
16         mHandler = handler;
17         mLogView = logView;
18     }
19
20     private static void addLogText(final String msg) {
21
22         mHandler.post(new Runnable() {
23
24             @Override
25             public void run() {
26
27                 if (mLogView == null)
28                     return;
29
30                 StringBuilder builder = new StringBuilder(mLogView.getText());
31                 // add front
32                 builder.append(msg + "\n");
33
34                 mLogView.setText(builder.toString());
35             }
36
37         });
38
39     }
40
41     public static final void v(String className, String msg) {
42         android.util.Log.v(MAIN_TAG, className + "." + msg);
43
44         if (mLogView != null) {
45             addLogText(msg);
46         }
47     }
48
49     public static final void d(String className, String msg) {
50         android.util.Log.d(MAIN_TAG, className + "." + msg);
51
52         if (mLogView != null) {
53             addLogText(msg);
54         }
55     }
56
57     public static final void i(String className, String msg) {
58         android.util.Log.i(MAIN_TAG, className + "." + msg);
59
60         if (mLogView != null) {
61             addLogText(msg);
62         }
63     }
64
65     public static final void w(String className, String msg) {
66         android.util.Log.w(MAIN_TAG, className + "." + msg);
67
68         if (mLogView != null) {
69             addLogText(msg);
70         }
71     }
72
73     public static final void w(String className, String msg, Exception ex) {
74         android.util.Log.w(MAIN_TAG, className + "." + msg + ":" + ex.getMessage());
75
76         if (mLogView != null) {
77             addLogText(msg);
78         }
79     }
80
81     public static final void w(String className, String msg, Error e) {
82         android.util.Log.w(MAIN_TAG, className + "." + msg + ":" + e.getMessage());
83
84         if (mLogView != null) {
85             addLogText(msg);
86         }
87     }
88
89 }
90