个人记录 | 随心所意,记录点滴
private void setImageUrl() {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(model.getImage()))
.setImageDecodeOptions(Utils.getFileTypeIsGif(model.getImage()) ? null ://null表示使用原有默认decoder
ImageDecodeOptions.newBuilder()
.setCustomImageDecoder(new ImageDecoder() {
@Override
public CloseableImage decode(EncodedImage encodedImage, int length, QualityInfo qualityInfo, ImageDecodeOptions options) {
Bitmap bitmap = null;
if (encodedImage.getHeight() > Utils.dip2px(manager.getContext(), 150)) {
int height = Utils.dip2px(manager.getContext(), 150);
int width = Utils.getWidth(manager.getContext());
width = width > encodedImage.getWidth() ? encodedImage.getWidth() : width;
SkiaImageRegionDecoder inDecoder = new SkiaImageRegionDecoder();
Rect region = new Rect();
region.left = (encodedImage.getWidth() - width) / 2;
region.right = region.left + width;
region.top = (encodedImage.getHeight() - height) / 2;
region.bottom = region.top + height;
try {
inDecoder.init(manager.getContext(), Uri.parse("file://" + FrescoUtils.getImageFileOnDisk(Uri.parse(model.getImage())).getAbsolutePath()));
bitmap = inDecoder.decodeRegion(region, 1);
} catch (Exception e) {
LogInfo.LogOut(e);
}
}
if (bitmap == null) {//TODO 此处最好使用原有默认decoder
bitmap = BitmapFactory.decodeStream(encodedImage.getInputStream());
}
return new CloseableStaticBitmap(
bitmap,
SimpleBitmapReleaser.getInstance(),
ImmutableQualityInfo.FULL_QUALITY,
0);
}
})
.build())
.build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setAutoPlayAnimations(Utils.getFileTypeIsGif(model.getImage()))
.setOldController(image.getController())
.setControllerListener(new BaseControllerListener())
.build();
image.setController(controller);
}
本文为转载,原文地址
什么是正则表达式? 🔗 正则表达式是一组由字母和符号组成的特殊文本, 它可以用来从文本中找出满足你想要的格式的句子.
一个正则表达式是在一个主体字符串中从左到右匹配字符串时的一种样式. 例如"Regular expression"是一个完整的句子, 但我们常使用缩写的术语"regex"或"regexp". 正则表达式可以用来替换文本中的字符串,验证形式,提取字符串等等.
想象你正在写一个应用, 然后你想设定一个用户命名的规则, 让用户名包含字符,数字,下划线和连字符,以及限制字符的个数,好让名字看起来没那么丑. 我们使用以下正则表达式来验证一个用户名:
以上的正则表达式可以接受 john_doe, jo-hn_doe, john12_as. 但不匹配Jo, 因为它包含了大写的字母而且太短了.
目录 🔗 1. 基本匹配 2. 元字符 2.1 点运算符 . 2.2 字符集 2.2.1 否定字符集 2.3 重复次数 2.3.1 * 号 2.3.2 号 2.3.3 ? 号 2.4 {} 号 2.5 (…) 特征标群 2.6 | 或运算符 2.7 转码特殊字符 2.8 锚点 2.8.1 ^ 号 2.8.2 $ 号 3. 简写字符集 4. 前后关联约束(前后预查) 4.1 ?=… 前置约束(存在) 4.2 ?!… 前置约束-排除 4.3 ?<= … 后置约束-存在 [4.4 ? the, 它表示一个规则: 由字母t开始,接着是h,再接着是e. “the” => The fat cat sat on the mat.
如果现有的 Android Studio 项目使用的是 Android plugin 3.0.0 的 Alpha 版本(如 3.0.0-alpha9),那么迁移到 Android plugin 3.0.0-beta1 并进行项目同步时,可能会收到以下错误 :Gradle project refresh failed。
解决方法:
从菜单栏中选择 Build > Clean Project,需要为每个项目执行一次这个操作。然后,可以通过从工具栏中单击同步项目,使用 Gradle 将项目文件同步。 官方解决方案链接
现象: 2.3后不支持apt了,所以旧版本Realm编译不通过。
升级Realm后,DataBinding编译失败,报找不到BR错误。
借助kotlin使用kapt “com.android.databinding:compiler:2.3.3"编译后,Realm的相应注解没有被解析,报is not part of the schema for this Realm错误
最终解决: 所有用到注解的三方库,都得加上解释器: annotationProcessor “com.android.databinding:compiler:2.3.3” annotationProcessor ‘org.greenrobot:eventbus-annotation-processor:3.0.1’ annotationProcessor “io.realm:realm-annotations-processor:3.3.2”
参考 1.https://stackoverflow.com/questions/38642712/enable-annotation-processors-option-in-android-studio-2-2 2.https://stackoverflow.com/questions/40940253/realm-and-android-databinding 3.https://developer.android.com/topic/libraries/data-binding/index.html
^((?!(*|//)).)+[\u4e00-\u9fa5]