Skip to content

Instantly share code, notes, and snippets.

objcode / ConcurrencyHelpers.kt
Last active Sep 22, 2021
Helpers to control concurrency for one shot requests using Kotlin coroutines.
View ConcurrencyHelpers.kt
import kotlinx.coroutines.CoroutineStart.LAZY
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
import java.util.concurrent.atomic.AtomicReference
import kotlin.DeprecationLevel.ERROR
View CrossesSquaresView.kt
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.annotation.ColorInt
import java.lang.Math.pow
import kotlin.math.cos
egemenhamutcu / BitmapExtension.kt
Created Mar 20, 2019
Masking bitmap with given destinationImage. Useful for masking ImageViews
View BitmapExtension.kt
fun Bitmap.maskWith(destinationImage: Bitmap, mode: PorterDuff.Mode): Bitmap {
val result = this.copy(Bitmap.Config.ARGB_8888, true)
val canvas = Canvas(result)
val paint = Paint()
canvas.drawBitmap(destinationImage, 0f, 0f, paint)
paint.xfermode = PorterDuffXfermode(mode)
canvas.drawBitmap(this, 0f, 0f, paint)
alexjlockwood / WaveSquare.kt
Created Mar 11, 2019
Kotlin implementation of a wave square animation, inspired by
View WaveSquare.kt
import android.content.Context
import android.util.AttributeSet
import android.view.View
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
View BaseDao.kt
* Copyright (C) 2017 The Android Open Source Project
* 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
* Unless required by applicable law or agreed to in writing, software
yanngx / FragmentArgumentDelegate.kt
Last active Feb 20, 2021
Fragment arguments without hassle !
View FragmentArgumentDelegate.kt
package be.brol
import android.os.Binder
import android.os.Bundle
* Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate
* Just write the property in newInstance and read it like any other property after the fragment has been created
muratcanbur /
Last active Jul 24, 2017
DolapSubscriber is a base Rx Subscriber class that handles all API requests.
public abstract class DolapSubscriber<T> extends Subscriber<T> {
private MVPView mvpView;
public DolapSubscriber(MVPView mvpView) {
this.mvpView = mvpView;
public void onCompleted() {
burgalon /
Last active Sep 1, 2021
Implementing OAuth2 with AccountManager, Retrofit and Dagger
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
patrickcousins /
Last active Sep 21, 2016
VerticalSmoothScrollView from Added vertical computation. NOTE: to use with API 8 or lower you need to find a compat Scroller, ViewPagerIndicator is a good source to look for a compat Scroller.
public class VerticalSmoothScrollView extends ScrollView
private OverScroller myScroller; //TODO implement our own scroller, Scroller and OverScroller can usually be swapped
public VerticalSmoothScrollView( Context context, AttributeSet attrs, int defStyle )
super( context, attrs, defStyle );