forked from Blankj/AndroidUtilCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogActivity.java
More file actions
195 lines (177 loc) · 7.1 KB
/
LogActivity.java
File metadata and controls
195 lines (177 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.blankj.androidutilcode.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.UtilsApp;
import com.blankj.utilcode.util.LogUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2017/03/22
* desc : Log工具类Demo
* </pre>
*/
public class LogActivity extends Activity
implements View.OnClickListener {
private static final String TAG = "CMJ";
private LogUtils.Builder mBuilder;
private TextView tvAboutLog;
private String globalTag = "";
private boolean head = true;
private boolean file = false;
private boolean border = true;
private int filter = LogUtils.V;
private static final int UPDATE_TAG = 0x01 << 0;
private static final int UPDATE_HEAD = 0x01 << 1;
private static final int UPDATE_FILE = 0x01 << 2;
private static final int UPDATE_BORDER = 0x01 << 3;
private static final int UPDATE_FILTER = 0x01 << 4;
private Runnable mRunnable = new Runnable() {
@Override
public void run() {
LogUtils.v("verbose");
LogUtils.d("debug");
LogUtils.i("info");
LogUtils.w("warn");
LogUtils.e("error");
LogUtils.a("assert");
}
};
private static final String longStr;
private String json = "{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"json format\" , \"site\":\"http://tools.w3cschool.cn/code/json\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}";
private String xml = "<books><book><author>Jack Herrington</author><title>PHP Hacks</title><publisher>O'Reilly</publisher></book><book><author>Jack Herrington</author><title>Podcasting Hacks</title><publisher>O'Reilly</publisher></book></books>";
static {
StringBuilder sb = new StringBuilder();
sb.append("len = 10400\ncontent = \"");
for (int i = 0; i < 800; ++i) {
sb.append("Hello world. ");
}
sb.append("\"");
longStr = sb.toString();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log);
mBuilder = UtilsApp.lBuilder;
findViewById(R.id.btn_toggle_tag).setOnClickListener(this);
findViewById(R.id.btn_toggle_head).setOnClickListener(this);
findViewById(R.id.btn_toggle_border).setOnClickListener(this);
findViewById(R.id.btn_toggle_file).setOnClickListener(this);
findViewById(R.id.btn_toggle_filter).setOnClickListener(this);
findViewById(R.id.btn_log_no_tag).setOnClickListener(this);
findViewById(R.id.btn_log_with_tag).setOnClickListener(this);
findViewById(R.id.btn_log_in_new_thread).setOnClickListener(this);
findViewById(R.id.btn_log_null).setOnClickListener(this);
findViewById(R.id.btn_log_many_params).setOnClickListener(this);
findViewById(R.id.btn_log_long).setOnClickListener(this);
findViewById(R.id.btn_log_file).setOnClickListener(this);
findViewById(R.id.btn_log_json).setOnClickListener(this);
findViewById(R.id.btn_log_xml).setOnClickListener(this);
tvAboutLog = (TextView) findViewById(R.id.tv_about_log);
updateAbout(0);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_toggle_tag:
updateAbout(UPDATE_TAG);
break;
case R.id.btn_toggle_head:
updateAbout(UPDATE_HEAD);
break;
case R.id.btn_toggle_file:
updateAbout(UPDATE_FILE);
break;
case R.id.btn_toggle_border:
updateAbout(UPDATE_BORDER);
break;
case R.id.btn_toggle_filter:
updateAbout(UPDATE_FILTER);
break;
case R.id.btn_log_no_tag:
LogUtils.v("verbose");
LogUtils.d("debug");
LogUtils.i("info");
LogUtils.w("warn");
LogUtils.e("error");
LogUtils.a("assert");
break;
case R.id.btn_log_with_tag:
LogUtils.v("customTag", "verbose");
LogUtils.d("customTag", "debug");
LogUtils.i("customTag", "info");
LogUtils.w("customTag", "warn");
LogUtils.e("customTag", "error");
LogUtils.a("customTag", "assert");
break;
case R.id.btn_log_in_new_thread:
Thread thread = new Thread(mRunnable);
thread.start();
break;
case R.id.btn_log_null:
LogUtils.v(null);
LogUtils.d(null);
LogUtils.i(null);
LogUtils.w(null);
LogUtils.e(null);
LogUtils.a(null);
break;
case R.id.btn_log_many_params:
LogUtils.v("customTag", "verbose0", "verbose1");
LogUtils.d("customTag", "debug0", "debug1");
LogUtils.i("customTag", "info0", "info1");
LogUtils.w("customTag", "warn0", "warn1");
LogUtils.e("customTag", "error0", "error1");
LogUtils.a("customTag", "assert0", "assert1");
break;
case R.id.btn_log_long:
LogUtils.d(longStr);
break;
case R.id.btn_log_file:
LogUtils.file("test0 log to file");
LogUtils.file("test1 log to file");
LogUtils.file("test2 log to file");
break;
case R.id.btn_log_json:
LogUtils.json(json);
break;
case R.id.btn_log_xml:
LogUtils.xml(xml);
break;
}
}
private void updateAbout(int args) {
switch (args) {
case UPDATE_TAG:
globalTag = globalTag.equals(TAG) ? "" : TAG;
break;
case UPDATE_HEAD:
head = !head;
break;
case UPDATE_FILE:
file = !file;
break;
case UPDATE_BORDER:
border = !border;
break;
case UPDATE_FILTER:
filter = filter == LogUtils.V ? LogUtils.W : LogUtils.V;
break;
}
mBuilder.setGlobalTag(globalTag)
.setLogHeadSwitch(head)
.setLog2FileSwitch(file)
.setBorderSwitch(border)
.setLogFilter(filter);
tvAboutLog.setText("tag: " + (globalTag.equals("") ? "null" : TAG)
+ "\nhead: " + String.valueOf(head)
+ "\nfile: " + String.valueOf(file)
+ "\nborder: " + String.valueOf(border)
+ "\nfilter: " + (filter == LogUtils.V ? "Verbose" : "Warn")
);
}
}