| | |
| | | package com.android.app_base.utils; |
| | | |
| | | import android.animation.ValueAnimator; |
| | | import android.app.ActionBar; |
| | | import android.app.ActivityManager; |
| | | import android.app.Application; |
| | | import android.content.Context; |
| | |
| | | import com.blankj.utilcode.util.LogUtils; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URL; |
| | | import java.security.DigestInputStream; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | |
| | | return new BitmapDrawable(view.getResources(), bitmap); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计算文件的MD5哈希值 |
| | | * |
| | | * @param file 文件 |
| | | * @return 文件的MD5哈希值,如果计算失败则返回null |
| | | */ |
| | | public static String calculateMD5(File file) { |
| | | try { |
| | | // 获取MD5消息摘要算法的实例 |
| | | MessageDigest md = MessageDigest.getInstance("MD5"); |
| | | // 创建文件URL |
| | | // 打开文件输入流,并使用DigestInputStream更新消息摘要 |
| | | try (FileInputStream is = new FileInputStream(file); |
| | | DigestInputStream dis = new DigestInputStream(is, md)) { |
| | | // 读取输入流并更新消息摘要 |
| | | byte[] buffer = new byte[1024*256]; |
| | | while(true){ |
| | | if (!(dis.read(buffer) > 0)) break; |
| | | } |
| | | // 获取MD5哈希值的字节数组 |
| | | md = dis.getMessageDigest(); |
| | | byte[] mdBytes = md.digest(); |
| | | // 将字节数组转换为十六进制字符串 |
| | | StringBuilder hexString = new StringBuilder(); |
| | | for (byte mdByte : mdBytes) { |
| | | hexString.append(Integer.toHexString(0xFF & mdByte)); |
| | | } |
| | | return hexString.toString(); |
| | | } |
| | | } catch (NoSuchAlgorithmException | IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | } |