Skip to content

Commit

Permalink
see 04/13 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Apr 12, 2020
1 parent ccd1783 commit deb9f5c
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 78 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* `20/04/13` [add] NumberUtils. Publish v1.28.0.
* `20/04/12` [opt] TimeUtils#SDF_THREAD_LOCAL.
* `20/04/11` [add] SDCardUtils#getXxTotalSize, SDCardUtils#getXxAvailableSize. FileUtils#getFsTotalSize, FileUtils#getFsAvailableSize.
* `20/04/10` [fix] FileUtils#isFileExists; FragmentUtils#getTop bug. Publish v1.27.6.
* `20/04/09` [add] UriUtils#res2Uri, UriUtils#uri2File support QQBrowser; ThreadUtils#getMainHandler; PathUtils#getxxPathExternalFirst.
* `20/04/08` [fix] ActivityUtils#finish bug. Publish v1.27.5.
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Config {
static minSdkVersion = 14
static targetSdkVersion = 29
static versionCode = 1_026_001
static versionName = '1.27.6'// E.g. 1.9.72 => 1,009,072
static versionName = '1.28.0'// E.g. 1.9.72 => 1,009,072

// lib version
static gradlePluginVersion = '3.5.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import com.blankj.common.activity.CommonActivity
import com.blankj.common.activity.CommonActivityItemsView
import com.blankj.common.activity.CommonActivityTitleView
import com.blankj.common.item.CommonItem
import com.blankj.common.item.CommonItemTitle
import com.blankj.utilcode.pkg.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@ class SDCardActivity : CommonActivity() {
}

override fun bindItems(): MutableList<CommonItem<*>> {
val mountedSDCardPath = SDCardUtils.getMountedSDCardPath()
val sizeItems = CollectionUtils.collect(mountedSDCardPath) { input ->
val totalInfo = "total: " + ConvertUtils.byte2FitMemorySize(SDCardUtils.getTotalSize(input))
val availableInfo = "available: " + ConvertUtils.byte2FitMemorySize(SDCardUtils.getAvailableSize(input))
CommonItemTitle(input, "$totalInfo, $availableInfo")
}
val result: ArrayList<CommonItem<*>> = CollectionUtils.newArrayList(
return CollectionUtils.newArrayList(
CommonItemTitle("isSDCardEnableByEnvironment", SDCardUtils.isSDCardEnableByEnvironment().toString()),
CommonItemTitle("getSDCardPathByEnvironment", SDCardUtils.getSDCardPathByEnvironment()),
CommonItemTitle("getSDCardInfo", SDCardUtils.getSDCardInfo().toString()),
CommonItemTitle("getMountedSDCardPath", mountedSDCardPath.toString())
CommonItemTitle("getMountedSDCardPath", SDCardUtils.getMountedSDCardPath().toString()),
CommonItemTitle("getExternalTotalSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getExternalTotalSize(), 2)),
CommonItemTitle("getExternalAvailableSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getExternalAvailableSize(), 2)),
CommonItemTitle("getInternalTotalSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getInternalTotalSize(), 2)),
CommonItemTitle("getInternalAvailableSize", ConvertUtils.byte2FitMemorySize(SDCardUtils.getInternalAvailableSize(), 2))
)
result.addAll(sizeItems)
return result
}
}
22 changes: 18 additions & 4 deletions lib/utilcode/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.27.6'
implementation 'com.blankj:utilcode:1.28.0'
// if u use AndroidX, use the following
implementation 'com.blankj:utilcodex:1.27.6'
implementation 'com.blankj:utilcodex:1.28.0'
```


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

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

* ### 数字相关 -> [NumberUtils.java][number.java] -> [Test][number.test]
```
format : 格式化
float2Double: 浮点转双精度
```

* ### 对象相关 -> [ObjectUtils.java][object.java] -> [Test][object.test]
```
isEmpty : 判断对象是否为空
Expand Down Expand Up @@ -913,8 +921,10 @@ isSDCardEnableByEnvironment: 根据 Environment 判断 SD 卡是否可用
getSDCardPathByEnvironment : 根据 Environment 获取 SD 卡路径
getSDCardInfo : 获取 SD 卡信息
getMountedSDCardPath : 获取已挂载的 SD 卡路径
getTotalSize : 获取 SD 卡总大小
getAvailableSize : 获取 SD 卡可用大小
getExternalTotalSize : 获取外置 SD 卡总大小
getExternalAvailableSize : 获取外置 SD 卡可用大小
getInternalTotalSize : 获取内置 SD 卡总大小
getInternalAvailableSize : 获取内置 SD 卡可用大小
```

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

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

[number.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/NumberUtils.java
[number.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/NumberUtilsTest.java

[object.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java
[object.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/ObjectUtilsTest.java

Expand Down
22 changes: 18 additions & 4 deletions lib/utilcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.27.6'
implementation 'com.blankj:utilcode:1.28.0'
// if u use AndroidX, use the following
implementation 'com.blankj:utilcodex:1.27.6'
implementation 'com.blankj:utilcodex:1.28.0'
```


Expand Down Expand Up @@ -487,6 +487,8 @@ getFileName
getFileNameNoExtension
getFileExtension
notifySystemToScan
getFsTotalSize
getFsAvailableSize
```

* ### About Fragment -> [FragmentUtils.java][fragment.java] -> [Demo][fragment.demo]
Expand Down Expand Up @@ -695,6 +697,12 @@ cancelAll
setNotificationBarVisibility
```

* ### About Number -> [NumberUtils.java][number.java] -> [Test][number.test]
```
format
float2Double
```

* ### About Object -> [ObjectUtils.java][object.java] -> [Test][object.test]
```
isEmpty
Expand Down Expand Up @@ -913,8 +921,10 @@ isSDCardEnableByEnvironment
getSDCardPathByEnvironment
getSDCardInfo
getMountedSDCardPath
getTotalSize
getAvailableSize
getExternalTotalSize
getExternalAvailableSize
getInternalTotalSize
getInternalAvailableSize
```

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

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

[number.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/NumberUtils.java
[number.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/NumberUtilsTest.java

[object.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java
[object.test]: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/src/test/java/com/blankj/utilcode/util/ObjectUtilsTest.java

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,32 @@ public static double byte2MemorySize(final long byteSize,
*/
@SuppressLint("DefaultLocale")
public static String byte2FitMemorySize(final long byteSize) {
return byte2FitMemorySize(byteSize, 3);
}

/**
* Size of byte to fit size of memory.
* <p>to three decimal places</p>
*
* @param byteSize Size of byte.
* @param precision The precision
* @return fit size of memory
*/
@SuppressLint("DefaultLocale")
public static String byte2FitMemorySize(final long byteSize, int precision) {
if (precision < 0) {
throw new IllegalArgumentException("precision shouldn't be less than zero!");
}
if (byteSize < 0) {
return "shouldn't be less than zero!";
throw new IllegalArgumentException("byteSize shouldn't be less than zero!");
} else if (byteSize < MemoryConstants.KB) {
return String.format("%.3fB", (double) byteSize);
return String.format("%." + precision + "fB", (double) byteSize);
} else if (byteSize < MemoryConstants.MB) {
return String.format("%.3fKB", (double) byteSize / MemoryConstants.KB);
return String.format("%." + precision + "fKB", (double) byteSize / MemoryConstants.KB);
} else if (byteSize < MemoryConstants.GB) {
return String.format("%.3fMB", (double) byteSize / MemoryConstants.MB);
return String.format("%." + precision + "fMB", (double) byteSize / MemoryConstants.MB);
} else {
return String.format("%.3fGB", (double) byteSize / MemoryConstants.GB);
return String.format("%." + precision + "fGB", (double) byteSize / MemoryConstants.GB);
}
}

Expand Down
56 changes: 50 additions & 6 deletions lib/utilcode/src/main/java/com/blankj/utilcode/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.os.Build;
import android.os.StatFs;
import android.text.TextUtils;

import java.io.BufferedInputStream;
import java.io.File;
Expand Down Expand Up @@ -76,10 +78,10 @@ public static boolean isFileExists(final String filePath) {
if (file.exists()) {
return true;
}
return isFileExists29(filePath);
return isFileExistsApi29(filePath);
}

private static boolean isFileExists29(String filePath) {
private static boolean isFileExistsApi29(String filePath) {
if (Build.VERSION.SDK_INT >= 29) {
try {
Uri uri = Uri.parse(filePath);
Expand Down Expand Up @@ -1379,6 +1381,15 @@ public static String getFileExtension(final String filePath) {
return filePath.substring(lastPoi + 1);
}

/**
* Notify system to scan the file.
*
* @param filePath The path of file.
*/
public static void notifySystemToScan(final String filePath) {
notifySystemToScan(getFileByPath(filePath));
}

/**
* Notify system to scan the file.
*
Expand All @@ -1393,12 +1404,45 @@ public static void notifySystemToScan(final File file) {
}

/**
* Notify system to scan the file.
* Return the total size of file system.
*
* @param filePath The path of file.
* @param anyPathInFs Any path in file system.
* @return the total size of file system
*/
public static void notifySystemToScan(final String filePath) {
notifySystemToScan(getFileByPath(filePath));
public static long getFsTotalSize(String anyPathInFs) {
if (TextUtils.isEmpty(anyPathInFs)) return 0;
StatFs statFs = new StatFs(anyPathInFs);
long blockSize;
long totalSize;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = statFs.getBlockSizeLong();
totalSize = statFs.getBlockCountLong();
} else {
blockSize = statFs.getBlockSize();
totalSize = statFs.getBlockCount();
}
return blockSize * totalSize;
}

/**
* Return the available size of file system.
*
* @param anyPathInFs Any path in file system.
* @return the available size of file system
*/
public static long getFsAvailableSize(final String anyPathInFs) {
if (TextUtils.isEmpty(anyPathInFs)) return 0;
StatFs statFs = new StatFs(anyPathInFs);
long blockSize;
long availableSize;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = statFs.getBlockSizeLong();
availableSize = statFs.getAvailableBlocksLong();
} else {
blockSize = statFs.getBlockSize();
availableSize = statFs.getAvailableBlocks();
}
return blockSize * availableSize;
}

///////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static void fixAndroidBug5497(@NonNull final Activity activity) {

/**
* Fix the bug of 5497 in Android.
* <p>Don't set adjustResize</p>
* <p>It will clean the adjustResize</p>
*
* @param window The window.
*/
Expand Down
Loading

0 comments on commit deb9f5c

Please sign in to comment.