Skip to content

Commit abf2ed1

Browse files
committed
see 05/08 log
1 parent 23dd088 commit abf2ed1

File tree

13 files changed

+373
-330
lines changed

13 files changed

+373
-330
lines changed

README-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ getAddress : 根据经纬度获取地理位置
307307
getCountryName : 根据经纬度获取所在国家
308308
getLocality : 根据经纬度获取所在地
309309
getStreet : 根据经纬度获取所在街道
310+
isBetterLocation : 是否更好的位置
311+
isSameProvider : 是否相同的提供者
310312
```
311313

312314
* ### 日志相关→[LogUtils.java][log.java][Demo][log.demo]
@@ -617,7 +619,7 @@ getEntries : 获取压缩文件中的文件对象
617619

618620
Gradle:
619621
``` groovy
620-
compile 'com.blankj:utilcode:1.4.1'
622+
compile 'com.blankj:utilcode:1.5.0'
621623
```
622624

623625

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ getEntries
619619

620620
Gradle:
621621
``` groovy
622-
compile 'com.blankj:utilcode:1.4.1'
622+
compile 'com.blankj:utilcode:1.5.0'
623623
```
624624

625625

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 17/05/08 更新BarUtils,LogUtils新增配置文件,TimeUtils将pattern改为format,发布1.5.0
12
* 17/05/04 新增签名
23
* 17/05/03 对齐头部日期
34
* 17/05/02 Demo的string字符串变更,完善ToastUtils和SnackbarUtils

utilcode/build.gradle

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'jacoco'
3+
4+
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
5+
6+
reports {
7+
xml.enabled = true
8+
html.enabled = true
9+
}
10+
11+
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
12+
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
13+
def mainSrc = "${project.projectDir}/src/main/java"
14+
15+
sourceDirectories = files([mainSrc])
16+
classDirectories = files([debugTree])
17+
executionData = fileTree(dir: "$buildDir", includes: [
18+
"jacoco/testDebugUnitTest.exec",
19+
"outputs/code-coverage/connected/*coverage.ec"
20+
])
21+
}
222

323
android {
424
compileSdkVersion 25
@@ -25,10 +45,6 @@ android {
2545
lintOptions {
2646
abortOnError false
2747
}
28-
29-
testOptions {
30-
reportDir = "$project.buildDir/foo/report"
31-
}
3248
}
3349

3450
tasks.matching { it instanceof Test }.all {

utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,13 @@ public static boolean isAppForeground(Context context, String packageName) {
501501
*/
502502
public static class AppInfo {
503503

504-
private String name;
504+
private String name;
505505
private Drawable icon;
506-
private String packageName;
507-
private String packagePath;
508-
private String versionName;
509-
private int versionCode;
510-
private boolean isSystem;
506+
private String packageName;
507+
private String packagePath;
508+
private String versionName;
509+
private int versionCode;
510+
private boolean isSystem;
511511

512512
public Drawable getIcon() {
513513
return icon;

utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,15 @@
3131
*/
3232
public class BarUtils {
3333

34-
private BarUtils() {
35-
throw new UnsupportedOperationException("u can't instantiate me...");
36-
}
37-
38-
public static class StatusBarView extends View {
39-
public StatusBarView(Context context, AttributeSet attrs) {
40-
super(context, attrs);
41-
}
42-
43-
public StatusBarView(Context context) {
44-
super(context);
45-
}
46-
}
47-
4834
private static final int DEFAULT_STATUS_BAR_ALPHA = 112;
4935
private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.statusbarutil_fake_status_bar_view;
5036
private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.statusbarutil_translucent_view;
5137
private static final int TAG_KEY_HAVE_SET_OFFSET = -123;
5238

39+
private BarUtils() {
40+
throw new UnsupportedOperationException("u can't instantiate me...");
41+
}
42+
5343
/**
5444
* 设置状态栏颜色
5545
*
@@ -661,8 +651,7 @@ private static View createTranslucentStatusBarView(Activity activity, int alpha)
661651
* @param context context
662652
* @return 状态栏高度
663653
*/
664-
private static int getStatusBarHeight(Context context) {
665-
// 获得状态栏高度
654+
public static int getStatusBarHeight(Context context) {
666655
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
667656
return context.getResources().getDimensionPixelSize(resourceId);
668657
}

utilcode/src/main/java/com/blankj/utilcode/util/LocationUtils.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ public static String getStreet(double latitude, double longitude) {
186186
}
187187

188188
/**
189-
* Determines whether one Location reading is better than the current Location fix
189+
* 是否更好的位置
190190
*
191191
* @param newLocation The new Location that you want to evaluate
192192
* @param currentBestLocation The current Location fix, to which you want to compare the new one
193+
* @return {@code true}: 是<br>{@code false}: 否
193194
*/
194195
public static boolean isBetterLocation(Location newLocation, Location currentBestLocation) {
195196
if (currentBestLocation == null) {
@@ -234,13 +235,17 @@ public static boolean isBetterLocation(Location newLocation, Location currentBes
234235
}
235236

236237
/**
237-
* Checks whether two providers are the same
238+
* 是否相同的提供者
239+
*
240+
* @param provider0 提供者1
241+
* @param provider1 提供者2
242+
* @return {@code true}: 是<br>{@code false}: 否
238243
*/
239-
private static boolean isSameProvider(String provider1, String provider2) {
240-
if (provider1 == null) {
241-
return provider2 == null;
244+
public static boolean isSameProvider(String provider0, String provider1) {
245+
if (provider0 == null) {
246+
return provider1 == null;
242247
}
243-
return provider1.equals(provider2);
248+
return provider0.equals(provider1);
244249
}
245250

246251
private static class MyLocationListener

utilcode/src/main/java/com/blankj/utilcode/util/LogUtils.java

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.Environment;
44
import android.support.annotation.IntDef;
5+
import android.support.annotation.NonNull;
56
import android.util.Log;
67

78
import org.json.JSONArray;
@@ -16,6 +17,7 @@
1617
import java.io.StringWriter;
1718
import java.lang.annotation.Retention;
1819
import java.lang.annotation.RetentionPolicy;
20+
import java.text.Format;
1921
import java.text.SimpleDateFormat;
2022
import java.util.Date;
2123
import java.util.Formatter;
@@ -67,15 +69,17 @@ public final class LogUtils {
6769
private static boolean sLogBorderSwitch = true; // log边框开关,默认开
6870
private static int sLogFilter = V; // log过滤器
6971

70-
private static final String TOP_BORDER = "╔═══════════════════════════════════════════════════════════════════════════════════════════════════";
71-
private static final String LEFT_BORDER = "║ ";
72-
private static final String BOTTOM_BORDER = "╚═══════════════════════════════════════════════════════════════════════════════════════════════════";
73-
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
74-
private static final int MAX_LEN = 4000;
72+
private static final String FILE_SEP = System.getProperty("file.separator");
73+
private static final String LINE_SEP = System.getProperty("line.separator");
74+
private static final String TOP_BORDER = "╔═══════════════════════════════════════════════════════════════════════════════════════════════════";
75+
private static final String LEFT_BORDER = "║ ";
76+
private static final String BOTTOM_BORDER = "╚═══════════════════════════════════════════════════════════════════════════════════════════════════";
77+
private static final int MAX_LEN = 4000;
7578

7679
private static final String NULL_TIPS = "Log with null object.";
7780
private static final String NULL = "null";
7881
private static final String ARGS = "args";
82+
private static final Format FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS ", Locale.getDefault());
7983

8084
private LogUtils() {
8185
throw new UnsupportedOperationException("u can't instantiate me...");
@@ -86,12 +90,22 @@ public static class Builder {
8690
public Builder() {
8791
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
8892
&& Utils.getContext().getExternalCacheDir() != null)
89-
dir = Utils.getContext().getExternalCacheDir() + File.separator + "log" + File.separator;
93+
dir = Utils.getContext().getExternalCacheDir() + FILE_SEP + "log" + FILE_SEP;
9094
else {
91-
dir = Utils.getContext().getCacheDir() + File.separator + "log" + File.separator;
95+
dir = Utils.getContext().getCacheDir() + FILE_SEP + "log" + FILE_SEP;
9296
}
9397
}
9498

99+
public Builder(@NonNull String dir) {
100+
LogUtils.dir = dir;
101+
if (!dir.endsWith(FILE_SEP))
102+
LogUtils.dir += FILE_SEP;
103+
}
104+
105+
public Builder(@NonNull File dir) {
106+
LogUtils.dir = dir.getAbsolutePath() + FILE_SEP;
107+
}
108+
95109
public Builder setLogSwitch(boolean logSwitch) {
96110
LogUtils.sLogSwitch = logSwitch;
97111
return this;
@@ -249,7 +263,7 @@ private static String[] processContents(int type, String tag, Object... contents
249263
}
250264
String head = sLogHeadSwitch
251265
? new Formatter()
252-
.format("Thread: %s, %s(%s.java:%d)" + LINE_SEPARATOR,
266+
.format("Thread: %s, %s(%s.java:%d)" + LINE_SEP,
253267
Thread.currentThread().getName(),
254268
targetElement.getMethodName(),
255269
className,
@@ -275,17 +289,17 @@ private static String[] processContents(int type, String tag, Object... contents
275289
.append("]")
276290
.append(" = ")
277291
.append(content == null ? NULL : content.toString())
278-
.append(LINE_SEPARATOR);
292+
.append(LINE_SEP);
279293
}
280294
body = sb.toString();
281295
}
282296
}
283297
String msg = head + body;
284298
if (sLogBorderSwitch) {
285299
StringBuilder sb = new StringBuilder();
286-
String[] lines = msg.split(LINE_SEPARATOR);
300+
String[] lines = msg.split(LINE_SEP);
287301
for (String line : lines) {
288-
sb.append(LEFT_BORDER).append(line).append(LINE_SEPARATOR);
302+
sb.append(LEFT_BORDER).append(line).append(LINE_SEP);
289303
}
290304
msg = sb.toString();
291305
}
@@ -313,7 +327,7 @@ private static String formatXml(String xml) {
313327
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
314328
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
315329
transformer.transform(xmlInput, xmlOutput);
316-
xml = xmlOutput.getWriter().toString().replaceFirst(">", ">" + LINE_SEPARATOR);
330+
xml = xmlOutput.getWriter().toString().replaceFirst(">", ">" + LINE_SEP);
317331
} catch (Exception e) {
318332
e.printStackTrace();
319333
}
@@ -365,31 +379,32 @@ private static void print(final int type, final String tag, String msg) {
365379
}
366380

367381
private static void print2File(final String tag, final String msg) {
368-
Date now = new Date();
369-
String date = new SimpleDateFormat("MM-dd", Locale.getDefault()).format(now);
382+
Date now = new Date(System.currentTimeMillis());
383+
String format = FORMAT.format(now);
384+
String date = format.substring(0, 5);
385+
String time = format.substring(6);
370386
final String fullPath = dir + date + ".txt";
371387
if (!createOrExistsFile(fullPath)) {
372388
Log.e(tag, "log to " + fullPath + " failed!");
373389
return;
374390
}
375-
String time = new SimpleDateFormat("MM-dd HH:mm:ss.SSS ", Locale.getDefault()).format(now);
376391
StringBuilder sb = new StringBuilder();
377392
if (sLogBorderSwitch) {
378-
sb.append(TOP_BORDER).append(LINE_SEPARATOR);
393+
sb.append(TOP_BORDER).append(LINE_SEP);
379394
sb.append(LEFT_BORDER)
380395
.append(time)
381396
.append(tag)
382-
.append(LINE_SEPARATOR)
397+
.append(LINE_SEP)
383398
.append(msg);
384-
sb.append(BOTTOM_BORDER).append(LINE_SEPARATOR);
399+
sb.append(BOTTOM_BORDER).append(LINE_SEP);
385400
} else {
386401
sb.append(time)
387402
.append(tag)
388-
.append(LINE_SEPARATOR)
403+
.append(LINE_SEP)
389404
.append(msg)
390-
.append(LINE_SEPARATOR);
405+
.append(LINE_SEP);
391406
}
392-
sb.append(LINE_SEPARATOR);
407+
sb.append(LINE_SEP);
393408
final String dateLogContent = sb.toString();
394409
if (executor == null) {
395410
executor = Executors.newSingleThreadExecutor();

0 commit comments

Comments
 (0)