提交 c3d15021 编写于 作者: B blankj

see 08/18 log

上级 98536ab3
......@@ -291,7 +291,7 @@ public class AppUtils {
/**
* 判断当前App处于前台还是后台
* <p>需添加权限 android.permission.GET_TASKS</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>
* <p>并且必须是系统应用该方法才有效</p>
*
* @param context 上下文
......
......@@ -27,7 +27,7 @@ public class DeviceUtils {
/**
* 获取设备MAC地址
* <p>需添加权限 android.permission.ACCESS_WIFI_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
*
* @param context 上下文
* @return MAC地址
......@@ -42,7 +42,8 @@ public class DeviceUtils {
/**
* 获取设备MAC地址
* <p>需添加权限 android.permission.ACCESS_WIFI_STATE</p>
*
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
*
* @return MAC地址
*/
......
......@@ -59,7 +59,7 @@ public class NetworkUtils {
/**
* 判断网络是否可用
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 可用<br>false: 不可用
......@@ -71,7 +71,7 @@ public class NetworkUtils {
/**
* 判断网络是否连接
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 是<br>false: 否
......@@ -83,7 +83,7 @@ public class NetworkUtils {
/**
* 判断网络是否是4G
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 是<br>false: 不是
......@@ -95,7 +95,7 @@ public class NetworkUtils {
/**
* 判断wifi是否连接状态
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 连接<br>false: 未连接
......@@ -140,7 +140,7 @@ public class NetworkUtils {
/**
* 获取当前的网络类型(WIFI,2G,3G,4G)
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return 网络类型
......
......@@ -46,8 +46,8 @@ public class PhoneUtils {
/**
* 获取手机的IMIE
* <p>需与上面的isPhone一起使用</p>
* <p>需添加权限 android.permission.READ_PHONE_STATE</p>
* <p>需与{@link #isPhone(Context)}一起使用</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @param context 上下文
* @return IMIE码
......@@ -65,7 +65,7 @@ public class PhoneUtils {
/**
* 获取手机状态信息
* <p>需添加权限 android.permission.READ_PHONE_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @param context 上下文
* @return DeviceId(IMEI) = 99000311726612<br>
......@@ -118,7 +118,7 @@ public class PhoneUtils {
/**
* 拨打phoneNumber
* <p>需添加权限 android.permission.CALL_PHONE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.CALL_PHONE"/>}</p>
*
* @param context 上下文
* @param phoneNumber 电话号码
......@@ -143,8 +143,8 @@ public class PhoneUtils {
/**
* 获取手机联系人
* <p>需添加权限 android.permission.READ_EXTERNAL_STORAGE</p>
* <p>需添加权限 android.permission.READ_CONTACTS</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_CONTACTS"/>}</p>
*
* @param context 上下文;
* @return 联系人链表
......@@ -240,8 +240,8 @@ public class PhoneUtils {
/**
* 获取手机短信并保存到xml中
* <p>需添加权限 android.permission.READ_SMS</p>
* <p>需添加权限 android.permission.WRITE_EXTERNAL_STORAGE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_SMS"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
*
* @param context 上下文
*/
......
......@@ -132,7 +132,7 @@ public class ScreenUtils {
/**
* 显示通知栏
* <p>需添加权限 android.permission.EXPAND_STATUS_BAR</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
*
* @param context 上下文
* @param isSettingPanel true: 打开设置<br>false: 打开通知
......@@ -145,7 +145,7 @@ public class ScreenUtils {
/**
* 隐藏通知栏
* <p>需添加权限 android.permission.EXPAND_STATUS_BAR</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
*
* @param context 上下文
*/
......
# 尺寸相关
``` 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 {
* <pre>
* SizeUtils.forceGetViewSize(view);
* SizeUtils.setListener(new SizeUtils.onGetSizeListener() {
* <span></span>@Override
* {@code @Override}
* public void onGetSize(View view) {
* Log.d("tag", view.getWidth() + " " + view.getHeight());
* }
......
### 更新Log
#### 16/08/18 完善FileUtils及单元测试,完善ImageUtils
#### 16/08/17 完善FileUtils
#### 16/08/16 新增StringUtils及单元测试,完善正则工具类,版本更新1.1.0
#### 16/08/15 新增3DES和AES加密及单元检测,加密解密工具类基本完善,目录更新
......
......@@ -206,7 +206,7 @@ public class AppUtils {
/**
* 获取所有已安装App信息
* <p>AppInfo(名称,图标,包名,版本号,版本Code,是否安装在SD卡,是否是用户程序)</p>
* <p>{@see #app}(名称,图标,包名,版本号,版本Code,是否安装在SD卡,是否是用户程序)</p>
* <p>依赖上面的getBean方法</p>
*
* @param context 上下文
......@@ -291,7 +291,7 @@ public class AppUtils {
/**
* 判断当前App处于前台还是后台
* <p>需添加权限 android.permission.GET_TASKS</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>
* <p>并且必须是系统应用该方法才有效</p>
*
* @param context 上下文
......
......@@ -27,7 +27,7 @@ public class DeviceUtils {
/**
* 获取设备MAC地址
* <p>需添加权限 android.permission.ACCESS_WIFI_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
*
* @param context 上下文
* @return MAC地址
......@@ -42,7 +42,8 @@ public class DeviceUtils {
/**
* 获取设备MAC地址
* <p>需添加权限 android.permission.ACCESS_WIFI_STATE</p>
*
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
*
* @return MAC地址
*/
......
......@@ -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;
/**
* <pre>
* 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<String> readFileByLine(File file) {
return readFileByLine(file, null);
}
/**
* 按行读取文件
*
* @param file 文件
* @param charsetName 字符编码格式
* @return 行链表
*/
public static List<String> readFileByLine(File file, String charsetName) {
if (file == null) return null;
List<String> 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<String> readFileByLine(File file, int endLineNum) {
if (file == null) return null;
List<String> 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<String> 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();
}
}
}
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;
/**
* <pre>
* author: Blankj
......@@ -9,9 +27,103 @@ package com.blankj.utilcode.utils;
* </pre>
*/
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;
}
}
......@@ -59,7 +59,7 @@ public class NetworkUtils {
/**
* 判断网络是否可用
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 可用<br>false: 不可用
......@@ -71,7 +71,7 @@ public class NetworkUtils {
/**
* 判断网络是否连接
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 是<br>false: 否
......@@ -83,7 +83,7 @@ public class NetworkUtils {
/**
* 判断网络是否是4G
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 是<br>false: 不是
......@@ -95,7 +95,7 @@ public class NetworkUtils {
/**
* 判断wifi是否连接状态
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return true: 连接<br>false: 未连接
......@@ -140,7 +140,7 @@ public class NetworkUtils {
/**
* 获取当前的网络类型(WIFI,2G,3G,4G)
* <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return 网络类型
......
......@@ -46,8 +46,8 @@ public class PhoneUtils {
/**
* 获取手机的IMIE
* <p>需与上面的isPhone一起使用</p>
* <p>需添加权限 android.permission.READ_PHONE_STATE</p>
* <p>需与{@link #isPhone(Context)}一起使用</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @param context 上下文
* @return IMIE码
......@@ -65,7 +65,7 @@ public class PhoneUtils {
/**
* 获取手机状态信息
* <p>需添加权限 android.permission.READ_PHONE_STATE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @param context 上下文
* @return DeviceId(IMEI) = 99000311726612<br>
......@@ -118,7 +118,7 @@ public class PhoneUtils {
/**
* 拨打phoneNumber
* <p>需添加权限 android.permission.CALL_PHONE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.CALL_PHONE"/>}</p>
*
* @param context 上下文
* @param phoneNumber 电话号码
......@@ -143,8 +143,8 @@ public class PhoneUtils {
/**
* 获取手机联系人
* <p>需添加权限 android.permission.READ_EXTERNAL_STORAGE</p>
* <p>需添加权限 android.permission.READ_CONTACTS</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_CONTACTS"/>}</p>
*
* @param context 上下文;
* @return 联系人链表
......@@ -240,8 +240,8 @@ public class PhoneUtils {
/**
* 获取手机短信并保存到xml中
* <p>需添加权限 android.permission.READ_SMS</p>
* <p>需添加权限 android.permission.WRITE_EXTERNAL_STORAGE</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_SMS"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
*
* @param context 上下文
*/
......
......@@ -132,7 +132,7 @@ public class ScreenUtils {
/**
* 显示通知栏
* <p>需添加权限 android.permission.EXPAND_STATUS_BAR</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
*
* @param context 上下文
* @param isSettingPanel true: 打开设置<br>false: 打开通知
......@@ -145,7 +145,7 @@ public class ScreenUtils {
/**
* 隐藏通知栏
* <p>需添加权限 android.permission.EXPAND_STATUS_BAR</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>}</p>
*
* @param context 上下文
*/
......
......@@ -102,7 +102,7 @@ public class SizeUtils {
* <pre>
* SizeUtils.forceGetViewSize(view);
* SizeUtils.setListener(new SizeUtils.onGetSizeListener() {
* <span></span>@Override
* {@code @Override}
* public void onGetSize(View view) {
* Log.d("tag", view.getWidth() + " " + view.getHeight());
* }
......
package com.blankj.utilcode.utils;
import org.junit.Test;
import static com.blankj.utilcode.utils.FileUtils.*;
import static com.google.common.truth.Truth.assertThat;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/8/18
* desc :
* </pre>
*/
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
package com.blankj.utilcode.utils;
import org.junit.Test;
import static com.blankj.utilcode.utils.StringUtils.*;
import static com.google.common.truth.Truth.assertThat;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/8/16
* desc : StringUtils单元测试
* </pre>
*/
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;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/8/16
* desc : StringUtils单元测试
* </pre>
*/
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册