Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.seeways:AndroidUtils:5.4'
}
dependencies {
implementation("com.github.seeways:AndroidUtils:5.4")
}
<dependency>
<groupId>com.github.seeways</groupId>
<artifactId>AndroidUtils</artifactId>
<version>5.4</version>
</dependency>
libraryDependencies += "com.github.seeways" % "AndroidUtils" % "5.4"
:dependencies [[com.github.seeways/AndroidUtils "5.4"]]
A Basic Android Tools
maven { url 'https://jitpack.io' }
如下:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.seeways:AndroidUtils:3.2'
@mipmap
文件夹bitmap转成png保存(New:自定义保存)
CompressFormat.PNG
)文件名合并至路径中(亦可直接用File)
boolean save(Bitmap src, String filePath, CompressFormat format)
boolean save(Bitmap src, File file, CompressFormat format)
boolean save(Bitmap src, String filePath, CompressFormat format, boolean recycle)
boolean save(Bitmap src, File file, CompressFormat format, boolean recycle)
byte[] bitmap2Bytes(Bitmap bitmap, CompressFormat format)
Bitmap bytes2Bitmap(byte[] bytes)
Bitmap drawable2Bitmap(Drawable drawable)
Drawable bitmap2Drawable(Resources res, Bitmap bitmap)
byte[] drawable2Bytes(Drawable drawable, CompressFormat format)
Drawable bytes2Drawable(Resources res, byte[] bytes)
各种单向获取bitmap()
Bitmap view2Bitmap(View view)
Bitmap getBitmap(File file)
Bitmap getBitmap(File file, int maxWidth, int maxHeight)
Bitmap getBitmap(String filePath)
Bitmap getBitmap(String filePath, int maxWidth, int maxHeight)
Bitmap getBitmap(InputStream is)
Bitmap getBitmap(InputStream is, int maxWidth, int maxHeight)
Bitmap getBitmap(byte[] data, int offset)
Bitmap getBitmap(byte[] data, int offset, int maxWidth, int maxHeight)
Bitmap getBitmap(Resources res, int id)
Bitmap getBitmap(Resources res, int id, int maxWidth, int maxHeight)
Bitmap getBitmap(FileDescriptor fd)
Bitmap getBitmap(FileDescriptor fd, int maxWidth, int maxHeight)
缩放图片 > newWidth,newHeight代表新值 > scaleWidth,scaleHeight代表基于原来的倍数
Bitmap scale(Bitmap src, int newWidth, int newHeight)
Bitmap scale(Bitmap src, int newWidth, int newHeight, boolean recycle)
Bitmap scale(Bitmap src, float scaleWidth, float scaleHeight)
Bitmap scale(Bitmap src, float scaleWidth, float scaleHeight, boolean recycle)
裁剪图片 Bitmap clip(Bitmap src, int x, int y, int width, int height, boolean recycle)
Bitmap skew(Bitmap src, float kx, float ky, boolean recycle)
Bitmap skew(Bitmap src, float kx, float ky, float px, float py, boolean recycle)
Bitmap rotate(Bitmap src, int degrees, float px, float py, boolean recycle)
int getRotateDegree(String filePath)
Bitmap toRound(Bitmap src, boolean recycle)
Bitmap toRoundCorner(Bitmap src, float radius, boolean recycle)
Bitmap addFrame(Bitmap src, int borderWidth, int color, boolean recycle)
Bitmap addTextWatermark(Bitmap src, String content, float textSize, int color, float x,float y, boolean recycle)
Bitmap addImageWatermark(Bitmap src, Bitmap watermark, int x, int y, int alpha, boolean recycle)
本类根据BlankJ的Image改的,压缩方法上与原作者就压缩格式有争议,所以将以下部分的压缩格式提取,由使用者选择。
按缩放压缩(原图缩放不涉及压缩格式)
Bitmap compressByScale(Bitmap src, int newWidth, int newHeight, boolean recycle)
Bitmap compressByScale(Bitmap src, float scaleWidth, float scaleHeight, boolean recycle)
按质量压缩
Bitmap compressByQuality(Bitmap src,Bitmap.CompressFormat format, @IntRange(from = 0, to = 100) int quality, boolean recycle)
Bitmap compressByQuality(Bitmap src, Bitmap.CompressFormat format,long maxByteSize, boolean recycle)
按采样大小压缩
Bitmap compressBySampleSize(Bitmap src, Bitmap.CompressFormat format,int sampleSize, boolean recycle)
新增FileUtils
File getFileByPath(String filePath)
boolean isFileExists(String filePath)
boolean renameFile(String filePath, String newName)
boolean isDir(String dirPath)
boolean isFile(String filePath)
boolean createOrExistsDir(String dirPath)
List<File> listFilesInDirWithFilter(String dirPath, String suffix, boolean isRecursive)
byte[] File2Bytes(String filePath)
String getFileSize(String PathOrURL)
long getFileLength(String filePath)
String getFileName(String filePath)
String getFileExtension(String filePath)
新增EncodeUtils,EncryptUtils,StringUtils
字符串工具类 StringUtils
boolean isEmpty(String s)
isEquals(String a, String b,boolean isIgnoreCase)
编码工具类 EncodeUtils
String urlDecode(String input)
String urlDecode(String input, String charset)
byte[] base64Encode(byte[] input)
byte[] base64Decode(byte[] input)
byte[] base64Encode(byte[] input,int flags)
byte[] base64Decode(byte[] input,int flags)
String htmlEncode(CharSequence input)
CharSequence htmlDecode(String input)
加密工具类 EncryptUtils
String String2Md5(String data)
String String2Md5(String data, String salt)
String byte2Md5(byte[] data)
String byte2Md5(byte[] data, byte[] salt)
byte[] encryptMD5(byte[] data)
AES系列
byte[] AESEncrypt(byte[] data, byte[] key)
byte[] AES2Base64(byte[] data, byte[] key)
String AES2Hex(byte[] data, byte[] key)
byte[] AESDecrypt(byte[] data, byte[] key)
byte[] decryptBase64AES(byte[] data, byte[] key)
byte[] decryptHexAES(String data, byte[] key)
SHA系列(SHA1,SHA256,SHA512)
String SHA1Encrypt(String data)
String SHA1Encrypt(byte[] data)
byte[] SHA1Hash(byte[] data)
String SHA256Encrypt(String data)
String SHA256Encrypt(byte[] data)
byte[] SHA256Hash(byte[] data)
String SHA512Encrypt(String data)
String SHA512Encrypt(byte[] data)
byte[] SHA512Hash(byte[] data)
新增DeviceUtils
感谢Blankj,对Blankj的代码作了部分修改
Utils.init(Context context);
使用
判断设备是否root
创建版本
dp转px
sp转px
px转dp
px转sp
获得屏幕高度
获得屏幕宽度
获得状态栏的高度
获取当前屏幕截图,包含状态栏
获取当前屏幕截图,不包含状态栏
由于我比较懒,所以以后更新部分返回值类型全部写在方法名前面