Skip to content

Instantly share code, notes, and snippets.

package com.keyboardr.testing
import com.google.common.truth.*
import com.google.common.truth.Truth.assertWithMessage
import com.google.common.truth.Truth.assert_
import java.math.BigDecimal
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
package com.keyboardr.bluejay.audio
import com.keyboardr.bluejay.util.toFraction
import java.nio.ByteBuffer
import kotlin.math.*
class LoudnessMeasurer(private val channelCount: Int, sampleRate: Float, totalFrames: Int) {
private class LoudnessMeasurerChannel(var bufferFrames: Int,
/** How many frames are needed for a gating block. Will correspond to 400ms
package com.keyboardr.bluejay.ui.playlist
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.media.MediaCodec
import android.media.MediaExtractor
import android.media.MediaFormat
import android.util.AttributeSet
@keyboardr
keyboardr / FirebaseLiveData.java
Created November 19, 2017 10:41
A LiveData sourced from Firebase Realtime Database
import android.arch.lifecycle.LiveData;
import android.support.annotation.NonNull;
import android.util.Log;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.GenericTypeIndicator;
import com.google.firebase.database.ValueEventListener;
@keyboardr
keyboardr / MusicKey.java
Last active October 15, 2017 11:47
A enum to parse and represent a music key
package com.keyboardr.bluejay.model;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
@keyboardr
keyboardr / HeadlessFragmentFactory.java
Created December 8, 2016 01:54
Demonstration of why the HeadlessFragment gist can't be done as an abstract Factory class
/**
* What you'd think an abstract factory would look like. Unfortunately, this class won't compile.
*/
public abstract class HeadlessFragmentFactory<F extends Fragment & ParentedFragment<F, ? extends P>, P> {
protected abstract F newInstance();
/* There will be a compiler warning on P. When joining types, only the first type is allowed to
be a class. All others MUST be interfaces. In this situation, there is no way for the compiler
to know that P will be an interface. If P is removed, there is no longer a compile-time check
@keyboardr
keyboardr / CursorReaderExample.java
Created November 15, 2016 23:46
Cursor example
import android.support.annotation.WorkerThread;
import android.support.annotation.Nullable;
import android.database.Cursor;
public class CursorReaderExample {
// Example columns, would likely be in a different file (e.g. a contract class).
private static String COLUMN_FOO = "foo";
private static String COLUMN_BAR = "bar";
@keyboardr
keyboardr / gist:572a5eae9f57be286c24
Created July 7, 2015 21:59
Centered circular reveal animator
@TargetApi(VERSION_CODES.LOLLIPOP)
private Animator createCenteredReveal(View view) {
// Could optimize by reusing a temporary Rect instead of allocating a new one
Rect bounds = new Rect();
view.getDrawingRect(bounds);
int centerX = bounds.centerX();
int centerY = bounds.centerY();
int finalRadius = Math.max(bounds.width(), bounds.height());
return ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0f, finalRadius);
}
@keyboardr
keyboardr / HeadlessFragment.java
Last active December 31, 2021 01:05
A file template for creating a headless Fragment. The attach() methods add the fragment to the parent if it doesn't already exist and returns the attached fragment. The methods ensure that the parent implements the parent interface. If needed, parameters may be added to the attach() methods to supply fragment arguments.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
#parse("File Header.java")
public class ${NAME} extends Fragment {
private static final String FRAG_TAG = ${NAME}.class.getCanonicalName();
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.util.Log;
import com.squareup.picasso.Picasso;