From 4a465afb41431595b540addb4c8e06ced34d58d6 Mon Sep 17 00:00:00 2001 From: blankj <625783482@qq.com> Date: Tue, 16 Aug 2016 21:03:58 +0800 Subject: [PATCH] see 08/16 log --- README.md | 2 +- md/about_network.md | 3 + md/about_shell.md | 1 + md/about_size.md | 2 +- md/about_time.md | 180 ++++++------ md/update_log.md | 2 +- utilcode/build.gradle | 7 +- utilcode/project.properties | 10 + .../blankj/utilcode/utils/NetworkUtils.java | 3 + .../blankj/utilcode/utils/SDCardUtils.java | 266 +++++++++--------- .../com/blankj/utilcode/utils/ShellUtils.java | 1 + .../com/blankj/utilcode/utils/SizeUtils.java | 2 +- .../com/blankj/utilcode/utils/TimeUtils.java | 24 +- utilcode/utilcode.iml | 40 +-- 14 files changed, 282 insertions(+), 261 deletions(-) create mode 100644 utilcode/project.properties diff --git a/README.md b/README.md index 53c8f43f..463486c3 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ *** Gradle: ``` groovy -compile 'com.blankj:utilcode:1.0' +compile 'com.blankj:utilcode:1.1.0' ``` ### Proguard diff --git a/md/about_network.md b/md/about_network.md index 938d62a5..bf24a1f1 100644 --- a/md/about_network.md +++ b/md/about_network.md @@ -60,6 +60,9 @@ public class NetworkUtils { /** * 判断网络是否可用 *
需添加权限 android.permission.ACCESS_NETWORK_STATE
+ * + * @param context 上下文 + * @return true: 可用* SizeUtils.forceGetViewSize(view); * SizeUtils.setListener(new SizeUtils.onGetSizeListener() { - *
@Override + * @Override * public void onGetSize(View view) { * Log.d("tag", view.getWidth() + " " + view.getHeight()); * } diff --git a/md/about_time.md b/md/about_time.md index ce287b35..a19bb2c2 100644 --- a/md/about_time.md +++ b/md/about_time.md @@ -3,6 +3,9 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; + +import static com.blankj.utilcode.utils.ConstUtils.*; /** *@@ -27,7 +30,7 @@ public class TimeUtils { * * 定义了以下模式字母(所有其他字符 'A' 到 'Z' 和 'a' 到 'z' 都被保留):
*
字母 | *日期或时间元素 | *表示 | @@ -39,7 +42,7 @@ public class TimeUtils { *Text | *AD |
*
---|---|---|---|---|
y |
* 年 | *Year | @@ -51,7 +54,7 @@ public class TimeUtils { *Month | *July ; Jul ; 07 |
*
w |
* 年中的周数 | *Number | @@ -63,7 +66,7 @@ public class TimeUtils { *Number | *2 |
*
D |
* 年中的天数 | *Number | @@ -75,7 +78,7 @@ public class TimeUtils { *Number | *10 |
*
F |
* 月份中的星期 | *Number | @@ -87,7 +90,7 @@ public class TimeUtils { *Text | *Tuesday ; Tue |
*
a |
* Am/pm 标记 | *Text | @@ -99,7 +102,7 @@ public class TimeUtils { *Number | *0 |
*
k |
* 一天中的小时数(1-24) | *Number | @@ -111,7 +114,7 @@ public class TimeUtils { *Number | *0 |
*
h |
* am/pm 中的小时数(1-12) | *Number | @@ -123,7 +126,7 @@ public class TimeUtils { *Number | *30 |
*
s |
* 分钟中的秒数 | *Number | @@ -135,7 +138,7 @@ public class TimeUtils { *Number | *978 |
*
z |
* 时区 | *General time zone | @@ -149,27 +152,32 @@ public class TimeUtils { *
- * yyyy-MM-dd 1969-12-31 - * yyyy-MM-dd 1970-01-01 - * yyyy-MM-dd HH:mm 1969-12-31 16:00 - * yyyy-MM-dd HH:mm 1970-01-01 00:00 - * yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800 - * yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000 - * yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800 - * yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000 - * yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800 - * yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000 + * HH:mm 15:44 + * h:mm a 3:44 下午 + * HH:mm z 15:44 CST + * HH:mm Z 15:44 +0800 + * HH:mm zzzz 15:44 中国标准时间 + * HH:mm:ss 15:44:40 + * yyyy-MM-dd 2016-08-12 + * yyyy-MM-dd HH:mm 2016-08-12 15:44 + * yyyy-MM-dd HH:mm:ss 2016-08-12 15:44:40 + * yyyy-MM-dd HH:mm:ss zzzz 2016-08-12 15:44:40 中国标准时间 + * EEEE yyyy-MM-dd HH:mm:ss zzzz 星期五 2016-08-12 15:44:40 中国标准时间 + * yyyy-MM-dd HH:mm:ss.SSSZ 2016-08-12 15:44:40.461+0800 + * yyyy-MM-dd'T'HH:mm:ss.SSSZ 2016-08-12T15:44:40.461+0800 + * yyyy.MM.dd G 'at' HH:mm:ss z 2016.08.12 公元 at 15:44:40 CST + * K:mm a 3:44 下午 + * EEE, MMM d, ''yy 星期五, 八月 12, '16 + * hh 'o''clock' a, zzzz 03 o'clock 下午, 中国标准时间 + * yyyyy.MMMMM.dd GGG hh:mm aaa 02016.八月.12 公元 03:44 下午 + * EEE, d MMM yyyy HH:mm:ss Z 星期五, 12 八月 2016 15:44:40 +0800 + * yyMMddHHmmssZ 160812154440+0800 + * yyyy-MM-dd'T'HH:mm:ss.SSSZ 2016-08-12T15:44:40.461+0800 + * EEEE 'DATE('yyyy-MM-dd')' 'TIME('HH:mm:ss')' zzzz 星期五 DATE(2016-08-12) TIME(15:44:40) 中国标准时间 **/ - public static final SimpleDateFormat DEFAULT_SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - /** - * 各时间单位与毫秒的倍数 - */ - public static final int UNIT_MSEC = 1; - public static final int UNIT_SEC = 1000; - public static final int UNIT_MIN = 60000; - public static final int UNIT_HOUR = 3600000; - public static final int UNIT_DAY = 86400000; + public static final SimpleDateFormat DEFAULT_SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + /** * 将时间戳转为时间字符串 @@ -293,22 +301,22 @@ public class TimeUtils { * * @param milliseconds 毫秒时间戳 * @param unit
time1和time2格式都为yyyy-MM-dd HH:mm:ss
* - * @param time1 时间字符串1 - * @param time2 时间字符串2 + * @param time0 时间字符串1 + * @param time1 时间字符串2 * @param unittime1和time2格式都为format
* - * @param time1 时间字符串1 - * @param time2 时间字符串2 + * @param time0 时间字符串1 + * @param time1 时间字符串2 * @param unittime1和time2都为Date类型
* - * @param time1 Date类型时间1 - * @param time2 Date类型时间2 + * @param time0 Date类型时间1 + * @param time1 Date类型时间2 * @param unit需添加权限 android.permission.ACCESS_NETWORK_STATE
+ * + * @param context 上下文 + * @return true: 可用@@ -41,136 +37,134 @@ public class SDCardUtils { return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator; } - /** - * 获取SD卡的剩余容量 单位byte - * - * @return - */ - public static long getSDCardAllSize() { - if (isSDCardEnable()) { - StatFs stat = new StatFs(getSDCardPath()); - // 获取空闲的数据块的数量 - long availableBlocks = (long) stat.getAvailableBlocks() - 4; - // 获取单个数据块的大小(byte) - long freeBlocks = stat.getAvailableBlocks(); - return freeBlocks * availableBlocks; - } - return 0; - } - - /** - * 获取指定路径所在空间的剩余可用容量字节数,单位byte - * - * @param filePath - * @return 容量字节 SDCard可用空间,内部存储可用空间 - */ - public static long getFreeBytes(String filePath) { - // 如果是sd卡的下的路径,则获取sd卡可用容量 - if (filePath.startsWith(getSDCardPath())) { - filePath = getSDCardPath(); - } else {// 如果是内部存储的路径,则获取内存存储的可用容量 - filePath = Environment.getDataDirectory().getAbsolutePath(); - } - StatFs stat = new StatFs(filePath); - long availableBlocks = (long) stat.getAvailableBlocks() - 4; - return stat.getBlockSize() * availableBlocks; - } - - /** - * 获取系统存储路径 - * - * @return - */ - public static String getRootDirectoryPath() { - return Environment.getRootDirectory().getAbsolutePath(); - } - - /** - * Check if the file is exists - * - * @param filePath - * @param fileName - * @return - */ - public static boolean isFileExistsInSDCard(String filePath, String fileName) { - boolean flag = false; - if (isSDCardEnable()) { - File file = new File(filePath, fileName); - if (file.exists()) { - flag = true; - } - } - return flag; - } - - /** - * Write file to SD card - * @param filePath - * @param filename - * @param content - * @return - * @throws Exception - */ - public static boolean saveFileToSDCard(String filePath, String filename, String content) - throws Exception { - boolean flag = false; - if (isSDCardEnable()) { - File dir = new File(filePath); - if (!dir.exists()) { - dir.mkdir(); - } - File file = new File(filePath, filename); - FileOutputStream outStream = new FileOutputStream(file); - outStream.write(content.getBytes()); - outStream.close(); - flag = true; - } - return flag; - } - - /** - * Read file as stream from SD card - * - * @param fileName - * String PATH = - * Environment.getExternalStorageDirectory().getAbsolutePath() + - * "/dirName"; - * @return - */ - public static byte[] readFileFromSDCard(String filePath, String fileName) { - byte[] buffer = null; - FileInputStream fin = null; - try { - if (isSDCardEnable()) { - String filePaht = filePath + "/" + fileName; - fin = new FileInputStream(filePaht); - int length = fin.available(); - buffer = new byte[length]; - fin.read(buffer); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (fin != null) fin.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return buffer; - } - - /** - * Delete file - * - * @param filePath - * @param fileName - * filePath = - * android.os.Environment.getExternalStorageDirectory().getPath() - * @return - */ - public static boolean deleteSDFile(String filePath, String fileName) { - File file = new File(filePath + "/" + fileName); - return !(!file.exists() || file.isDirectory()) && file.delete(); - } +// /** +// * 获取SD卡的剩余容量 单位byte +// * +// * @return +// */ +// public static long getSDCardAllSize() { +// if (isSDCardEnable()) { +// StatFs stat = new StatFs(getSDCardPath()); +// // 获取空闲的数据块的数量 +// long availableBlocks = (long) stat.getAvailableBlocks() - 4; +// // 获取单个数据块的大小(byte) +// long freeBlocks = stat.getAvailableBlocks(); +// return freeBlocks * availableBlocks; +// } +// return 0; +// } +// +// /** +// * 获取指定路径所在空间的剩余可用容量字节数,单位byte +// * +// * @param filePath +// * @return 容量字节 SDCard可用空间,内部存储可用空间 +// */ +// public static long getFreeBytes(String filePath) { +// // 如果是sd卡的下的路径,则获取sd卡可用容量 +// if (filePath.startsWith(getSDCardPath())) { +// filePath = getSDCardPath(); +// } else {// 如果是内部存储的路径,则获取内存存储的可用容量 +// filePath = Environment.getDataDirectory().getAbsolutePath(); +// } +// StatFs stat = new StatFs(filePath); +// long availableBlocks = (long) stat.getAvailableBlocks() - 4; +// return stat.getBlockSize() * availableBlocks; +// } +// +// /** +// * 获取系统存储路径 +// * +// * @return +// */ +// public static String getRootDirectoryPath() { +// return Environment.getRootDirectory().getAbsolutePath(); +// } +// +// /** +// * Check if the file is exists +// * +// * @param filePath +// * @param fileName +// * @return +// */ +// public static boolean isFileExistsInSDCard(String filePath, String fileName) { +// boolean flag = false; +// if (isSDCardEnable()) { +// File file = new File(filePath, fileName); +// if (file.exists()) { +// flag = true; +// } +// } +// return flag; +// } +// +// /** +// * Write file to SD card +// * +// * @param filePath +// * @param filename +// * @param content +// * @return +// * @throws Exception +// */ +// public static boolean saveFileToSDCard(String filePath, String filename, String content) +// throws Exception { +// boolean flag = false; +// if (isSDCardEnable()) { +// File dir = new File(filePath); +// if (!dir.exists()) { +// dir.mkdir(); +// } +// File file = new File(filePath, filename); +// FileOutputStream outStream = new FileOutputStream(file); +// outStream.write(content.getBytes()); +// outStream.close(); +// flag = true; +// } +// return flag; +// } +// +// /** +// * Read file as stream from SD card +// * +// * @param fileName String PATH = +// * Environment.getExternalStorageDirectory().getAbsolutePath() + +// * "/dirName"; +// * @return +// */ +// public static byte[] readFileFromSDCard(String filePath, String fileName) { +// byte[] buffer = null; +// FileInputStream fin = null; +// try { +// if (isSDCardEnable()) { +// String filePaht = filePath + "/" + fileName; +// fin = new FileInputStream(filePaht); +// int length = fin.available(); +// buffer = new byte[length]; +// fin.read(buffer); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// try { +// if (fin != null) fin.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// return buffer; +// } +// +// /** +// * Delete file +// * +// * @param filePath 文件路径 +// * @param fileName 文件名 +// * @return true: 成功
false: 失败 +// */ +// public static boolean deleteSDFile(String filePath, String fileName) { +// File file = new File(filePath + "/" + fileName); +// return !(!file.exists() || file.isDirectory()) && file.delete(); +// } } \ No newline at end of file diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/ShellUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/ShellUtils.java index 0a756c03..4df63f5e 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/ShellUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/ShellUtils.java @@ -27,6 +27,7 @@ public class ShellUtils { /** * 判断设备是否root + * @return true: root
false: 没root */ public static boolean isRoot() { return execCmd("echo root", true, false).result == 0; diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/SizeUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/SizeUtils.java index 076e78a4..0f2620d5 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/SizeUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/SizeUtils.java @@ -102,7 +102,7 @@ public class SizeUtils { ** SizeUtils.forceGetViewSize(view); * SizeUtils.setListener(new SizeUtils.onGetSizeListener() { - * @Override + * @Override * public void onGetSize(View view) { * Log.d("tag", view.getWidth() + " " + view.getHeight()); * } diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/TimeUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/TimeUtils.java index d612ff43..23e9fa91 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/TimeUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/TimeUtils.java @@ -30,7 +30,7 @@ public class TimeUtils { * * 定义了以下模式字母(所有其他字符 'A' 到 'Z' 和 'a' 到 'z' 都被保留):
*
字母 | *日期或时间元素 | *表示 | @@ -42,7 +42,7 @@ public class TimeUtils { *Text | *AD |
*
---|---|---|---|---|
y |
* 年 | *Year | @@ -54,7 +54,7 @@ public class TimeUtils { *Month | *July ; Jul ; 07 |
*
w |
* 年中的周数 | *Number | @@ -66,7 +66,7 @@ public class TimeUtils { *Number | *2 |
*
D |
* 年中的天数 | *Number | @@ -78,7 +78,7 @@ public class TimeUtils { *Number | *10 |
*
F |
* 月份中的星期 | *Number | @@ -90,7 +90,7 @@ public class TimeUtils { *Text | *Tuesday ; Tue |
*
a |
* Am/pm 标记 | *Text | @@ -102,7 +102,7 @@ public class TimeUtils { *Number | *0 |
*
k |
* 一天中的小时数(1-24) | *Number | @@ -114,7 +114,7 @@ public class TimeUtils { *Number | *0 |
*
h |
* am/pm 中的小时数(1-12) | *Number | @@ -126,7 +126,7 @@ public class TimeUtils { *Number | *30 |
*
s |
* 分钟中的秒数 | *Number | @@ -138,7 +138,7 @@ public class TimeUtils { *Number | *978 |
*
z |
* 时区 | *General time zone | @@ -485,6 +485,4 @@ public class TimeUtils { public static boolean isLeapYear(int year) { return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; } - -} - +} \ No newline at end of file diff --git a/utilcode/utilcode.iml b/utilcode/utilcode.iml index ceedc0ed..79a744d8 100644 --- a/utilcode/utilcode.iml +++ b/utilcode/utilcode.iml @@ -65,14 +65,6 @@