Skip to content

Commit 2f9b36a

Browse files
committed
see 03/25 log
1 parent 1dd0a91 commit 2f9b36a

File tree

6 files changed

+278
-131
lines changed

6 files changed

+278
-131
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
android:name=".activity.KeyboardActivity"
6363
android:windowSoftInputMode="stateHidden|adjustPan"/>
6464
<activity android:name=".activity.LocationActivity"/>
65+
<activity android:name=".activity.LogActivity"/>
6566
<activity android:name=".activity.MainActivity">
6667
<intent-filter>
6768
<action android:name="android.intent.action.MAIN"/>

app/src/main/java/com/blankj/androidutilcode/activity/LogActivity.java

Lines changed: 102 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,37 @@ public class LogActivity extends Activity
3232
private boolean border = false;
3333
private int filter = LogUtils.V;
3434

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+
3566
@Override
3667
protected void onCreate(Bundle savedInstanceState) {
3768
super.onCreate(savedInstanceState);
@@ -41,60 +72,100 @@ protected void onCreate(Bundle savedInstanceState) {
4172
findViewById(R.id.btn_toggle_tag).setOnClickListener(this);
4273
findViewById(R.id.btn_toggle_border).setOnClickListener(this);
4374
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);
5084
tvAboutLog = (TextView) findViewById(R.id.tv_about_log);
85+
updateAbout(0);
5186
}
5287

5388
@Override
5489
public void onClick(View view) {
5590
switch (view.getId()) {
5691
case R.id.btn_toggle_tag:
57-
updateAbout();
92+
updateAbout(UPDATE_TAG);
5893
break;
5994
case R.id.btn_toggle_border:
60-
updateAbout();
95+
updateAbout(UPDATE_BORDER);
6196
break;
6297
case R.id.btn_toggle_filter:
63-
updateAbout();
98+
updateAbout(UPDATE_FILTER);
6499
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");
67107
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");
70115
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);
73127
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:
75140
//TODO implement
76141
break;
77-
case R.id.btn_log_e:
142+
case R.id.btn_log_json:
78143
//TODO implement
79144
break;
80-
case R.id.btn_log_a:
145+
case R.id.btn_log_xml:
81146
//TODO implement
82147
break;
83148
}
84149
}
85150

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+
+ "\nborder: " + String.valueOf(border)
168+
+ "\nfilter: " + (filter == LogUtils.V ? "Verbose" : "Warn")
169+
);
99170
}
100171
}

app/src/main/res/layout/activity_log.xml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,67 @@
3232
android:text="@string/log.toggle_filter" />
3333

3434
<Button
35-
android:id="@+id/btn_log_v"
35+
android:id="@+id/btn_log_no_tag"
3636
style="@style/BtnFont"
3737
android:layout_width="match_parent"
3838
android:layout_height="wrap_content"
39-
android:text="@string/log.v" />
39+
android:text="@string/log.with_no_tag" />
4040

4141
<Button
42-
android:id="@+id/btn_log_d"
42+
android:id="@+id/btn_log_with_tag"
4343
style="@style/BtnFont"
4444
android:layout_width="match_parent"
4545
android:layout_height="wrap_content"
46-
android:text="@string/log.d" />
46+
android:text="@string/log.with_tag" />
4747

4848
<Button
49-
android:id="@+id/btn_log_i"
49+
android:id="@+id/btn_log_in_new_thread"
5050
style="@style/BtnFont"
5151
android:layout_width="match_parent"
5252
android:layout_height="wrap_content"
53-
android:text="@string/log.i" />
53+
android:text="@string/log.in_new_thread" />
5454

5555
<Button
56-
android:id="@+id/btn_log_w"
56+
android:id="@+id/btn_log_null"
5757
style="@style/BtnFont"
5858
android:layout_width="match_parent"
5959
android:layout_height="wrap_content"
60-
android:text="@string/log.w" />
60+
android:text="@string/log.null" />
6161

6262
<Button
63-
android:id="@+id/btn_log_e"
63+
android:id="@+id/btn_log_many_params"
6464
style="@style/BtnFont"
6565
android:layout_width="match_parent"
6666
android:layout_height="wrap_content"
67-
android:text="@string/log.e" />
67+
android:text="@string/log.many_params" />
6868

6969
<Button
70-
android:id="@+id/btn_log_a"
70+
android:id="@+id/btn_log_long"
7171
style="@style/BtnFont"
7272
android:layout_width="match_parent"
7373
android:layout_height="wrap_content"
74-
android:text="@string/log.a" />
74+
android:text="@string/log.long_string" />
75+
76+
<Button
77+
android:id="@+id/btn_log_file"
78+
style="@style/BtnFont"
79+
android:layout_width="match_parent"
80+
android:layout_height="wrap_content"
81+
android:text="@string/log.to_file" />
82+
83+
<Button
84+
android:id="@+id/btn_log_json"
85+
style="@style/BtnFont"
86+
android:layout_width="match_parent"
87+
android:layout_height="wrap_content"
88+
android:text="@string/log.json" />
89+
90+
<Button
91+
android:id="@+id/btn_log_xml"
92+
style="@style/BtnFont"
93+
android:layout_width="match_parent"
94+
android:layout_height="wrap_content"
95+
android:text="@string/log.xml" />
7596

7697
<TextView
7798
android:id="@+id/tv_about_log"

app/src/main/res/values/strings.xml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@
8080
<string name="log.toggle_tag">Toggle Tag</string>
8181
<string name="log.toggle_border">Toggle Border</string>
8282
<string name="log.toggle_filter">Toggle Filter</string>
83-
<string name="log.v">v</string>
84-
<string name="log.d">d</string>
85-
<string name="log.i">i</string>
86-
<string name="log.w">w</string>
87-
<string name="log.e">e</string>
88-
<string name="log.a">a</string>
83+
<string name="log.with_no_tag">Log With No Tag</string>
84+
<string name="log.with_tag">Log With Tag</string>
85+
<string name="log.in_new_thread">Log In New Thread</string>
86+
<string name="log.null">Log Null</string>
87+
<string name="log.many_params">Log Many Params</string>
88+
<string name="log.long_string">Log Long String</string>
89+
<string name="log.to_file">Log To File</string>
90+
<string name="log.json">Log Json</string>
91+
<string name="log.xml">Log Xml</string>
8992

9093
<!--Phone相关-->
9194
<string name="phone.dial">Dial</string>

0 commit comments

Comments
 (0)