Skip to content

Instantly share code, notes, and snippets.

@CodeK1988
CodeK1988 / Gson parse same field name but different types
Created June 20, 2019 08:15
Gson parse same field name but different types
public class NMPrivilegeDeserializer implements JsonDeserializer<NMPrivilege> {
@Override
public NMPrivilege deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
NMPrivilege fromJson = new Gson().fromJson(json, NMPrivilege.class);
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("privilege_card")) {
JsonArray privilege_card = jsonObject.getAsJsonArray("privilege_card");
if (privilege_card != null && privilege_card.size() > 0) {
for (int i = 0; i < privilege_card.size(); i++) {
@CodeK1988
CodeK1988 / 杂记 避免遗忘
Last active August 26, 2019 08:06
Artifactory搭建本地JFrog的Library仓库 publishing点击顺序
1.publishing点击顺序
build目录->双击assembleRelease : 打release 包
publishing目录->双击generatePomFileForAarPublication : 生成 pom.xml 文件
publishing目录->双击artifactoryPublish :上传
避免遗忘
thanks
https://tiimor.cn/Artifactory%E6%90%AD%E5%BB%BA%E6%9C%AC%E5%9C%B0JFrog%E7%9A%84Library%E4%BB%93%E5%BA%93/
2.
hdpi 72x72
mdpi 48x48
xhdpi 96x96
xxhdpi 144x144
xxxhdpi 192x192
android中的dp在渲染前会将dp转为px,计算公式:
px = density * dp;
density = dpi / 160;
@CodeK1988
CodeK1988 / Kotlin custom constructor ways
Created July 23, 2019 02:59
kotlin handsome code 集合
thanks:
https://medium.com/@rygel/stop-repeating-yourself-and-create-custom-views-on-android-with-kotlin-f5b3fc581c0e
https://medium.com/@elye.project/building-custom-component-with-kotlin-fc082678b080
https://medium.com/@mmlodawski/https-medium-com-mmlodawski-do-not-always-trust-jvmoverloads-5251f1ad2cfe
1.
constructor(context: Context) : super(context) {
init(context)
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
@CodeK1988
CodeK1988 / Using AppBarLayout.Behavior.DragCallback to control scroll of collapsing toolbar layout
Last active July 30, 2019 02:43
Using AppBarLayout.Behavior.DragCallback to control scroll of collapsing toolbar layout
private void disAppBarScroll() {
try {
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) apl_module.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) layoutParams.getBehavior();
if (behavior != null) {
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
@Override
public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
return false;
}
@CodeK1988
CodeK1988 / Bitmap too large to be uploaded into a texture
Last active July 31, 2019 04:50
图片满屏宽高比1:5 长图 小米机上报错 Bitmap too large to be uploaded into a texture
Bitmap too large to be uploaded into a texture (1080x4153, max=4096x4096)
thanks:
https://medium.com/digio-australia/custom-image-manipulation-crop-and-translate-at-load-time-with-glide-on-android-cb556f5a5aae
https://github.com/mantel-digio/GlideCropper/blob/master/app/src/main/java/au/com/digio/glidecropper/widget/CroppedImageView.kt
https://developer.android.com/topic/performance/graphics/load-bitmap
吐槽:
csdn 上的技术博文大大大大大部分质量真是差劲 一点验证意识都没有。
@CodeK1988
CodeK1988 / RecyclerView notes
Last active August 5, 2019 10:27
RecyclerView相关笔记
1.NestedScrollView RecyclerView recyclerView always scroll top
add
recyclerView.isFocusableInTouchMode = false
recyclerView.requestFocus()
its working!
2.addItemDecoration
if (recyclerView.itemDecorationCount > 0) {
val itemDecorationAt = recyclerView.getItemDecorationAt(0)
if (itemDecorationAt == null) {
@CodeK1988
CodeK1988 / xiaomi takephoto Gallery Intent.ACTION_GET_CONTENT
Created August 12, 2019 03:30
xiaomi takephoto Gallery Intent.ACTION_GET_CONTENT not working
@CodeK1988
CodeK1988 / VerticalOnlyNestedScrollView
Created August 14, 2019 09:04
VerticalOnlyNestedScrollView
/**
* thanks https://stackoverflow.com/questions/36093384/stop-nestedscrollview-inside-viewpager-to-process-horizontal-scrolls
*/
public class VerticalOnlyNestedScrollView extends NestedScrollView {
public VerticalOnlyNestedScrollView(Context context) {
super(context);
}
@CodeK1988
CodeK1988 / AppBarLayout NestedScrollView 以及顶部视频调节亮度进度等事件处理
Created August 14, 2019 10:07
AppBarLayout NestedScrollView 以及顶部视频调节亮度进度等事件处理
thanks:
[Manage touch events in a ViewGroup](https://developer.android.com/training/gestures/viewgroup)
https://medium.com/@suragch/how-touch-events-are-delivered-in-android-eee3b607b038
焦点问题遇到的比较少 特此记录一下 加深理解和记忆