Skip to content

Instantly share code, notes, and snippets.

View atoennis's full-sized avatar

Adam Toennis atoennis

View GitHub Profile
@patrickhammond
patrickhammond / MainActivity.kt
Created January 9, 2017 02:59
Raspberry Pi 3 running Android Things driving an Arduino Uno to control an RGB LED
package com.madebyatomicrobot.things
import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import com.google.android.things.pio.PeripheralManagerService
import com.google.android.things.pio.UartDevice
@patrickhammond
patrickhammond / DrawableHelper.java
Created October 18, 2015 00:24
Drawable helper
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
public class DrawableHelper {
public static Drawable setupTintedIcon(Context context, @DrawableRes int iconDrawableResId, @ColorRes int iconColorResId) {
Drawable icon = ContextCompat.getDrawable(context, iconDrawableResId);
@atoennis
atoennis / SomeFragment.java
Last active April 23, 2020 06:30
Solution to having nested scrolling within Android. In this scenario a multiline EditText resides within a root level ScrollView. In order to have scroll momentum, the EditText itself doesn't scroll but it is wrapped within a ScrollView.
// When the EditText is touched, disable touches on it's ScrollView's parents.
// Once the user lifts up their finger, enable touches on on the ScrollView's parents once again.
@OnTouch(R.id.edit_text)
boolean handleNoteFieldTouch(View v, MotionEvent event) {
v.getParent().getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
v.getParent().getParent().requestDisallowInterceptTouchEvent(false);
break;
@patrickhammond
patrickhammond / 1_models.java
Last active August 29, 2015 14:26
Sample of how we might make variant types suck less with Java. See: https://en.wikipedia.org/wiki/Tagged_union for part of the CS theory.
// ------------------------------------------------------------------------
// App code: These classes that describe the state of executing a query
// that we want to consume as a stream of events.
public class Loading {
}
public class Results<T> {
final List<T> results;
@swankjesse
swankjesse / RetrofitCachingExample.java
Created June 29, 2013 03:03
Demonstrate HTTP caching with OkHttp and Retrofit.
/*
* Copyright (C) 2013 Square, Inc.
*
* 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