Skip to content

Commit deb9f5c

Browse files
committed
see 04/13 log
1 parent ccd1783 commit deb9f5c

File tree

15 files changed

+441
-78
lines changed

15 files changed

+441
-78
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* `20/04/13` [add] NumberUtils. Publish v1.28.0.
2+
* `20/04/12` [opt] TimeUtils#SDF_THREAD_LOCAL.
3+
* `20/04/11` [add] SDCardUtils#getXxTotalSize, SDCardUtils#getXxAvailableSize. FileUtils#getFsTotalSize, FileUtils#getFsAvailableSize.
14
* `20/04/10` [fix] FileUtils#isFileExists; FragmentUtils#getTop bug. Publish v1.27.6.
25
* `20/04/09` [add] UriUtils#res2Uri, UriUtils#uri2File support QQBrowser; ThreadUtils#getMainHandler; PathUtils#getxxPathExternalFirst.
36
* `20/04/08` [fix] ActivityUtils#finish bug. Publish v1.27.5.

buildSrc/src/main/groovy/Config.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Config {
1515
static minSdkVersion = 14
1616
static targetSdkVersion = 29
1717
static versionCode = 1_026_001
18-
static versionName = '1.27.6'// E.g. 1.9.72 => 1,009,072
18+
static versionName = '1.28.0'// E.g. 1.9.72 => 1,009,072
1919

2020
// lib version
2121
static gradlePluginVersion = '3.5.0'

feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/device/DeviceActivity.kt

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import android.content.Context
44
import android.content.Intent
55
import android.os.Build
66
import com.blankj.common.activity.CommonActivity
7-
import com.blankj.common.activity.CommonActivityItemsView
8-
import com.blankj.common.activity.CommonActivityTitleView
97
import com.blankj.common.item.CommonItem
108
import com.blankj.common.item.CommonItemTitle
119
import com.blankj.utilcode.pkg.R

feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/sdcard/SDCardActivity.kt

+6-10
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,15 @@ class SDCardActivity : CommonActivity() {
3232
}
3333

3434
override fun bindItems(): MutableList<CommonItem<*>> {
35-
val mountedSDCardPath = SDCardUtils.getMountedSDCardPath()
36-
val sizeItems = CollectionUtils.collect(mountedSDCardPath) { input ->
37-
val totalInfo = "total: " + ConvertUtils.byte2FitMemorySize(SDCardUtils.getTotalSize(input))
38-
val availableInfo = "available: " + ConvertUtils.byte2FitMemorySize(SDCardUtils.getAvailableSize(input))
39-
CommonItemTitle(input, "$totalInfo, $availableInfo")
40-
}
41-
val result: ArrayList<CommonItem<*>> = CollectionUtils.newArrayList(
35+
return CollectionUtils.newArrayList(
4236
CommonItemTitle("isSDCardEnableByEnvironment", SDCardUtils.isSDCardEnableByEnvironment().toString()),
4337
CommonItemTitle("getSDCardPathByEnvironment", SDCardUtils.getSDCardPathByEnvironment()),
4438
CommonItemTitle("getSDCardInfo", SDCardUtils.getSDCardInfo().toString()),
45-
CommonItemTitle("getMountedSDCardPath", mountedSDCardPath.toString())
39+
CommonItemTitle("getMountedSDCardPath", SDCardUtils.getMountedSDCardPath().toString()),
40+
CommonItemTitle("getExternalTotalSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getExternalTotalSize(), 2)),
41+
CommonItemTitle("getExternalAvailableSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getExternalAvailableSize(), 2)),
42+
CommonItemTitle("getInternalTotalSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getInternalTotalSize(), 2)),
43+
CommonItemTitle("getInternalAvailableSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getInternalAvailableSize(), 2))
4644
)
47-
result.addAll(sizeItems)
48-
return result
4945
}
5046
}

lib/utilcode/README-CN.md

+18-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.27.6'
5+
implementation 'com.blankj:utilcode:1.28.0'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.27.6'
8+
implementation 'com.blankj:utilcodex:1.28.0'
99
```
1010

1111

@@ -487,6 +487,8 @@ getFileName : 根据全路径获取文件名
487487
getFileNameNoExtension : 根据全路径获取文件名不带拓展名
488488
getFileExtension : 根据全路径获取文件拓展名
489489
notifySystemToScan : 通知系统扫描文件
490+
getFsTotalSize : 获取文件系统总大小
491+
getFsAvailableSize : 获取文件系统可用大小
490492
```
491493

492494
* ### Fragment 相关 -> [FragmentUtils.java][fragment.java] -> [Demo][fragment.demo]
@@ -695,6 +697,12 @@ cancelAll : 取消所有通知
695697
setNotificationBarVisibility: 设置通知栏是否可见
696698
```
697699

700+
* ### 数字相关 -> [NumberUtils.java][number.java] -> [Test][number.test]
701+
```
702+
format : 格式化
703+
float2Double: 浮点转双精度
704+
```
705+
698706
* ### 对象相关 -> [ObjectUtils.java][object.java] -> [Test][object.test]
699707
```
700708
isEmpty : 判断对象是否为空
@@ -913,8 +921,10 @@ isSDCardEnableByEnvironment: 根据 Environment 判断 SD 卡是否可用
913921
getSDCardPathByEnvironment : 根据 Environment 获取 SD 卡路径
914922
getSDCardInfo : 获取 SD 卡信息
915923
getMountedSDCardPath : 获取已挂载的 SD 卡路径
916-
getTotalSize : 获取 SD 卡总大小
917-
getAvailableSize : 获取 SD 卡可用大小
924+
getExternalTotalSize : 获取外置 SD 卡总大小
925+
getExternalAvailableSize : 获取外置 SD 卡可用大小
926+
getInternalTotalSize : 获取内置 SD 卡总大小
927+
getInternalAvailableSize : 获取内置 SD 卡可用大小
918928
```
919929

920930
* ### 服务相关 -> [ServiceUtils.java][service.java]
@@ -1086,6 +1096,7 @@ setDeliver : 设置任务结束后交付的线程
10861096

10871097
* ### 时间相关 -> [TimeUtils.java][time.java] -> [Test][time.test]
10881098
```
1099+
getSafeDateFormat : 获取安全的日期格式
10891100
millis2String : 将时间戳转为时间字符串
10901101
string2Millis : 将时间字符串转为时间戳
10911102
string2Date : 将时间字符串转为 Date 类型
@@ -1306,6 +1317,9 @@ getComments : 获取压缩文件中的注释链表
13061317
[notification.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/NotificationUtils.java
13071318
[notification.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/notification/NotificationActivity.kt
13081319

1320+
[number.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/NumberUtils.java
1321+
[number.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/NumberUtilsTest.java
1322+
13091323
[object.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java
13101324
[object.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/ObjectUtilsTest.java
13111325

lib/utilcode/README.md

+18-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.27.6'
5+
implementation 'com.blankj:utilcode:1.28.0'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.27.6'
8+
implementation 'com.blankj:utilcodex:1.28.0'
99
```
1010

1111

@@ -487,6 +487,8 @@ getFileName
487487
getFileNameNoExtension
488488
getFileExtension
489489
notifySystemToScan
490+
getFsTotalSize
491+
getFsAvailableSize
490492
```
491493

492494
* ### About Fragment -> [FragmentUtils.java][fragment.java] -> [Demo][fragment.demo]
@@ -695,6 +697,12 @@ cancelAll
695697
setNotificationBarVisibility
696698
```
697699

700+
* ### About Number -> [NumberUtils.java][number.java] -> [Test][number.test]
701+
```
702+
format
703+
float2Double
704+
```
705+
698706
* ### About Object -> [ObjectUtils.java][object.java] -> [Test][object.test]
699707
```
700708
isEmpty
@@ -913,8 +921,10 @@ isSDCardEnableByEnvironment
913921
getSDCardPathByEnvironment
914922
getSDCardInfo
915923
getMountedSDCardPath
916-
getTotalSize
917-
getAvailableSize
924+
getExternalTotalSize
925+
getExternalAvailableSize
926+
getInternalTotalSize
927+
getInternalAvailableSize
918928
```
919929

920930
* ### About Service -> [ServiceUtils.java][service.java]
@@ -1086,6 +1096,7 @@ setDeliver
10861096

10871097
* ### About Time -> [TimeUtils.java][time.java] -> [Test][time.test]
10881098
```
1099+
getSafeDateFormat
10891100
millis2String
10901101
string2Millis
10911102
string2Date
@@ -1303,6 +1314,9 @@ getComments
13031314
[notification.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/NotificationUtils.java
13041315
[notification.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/notification/NotificationActivity.kt
13051316

1317+
[number.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/NumberUtils.java
1318+
[number.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/NumberUtilsTest.java
1319+
13061320
[object.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java
13071321
[object.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/ObjectUtilsTest.java
13081322

lib/utilcode/src/main/java/com/blankj/utilcode/util/ConvertUtils.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,32 @@ public static double byte2MemorySize(final long byteSize,
418418
*/
419419
@SuppressLint("DefaultLocale")
420420
public static String byte2FitMemorySize(final long byteSize) {
421+
return byte2FitMemorySize(byteSize, 3);
422+
}
423+
424+
/**
425+
* Size of byte to fit size of memory.
426+
* <p>to three decimal places</p>
427+
*
428+
* @param byteSize Size of byte.
429+
* @param precision The precision
430+
* @return fit size of memory
431+
*/
432+
@SuppressLint("DefaultLocale")
433+
public static String byte2FitMemorySize(final long byteSize, int precision) {
434+
if (precision < 0) {
435+
throw new IllegalArgumentException("precision shouldn't be less than zero!");
436+
}
421437
if (byteSize < 0) {
422-
return "shouldn't be less than zero!";
438+
throw new IllegalArgumentException("byteSize shouldn't be less than zero!");
423439
} else if (byteSize < MemoryConstants.KB) {
424-
return String.format("%.3fB", (double) byteSize);
440+
return String.format("%." + precision + "fB", (double) byteSize);
425441
} else if (byteSize < MemoryConstants.MB) {
426-
return String.format("%.3fKB", (double) byteSize / MemoryConstants.KB);
442+
return String.format("%." + precision + "fKB", (double) byteSize / MemoryConstants.KB);
427443
} else if (byteSize < MemoryConstants.GB) {
428-
return String.format("%.3fMB", (double) byteSize / MemoryConstants.MB);
444+
return String.format("%." + precision + "fMB", (double) byteSize / MemoryConstants.MB);
429445
} else {
430-
return String.format("%.3fGB", (double) byteSize / MemoryConstants.GB);
446+
return String.format("%." + precision + "fGB", (double) byteSize / MemoryConstants.GB);
431447
}
432448
}
433449

lib/utilcode/src/main/java/com/blankj/utilcode/util/FileUtils.java

+50-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.content.res.AssetFileDescriptor;
66
import android.net.Uri;
77
import android.os.Build;
8+
import android.os.StatFs;
9+
import android.text.TextUtils;
810

911
import java.io.BufferedInputStream;
1012
import java.io.File;
@@ -76,10 +78,10 @@ public static boolean isFileExists(final String filePath) {
7678
if (file.exists()) {
7779
return true;
7880
}
79-
return isFileExists29(filePath);
81+
return isFileExistsApi29(filePath);
8082
}
8183

82-
private static boolean isFileExists29(String filePath) {
84+
private static boolean isFileExistsApi29(String filePath) {
8385
if (Build.VERSION.SDK_INT >= 29) {
8486
try {
8587
Uri uri = Uri.parse(filePath);
@@ -1379,6 +1381,15 @@ public static String getFileExtension(final String filePath) {
13791381
return filePath.substring(lastPoi + 1);
13801382
}
13811383

1384+
/**
1385+
* Notify system to scan the file.
1386+
*
1387+
* @param filePath The path of file.
1388+
*/
1389+
public static void notifySystemToScan(final String filePath) {
1390+
notifySystemToScan(getFileByPath(filePath));
1391+
}
1392+
13821393
/**
13831394
* Notify system to scan the file.
13841395
*
@@ -1393,12 +1404,45 @@ public static void notifySystemToScan(final File file) {
13931404
}
13941405

13951406
/**
1396-
* Notify system to scan the file.
1407+
* Return the total size of file system.
13971408
*
1398-
* @param filePath The path of file.
1409+
* @param anyPathInFs Any path in file system.
1410+
* @return the total size of file system
13991411
*/
1400-
public static void notifySystemToScan(final String filePath) {
1401-
notifySystemToScan(getFileByPath(filePath));
1412+
public static long getFsTotalSize(String anyPathInFs) {
1413+
if (TextUtils.isEmpty(anyPathInFs)) return 0;
1414+
StatFs statFs = new StatFs(anyPathInFs);
1415+
long blockSize;
1416+
long totalSize;
1417+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
1418+
blockSize = statFs.getBlockSizeLong();
1419+
totalSize = statFs.getBlockCountLong();
1420+
} else {
1421+
blockSize = statFs.getBlockSize();
1422+
totalSize = statFs.getBlockCount();
1423+
}
1424+
return blockSize * totalSize;
1425+
}
1426+
1427+
/**
1428+
* Return the available size of file system.
1429+
*
1430+
* @param anyPathInFs Any path in file system.
1431+
* @return the available size of file system
1432+
*/
1433+
public static long getFsAvailableSize(final String anyPathInFs) {
1434+
if (TextUtils.isEmpty(anyPathInFs)) return 0;
1435+
StatFs statFs = new StatFs(anyPathInFs);
1436+
long blockSize;
1437+
long availableSize;
1438+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
1439+
blockSize = statFs.getBlockSizeLong();
1440+
availableSize = statFs.getAvailableBlocksLong();
1441+
} else {
1442+
blockSize = statFs.getBlockSize();
1443+
availableSize = statFs.getAvailableBlocks();
1444+
}
1445+
return blockSize * availableSize;
14021446
}
14031447

14041448
///////////////////////////////////////////////////////////////////////////

lib/utilcode/src/main/java/com/blankj/utilcode/util/KeyboardUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public static void fixAndroidBug5497(@NonNull final Activity activity) {
243243

244244
/**
245245
* Fix the bug of 5497 in Android.
246-
* <p>Don't set adjustResize</p>
246+
* <p>It will clean the adjustResize</p>
247247
*
248248
* @param window The window.
249249
*/

0 commit comments

Comments
 (0)