提交 f88f4f34 编写于 作者: C cmj

see 09/18 log

上级 942ef0be
......@@ -8,7 +8,7 @@ android {
minSdkVersion 11
targetSdkVersion 23
versionCode 8
versionName "1.2.0"
versionName "1.2.1"
}
buildTypes {
release {
......
......@@ -31,24 +31,22 @@ public class AppUtils {
}
/**
* 获取安装App(支持6.0以上)的意图
* 获取安装App(支持6.0)的意图
*
* @param context 上下文
* @param filePath 文件路径
* @return 意图
*/
public static Intent installApp(Context context, String filePath) {
return installApp(context, FileUtils.getFileByPath(filePath));
public static Intent getInstallAppIntent(String filePath) {
return getInstallAppIntent(FileUtils.getFileByPath(filePath));
}
/**
* 获取安装App(支持6.0以上)的意图
* 获取安装App(支持6.0)的意图
*
* @param context 上下文
* @param file 文件
* @param file 文件
* @return 意图
*/
public static Intent installApp(Context context, File file) {
public static Intent getInstallAppIntent(File file) {
if (file == null) return null;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
......@@ -58,22 +56,75 @@ public class AppUtils {
} else {
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(FileUtils.getFileExtension(file));
}
intent.setDataAndType(Uri.fromFile(file), type);
return intent;
return intent.setDataAndType(Uri.fromFile(file), type);
}
/**
* 获取卸载指定包名的App的意图
* 获取卸载App的意图
*
* @param context 上下文
* @param packageName 包名
* @return 意图
*/
public Intent uninstallApp(Context context, String packageName) {
public Intent getUninstallAppIntent(String packageName) {
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:" + packageName));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
/**
* 获取打开App的意图
*
* @param context 上下文
* @param packageName 包名
* @return 意图
*/
public static Intent getOpenAppItent(Context context, String packageName) {
return getIntentByPackageName(context, packageName);
}
/**
* 获取App信息的意图
*
* @param packageName 包名
* @return 意图
*/
public static Intent getAppInfoIntent(String packageName) {
Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
return intent.setData(Uri.parse("package:" + packageName));
}
/**
* 获取App信息分享的意图
*
* @param info 分享信息
* @return 意图
*/
public static Intent getShareInfoIntent(String info) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
return intent.putExtra(Intent.EXTRA_TEXT, info);
}
/**
* 判断App是否安装
*
* @param context 上下文
* @param packageName 包名
* @return {@code true}: 已安装<br>{@code false}: 未安装
*/
public static boolean isInstallApp(Context context, String packageName) {
return getIntentByPackageName(context, packageName) != null;
}
/**
* 根据包名获取意图
*
* @param context 上下文
* @param packageName 包名
* @return Intent
*/
private static Intent getIntentByPackageName(Context context, String packageName) {
return context.getPackageManager().getLaunchIntentForPackage(packageName);
}
/**
......@@ -248,67 +299,6 @@ public class AppUtils {
return list;
}
/**
* 根据包名获取意图
*
* @param context 上下文
* @param packageName 包名
* @return Intent
*/
private static Intent getIntentByPackageName(Context context, String packageName) {
return context.getPackageManager().getLaunchIntentForPackage(packageName);
}
/**
* 根据包名判断App是否安装
*
* @param context 上下文
* @param packageName 包名
* @return {@code true}: 已安装<br>{@code false}: 未安装
*/
public static boolean isInstallApp(Context context, String packageName) {
return getIntentByPackageName(context, packageName) != null;
}
/**
* 获取打开指定包名App的意图
*
* @param context 上下文
* @param packageName 包名
* @return 意图
*/
public static Intent openAppByPackageName(Context context, String packageName) {
return getIntentByPackageName(context, packageName);
}
/**
* 获取打开指定包名的App应用信息的意图
*
* @param context 上下文
* @param packageName 包名
* @return 意图
*/
public static Intent openAppInfo(Context context, String packageName) {
Intent intent = new Intent();
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.setData(Uri.parse("package:" + packageName));
return intent;
}
/**
* 获取App信息分享的意图
*
* @param context 上下文
* @param info 分享信息
* @return 意图
*/
public static Intent shareAppInfo(Context context, String info) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, info);
return intent;
}
/**
* 判断当前App处于前台还是后台
* <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>
......
......@@ -114,6 +114,59 @@ public class EncryptUtils {
return encryptAlgorithm(data, "MD5");
}
/**
* MD5加密文件
*
* @param filePath 文件路径
* @return 文件的16进制密文
*/
public static String encryptMD5File2String(String filePath) {
return encryptMD5File2String(new File(filePath));
}
/**
* MD5加密文件
*
* @param filePath 文件路径
* @return 文件的MD5校验码
*/
public static byte[] encryptMD5File(String filePath) {
return encryptMD5File(new File(filePath));
}
/**
* MD5加密文件
*
* @param file 文件
* @return 文件的16进制密文
*/
public static String encryptMD5File2String(File file) {
return encryptMD5File(file) != null ? bytes2HexString(encryptMD5File(file)) : "";
}
/**
* MD5加密文件
*
* @param file 文件
* @return 文件的MD5校验码
*/
public static byte[] encryptMD5File(File file) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
FileChannel channel = fis.getChannel();
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(buffer);
return md.digest();
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace();
} finally {
FileUtils.closeIO(fis);
}
return null;
}
/**
* SHA1加密
*
......@@ -282,59 +335,6 @@ public class EncryptUtils {
return new byte[0];
}
/**
* 获取文件的MD5校验码
*
* @param filePath 文件路径
* @return 文件的16进制密文
*/
public static String encryptMD5File2String(String filePath) {
return encryptMD5File2String(new File(filePath));
}
/**
* 获取文件的MD5校验码
*
* @param filePath 文件路径
* @return 文件的MD5校验码
*/
public static byte[] encryptMD5File(String filePath) {
return encryptMD5File(new File(filePath));
}
/**
* 获取文件的MD5校验码
*
* @param file 文件
* @return 文件的16进制密文
*/
public static String encryptMD5File2String(File file) {
return encryptMD5File(file) != null ? bytes2HexString(encryptMD5File(file)) : "";
}
/**
* 获取文件的MD5校验码
*
* @param file 文件
* @return 文件的MD5校验码
*/
public static byte[] encryptMD5File(File file) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
FileChannel channel = fis.getChannel();
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(buffer);
return md.digest();
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace();
} finally {
FileUtils.closeIO(fis);
}
return null;
}
/************************ DES加密相关 ***********************/
/**
* DES转变
......
......@@ -950,6 +950,26 @@ public class FileUtils {
return ConvertUtils.byte2FitSize(file.length());
}
/**
* 获取文件的MD5校验码
*
* @param filePath 文件
* @return 文件的MD5校验码
*/
public static String getFileMD5(String filePath) {
return getFileMD5(getFileByPath(filePath));
}
/**
* 获取文件的MD5校验码
*
* @param file 文件
* @return 文件的MD5校验码
*/
public static String getFileMD5(File file) {
return EncryptUtils.encryptMD5File2String(file);
}
/**
* 关闭IO
*
......@@ -1044,7 +1064,6 @@ public class FileUtils {
return filePath.substring(lastSep + 1, lastPoi);
}
/**
* 获取全路径中的文件拓展名
*
......
......@@ -389,6 +389,7 @@ public class ImageUtils {
* @param src 源图片
* @param newWidth 新宽度
* @param newHeight 新高度
* @param recycle 是否回收
* @return 缩放后的图片
*/
public static Bitmap scale(Bitmap src, int newWidth, int newHeight, boolean recycle) {
......@@ -1250,6 +1251,7 @@ public class ImageUtils {
* 根据文件名判断文件是否为图片
*
* @param file  文件
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isImage(File file) {
return file != null && isImage(file.getPath());
......@@ -1259,6 +1261,7 @@ public class ImageUtils {
* 根据文件名判断文件是否为图片
*
* @param filePath  文件路径
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isImage(String filePath) {
String path = filePath.toUpperCase();
......@@ -1383,6 +1386,7 @@ public class ImageUtils {
* @param src 源图片
* @param newWidth 新宽度
* @param newHeight 新高度
* @param recycle 是否回收
* @return 缩放压缩后的图片
*/
public static Bitmap compressByScale(Bitmap src, int newWidth, int newHeight, boolean recycle) {
......
......@@ -133,6 +133,7 @@ public class ThreadPoolUtils {
* @param timeout 最长等待时间
* @param unit 时间单位
* @return {@code true}: 请求成功<br>{@code false}: 请求超时
* @throws InterruptedException 终端异常
*/
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
return exec.awaitTermination(timeout, unit);
......@@ -143,6 +144,7 @@ public class ThreadPoolUtils {
* <p>如果想立即阻塞任务的等待,则可以使用{@code result = exec.submit(aCallable).get();}形式的构造。</p>
*
* @param task 任务
* @param <T> 泛型
* @return 表示任务等待完成的Future, 该Future的{@code get}方法在成功完成时将会返回该任务的结果。
*/
public <T> Future<T> submit(Callable<T> task) {
......@@ -154,6 +156,7 @@ public class ThreadPoolUtils {
*
* @param task 任务
* @param result 返回的结果
* @param <T> 泛型
* @return 表示任务等待完成的Future, 该Future的{@code get}方法在成功完成时将会返回该任务的结果。
*/
public <T> Future<T> submit(Runnable task, T result) {
......@@ -178,6 +181,7 @@ public class ThreadPoolUtils {
* 如果正在进行此操作时修改了给定的 collection,则此方法的结果是不确定的。</p>
*
* @param tasks 任务集合
* @param <T> 泛型
* @return 表示任务的 Future 列表,列表顺序与给定任务列表的迭代器所生成的顺序相同,每个任务都已完成。
* @throws InterruptedException 如果等待时发生中断,在这种情况下取消尚未完成的任务。
*/
......@@ -196,6 +200,7 @@ public class ThreadPoolUtils {
* @param tasks 任务集合
* @param timeout 最长等待时间
* @param unit 时间单位
* @param <T> 泛型
* @return 表示任务的 Future 列表,列表顺序与给定任务列表的迭代器所生成的顺序相同。如果操作未超时,则已完成所有任务。如果确实超时了,则某些任务尚未完成。
* @throws InterruptedException 如果等待时发生中断,在这种情况下取消尚未完成的任务
*/
......@@ -211,6 +216,7 @@ public class ThreadPoolUtils {
* 如果此操作正在进行时修改了给定的collection,则此方法的结果是不确定的。</p>
*
* @param tasks 任务集合
* @param <T> 泛型
* @return 某个任务返回的结果
* @throws InterruptedException 如果等待时发生中断
* @throws ExecutionException 如果没有任务成功完成
......@@ -228,6 +234,7 @@ public class ThreadPoolUtils {
* @param tasks 任务集合
* @param timeout 最长等待时间
* @param unit 时间单位
* @param <T> 泛型
* @return 某个任务返回的结果
* @throws InterruptedException 如果等待时发生中断
* @throws ExecutionException 如果没有任务成功完成
......@@ -256,6 +263,7 @@ public class ThreadPoolUtils {
* @param callable 命令
* @param delay 延迟时间
* @param unit 时间单位
* @param <V> 泛型
* @return 可用于提取结果或取消的ScheduledFuture
*/
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册