Skip to content

Instantly share code, notes, and snippets.

View MinceMan's full-sized avatar

Chris Pierick MinceMan

  • Boulder, CO, USA
View GitHub Profile
@MinceMan
MinceMan / BackgroundAwareness.java
Last active January 4, 2016 09:49
This shows how to let your app know that it had been sent to the background. The only thing it doesn't detect is if you turn of the screen and unlock directly to the app. It will detect if you unlock to another app. It can also handle rotation just fine.
public class App extends Application {
// Bunches of application code
public boolean isAppInForeground() {
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses != null) {
final String packageName = getPackageName();
for (RunningAppProcessInfo appProcess : appProcesses) {
@MinceMan
MinceMan / AnimatorChainer.java
Last active August 29, 2015 14:06
AnimatorChainer with Examples, Android
package com.twotoasters.util.anim;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.view.ViewPropertyAnimator;
import java.util.ArrayList;
/**
* A class which makes it really easy to implement sequencal animations with ViewPropertyAnimators.
@MinceMan
MinceMan / JsonWrapper.java
Last active April 22, 2016 13:59
How to serialize and de-serialize an unknown class with GSON.
package com.example;
@JsonAdapter(JsonWrapperAdapter.class)
public class JsonWrapper {
private static final String classNameKey = "className";
private static final String wrappedObjectKey = "wrappedObject";
private final String className;
private final Object wrappedObject;
@MinceMan
MinceMan / CheckUriPermission.java
Last active August 29, 2015 14:17
This will tell you if the give package currently has the URI permissions that you granted. It will fail it the app has been killed or uninstalled. This may not work for persistent permissions if the app is not running.
public class App extends Application {
// Bunches of application code
/**
* This will tell you if the give package currently has the URI permissions that you granted.
* It will fail it the app has been killed or uninstalled.
* This may not work for persistent permissions if the app is not running.
* @return PackageManager.PERMISSION_DENIED if it does not have permission and
* PackageManager.PERMISSION_GRANTED if it does have permission.
@MinceMan
MinceMan / Example
Created March 23, 2015 21:13
App Engine Endpoints Client and OkHttp. This has been shamelessly stolen and updated to work with newer versions of OkHttp
private static HttpTransport httpTransport;
private static OkHttpClient client;
private static OkHttpClient getClient() {
if (client == null) {
client = new OkHttpClient();
}
return client;
}
@MinceMan
MinceMan / build.gradle
Created June 10, 2015 20:53
Change output file name for Android with build.gradle
apply plugin: 'com.android.library'
/** This closure will rename your output file with your outputName, versionName and git commit. */
android.metaClass.renameVariants = { String moduleName, String outputName ->
def isApplication = binding.variables.containsKey('applicationVariants')
def variants = isApplication ? applicationVariants : libraryVariants
def gitCommit = "git rev-parse --short HEAD".execute().text.trim()
def ext = isApplication ? '.apk' : '.aar'
variants.all { -> outputs.each {
@MinceMan
MinceMan / CenteringRecyclerView.java
Last active April 22, 2016 13:51
Easy way to make scrollable views(or any views) center on in a tablet and have them scrollable by thumbs.
package com.example;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import com.exmaple.CenteringWidgetDelegate;
public class CenteringRecyclerView extends RecyclerView {
private CenteringWidgetDelegate centeringDelegate = new CenteringWidgetDelegate();
@MinceMan
MinceMan / TintingColorFilter.java
Last active January 13, 2017 00:11
TintingColorFilter
public final class TintingColorFilter {
private TintingColorFilter() { }
/**
* @param color, The rgb color you would like to tint with.
* @param alpha, How strong you would like the color to tint. 0 is none, 1 is completely.
*/
public static ColorFilter createFilter(@ColorInt int color, float alpha) {
int red = Color.red(color);
int green = Color.green(color);
package com.bfreq.dice.widget
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import com.bfreq.dice.R
import com.bfreq.dice.util.forEachChild
import com.bfreq.dice.util.forEachChildIndexed