Skip to content

Instantly share code, notes, and snippets.

@CodeK1988
CodeK1988 / git_toturial
Created December 13, 2016 07:34 — forked from guweigang/git_toturial
git命令大全
git init # 初始化本地git仓库(创建新仓库)
git config --global user.name "xxx" # 配置用户名
git config --global user.email "xxx@xxx.com" # 配置邮件
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
git clone git+ssh://git@192.168.53.168/VT.git # clone远程仓库
var snapHelper: LinearSnapHelper = object : LinearSnapHelper() {
override fun findTargetSnapPosition(layoutManager: RecyclerView.LayoutManager?, velocityX: Int, velocityY: Int): Int {
val centerView = findSnapView(layoutManager!!) ?: return RecyclerView.NO_POSITION
val position = layoutManager.getPosition(centerView)
var targetPosition = -1
if (layoutManager.canScrollHorizontally()) {
targetPosition = if (velocityX < 0) {
position - 1
} else {
position + 1
@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) {
@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 / 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 / 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 / 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 / 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 / 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++) {