Skip to content

Instantly share code, notes, and snippets.

View yoonseopshin's full-sized avatar
🏠
Working from home

Yoonseop Shin yoonseopshin

🏠
Working from home
View GitHub Profile
@yoonseopshin
yoonseopshin / color-blender-rgba.kt
Last active July 16, 2022 07:27
Color blender(RGBA)
data class RGBA(var red: Long = 0, var green: Long = 0, var blue: Long = 0, var alpha: Double = 0.0)
fun main() {
// rgba-order
val base = RGBA(124, 77, 255, 0.06)
val added = RGBA(255, 255, 255, 0.06)
val mix = RGBA()
// alpha
mix.alpha = 1 - (1 - added.alpha) * (1 - base.alpha)
@yoonseopshin
yoonseopshin / README.md
Created July 16, 2022 06:48 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store

@yoonseopshin
yoonseopshin / AndroidRsaCipherHelper.kt
Created March 17, 2022 05:32 — forked from FrancescoJo/AndroidRsaCipherHelper.kt
Android RSA cipher helper with system generated key. No more static final String key in our class - an approach which is very vulnerable to reverse engineering attack.
import android.os.Build
import android.security.KeyPairGeneratorSpec
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.Base64
import timber.log.Timber
import java.math.BigInteger
import java.security.GeneralSecurityException
import java.security.KeyPairGenerator
import java.security.KeyStore
@yoonseopshin
yoonseopshin / SecureSharedPreferences.kt
Created March 17, 2022 05:32 — forked from FrancescoJo/SecureSharedPreferences.kt
A SharedPreferences wrapper implementation with encryption/decryption, using CipherHelper implementation.
import android.content.SharedPreferences
/**
* A [android.content.SharedPreferences] wrapper that helps easy reading/writing values.
*
* @author Francesco Jo([email protected])
* @since 22 - Mar - 2018
*/
class SecureSharedPreferences(private val sharedPref: SharedPreferences) {
fun contains(key: String) = sharedPref.contains(key)
@yoonseopshin
yoonseopshin / WorkManagerDataExtension.kt
Created March 15, 2022 12:29
WorkManager serialization extension (Parcelable, Serializable)
package com.andevapps.ontv.extension
import android.os.Parcel
import android.os.Parcelable
import androidx.work.Data
import java.io.*
fun Data.Builder.putParcelable(key: String, parcelable: Parcelable): Data.Builder {
val parcel = Parcel.obtain()
try {
@yoonseopshin
yoonseopshin / ItemDecorationWithoutLastItem.kt
Created February 13, 2022 10:10
Add RecyclerView divider without last item
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import androidx.recyclerview.widget.RecyclerView
class ItemDecorationWithoutLastItem(private val divider: Drawable) : RecyclerView.ItemDecoration() {
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
super.onDrawOver(c, parent, state)
val left = parent.paddingLeft
val right = parent.width - parent.paddingRight
@yoonseopshin
yoonseopshin / FlowExt.kt
Created December 19, 2021 11:54
Lifecycle flow extension
fun <T> ComponentActivity.collectLatestLifecycleFlow(flow: Flow<T>, collect: suspend (T) -> Unit) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
flow.collectLatest(collect)
}
}
}
@yoonseopshin
yoonseopshin / OnThrottleClickListener.kt
Last active December 19, 2021 10:17
Android throttle click extension implementation (for single click)
class OnThrottleClickListener(
private val dispatcher: CoroutineDispatcher,
private val onClickListener: View.OnClickListener,
private val interval: Long,
) : View.OnClickListener {
private var isClickable = true
override fun onClick(view: View) {
if (isClickable) {
@yoonseopshin
yoonseopshin / Preference.kt
Created October 14, 2021 06:32
Preference Usage
import android.content.SharedPreferences
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.properties.ReadWriteProperty
@yoonseopshin
yoonseopshin / .gitmessage
Last active June 29, 2021 10:25
Git commit template
# <type>: <subject>
##### Subject 50 characters ################# -> |
# Body Message
######## Body 72 characters ####################################### -> |
# Issue Tracker Number or URL
# --- COMMIT END ---