Skip to content

Instantly share code, notes, and snippets.

@snowpero
snowpero / smoothScrollToPositionWithOffset.kt
Created February 14, 2025 09:13
smoothScrollToPositionWithOffset.kt
private fun RecyclerView.smoothScrollToPositionWithOffset(position: Int, offset: Int) {
if (position < 0 || position >= (adapter?.itemCount ?: 0)) return
val linearSmoothScroller = object : LinearSmoothScroller(context) {
override fun onTargetFound(targetView: View, state: RecyclerView.State, action: Action) {
super.onTargetFound(targetView, state, action)
val dx = calculateDxToMakeVisible(targetView, horizontalSnapPreference)
val dy = calculateDyToMakeVisible(targetView, SNAP_TO_START)
val distance = sqrt((dx * dx + dy * dy).toDouble()).toInt()
@snowpero
snowpero / HeaderItemDecoration.kt
Created February 29, 2024 02:18 — forked from filipkowicz/HeaderItemDecoration.kt
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders
@snowpero
snowpero / EllipsizeTextView.kt
Created October 20, 2022 00:23
SpannableString 을 사용할 경우 ellipsize=end 설정이 적용되지 않는 경우
class EllipsizeTextView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : AppCompatTextView(context, attrs) {
override fun onDraw(canvas: Canvas?) {
// maxLines 를 넘어갈 경우만 처리
if( lineCount >= maxLines ) {
val charSequence = text
val lastCharDown = layout.getLineVisibleEnd(maxLines - 1)
if( charSequence.length > lastCharDown ) {
val ssb = SpannableStringBuilder()
@snowpero
snowpero / find_route_map_intent.kt
Last active August 11, 2020 01:55
길찾기 관련 Map Intent 정리
val desLng = 126.978390
val desLat = 37.303638
val title = "목적"
// 구글맵 길찾기
private fun findGoogleMap() {
Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=$desLat, $desLng&title=$title")).apply {
`package` = "com.google.android.apps.maps"
}.let {
startActivity(it)
/*
* Copyright 2019 Google LLC
*
* 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
@snowpero
snowpero / shadow.xml
Created June 11, 2019 08:35 — forked from lecho/shadow.xml
Android shadow drawable xml.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"