@@ -32,6 +32,37 @@ public class LogActivity extends Activity
32
32
private boolean border = false ;
33
33
private int filter = LogUtils .V ;
34
34
35
+ private static final int UPDATE_TAG = 0x01 ;
36
+ private static final int UPDATE_BORDER = 0x01 << 1 ;
37
+ private static final int UPDATE_FILTER = 0x01 << 2 ;
38
+
39
+ private Thread mThread ;
40
+ private Runnable mRunnable = new Runnable () {
41
+ @ Override
42
+ public void run () {
43
+ LogUtils .v ("verbose" );
44
+ LogUtils .d ("debug" );
45
+ LogUtils .i ("info" );
46
+ LogUtils .w ("warn" );
47
+ LogUtils .e ("error" );
48
+ LogUtils .a ("assert" );
49
+ }
50
+ };
51
+
52
+ private static final String longStr ;
53
+ 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\" }]}" ;
54
+ 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>" ;
55
+
56
+ static {
57
+ StringBuilder sb = new StringBuilder ();
58
+ sb .append ("len = 10400\n content = \" " );
59
+ for (int i = 0 ; i < 800 ; ++i ) {
60
+ sb .append ("Hello world. " );
61
+ }
62
+ sb .append ("\" " );
63
+ longStr = sb .toString ();
64
+ }
65
+
35
66
@ Override
36
67
protected void onCreate (Bundle savedInstanceState ) {
37
68
super .onCreate (savedInstanceState );
@@ -41,60 +72,100 @@ protected void onCreate(Bundle savedInstanceState) {
41
72
findViewById (R .id .btn_toggle_tag ).setOnClickListener (this );
42
73
findViewById (R .id .btn_toggle_border ).setOnClickListener (this );
43
74
findViewById (R .id .btn_toggle_filter ).setOnClickListener (this );
44
- findViewById (R .id .btn_log_v ).setOnClickListener (this );
45
- findViewById (R .id .btn_log_d ).setOnClickListener (this );
46
- findViewById (R .id .btn_log_i ).setOnClickListener (this );
47
- findViewById (R .id .btn_log_w ).setOnClickListener (this );
48
- findViewById (R .id .btn_log_e ).setOnClickListener (this );
49
- findViewById (R .id .btn_log_a ).setOnClickListener (this );
75
+ findViewById (R .id .btn_log_no_tag ).setOnClickListener (this );
76
+ findViewById (R .id .btn_log_with_tag ).setOnClickListener (this );
77
+ findViewById (R .id .btn_log_in_new_thread ).setOnClickListener (this );
78
+ findViewById (R .id .btn_log_null ).setOnClickListener (this );
79
+ findViewById (R .id .btn_log_many_params ).setOnClickListener (this );
80
+ findViewById (R .id .btn_log_long ).setOnClickListener (this );
81
+ findViewById (R .id .btn_log_file ).setOnClickListener (this );
82
+ findViewById (R .id .btn_log_json ).setOnClickListener (this );
83
+ findViewById (R .id .btn_log_xml ).setOnClickListener (this );
50
84
tvAboutLog = (TextView ) findViewById (R .id .tv_about_log );
85
+ updateAbout (0 );
51
86
}
52
87
53
88
@ Override
54
89
public void onClick (View view ) {
55
90
switch (view .getId ()) {
56
91
case R .id .btn_toggle_tag :
57
- updateAbout ();
92
+ updateAbout (UPDATE_TAG );
58
93
break ;
59
94
case R .id .btn_toggle_border :
60
- updateAbout ();
95
+ updateAbout (UPDATE_BORDER );
61
96
break ;
62
97
case R .id .btn_toggle_filter :
63
- updateAbout ();
98
+ updateAbout (UPDATE_FILTER );
64
99
break ;
65
- case R .id .btn_log_v :
66
- //TODO implement
100
+ case R .id .btn_log_no_tag :
101
+ LogUtils .v ("verbose" );
102
+ LogUtils .d ("debug" );
103
+ LogUtils .i ("info" );
104
+ LogUtils .w ("warn" );
105
+ LogUtils .e ("error" );
106
+ LogUtils .a ("assert" );
67
107
break ;
68
- case R .id .btn_log_d :
69
- //TODO implement
108
+ case R .id .btn_log_with_tag :
109
+ LogUtils .v ("customTag" , "verbose" );
110
+ LogUtils .d ("customTag" , "debug" );
111
+ LogUtils .i ("customTag" , "info" );
112
+ LogUtils .w ("customTag" , "warn" );
113
+ LogUtils .e ("customTag" , "error" );
114
+ LogUtils .a ("customTag" , "assert" );
70
115
break ;
71
- case R .id .btn_log_i :
72
- //TODO implement
116
+ case R .id .btn_log_in_new_thread :
117
+ mThread = new Thread (mRunnable );
118
+ mThread .start ();
119
+ break ;
120
+ case R .id .btn_log_null :
121
+ LogUtils .v (null );
122
+ LogUtils .d (null );
123
+ LogUtils .i (null );
124
+ LogUtils .w (null );
125
+ LogUtils .e (null );
126
+ LogUtils .a (null );
73
127
break ;
74
- case R .id .btn_log_w :
128
+ case R .id .btn_log_many_params :
129
+ LogUtils .v ("customTag" , "verbose0" , "verbose1" );
130
+ LogUtils .d ("customTag" , "debug0" , "debug1" );
131
+ LogUtils .i ("customTag" , "info0" , "info1" );
132
+ LogUtils .w ("customTag" , "warn0" , "warn1" );
133
+ LogUtils .e ("customTag" , "error0" , "error1" );
134
+ LogUtils .a ("customTag" , "assert0" , "assert1" );
135
+ break ;
136
+ case R .id .btn_log_long :
137
+ LogUtils .d (longStr );
138
+ break ;
139
+ case R .id .btn_log_file :
75
140
//TODO implement
76
141
break ;
77
- case R .id .btn_log_e :
142
+ case R .id .btn_log_json :
78
143
//TODO implement
79
144
break ;
80
- case R .id .btn_log_a :
145
+ case R .id .btn_log_xml :
81
146
//TODO implement
82
147
break ;
83
148
}
84
149
}
85
150
86
- private void updateAbout () {
87
- StringBuilder sb = new StringBuilder ();
88
- globalTag = globalTag .equals (TAG ) ? "" : TAG ;
89
- mBuilder .setGlobalTag (globalTag );
90
- sb .append ("tag: " )
91
- .append (globalTag .equals ("" ) ? "null" : TAG );
92
-
93
- border = !border ;
94
- mBuilder .set
95
-
96
-
97
-
98
- tvAboutLog .setText (sb .toString ());
151
+ private void updateAbout (int args ) {
152
+ switch (args ) {
153
+ case UPDATE_TAG :
154
+ globalTag = globalTag .equals (TAG ) ? "" : TAG ;
155
+ break ;
156
+ case UPDATE_BORDER :
157
+ border = !border ;
158
+ break ;
159
+ case UPDATE_FILTER :
160
+ filter = filter == LogUtils .V ? LogUtils .W : LogUtils .V ;
161
+ break ;
162
+ }
163
+ mBuilder .setGlobalTag (globalTag )
164
+ .setBorderSwitch (border )
165
+ .setLogFilter (filter );
166
+ tvAboutLog .setText ("tag: " + (globalTag .equals ("" ) ? "null" : TAG )
167
+ + "\n border: " + String .valueOf (border )
168
+ + "\n filter: " + (filter == LogUtils .V ? "Verbose" : "Warn" )
169
+ );
99
170
}
100
171
}
0 commit comments