Skip to content

Instantly share code, notes, and snippets.

@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.
@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 / takephoto Uri.fromFile
Created June 13, 2019 06:33
Uri.fromFile error android 7.0
Application
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
}
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@CodeK1988
CodeK1988 / change volume
Created May 22, 2019 08:01
change volume
private var audioManager: AudioManager? = null
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
}
KeyEvent.KEYCODE_VOLUME_DOWN -> {
audioManager?.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI)
@CodeK1988
CodeK1988 / ConstraintLayout edittext keyboard bottom
Created May 15, 2019 02:14
ConstraintLayout edittext keyboard bottom
遇到的问题
https://stackoverflow.com/questions/17630336/space-between-keyboard-and-edittext-in-android/25400043
1.edittext 试着加paddingBottom 是有用的 但是edittext字体sp != dp 不太好写布局
2.stateHidden|adjustResize 或者 adjustPan 选一种 前者是页面允许压缩 但是我的页面比较紧凑不太合适 所以只有用 adjustPan
3.接着想是不是监听键盘展开收起 试着ConstraintLayout外层添加滑动布局让其滑动到一定的高度呢?
ScrollView scrollto (0,height) 不管用 试了很久 忽然想到 是不是ScrollView android:layout_height="match_parent" 导致的?
又尝试了很久。。。
@CodeK1988
CodeK1988 / AndroidX迁移遇到的问题以及解决
Last active August 26, 2019 08:33
AndroidX迁移遇到的问题以及解决
1.AndroidX migrate dependency / libraries
I solved this issue by deleting .idea folder and syncing project again.
https://stackoverflow.com/questions/52518935/androidx-migrate-dependency-libraries
2.After migrating to androidx: Didn't find class “androidx.constraintlayout.ConstraintLayout” on path: DexPathList
https://stackoverflow.com/questions/54757911/after-migrating-to-androidx-didnt-find-class-androidx-constraintlayout-constr
3.Databinding kotlin
@CodeK1988
CodeK1988 / Recyclerview
Created April 28, 2019 01:50
Recyclerview 无限滑动
override fun getItemCount(): Int {
return Int.MAX_VALUE
}
override fun onBindViewHolder(holder: CustomPlanViewHolder, position: Int) {
if (list.isNotEmpty()) {
holder.bind(list[position % list.size])
}
}
@CodeK1988
CodeK1988 / RecyclerView
Last active April 28, 2019 02:07
RecyclerView 拓展
fun RecyclerView.attachSnapHelperWithListener(
snapHelper: SnapHelper,
onSnapPositionChangeListener: Utils.OnSnapPositionChangeListener) {
snapHelper.attachToRecyclerView(this)
val snapOnScrollListener = SnapOnScrollListener(snapHelper, onSnapPositionChangeListener)
addOnScrollListener(snapOnScrollListener)
}
fun SnapHelper.getSnapPosition(recyclerView: RecyclerView): Int {
val layoutManager = recyclerView.layoutManager ?: return RecyclerView.NO_POSITION
@CodeK1988
CodeK1988 / SnapOnScrollListener
Created April 28, 2019 01:37
SnapOnScrollListener
class SnapOnScrollListener(
private val snapHelper: SnapHelper,
var onSnapPositionChangeListener: Utils.OnSnapPositionChangeListener? = null
) : RecyclerView.OnScrollListener() {
private var snapPosition = RecyclerView.NO_POSITION
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
/*val snapPosition = snapHelper.getSnapPosition(recyclerView)
val snapPositionChanged = this.snapPosition != snapPosition
@CodeK1988
CodeK1988 / CenterZoomLinearLayoutManager
Created April 28, 2019 01:35
滑动缩放 CenterZoomLinearLayoutManager
class CenterZoomLinearLayoutManager(context: Context)
: LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
override fun onLayoutCompleted(state: RecyclerView.State?) {
super.onLayoutCompleted(state)
scaleChildren()
}
override fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler?, state: RecyclerView.State?): Int {
return if (orientation == HORIZONTAL) {