-
showLongSafe
-
showShortSafe
-
showShort
-
showLong
showLongSafe 方法与 showLong 方法的区别在于 showLongSafe 是安全地,它可以直接在子线程中调用
IntentUtils
- Intent openFile(String filePath)
用来产生打开各种类型文件的 Intent,包括 图片,音频文件,视频文件,APK,ppt,xls,doc,chm,txt 等文件
DensityUtil
-
dip2px
-
px2dip
-
px2sp
-
sp2px
主要用来处理 dp 与 px 的互转,sp 与 px 的互转等。
AppUtil
- String getAppVersionName(Context context)
获取app版本名
- int getAppVersionCode(Context context)
获取app版本号
获取网络状态
NetStateUtils
- boolean is3G(Context context)
判断是否是 3G 网络
- isWifi(Context context)
判断是否是 wifi 网络
- is2G(Context context)
判断是否是 2G 网络
- boolean isWifiEnabled(Context context)
判断 WiFi 是否打开
- isNetworkConnected(Context context)
判断是否有网络连接
- boolean isMobileConnected(Context context)
判断当前是否是移动网络,并且网络是否可用
- getAPNType(Context context)
获取当前的网络状态:(该方法是自定义的) :没有网络-0:WIFI网络1:4G网络-4:3G网络-3:2G网络-2
- String getHostIp()
获取本地的 IP 地址
- boolean isGPSEnabled(Context context)
判断 GPS 是否开启
更多方法,请参考该类,这里不一一说明了。
监听网络变化
监听网络变化的,主要有三个广播
需要注意的 android.NET.conn.CONNECTIVITY_CHANGE 这个广播,从 Android 7.0 开始,如果是静态注册的,将无法收到广播。
更多行为变更请查看官网地址
KeyBoardUtil
- KeyBoardUtil getInstance(Activity activity)
获取实例对象
- show()
显示输入法
- hide()
隐藏输入法
StringUtils
- isEmpty(CharSequence str)
判断是否是空字符串
- String getStr(String str,String defStr)
获取字符串的值,如果是 null,返回 defStr。当然你也可以调用 getStr(String str) 方法,为 null 的话,返回 “”。
好处:如果字符串为空,则会包空指针异常。调用该方法,我们可以不必每次判断字符串是否为空。
- length(CharSequence str)
获取字符串的长度。平时我们如果调用 String.length ,如果字符串为空,则会包空指针异常。调用该方法,我们可以不必每次判断字符串是否为空。
- String capitalizeFirstLetter(String str)
该方法是将字符串的首字母变为大小写
/**
-
capitalize first letter
-
capitalizeFirstLetter(null) = null;
-
capitalizeFirstLetter("") = “”;
-
capitalizeFirstLetter(“2ab”) = “2ab”
-
capitalizeFirstLetter(“a”) = “A”
-
capitalizeFirstLetter(“ab”) = “Ab”
-
capitalizeFirstLetter(“Abc”) = “Abc”
-
@param str
-
@return
*/
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
ListUtils
在 Android 开发中,对 List 的操作也是非常常见的。
- getSize(List sourceList)
获取 List 的数量。该方法相比传统的方法,不需要每一次都去判空。
if(sourceList==null){
return 0;
}else{
sourceList.size();
}
// 或者 相当于以下代码
sourceList == null ? 0 : sourceList.size()
- isEmpty(List sourceList)
判断 List 是否为空
- boolean isEquals(List actual, List expected)
判断两个链表是否相等
- addDistinctEntry(List sourceList, V entry)
if entry already exist in sourceList, return false, else add it and return true.
- addDistinctList(List sourceList, List entryList)
add all distinct entry to list1 from list2
- distinctList(List sourceList)
remove duplicate entries in list
- getNext(List sourceList, V value)
ArrayUtils
ArrayUtils 里面的方法与 ListUtils 基本是一一对应的,这里就不再一一阐述了
RexUtils
- checkIdCard(String idCard)
验证身份证号码
- checkMobile(String mobile)
验证手机号码(支持国际格式,+86135xxxx…(中国内地),+00852137xxxx…(中国香港))
-
boolean checkPhone(String phone)
-
checkEmail
检验是否是电子邮箱。格式是数字,字母,下划线,但不含有 -。
- checkDigit
验证是否是整数
- checkDecimals
验证整数和浮点数
- checkBlankSpace
检验是否是空白字符
- checkChinese
检验是否是中文
- checkBirthday
验证日期(日期,格式:1992-09-03,或1992.09.03)
- 验证 URL 地址
格式:http://blog.csdn.net/gdutxiaoxu/article/details/71732642或 http://www.csdn.net:80
- checkIpAddress
匹配 IP 地址
- phoneNoHide
手机号码,中间4位星号替换
- cardIdHide
银行卡号,保留最后4位,其他星号替换
关于更多正则表达式的,可以参考我的这一篇博客。 Android 常用正则表达式
DateUtils
- String getCurrentDate()
获取当前的日期 ,格式为 yyyy-MM-dd
- String getWeekOfDate(Date date)
获取指定日期是星期几,参数为null时表示获取当前日期是星期日
- String getWeekOfDate(long timeMiss)
根据毫秒数获取当前是星期几
- getCurrentDateAndTime
获取当前时间和日期,yyyy-MM-dd HH:mm:ss。
FileUtils
-
File getFileByPath(final String filePath)
-
isFileExists
-
rename
-
isDir
-
isFile
-
createOrExistsDir
-
createOrExistsFile
-
copyOrMoveDir
ZipUtils
- boolean zipFiles(final Collection resFiles, final String zipFilePath)
throws IOException
- boolean zipFiles(final Collection resFiles, final String zipFilePath, final String comment)