Skip to content

Instantly share code, notes, and snippets.

View xckevin's full-sized avatar
🎯
Focusing

kevin.liu xckevin

🎯
Focusing
  • Alibaba Group
  • Hangzhou China
View GitHub Profile
@xckevin
xckevin / ColorConverter.js
Created October 9, 2024 11:32
color converter: rgb 2 HSL, hex 2 rgb
class ColorConverter {
// Hex to RGB
static hexToRgb(hex) {
let cleanHex = hex.replace('#', '');
if (cleanHex.length === 3) {
cleanHex = cleanHex.split('').map(char => char + char).join('');
}
const bigint = parseInt(cleanHex, 16);
const r = (bigint >> 16) & 255;
const g = (bigint >> 8) & 255;
@xckevin
xckevin / TextFlowLayout.kt
Last active March 3, 2023 07:37
支持View跟随Text的布局组件。如果TextView最后一行足够放下,则跟随TextView最后一行;放不下则换行。支持margin padding调整跟随位置。
class TextFlowLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ViewGroup(context, attrs, defStyleAttr) {
private lateinit var baseTextView: TextView
fun attachTextView(tv: TextView) {
@xckevin
xckevin / RecyclerViewSticky.kt
Created February 3, 2023 03:38
实现RecyclerView的sticky吸顶功能,不通过ItemDecoration实现,解决click等各种event事件问题,解决webview无法渲染问题,但需要外层包一个FrameLayout
import android.graphics.Canvas
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnScrollListener
import androidx.recyclerview.widget.StaggeredGridLayoutManager
/*
* Copyright (C) 2014 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software