Skip to content

Instantly share code, notes, and snippets.

@objcode
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.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import androidx.annotation.ColorInt
import java.lang.Math.pow
import kotlin.math.cos
@egemenhamutcu
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
alexjlockwood / WaveSquare.kt
Created Mar 11, 2019
Kotlin implementation of a wave square animation, inspired by https://twitter.com/beesandbombs/status/1101169015299420163
View WaveSquare.kt
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@yanngx
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
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
/**
* 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
muratcanbur / DolapSubscriber.java
Last active Jul 24, 2017
DolapSubscriber is a base Rx Subscriber class that handles all API requests.
View DolapSubscriber.java
public abstract class DolapSubscriber<T> extends Subscriber<T> {
private MVPView mvpView;
public DolapSubscriber(MVPView mvpView) {
this.mvpView = mvpView;
}
@Override
public void onCompleted() {
@burgalon
burgalon / AccountAuthenticator.java
Last active Sep 1, 2021
Implementing OAuth2 with AccountManager, Retrofit and Dagger
View AccountAuthenticator.java
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);
@patrickcousins
patrickcousins / VerticalSmoothScrollView.java
Last active Sep 21, 2016
VerticalSmoothScrollView from http://stackoverflow.com/questions/5193678/android-horizontalscrollview-smoothscroll-animation-time/13639106 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.
View VerticalSmoothScrollView.java
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 );
init();
}