Skip to content

Instantly share code, notes, and snippets.

@TalbotGooday
TalbotGooday / ProgressDrawable.kt
Last active February 24, 2022 01:25
Android iOS-like progress
import android.content.Context
import android.graphics.*
import android.graphics.drawable.Drawable
import android.os.Handler
import android.os.Looper
import android.util.DisplayMetrics
import androidx.annotation.ColorInt
import kotlin.math.PI
import kotlin.math.cos
@TalbotGooday
TalbotGooday / MediaView.kt
Created October 29, 2021 07:03
MediaView
package com.comunitee.ui.widgets.media_view
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
@TalbotGooday
TalbotGooday / simple_emoji_convert.json
Created October 15, 2019 21:44
Simple Emoji Convert Data
[
{
"emoji": "☺️️",
"aliases": [
":‑)",
":)",
":-]",
":]",
":-3",
":3",
@TalbotGooday
TalbotGooday / PlaceholderController.kt
Last active May 11, 2019 10:22
Draw avatar plcaholder and save to cache dir. Need no permissions
fun drawTextToBitmapOrGetCache(context: Context, text: String, @ColorRes textColor: Int, @ColorRes backgroundColor: Int, textSize: Float = 33f): Bitmap? {
val name = "${text}_image"
val file = File(context.cacheDir, name)
Log.d("CACHE_IMAGE", "${file.exists()} $name ${file.absolutePath}")
return if (file.exists()) {
getNamePlaceholderFromCache(file)
} else {
val namePlaceholderBitmap = drawTextToBitmap(context, text, textColor, backgroundColor, textSize)
@TalbotGooday
TalbotGooday / RecyclerView.attachScrollToFade
Created April 29, 2019 10:46
Allows you to smoothly hide the View
fun RecyclerView.attachScrollToFade(view: View? = null) {
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val linearLayoutManager = layoutManager as LinearLayoutManager
if (linearLayoutManager.findFirstVisibleItemPosition() == 0) {
val firstVisible = linearLayoutManager.findViewByPosition(linearLayoutManager.findFirstVisibleItemPosition())
if (firstVisible != null) {
val distanceTop = firstVisible.top