diff --git a/md/about_app.md b/md/about_app.md index 1a5c570ed0e0e776ef82d6a6dd66040912f92793..7d39c7d593a225615160fba5bbc6fdd4f5b3dad6 100644 --- a/md/about_app.md +++ b/md/about_app.md @@ -291,7 +291,7 @@ public class AppUtils { /** * 判断当前App处于前台还是后台 - *

需添加权限 android.permission.GET_TASKS

+ *

需添加权限 {@code }

*

并且必须是系统应用该方法才有效

* * @param context 上下文 diff --git a/md/about_device.md b/md/about_device.md index f48f32bcd3b23e70605fb391c125c0bf6951f9bb..2de53c1c133e7d368c02499bb26b1c6f629a99ed 100644 --- a/md/about_device.md +++ b/md/about_device.md @@ -27,7 +27,7 @@ public class DeviceUtils { /** * 获取设备MAC地址 - *

需添加权限 android.permission.ACCESS_WIFI_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return MAC地址 @@ -42,7 +42,8 @@ public class DeviceUtils { /** * 获取设备MAC地址 - *

需添加权限 android.permission.ACCESS_WIFI_STATE

+ * + *

需添加权限 {@code }

* * @return MAC地址 */ diff --git a/md/about_network.md b/md/about_network.md index bf24a1f1284eac61d54f792cfe04f7a62300a9ea..f7fd50eab52c98fb24162e0755bee44d749b9371 100644 --- a/md/about_network.md +++ b/md/about_network.md @@ -59,7 +59,7 @@ public class NetworkUtils { /** * 判断网络是否可用 - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 可用
false: 不可用 @@ -71,7 +71,7 @@ public class NetworkUtils { /** * 判断网络是否连接 - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 是
false: 否 @@ -83,7 +83,7 @@ public class NetworkUtils { /** * 判断网络是否是4G - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 是
false: 不是 @@ -95,7 +95,7 @@ public class NetworkUtils { /** * 判断wifi是否连接状态 - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 连接
false: 未连接 @@ -140,7 +140,7 @@ public class NetworkUtils { /** * 获取当前的网络类型(WIFI,2G,3G,4G) - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return 网络类型 diff --git a/md/about_phone.md b/md/about_phone.md index 117628f26aea5c9dd4722ab97b814177e82f2a34..6373098189b85a3e21057aa12c05730f18029b74 100644 --- a/md/about_phone.md +++ b/md/about_phone.md @@ -46,8 +46,8 @@ public class PhoneUtils { /** * 获取手机的IMIE - *

需与上面的isPhone一起使用

- *

需添加权限 android.permission.READ_PHONE_STATE

+ *

需与{@link #isPhone(Context)}一起使用

+ *

需添加权限 {@code }

* * @param context 上下文 * @return IMIE码 @@ -65,7 +65,7 @@ public class PhoneUtils { /** * 获取手机状态信息 - *

需添加权限 android.permission.READ_PHONE_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return DeviceId(IMEI) = 99000311726612
@@ -118,7 +118,7 @@ public class PhoneUtils { /** * 拨打phoneNumber - *

需添加权限 android.permission.CALL_PHONE

+ *

需添加权限 {@code }

* * @param context 上下文 * @param phoneNumber 电话号码 @@ -143,8 +143,8 @@ public class PhoneUtils { /** * 获取手机联系人 - *

需添加权限 android.permission.READ_EXTERNAL_STORAGE

- *

需添加权限 android.permission.READ_CONTACTS

+ *

需添加权限 {@code }

+ *

需添加权限 {@code }

* * @param context 上下文; * @return 联系人链表 @@ -240,8 +240,8 @@ public class PhoneUtils { /** * 获取手机短信并保存到xml中 - *

需添加权限 android.permission.READ_SMS

- *

需添加权限 android.permission.WRITE_EXTERNAL_STORAGE

+ *

需添加权限 {@code }

+ *

需添加权限 {@code }

* * @param context 上下文 */ diff --git a/md/about_screen.md b/md/about_screen.md index da88681fee985ee9419f836f98270733592ec166..3a63aaceacc86209fdd0005e78dddc4323927a8e 100644 --- a/md/about_screen.md +++ b/md/about_screen.md @@ -132,7 +132,7 @@ public class ScreenUtils { /** * 显示通知栏 - *

需添加权限 android.permission.EXPAND_STATUS_BAR

+ *

需添加权限 {@code }

* * @param context 上下文 * @param isSettingPanel true: 打开设置
false: 打开通知 @@ -145,7 +145,7 @@ public class ScreenUtils { /** * 隐藏通知栏 - *

需添加权限 android.permission.EXPAND_STATUS_BAR

+ *

需添加权限 {@code }

* * @param context 上下文 */ diff --git a/md/about_size.md b/md/about_size.md index 3e162c94981db7d42a0564f9cb387b761e17cb22..632a9fd79f4cd1cab03f46ce0f3a05a43f2d5d7f 100644 --- a/md/about_size.md +++ b/md/about_size.md @@ -1,5 +1,7 @@ # 尺寸相关 ``` java +package com.blankj.utilcode.utils; + import android.content.Context; import android.util.DisplayMetrics; import android.util.Log; @@ -102,7 +104,7 @@ public class SizeUtils { *
      * SizeUtils.forceGetViewSize(view);
      * SizeUtils.setListener(new SizeUtils.onGetSizeListener() {
-     *     @Override
+     *    {@code @Override}
      *     public void onGetSize(View view) {
      *         Log.d("tag", view.getWidth() + " " + view.getHeight());
      *     }
diff --git a/md/update_log.md b/md/update_log.md
index 113ba7b0dc1f3143866d5daab9b4f77052f48ab4..b5bab2149d2259b4003a72b08893727d6cacbd71 100644
--- a/md/update_log.md
+++ b/md/update_log.md
@@ -1,4 +1,5 @@
 ### 更新Log
+#### 16/08/18 完善FileUtils及单元测试,完善ImageUtils
 #### 16/08/17 完善FileUtils
 #### 16/08/16 新增StringUtils及单元测试,完善正则工具类,版本更新1.1.0
 #### 16/08/15 新增3DES和AES加密及单元检测,加密解密工具类基本完善,目录更新
diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java
index a82340ace7dd72673a7da1d1968652c30735e268..cf37b8156da0f13a671ba96eea1f697b814b6c9a 100644
--- a/utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java
+++ b/utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java
@@ -206,7 +206,7 @@ public class AppUtils {
 
     /**
      * 获取所有已安装App信息
-     * 

AppInfo(名称,图标,包名,版本号,版本Code,是否安装在SD卡,是否是用户程序)

+ *

{@see #app}(名称,图标,包名,版本号,版本Code,是否安装在SD卡,是否是用户程序)

*

依赖上面的getBean方法

* * @param context 上下文 @@ -291,7 +291,7 @@ public class AppUtils { /** * 判断当前App处于前台还是后台 - *

需添加权限 android.permission.GET_TASKS

+ *

需添加权限 {@code }

*

并且必须是系统应用该方法才有效

* * @param context 上下文 diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/DeviceUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/DeviceUtils.java index 133b3c31fdd78c09c9f210eee2d36322261870c3..5b8396f5eadaa617ba737313d952a424d12bc15f 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/DeviceUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/DeviceUtils.java @@ -27,7 +27,7 @@ public class DeviceUtils { /** * 获取设备MAC地址 - *

需添加权限 android.permission.ACCESS_WIFI_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return MAC地址 @@ -42,7 +42,8 @@ public class DeviceUtils { /** * 获取设备MAC地址 - *

需添加权限 android.permission.ACCESS_WIFI_STATE

+ * + *

需添加权限 {@code }

* * @return MAC地址 */ diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java index 265cdb94dd3a8b3ed06ad6c641398e3db3c8ce4a..de3f04e3c7d7ca793ee13b909c6a427a2f9a148f 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java @@ -2,11 +2,14 @@ package com.blankj.utilcode.utils; import android.text.TextUtils; +import java.io.BufferedInputStream; import java.io.BufferedReader; +import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; @@ -15,6 +18,8 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import static com.blankj.utilcode.utils.ConstUtils.KB; + /** *
  *     author: Blankj
@@ -30,6 +35,229 @@ public class FileUtils {
     }
 
 
+    /**
+     * 递归创建文件夹
+     *
+     * @param directoryPath 需要创建的目录
+     * @return 是否成功
+     */
+    public static boolean createDir(String directoryPath) {
+        if (StringUtils.isSpace(directoryPath)) return false;
+        File directory = new File(directoryPath);
+        return !directory.exists() && directory.mkdirs();
+    }
+
+    /**
+     * 根据路径创建文件
+     *
+     * @param filePath 文件路径
+     * @return 是否成功
+     */
+    public static boolean createFile(String filePath) {
+        File file = new File(filePath);
+        File dir = file.getParentFile();
+        if (!dir.exists()) {
+            if (dir.mkdirs()) {
+                try {
+                    return file.createNewFile();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        } else {
+            if (!file.exists()) {
+                try {
+                    return file.createNewFile();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            } else {
+                System.out.println("file already existed!");
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * 根据文件路径获取文件
+     *
+     * @param filePath 文件路径
+     * @return 文件
+     */
+    public static File getFileByPath(String filePath) {
+        if (StringUtils.isSpace(filePath)) return null;
+        return new File(filePath);
+    }
+
+    /**
+     * 简单获取文件编码格式
+     *
+     * @param filePath 文件路径
+     * @return 文件编码
+     */
+    public static String getFileCharsetSimple(String filePath) {
+        return getFileCharsetSimple(getFileByPath(filePath));
+    }
+
+    /**
+     * 简单获取文件编码格式
+     *
+     * @param file 文件
+     * @return 文件编码
+     */
+    public static String getFileCharsetSimple(File file) {
+        int p = 0;
+        BufferedInputStream bin = null;
+        try {
+            bin = new BufferedInputStream(new FileInputStream(file));
+            p = (bin.read() << 8) + bin.read();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (bin != null) closeIO(bin);
+        }
+        switch (p) {
+            case 0xefbb:
+                return "UTF-8";
+            case 0xfffe:
+                return "Unicode";
+            case 0xfeff:
+                return "UTF-16BE";
+            default:
+                return "GBK";
+        }
+    }
+
+    /**
+     * 获取文件的行数
+     *
+     * @param filePath 文件路径
+     * @return 文件行数
+     */
+    public static int getFileLines(String filePath) {
+        return getFileLines(getFileByPath(filePath));
+    }
+
+    /**
+     * 获取文件行数
+     *
+     * @param file 文件
+     * @return 文件行数
+     */
+    public static int getFileLines(File file) {
+        int count = 1;
+        InputStream is = null;
+        try {
+            is = new BufferedInputStream(new FileInputStream(file));
+            byte[] buffer = new byte[KB];
+            int readChars;
+            while ((readChars = is.read(buffer)) != -1) {
+                for (int i = 0; i < readChars; ++i) {
+                    if (buffer[i] == '\n') ++count;
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (is != null) closeIO(is);
+        }
+        return count;
+    }
+
+    /**
+     * 按行读取文件
+     *
+     * @param file 文件
+     * @return 行链表
+     */
+    public static List readFileByLine(File file) {
+        return readFileByLine(file, null);
+    }
+
+    /**
+     * 按行读取文件
+     *
+     * @param file        文件
+     * @param charsetName 字符编码格式
+     * @return 行链表
+     */
+    public static List readFileByLine(File file, String charsetName) {
+        if (file == null) return null;
+        List list = new ArrayList<>();
+        BufferedReader reader = null;
+        try {
+            if (charsetName == null) {
+                reader = new BufferedReader(new FileReader(file));
+            } else {
+                reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
+            }
+            String line;
+            while ((line = reader.readLine()) != null) {
+                list.add(line);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (reader != null) closeIO(reader);
+        }
+        return list;
+    }
+
+    /**
+     * 读取前几行数据
+     *
+     * @param file       文件
+     * @param endLineNum 需要读取的行数
+     * @return 包含制定行的list
+     */
+    public static List readFileByLine(File file, int endLineNum) {
+        if (file == null) return null;
+        List list = new ArrayList<>();
+        BufferedReader reader = null;
+        try {
+            reader = new BufferedReader(new FileReader(file));
+            String line;
+            while ((line = reader.readLine()) != null) {
+                list.add(line);
+                if (list.size() == endLineNum) {
+                    break;
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (reader != null) closeIO(reader);
+        }
+        return list;
+    }
+
+
+    public static void moveFile(String sourceFilePath, String destFilePath) {
+        if (TextUtils.isEmpty(sourceFilePath) || TextUtils.isEmpty(destFilePath)) {
+            throw new RuntimeException("Both sourceFilePath and destFilePath cannot be null.");
+        }
+        moveFile(new File(sourceFilePath), new File(destFilePath));
+    }
+
+    public static void moveFile(File srcFile, File destFile) {
+        boolean rename = srcFile.renameTo(destFile);
+        if (!rename) {
+            copyFile(srcFile.getAbsolutePath(), destFile.getAbsolutePath());
+            deleteFile(srcFile.getAbsolutePath());
+        }
+    }
+
+    public static boolean copyFile(String sourceFilePath, String destFilePath) {
+        InputStream inputStream = null;
+        try {
+            inputStream = new FileInputStream(sourceFilePath);
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException("FileNotFoundException occurred. ", e);
+        }
+        return writeFile(destFilePath, inputStream);
+    }
+
     public static StringBuilder readFile(String filePath, String charsetName) {
         File file = new File(filePath);
         if (!file.isFile()) return null;
@@ -50,9 +278,8 @@ public class FileUtils {
                 sb.append(line);
             }
             reader.close();
-            return sb;
         } catch (IOException e) {
-            throw new RuntimeException("IOException occurred. ", e);
+            e.printStackTrace();
         } finally {
             if (reader != null) {
                 try {
@@ -62,6 +289,7 @@ public class FileUtils {
                 }
             }
         }
+        return sb;
     }
 
     public static boolean writeFile(String filePath, String content, boolean append) {
@@ -75,13 +303,7 @@ public class FileUtils {
         } catch (IOException e) {
             throw new RuntimeException("IOException occurred. ", e);
         } finally {
-            if (fileWriter != null) {
-                try {
-                    fileWriter.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
+            if (fileWriter != null) closeIO(fileWriter);
         }
     }
 
@@ -103,25 +325,24 @@ public class FileUtils {
     }
 
     public static boolean writeFile(File file, InputStream stream, boolean append) {
-        OutputStream o = null;
+        OutputStream os = null;
         try {
             makeDirs(file.getAbsolutePath());
-            o = new FileOutputStream(file, append);
-            byte data[] = new byte[1024];
-            int length;
-            while ((length = stream.read(data)) != -1) {
-                o.write(data, 0, length);
+            os = new FileOutputStream(file, append);
+            byte data[] = new byte[KB];
+            while (stream.read(data) != -1) {
+                os.write(data);
             }
-            o.flush();
+            os.flush();
             return true;
         } catch (FileNotFoundException e) {
             throw new RuntimeException("FileNotFoundException occurred. ", e);
         } catch (IOException e) {
             throw new RuntimeException("IOException occurred. ", e);
         } finally {
-            if (o != null) {
+            if (os != null) {
                 try {
-                    o.close();
+                    os.close();
                     stream.close();
                 } catch (IOException e) {
                     e.printStackTrace();
@@ -130,32 +351,12 @@ public class FileUtils {
         }
     }
 
-    public static void moveFile(String sourceFilePath, String destFilePath) {
-        if (TextUtils.isEmpty(sourceFilePath) || TextUtils.isEmpty(destFilePath)) {
-            throw new RuntimeException("Both sourceFilePath and destFilePath cannot be null.");
-        }
-        moveFile(new File(sourceFilePath), new File(destFilePath));
-    }
-
-    public static void moveFile(File srcFile, File destFile) {
-        boolean rename = srcFile.renameTo(destFile);
-        if (!rename) {
-            copyFile(srcFile.getAbsolutePath(), destFile.getAbsolutePath());
-            deleteFile(srcFile.getAbsolutePath());
-        }
-    }
-
-    public static boolean copyFile(String sourceFilePath, String destFilePath) {
-        InputStream inputStream = null;
-        try {
-            inputStream = new FileInputStream(sourceFilePath);
-        } catch (FileNotFoundException e) {
-            throw new RuntimeException("FileNotFoundException occurred. ", e);
-        }
-        return writeFile(destFilePath, inputStream);
-    }
-
 
+    /**
+     * @param filePath
+     * @param charsetName
+     * @return
+     */
     public static List readFileToList(String filePath, String charsetName) {
         File file = new File(filePath);
         if (!file.isFile()) return null;
@@ -268,4 +469,38 @@ public class FileUtils {
         File file = new File(path);
         return (file.exists() && file.isFile() ? file.length() : -1);
     }
+
+    /**
+     * 快速清空一个超大的文件
+     *
+     * @param file 需要处理的文件
+     * @return 是否成功
+     */
+    public static boolean cleanFile(File file) {
+        FileWriter fw = null;
+        try {
+            fw = new FileWriter(file);
+            fw.write("");
+            return true;
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (fw != null) {
+                closeIO(fw);
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * @param closeable
+     */
+    private static void closeIO(Closeable closeable) {
+        try {
+            closeable.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/ImageUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/ImageUtils.java
index d5778edb233875f98deaa2c950dbaed1be85d1da..63941f778068b43d9c8c2fdf6b99086325c015ce 100644
--- a/utilcode/src/main/java/com/blankj/utilcode/utils/ImageUtils.java
+++ b/utilcode/src/main/java/com/blankj/utilcode/utils/ImageUtils.java
@@ -1,5 +1,23 @@
 package com.blankj.utilcode.utils;
 
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.LinearGradient;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Shader;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+
+import java.io.ByteArrayOutputStream;
+
 /**
  * 
  *     author: Blankj
@@ -9,9 +27,103 @@ package com.blankj.utilcode.utils;
  * 
*/ public class ImageUtils { + private ImageUtils() { throw new UnsupportedOperationException("u can't fuck me..."); } + /** + * convert Bitmap to byte array + */ + public static byte[] bitmapToBytes(Bitmap b) { + if (b == null) return null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + b.compress(Bitmap.CompressFormat.PNG, 100, baos); + return baos.toByteArray(); + } + + public static Bitmap bytesToBitmap(byte[] b) { + return (b == null || b.length == 0) ? null : BitmapFactory.decodeByteArray(b, 0, b.length); + } + + /** + * convert Drawable to Bitmap + */ + public static Bitmap drawableToBitmap(Drawable drawable) { + return drawable == null ? null : ((BitmapDrawable) drawable).getBitmap(); + } + + /** + * convert Bitmap to Drawable + */ + public static Drawable bitmapToDrawable(Resources resources, Bitmap bitmap) { + return bitmap == null ? null : new BitmapDrawable(resources, bitmap); + } + + + public static Bitmap toRoundCorner(Bitmap bitmap) { + int height = bitmap.getHeight(); + int width = bitmap.getHeight(); + Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + + Canvas canvas = new Canvas(output); + + final Paint paint = new Paint(); + final Rect rect = new Rect(0, 0, width, height); + + paint.setAntiAlias(true); + canvas.drawARGB(0, 0, 0, 0); + //paint.setColor(0xff424242); + paint.setColor(Color.TRANSPARENT); + canvas.drawCircle(width / 2, height / 2, width / 2, paint); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); + canvas.drawBitmap(bitmap, rect, rect, paint); + return output; + } + + public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { + Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap + .getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(output); + final int color = 0xff424242; + final Paint paint = new Paint(); + final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); + final RectF rectF = new RectF(rect); + paint.setAntiAlias(true); + canvas.drawARGB(0, 0, 0, 0); + paint.setColor(color); + canvas.drawRoundRect(rectF, roundPx, roundPx, paint); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); + canvas.drawBitmap(bitmap, rect, rect, paint); + return output; + } + + public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { + final int reflectionGap = 4; + int width = bitmap.getWidth(); + int height = bitmap.getHeight(); + Matrix matrix = new Matrix(); + matrix.preScale(1, -1); + Bitmap reflectionImage = Bitmap.createBitmap(bitmap, + 0, height / 2, width, height / 2, matrix, false); + Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), + Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmapWithReflection); + canvas.drawBitmap(bitmap, 0, 0, null); + canvas.drawRect(0, height, width, height + reflectionGap, + new Paint()); + canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); + Paint paint = new Paint(); + LinearGradient shader = new LinearGradient(0, + bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + + reflectionGap, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP); + paint.setShader(shader); + // Set the Transfer mode to be porter duff and destination in + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); + // Draw a rectangle using the paint with our linear gradient + canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + + reflectionGap, paint); + return bitmapWithReflection; + } } diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java index a3dc72123e9010924ed53e41e31fba6a512d4ab0..716c6d90c38f831c34d769c7bc26b7d34e9c9019 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java @@ -59,7 +59,7 @@ public class NetworkUtils { /** * 判断网络是否可用 - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 可用
false: 不可用 @@ -71,7 +71,7 @@ public class NetworkUtils { /** * 判断网络是否连接 - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 是
false: 否 @@ -83,7 +83,7 @@ public class NetworkUtils { /** * 判断网络是否是4G - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 是
false: 不是 @@ -95,7 +95,7 @@ public class NetworkUtils { /** * 判断wifi是否连接状态 - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return true: 连接
false: 未连接 @@ -140,7 +140,7 @@ public class NetworkUtils { /** * 获取当前的网络类型(WIFI,2G,3G,4G) - *

需添加权限 android.permission.ACCESS_NETWORK_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return 网络类型 diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java index 2dd58e12bc71e170edf2c2972269e9b944cf7038..be7ced5f75e2b501d0bda7a5c242b0c4d4ba2448 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java @@ -46,8 +46,8 @@ public class PhoneUtils { /** * 获取手机的IMIE - *

需与上面的isPhone一起使用

- *

需添加权限 android.permission.READ_PHONE_STATE

+ *

需与{@link #isPhone(Context)}一起使用

+ *

需添加权限 {@code }

* * @param context 上下文 * @return IMIE码 @@ -65,7 +65,7 @@ public class PhoneUtils { /** * 获取手机状态信息 - *

需添加权限 android.permission.READ_PHONE_STATE

+ *

需添加权限 {@code }

* * @param context 上下文 * @return DeviceId(IMEI) = 99000311726612
@@ -118,7 +118,7 @@ public class PhoneUtils { /** * 拨打phoneNumber - *

需添加权限 android.permission.CALL_PHONE

+ *

需添加权限 {@code }

* * @param context 上下文 * @param phoneNumber 电话号码 @@ -143,8 +143,8 @@ public class PhoneUtils { /** * 获取手机联系人 - *

需添加权限 android.permission.READ_EXTERNAL_STORAGE

- *

需添加权限 android.permission.READ_CONTACTS

+ *

需添加权限 {@code }

+ *

需添加权限 {@code }

* * @param context 上下文; * @return 联系人链表 @@ -240,8 +240,8 @@ public class PhoneUtils { /** * 获取手机短信并保存到xml中 - *

需添加权限 android.permission.READ_SMS

- *

需添加权限 android.permission.WRITE_EXTERNAL_STORAGE

+ *

需添加权限 {@code }

+ *

需添加权限 {@code }

* * @param context 上下文 */ diff --git a/utilcode/src/main/java/com/blankj/utilcode/utils/ScreenUtils.java b/utilcode/src/main/java/com/blankj/utilcode/utils/ScreenUtils.java index 5f4d019142bb702aae5b3aa7bcdd946616ab531c..cc6ed899cd1bcbc7da92e5587f09e859b5892ac4 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/utils/ScreenUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/utils/ScreenUtils.java @@ -132,7 +132,7 @@ public class ScreenUtils { /** * 显示通知栏 - *

需添加权限 android.permission.EXPAND_STATUS_BAR

+ *

需添加权限 {@code }

* * @param context 上下文 * @param isSettingPanel true: 打开设置
false: 打开通知 @@ -145,7 +145,7 @@ public class ScreenUtils { /** * 隐藏通知栏 - *

需添加权限 android.permission.EXPAND_STATUS_BAR

+ *

需添加权限 {@code }

* * @param context 上下文 */ 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 0f2620d5b2a2ac051a09ee4ed69f90ebd8b10237..1462d1afe6c44f6a948fd4bb2ad8316fd17217dc 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
+     *    {@code @Override}
      *     public void onGetSize(View view) {
      *         Log.d("tag", view.getWidth() + " " + view.getHeight());
      *     }
diff --git a/utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest1.java b/utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest1.java
new file mode 100644
index 0000000000000000000000000000000000000000..bb0002a4bf8d6b44875b8a08716d0b19f308a2ad
--- /dev/null
+++ b/utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest1.java
@@ -0,0 +1,174 @@
+package com.blankj.utilcode.utils;
+
+import org.junit.Test;
+
+import static com.blankj.utilcode.utils.FileUtils.*;
+import static com.google.common.truth.Truth.assertThat;
+
+/**
+ * 
+ *     author: Blankj
+ *     blog  : http://blankj.com
+ *     time  : 2016/8/18
+ *     desc  :
+ * 
+ */ +public class FileUtilsTest1 { + + public static String path = System.getProperty("user.dir") + "\\src\\test\\res\\"; + + @Test + public void testGetFileByPath() throws Exception { + assertThat(getFileByPath(path + "GBK.txt")).isNotNull(); + } + + @Test + public void testGetFileCharset() throws Exception { +// createDir(path+"\\cmj"); + System.out.println(createFile(path + "cmj\\GBK.txt")); + System.out.println(getFileCharsetSimple(path + "GBK.txt")); + System.out.println(getFileCharsetSimple(path + "Unicode.txt")); + System.out.println(getFileCharsetSimple(path + "UTF8.txt")); + System.out.println(getFileCharsetSimple(path + "UTF16BE.txt")); + } + + @Test + public void testGetFileLines() throws Exception { + System.out.println(getFileLines(path + "UTF8.txt")); + } + + @Test + public void testReadFileByLine() throws Exception { + + } + + @Test + public void testReadFileByLine1() throws Exception { + + } + + @Test + public void testReadFileByLine2() throws Exception { + + } + + @Test + public void testCreateFile() throws Exception { + + } + + @Test + public void testMoveFile() throws Exception { + + } + + @Test + public void testMoveFile1() throws Exception { + + } + + @Test + public void testCopyFile() throws Exception { + + } + + @Test + public void testReadFile() throws Exception { + + } + + @Test + public void testReadFile1() throws Exception { + + } + + @Test + public void testWriteFile() throws Exception { + + } + + @Test + public void testWriteFile1() throws Exception { + + } + + @Test + public void testWriteFile2() throws Exception { + + } + + @Test + public void testWriteFile3() throws Exception { + + } + + @Test + public void testWriteFile4() throws Exception { + + } + + @Test + public void testWriteFile5() throws Exception { + + } + + @Test + public void testReadFileToList() throws Exception { + + } + + @Test + public void testGetFolderName() throws Exception { + + } + + @Test + public void testGetFileName() throws Exception { + + } + + @Test + public void testGetFileNameWithoutExtension() throws Exception { + + } + + @Test + public void testGetFileExtension() throws Exception { + + } + + @Test + public void testMakeDirs() throws Exception { + + } + + @Test + public void testMakeFolders() throws Exception { + + } + + @Test + public void testIsFileExist() throws Exception { + + } + + @Test + public void testIsFolderExist() throws Exception { + + } + + @Test + public void testDeleteFile() throws Exception { + + } + + @Test + public void testGetFileSize() throws Exception { + + } + + @Test + public void testCleanFile() throws Exception { + + } +} \ No newline at end of file diff --git a/utilcode/src/test/java/com/blankj/utilcode/utils/StringUtilsTest.java b/utilcode/src/test/java/com/blankj/utilcode/utils/StringUtilsTest.java index 5c6735058a12a01e2b76a0592a477f4f9b1c49ba..19f485e9945fa725eb570607f31d77e4172e6d17 100644 --- a/utilcode/src/test/java/com/blankj/utilcode/utils/StringUtilsTest.java +++ b/utilcode/src/test/java/com/blankj/utilcode/utils/StringUtilsTest.java @@ -1,68 +1,68 @@ -package com.blankj.utilcode.utils; - -import org.junit.Test; - -import static com.blankj.utilcode.utils.StringUtils.*; -import static com.google.common.truth.Truth.assertThat; - -/** - *
- *     author: Blankj
- *     blog  : http://blankj.com
- *     time  : 2016/8/16
- *     desc  : StringUtils单元测试
- * 
- */ -public class StringUtilsTest { - - @Test - public void testIsEmpty() throws Exception { - assertThat(isEmpty("")).isTrue(); - assertThat(isEmpty(null)).isTrue(); - assertThat(isEmpty(" ")).isFalse(); - } - - @Test - public void testIsBlank() throws Exception { - assertThat(isSpace("")).isTrue(); - assertThat(isSpace(null)).isTrue(); - assertThat(isSpace(" ")).isTrue(); - assertThat(isSpace(" ")).isFalse(); - } - - @Test - public void testNull2Length0() throws Exception { - assertThat(null2Length0(null)).isEqualTo(""); - } - - @Test - public void testLength() throws Exception { - assertThat(length(null)).isEqualTo(0); - assertThat(length("")).isEqualTo(0); - assertThat(length("blankj")).isEqualTo(6); - } - - @Test - public void testUpperFirstLetter() throws Exception { - assertThat(upperFirstLetter("blankj")).isEqualTo("Blankj"); - assertThat(upperFirstLetter("Blankj")).isEqualTo("Blankj"); - assertThat(upperFirstLetter("1Blankj")).isEqualTo("1Blankj"); - } - - @Test - public void testLowerFirstLetter() throws Exception { - assertThat(lowerFirstLetter("blankj")).isEqualTo("blankj"); - assertThat(lowerFirstLetter("Blankj")).isEqualTo("blankj"); - assertThat(lowerFirstLetter("1blankj")).isEqualTo("1blankj"); - } - - @Test - public void testToDBC() throws Exception { - assertThat(toDBC(" ,.&")).isEqualTo(" ,.&"); - } - - @Test - public void testToSBC() throws Exception { - assertThat(toSBC(" ,.&")).isEqualTo(" ,.&"); - } +package com.blankj.utilcode.utils; + +import org.junit.Test; + +import static com.blankj.utilcode.utils.StringUtils.*; +import static com.google.common.truth.Truth.assertThat; + +/** + *
+ *     author: Blankj
+ *     blog  : http://blankj.com
+ *     time  : 2016/8/16
+ *     desc  : StringUtils单元测试
+ * 
+ */ +public class StringUtilsTest { + + @Test + public void testIsEmpty() throws Exception { + assertThat(isEmpty("")).isTrue(); + assertThat(isEmpty(null)).isTrue(); + assertThat(isEmpty(" ")).isFalse(); + } + + @Test + public void testIsSpace() throws Exception { + assertThat(isSpace("")).isTrue(); + assertThat(isSpace(null)).isTrue(); + assertThat(isSpace(" ")).isTrue(); + assertThat(isSpace(" ")).isFalse(); + } + + @Test + public void testNull2Length0() throws Exception { + assertThat(null2Length0(null)).isEqualTo(""); + } + + @Test + public void testLength() throws Exception { + assertThat(length(null)).isEqualTo(0); + assertThat(length("")).isEqualTo(0); + assertThat(length("blankj")).isEqualTo(6); + } + + @Test + public void testUpperFirstLetter() throws Exception { + assertThat(upperFirstLetter("blankj")).isEqualTo("Blankj"); + assertThat(upperFirstLetter("Blankj")).isEqualTo("Blankj"); + assertThat(upperFirstLetter("1Blankj")).isEqualTo("1Blankj"); + } + + @Test + public void testLowerFirstLetter() throws Exception { + assertThat(lowerFirstLetter("blankj")).isEqualTo("blankj"); + assertThat(lowerFirstLetter("Blankj")).isEqualTo("blankj"); + assertThat(lowerFirstLetter("1blankj")).isEqualTo("1blankj"); + } + + @Test + public void testToDBC() throws Exception { + assertThat(toDBC(" ,.&")).isEqualTo(" ,.&"); + } + + @Test + public void testToSBC() throws Exception { + assertThat(toSBC(" ,.&")).isEqualTo(" ,.&"); + } } \ No newline at end of file