Skip to content

Instantly share code, notes, and snippets.

View brendanw's full-sized avatar

Brendan brendanw

View GitHub Profile
package com.simplelisp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class SimpleLisp {
//(+ 3 (+ 3 2) (+ 4 5))
package com.cinemagraph;
import android.graphics.Matrix;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
@brendanw
brendanw / gist:e79d0ad972fb715e96c5
Created February 19, 2016 23:32
Detect when a ViewPager smoothScroll initialized by viewPager.setCurrentItem() has completed
import android.support.v4.view.ViewPager;
import android.view.ViewTreeObserver;
/**
* A class that can be added to a viewTreeObserver for ViewPager's in order to determine
* when a smoothScroll transition is completed by viewPager.setCurrentItem();
*/
public class PagerScrollListener implements ViewTreeObserver.OnScrollChangedListener {
private int scrollX;
private int totalChange = 0;
@brendanw
brendanw / gist:1f3c60a1e886a365c084
Created February 19, 2016 23:32
Detect when a ViewPager smoothScroll initialized by viewPager.setCurrentItem() has completed
import android.support.v4.view.ViewPager;
import android.view.ViewTreeObserver;
/**
* A class that can be added to a viewTreeObserver for ViewPager's in order to determine
* when a smoothScroll transition is completed by viewPager.setCurrentItem();
*/
public class PagerScrollListener implements ViewTreeObserver.OnScrollChangedListener {
private int scrollX;
private int totalChange = 0;
@brendanw
brendanw / gist:512f4befbb8cb664cf25285d87960720
Created February 3, 2017 01:20
Pared Down NestedScrollingParent and NestedScrollingChild
public interface NestedScrollingParent {
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes);
public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes);
public void onStopNestedScroll(View target);
public void onNestedScroll(View target, int dxConsumed, int dyConsumed,
int dxUnconsumed, int dyUnconsumed);
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed);
public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed);
public boolean onNestedPreFling(View target, float velocityX, float velocityY);
public int getNestedScrollAxes();
/**
* Need to return true here to continue hearing updates from the child
* for the duration of the scroll
*/
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
return true;
}
@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
@brendanw
brendanw / gist:f71557a77d2a86d87a5286bd0465e8b4
Last active February 3, 2017 18:38
RecyclerView Scroll Tracking using a Sentinel View
headerTrackScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
float sentinelYPos = adapter.getSentinelViewYPos();
if (sentinelYPos >= Utility.getScreenHeight(getContext()) || !areAuxiliaryTouchEventsEnabled) {
return;
}
float topOfListScrollY = sentinelYPos - headerHeight;
@brendanw
brendanw / StickyRxBus.java
Created August 17, 2016 06:06
RxBus with Sticky Events
/**
* An RxJava-backed EventBus class that can support sending and receiving multiple event types.
*
* Based on https://gist.github.com/benjchristensen/04eef9ca0851f3a5d7bf
*/
public class EventBus<T> {
private static EventBus<Object> INSTANCE;
private List<T> events;
@brendanw
brendanw / RangeBar.kt
Created April 23, 2019 21:34
RangeBar with Two Thumbs Kotlin Implementation
/**
* RangeBar is a bar that allows a user to define a range of values by moving two thumbs.
*
* Normalized value refers to a number as it exists in a range from [min, max]
* Px value refers to a number as it exists in a range from [startX, endX]
*/
class RangeBar : View {
companion object {
// The diameter of the circle
@brendanw
brendanw / IPlainClient.kt
Last active April 21, 2020 00:19
A hacky means for making api calls with coroutines-native-mt while we wait for ktor bugs to get fixed.
/**
* An http client to use until ktor works with multithreaded coroutines.
* This goes in a common module that ios and android clients depend on.
* We just return a string as shared components can use kotlinx serialization
* thereafter to handle response parsing.
*/
interface IPlainClient {
fun get(
baseUrl: String,
path: String,