blankj / androidutilcode Goto Github PK
View Code? Open in Web Editor NEW:fire: Android developers should collect the following utils(updating).
Home Page: https://blankj.com/2016/07/31/android-utils-code/
License: Apache License 2.0
:fire: Android developers should collect the following utils(updating).
Home Page: https://blankj.com/2016/07/31/android-utils-code/
License: Apache License 2.0
不够完美
能不能加上计算 工具类 。BigDecimal
某些工具类使用时,需要在manifest里添加相关权限,最好在注释里写清楚
/**
* 获取文件大小
* <p>例如:getFileSize(file, ConstUtils.MB); 返回文件大小单位为MB</p>
*
* @param file 文件
* @return 文件大小
*/
public static String getFileSize(File file) {
if (!isFileExists(file)) return "";
return ConvertUtils.byte2FitSize(file.length());
}
楼主,android:fitsSystemWindows="true",在EditText的上一层布局中加入这个属性就可以了,但是有点问题,就是我用透明状态栏的时候,上一层的布局中会有一个和状态栏一样的高度的白色的条子,那是因为透明状态栏引起的,希望你能把这个加在这里,谢谢,如果可以的话帮我解决一下那个透明状态栏的问题吧。
FileUtils.getFileMD5 处理大文件,报内存溢出。
建议EncryptUtils.encryptMD5File中使用:
public static byte[] encryptMD5File(File file) { if (file == null) return null; FileInputStream fis = null; DigestInputStream digestInputStream = null; try { MessageDigest md = MessageDigest.getInstance("MD5"); fis = new FileInputStream(file); digestInputStream = new DigestInputStream(fis, md); byte[] buffer = new byte[256 * 1024]; while (digestInputStream.read(buffer) > 0) ; // 获取最终的MessageDigest md = digestInputStream.getMessageDigest(); return md.digest(); } catch (NoSuchAlgorithmException | IOException e) { e.printStackTrace(); return null; } finally { CloseUtils.closeIO(fis); } }
ZipUtils有没有地zip文件进行密码加密解密的方法?
?
javax.crypto.IllegalBlockSizeException: data not block size aligned
我使用另外一段加密代码可以正常加密
代码如下
public static byte[] des3EncodeCBC(byte[] key, byte[] keyiv, byte[] data)
throws Exception {
SecretKey deskey = null;
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
deskey = keyfactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance("desede" + "/CBC/PKCS5Padding");
IvParameterSpec ips = new IvParameterSpec(keyiv);
cipher.init(Cipher.ENCRYPT_MODE, deskey, ips);
byte[] bOut = cipher.doFinal(data);
return bOut;
}
猜测是因为代码中使用的DESede/ECB/NoPadding填充方式有不兼容的问题
是不是可以删掉AndroidManifest文件application 的label标签 ,
如果项目里的application的label@的string不是app_name,会出现Manifest merger faild
属性borderlessButtonStyle;colorAccent存在被定义的问题
给个建议,最好是能在代码片段上注明代码片段涉及的权限,这样用起来更加方便。
我在onCreat() 里面forceGetViewSize(heroImageView);
返回[3600, 2024]
实际上我的height只有差不多900,宽大概400
如题
public static String encryptMD5File2String(File file) {
return encryptMD5File(file) != null ? bytes2HexString(encryptMD5File(file)) : "";
}
改成:
public static String encryptMD5File2String(File file) {
byte[] bytes = encryptMD5File(file);
return bytes != null ? bytes2HexString(bytes ) : "";
}
android 6.0使用DeviceUtil.getMacAddress会返回02:00:00:00:00:00,期待更新,网上有具体的实现方法。
地址:http://www.yrom.net/blog/2015/10/28/android-m-getting-wifi-macaddress-1/?utm_source=tuicool&utm_medium=referral
用SpannableString打造绚丽多彩的文本显示效果
http://www.jianshu.com/p/84067ad289d2
我用手机端github打开md有乱码。forkhub
另外,作者可以把这些代码合并成几个utils类
是否考虑加一个Android 6.0之后动态权限管理相关的帮助类?
单位转换,比如dp转px . .. . . . .
文件操作,文件创建 删除 压缩等等....
Bitmap处理工具类,毛玻璃 圆角 转byte[]之类的.....
MD5 . Base64 工具类......
群号:25206533
验证相信你们都懂的,欢迎来交流。
json解析的可以加上
时间相关→TimeUtils.java→Test , 可能需要添加的方法
1.两个时间相差距离多少天多少小时多少分多少秒
2.两个时间之间相差距离多少天
3.本月第一天
4.计算当月最后一天
5.根据日期计算当前是什么星座,返回如"天蝎座"
6.返回当前日期xxxx年x月xx日 星期x(得到当前的年月日和星期几)
7.毫秒换成几天前几小时几分钟 (通过毫秒数得到天数小时和分钟)
8.判断两个时间是否相等,比大小
9.将秒转换成小时分钟
10.date时间增加一秒 And 时间增減少一秒 返回得到的时间
12.当前时间增加一天 And 减少一天 返回得到的时间
13.当前时间增加一个月 And 减少一个月 返回得到的时间
14.两个日期相隔的天数
图片相关→ImageUtils.java
1.图片转bitmap
2.将一个image,做成毛玻璃再设置给view
3.Drawable转换成Bitmap
4.毛玻璃效果
5.重新计算图片的最大尺寸
6.按指定宽高截取中间一段图片
7.保存图片
8.指定图片的切边,对图片进行圆角处理
正则相关→RegexUtils.java→Test
1.判断是否为整数
2.验证日期(年月日)
3.验证URL地址
4.匹配**邮政编码
屏幕相关的设置屏幕为横屏那一栏的代码渲染有问题,没渲染出Java高亮。 😂
private static SharedPreferences sp;
private static SharedPreferences getInstance(Context context) {
if(sp == null) {
sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
}
return sp;
}
获取sp推荐这样写的写法,效率高一点。
public static Bitmap addFrame(Bitmap src, int borderWidth, int color, boolean recycle) {
if (isEmptyBitmap(src)) return null;
//int newWidth = src.getWidth() + borderWidth >> 1;
//int newHeight = src.getHeight() + borderWidth >> 1;
int newWidth = src.getWidth() + (borderWidth << 1);
int newHeight = src.getHeight() + (borderWidth << 1);
Bitmap ret = Bitmap.createBitmap(newWidth, newHeight, src.getConfig());
Canvas canvas = new Canvas(ret);
Rect rec = canvas.getClipBounds();
Paint paint = new Paint();
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(borderWidth);
canvas.drawRect(rec, paint);
canvas.drawBitmap(src, borderWidth, borderWidth, null);
if (recycle && !src.isRecycled()) src.recycle();
return ret;
}
新create出来的图片长宽需要加上边框需要乘以2不是除以2,另外加减乘除的优先级比移位优先级高,需要带上括号。
添加后常用加密就都有了,HMACSha1现在还是挺常用的。
能不能做一些线程相关的工具类
1.淡化 系统bar
2.隐藏 系统bar
3.隐藏 导航 bar
4.全屏沉浸式应用
等
public static void closeIO(Closeable... closeables) { if (closeables == null) return; try { for (Closeable closeable : closeables) { if (closeable != null) { closeable.close(); } } } catch (IOException e) { e.printStackTrace(); } }
change to
public static void closeIO(Closeable... closeables) { if (closeables == null) return; for (Closeable closeable : closeables) { if (closeable != null) { try{ closeable.close(); } }catch(IOException e){ e.printStackTrace(); continue; } } }
现有提供的方案对布局中有SurfaceView的laytou不能完美适配,截屏的图片中surfaceView的背景是黑色的。
毕竟现在Kotlin也是Android开发的生力军了不是吗
先咨询一下,你们觉得什么样的排版合适(两门语言的当然要分开啦),然后我发个pull request给你们。 👍
RT,可以增加下,SQLite的CURD操作,开发中存储也常用到。
java.lang.NoSuchMethodError: android.os.StatFs.getAvailableBlocksLong
at com.blankj.utilcode.utils.SDCardUtils.getFreeSpace(SDCardUtils.java:100)
public static Signature[] getAppSignature(Context context, String packageName)
这个方法通过pm.getPackageInfo(packageName, 0)获取到的signatures是null。如果传入参数PackageManager.GET_SIGNATURES就可以正确获取到。系统是5.1.1 api22,小米
private static Pattern mobilePattern;
/**
* 移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188
* 联通:130、131、132、145、155、156、175、176、185、186
* 电信:133、153、173、177、180、181、189
* 全球星:1349
* 虚拟运营商:170
*
* @param mobileNo
* @return
*/
/**
* 验证手机格式
*/
public static boolean isMobileNO(String mobiles) {
if (mobilePattern == null) {
mobilePattern = Pattern.compile("^((13[0-9])|(14[5,7])|(15[0-3,5-8])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}$");
}
return mobilePattern.matcher(mobiles).matches();
}
https://github.com/ssyijiu/android-helper/blob/master/utils/NetUtil.java 判断网络类型2G、3G、4G、WIFI,感觉这个更谨慎一些,仅供参考。这个项目中其他utils有错误,谨慎观看。
对字符串 ‘“lxm” 进行MD5加密
getMD5 = 8fae1645fdb13cc84924ae63b08584ff, time = 6
md5 = 8fae1645fdb13cc84924ae63b08584ff, time = 0
encryptMD5 = -7051e9ba024ec337b6db519c4f7a7b01, time = 0
上面两个是以前用过的算法加密结果是一样的,在cmd5.com查询原文也是正确的,最后一个是你的算法的结果。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.