Skip to content

Instantly share code, notes, and snippets.

@kingargyle
kingargyle / PlainAndroidRunner.kt
Created February 19, 2019 13:56
A bare bones RobolectrictTestRunner that only starts up a sandbox and does not attempt to load any resources. This is good for non-ui tests where you still need portions of the android library but not any of the resources. Reduces robolectric startup time to 2 seconds. This comes from the following google group post: https://groups.google.com/fo…
package us.nineworlds.serenity.testrunner
import org.junit.runners.model.FrameworkMethod
import org.junit.runners.model.InitializationError
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.internal.SandboxTestRunner
import org.robolectric.internal.bytecode.Sandbox
import java.lang.reflect.Method
@kingargyle
kingargyle / MediaCodecInfoUtil.kt
Created January 13, 2019 23:06
Detect Media Codecs on Device
package us.nineworlds.serenity.common.android.mediacodec
import android.media.MediaCodecList
import android.util.Log
class MediaCodecInfoUtil {
val supportedContainers = hashMapOf<String, Boolean>("video/mkv" to true, "video/mp4" to true, "video/avi" to false, "video/webm" to true, "video/ogg" to true, "video/mv4" to true)
/**
@kingargyle
kingargyle / BindingAdapter.java
Created November 29, 2018 21:16 — forked from JakeWharton/BindingAdapter.java
An adapter base class that uses a new/bind pattern for its views.
// Apache 2.0 licensed.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/** An implementation of {@link BaseAdapter} which uses the new/bind pattern for its views. */
public abstract class BindableAdapter<T> extends BaseAdapter {
@kingargyle
kingargyle / AnimatingDialogFragment.kt
Last active November 18, 2018 03:26
A DialogFragment that support Animations useful for TV development
/**
* Dialog Fragment with hide animations
*/
class AnimatingDialogFragment : DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.TvTheme_Dialog)
}
@kingargyle
kingargyle / FocusableLinearLayoutManager.kt
Created October 31, 2018 01:48
Focusable Linear Smooth Scrolling for use with Android TV and Recycler View
/**
* The MIT License (MIT)
* Copyright (c) 2018 David Carver
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@kingargyle
kingargyle / AbstractSupportFragmentAssert
Created September 7, 2018 18:44
DialogSupportFragment Assertions
package com.abercrombie.abercrombie.assertions;
import android.annotation.TargetApi;
import android.support.v4.app.Fragment;
import org.assertj.core.api.AbstractAssert;
import static android.os.Build.VERSION_CODES.HONEYCOMB;
import static android.os.Build.VERSION_CODES.HONEYCOMB_MR2;
import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
import static org.assertj.core.api.Assertions.assertThat;
@kingargyle
kingargyle / proguard.pro
Created November 30, 2017 19:22
Toothpick Reflection Free Proguard Rules
# Note that if we could use kapt to generate registries, possible to get rid of this
-keepattributes Annotation
# Do not obfuscate classes with Injected Constructors
-keepclasseswithmembernames class * {
@javax.inject.Inject (...);
}
# Do not obfuscate classes with Injected Fields
-keepclasseswithmembernames class * {
@javax.inject.Inject ;
}
@kingargyle
kingargyle / SampleRecommendationContentProvider
Created November 15, 2014 21:39
RecomendationCardView ContentProvider Example
/**
* The MIT License (MIT)
* Copyright (c) 2014 David Carver
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@kingargyle
kingargyle / init.gradle
Created March 10, 2016 17:15
Add Nexus Mirrors to gradle builds with Init Script
// Replace the location of the nexus repository with your specific location.
// To enable this: gradlew build -I init.gradle
// This will now have gradle use the mirrors first and jcenter and other repositories second if it can't find the artifacts.
// Make sure your mirror Jcenter in your nexus repository.
allprojects{
buildscript{
repositories{
maven{ url 'http://localhost:8081/nexus/content/groups/public' }
}
@kingargyle
kingargyle / git-completion.bash
Created February 7, 2018 15:39 — forked from tomykaira/git-completion.bash
Show completion candidates for git-add, git-checkout --, and git-reset HEAD --
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#