Skip to content

Commit f88f4f3

Browse files
committed
see 09/18 log
1 parent 942ef0b commit f88f4f3

File tree

6 files changed

+152
-131
lines changed

6 files changed

+152
-131
lines changed

utilcode/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 11
99
targetSdkVersion 23
1010
versionCode 8
11-
versionName "1.2.0"
11+
versionName "1.2.1"
1212
}
1313
buildTypes {
1414
release {

utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java

Lines changed: 66 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,22 @@ private AppUtils() {
3131
}
3232

3333
/**
34-
* 获取安装App(支持6.0以上)的意图
34+
* 获取安装App(支持6.0)的意图
3535
*
36-
* @param context 上下文
3736
* @param filePath 文件路径
3837
* @return 意图
3938
*/
40-
public static Intent installApp(Context context, String filePath) {
41-
return installApp(context, FileUtils.getFileByPath(filePath));
39+
public static Intent getInstallAppIntent(String filePath) {
40+
return getInstallAppIntent(FileUtils.getFileByPath(filePath));
4241
}
4342

4443
/**
45-
* 获取安装App(支持6.0以上)的意图
44+
* 获取安装App(支持6.0)的意图
4645
*
47-
* @param context 上下文
48-
* @param file 文件
46+
* @param file 文件
4947
* @return 意图
5048
*/
51-
public static Intent installApp(Context context, File file) {
49+
public static Intent getInstallAppIntent(File file) {
5250
if (file == null) return null;
5351
Intent intent = new Intent(Intent.ACTION_VIEW);
5452
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -58,22 +56,75 @@ public static Intent installApp(Context context, File file) {
5856
} else {
5957
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(FileUtils.getFileExtension(file));
6058
}
61-
intent.setDataAndType(Uri.fromFile(file), type);
62-
return intent;
59+
return intent.setDataAndType(Uri.fromFile(file), type);
6360
}
6461

6562
/**
66-
* 获取卸载指定包名的App的意图
63+
* 获取卸载App的意图
6764
*
68-
* @param context 上下文
6965
* @param packageName 包名
7066
* @return 意图
7167
*/
72-
public Intent uninstallApp(Context context, String packageName) {
68+
public Intent getUninstallAppIntent(String packageName) {
7369
Intent intent = new Intent(Intent.ACTION_DELETE);
7470
intent.setData(Uri.parse("package:" + packageName));
75-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
76-
return intent;
71+
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
72+
}
73+
74+
/**
75+
* 获取打开App的意图
76+
*
77+
* @param context 上下文
78+
* @param packageName 包名
79+
* @return 意图
80+
*/
81+
public static Intent getOpenAppItent(Context context, String packageName) {
82+
return getIntentByPackageName(context, packageName);
83+
}
84+
85+
/**
86+
* 获取App信息的意图
87+
*
88+
* @param packageName 包名
89+
* @return 意图
90+
*/
91+
public static Intent getAppInfoIntent(String packageName) {
92+
Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
93+
return intent.setData(Uri.parse("package:" + packageName));
94+
}
95+
96+
/**
97+
* 获取App信息分享的意图
98+
*
99+
* @param info 分享信息
100+
* @return 意图
101+
*/
102+
public static Intent getShareInfoIntent(String info) {
103+
Intent intent = new Intent(Intent.ACTION_SEND);
104+
intent.setType("text/plain");
105+
return intent.putExtra(Intent.EXTRA_TEXT, info);
106+
}
107+
108+
/**
109+
* 判断App是否安装
110+
*
111+
* @param context 上下文
112+
* @param packageName 包名
113+
* @return {@code true}: 已安装<br>{@code false}: 未安装
114+
*/
115+
public static boolean isInstallApp(Context context, String packageName) {
116+
return getIntentByPackageName(context, packageName) != null;
117+
}
118+
119+
/**
120+
* 根据包名获取意图
121+
*
122+
* @param context 上下文
123+
* @param packageName 包名
124+
* @return Intent
125+
*/
126+
private static Intent getIntentByPackageName(Context context, String packageName) {
127+
return context.getPackageManager().getLaunchIntentForPackage(packageName);
77128
}
78129

79130
/**
@@ -248,67 +299,6 @@ public static List<AppInfo> getAllAppsInfo(Context context) {
248299
return list;
249300
}
250301

251-
/**
252-
* 根据包名获取意图
253-
*
254-
* @param context 上下文
255-
* @param packageName 包名
256-
* @return Intent
257-
*/
258-
private static Intent getIntentByPackageName(Context context, String packageName) {
259-
return context.getPackageManager().getLaunchIntentForPackage(packageName);
260-
}
261-
262-
/**
263-
* 根据包名判断App是否安装
264-
*
265-
* @param context 上下文
266-
* @param packageName 包名
267-
* @return {@code true}: 已安装<br>{@code false}: 未安装
268-
*/
269-
public static boolean isInstallApp(Context context, String packageName) {
270-
return getIntentByPackageName(context, packageName) != null;
271-
}
272-
273-
/**
274-
* 获取打开指定包名App的意图
275-
*
276-
* @param context 上下文
277-
* @param packageName 包名
278-
* @return 意图
279-
*/
280-
public static Intent openAppByPackageName(Context context, String packageName) {
281-
return getIntentByPackageName(context, packageName);
282-
}
283-
284-
/**
285-
* 获取打开指定包名的App应用信息的意图
286-
*
287-
* @param context 上下文
288-
* @param packageName 包名
289-
* @return 意图
290-
*/
291-
public static Intent openAppInfo(Context context, String packageName) {
292-
Intent intent = new Intent();
293-
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
294-
intent.setData(Uri.parse("package:" + packageName));
295-
return intent;
296-
}
297-
298-
/**
299-
* 获取App信息分享的意图
300-
*
301-
* @param context 上下文
302-
* @param info 分享信息
303-
* @return 意图
304-
*/
305-
public static Intent shareAppInfo(Context context, String info) {
306-
Intent intent = new Intent(Intent.ACTION_SEND);
307-
intent.setType("text/plain");
308-
intent.putExtra(Intent.EXTRA_TEXT, info);
309-
return intent;
310-
}
311-
312302
/**
313303
* 判断当前App处于前台还是后台
314304
* <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>

utilcode/src/main/java/com/blankj/utilcode/utils/EncryptUtils.java

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,59 @@ public static byte[] encryptMD5(byte[] data) {
114114
return encryptAlgorithm(data, "MD5");
115115
}
116116

117+
/**
118+
* MD5加密文件
119+
*
120+
* @param filePath 文件路径
121+
* @return 文件的16进制密文
122+
*/
123+
public static String encryptMD5File2String(String filePath) {
124+
return encryptMD5File2String(new File(filePath));
125+
}
126+
127+
/**
128+
* MD5加密文件
129+
*
130+
* @param filePath 文件路径
131+
* @return 文件的MD5校验码
132+
*/
133+
public static byte[] encryptMD5File(String filePath) {
134+
return encryptMD5File(new File(filePath));
135+
}
136+
137+
/**
138+
* MD5加密文件
139+
*
140+
* @param file 文件
141+
* @return 文件的16进制密文
142+
*/
143+
public static String encryptMD5File2String(File file) {
144+
return encryptMD5File(file) != null ? bytes2HexString(encryptMD5File(file)) : "";
145+
}
146+
147+
/**
148+
* MD5加密文件
149+
*
150+
* @param file 文件
151+
* @return 文件的MD5校验码
152+
*/
153+
public static byte[] encryptMD5File(File file) {
154+
FileInputStream fis = null;
155+
try {
156+
fis = new FileInputStream(file);
157+
FileChannel channel = fis.getChannel();
158+
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
159+
MessageDigest md = MessageDigest.getInstance("MD5");
160+
md.update(buffer);
161+
return md.digest();
162+
} catch (NoSuchAlgorithmException | IOException e) {
163+
e.printStackTrace();
164+
} finally {
165+
FileUtils.closeIO(fis);
166+
}
167+
return null;
168+
}
169+
117170
/**
118171
* SHA1加密
119172
*
@@ -282,59 +335,6 @@ private static byte[] encryptAlgorithm(byte[] data, String algorithm) {
282335
return new byte[0];
283336
}
284337

285-
/**
286-
* 获取文件的MD5校验码
287-
*
288-
* @param filePath 文件路径
289-
* @return 文件的16进制密文
290-
*/
291-
public static String encryptMD5File2String(String filePath) {
292-
return encryptMD5File2String(new File(filePath));
293-
}
294-
295-
/**
296-
* 获取文件的MD5校验码
297-
*
298-
* @param filePath 文件路径
299-
* @return 文件的MD5校验码
300-
*/
301-
public static byte[] encryptMD5File(String filePath) {
302-
return encryptMD5File(new File(filePath));
303-
}
304-
305-
/**
306-
* 获取文件的MD5校验码
307-
*
308-
* @param file 文件
309-
* @return 文件的16进制密文
310-
*/
311-
public static String encryptMD5File2String(File file) {
312-
return encryptMD5File(file) != null ? bytes2HexString(encryptMD5File(file)) : "";
313-
}
314-
315-
/**
316-
* 获取文件的MD5校验码
317-
*
318-
* @param file 文件
319-
* @return 文件的MD5校验码
320-
*/
321-
public static byte[] encryptMD5File(File file) {
322-
FileInputStream fis = null;
323-
try {
324-
fis = new FileInputStream(file);
325-
FileChannel channel = fis.getChannel();
326-
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
327-
MessageDigest md = MessageDigest.getInstance("MD5");
328-
md.update(buffer);
329-
return md.digest();
330-
} catch (NoSuchAlgorithmException | IOException e) {
331-
e.printStackTrace();
332-
} finally {
333-
FileUtils.closeIO(fis);
334-
}
335-
return null;
336-
}
337-
338338
/************************ DES加密相关 ***********************/
339339
/**
340340
* DES转变

utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,26 @@ public static String getFileSize(File file) {
950950
return ConvertUtils.byte2FitSize(file.length());
951951
}
952952

953+
/**
954+
* 获取文件的MD5校验码
955+
*
956+
* @param filePath 文件
957+
* @return 文件的MD5校验码
958+
*/
959+
public static String getFileMD5(String filePath) {
960+
return getFileMD5(getFileByPath(filePath));
961+
}
962+
963+
/**
964+
* 获取文件的MD5校验码
965+
*
966+
* @param file 文件
967+
* @return 文件的MD5校验码
968+
*/
969+
public static String getFileMD5(File file) {
970+
return EncryptUtils.encryptMD5File2String(file);
971+
}
972+
953973
/**
954974
* 关闭IO
955975
*
@@ -1044,7 +1064,6 @@ public static String getFileNameNoExtension(String filePath) {
10441064
return filePath.substring(lastSep + 1, lastPoi);
10451065
}
10461066

1047-
10481067
/**
10491068
* 获取全路径中的文件拓展名
10501069
*

utilcode/src/main/java/com/blankj/utilcode/utils/ImageUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ public static Bitmap scale(Bitmap src, int newWidth, int newHeight) {
389389
* @param src 源图片
390390
* @param newWidth 新宽度
391391
* @param newHeight 新高度
392+
* @param recycle 是否回收
392393
* @return 缩放后的图片
393394
*/
394395
public static Bitmap scale(Bitmap src, int newWidth, int newHeight, boolean recycle) {
@@ -1250,6 +1251,7 @@ public static boolean save(Bitmap src, File file, CompressFormat format, boolean
12501251
* 根据文件名判断文件是否为图片
12511252
*
12521253
* @param file  文件
1254+
* @return {@code true}: 是<br>{@code false}: 否
12531255
*/
12541256
public static boolean isImage(File file) {
12551257
return file != null && isImage(file.getPath());
@@ -1259,6 +1261,7 @@ public static boolean isImage(File file) {
12591261
* 根据文件名判断文件是否为图片
12601262
*
12611263
* @param filePath  文件路径
1264+
* @return {@code true}: 是<br>{@code false}: 否
12621265
*/
12631266
public static boolean isImage(String filePath) {
12641267
String path = filePath.toUpperCase();
@@ -1383,6 +1386,7 @@ public static Bitmap compressByScale(Bitmap src, int newWidth, int newHeight) {
13831386
* @param src 源图片
13841387
* @param newWidth 新宽度
13851388
* @param newHeight 新高度
1389+
* @param recycle 是否回收
13861390
* @return 缩放压缩后的图片
13871391
*/
13881392
public static Bitmap compressByScale(Bitmap src, int newWidth, int newHeight, boolean recycle) {

0 commit comments

Comments
 (0)